Hetong.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="phone-hetong-page">
  3. <view class="phone-navBar-box">
  4. <view @click="goUpPage" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">合同</text>
  6. <uni-icons class="nav-bar-right-icon bar-ml10" type="list" @click="handleGoLishi" size="30"></uni-icons>
  7. </view>
  8. <template v-if="tId">
  9. <view class="pdf-box">
  10. <image v-for="item in imgList" mode="aspectFit" :src="`data:image/png;base64,${item}`" @click="previewBase64Image(`data:image/png;base64,${item}`)"></image>
  11. </view>
  12. </template>
  13. <template v-else>
  14. <view class="no-hetong-box">暂无合同</view>
  15. </template>
  16. <view class="hetong-tip-box" v-if="tId && info.status == 0">
  17. 请务必仔细阅读上述内容,确认已完全理解所有条款后,点击【我已阅读】按钮完成签字确认。
  18. </view>
  19. <button v-if="tId && info.status == 0" type="default" class="phone-green-btn ht-btn"
  20. @click="handleQianming">我已阅读</button>
  21. <uni-popup ref="popupRef" type="bottom" background-color="#fff" :is-mask-click="false" :mask-click="false">
  22. <view class="ht-qm-popup">
  23. <view class="icon-title-navBar-box">
  24. <view @click="goback2" class="nav-bar-icon"></view>
  25. <text class="nav-bar-title">签名</text>
  26. </view>
  27. <writeSign @getBase64="getBase64"></writeSign>
  28. </view>
  29. </uni-popup>
  30. <!-- 加载提示 -->
  31. <view class="loading-overlay" v-if="isLoading">
  32. <view class="loading-spinner"></view>
  33. <text class="loading-text">加载中...</text>
  34. </view>
  35. </view>
  36. </template>
  37. <script setup>
  38. import {
  39. ref
  40. } from "vue";
  41. import * as httpApi from "@/api/hetong.js"
  42. import {
  43. onLoad
  44. } from "@dcloudio/uni-app"
  45. import writeSign from "@/components/writeSign/index.vue"
  46. import {throttleAdvanced} from "@/utils/common.js"
  47. import { base64ToPath } from 'image-tools';
  48. const tId = ref(null)
  49. const info = ref({})
  50. const popupRef = ref(null)
  51. const imgList = ref([])
  52. const isLoading = ref(true)
  53. const timer1 = ref(null)
  54. function goUpPage() {
  55. uni.navigateBack()
  56. clearTimeout(timer1.value);
  57. timer1.value = null;
  58. }
  59. onLoad(({id}) => {
  60. tId.value = id;
  61. init()
  62. })
  63. function init() {
  64. if (!tId.value) {
  65. uni.showToast({
  66. title: '数据异常,请确认路径是否完整'
  67. })
  68. return;
  69. }
  70. httpApi.getHetongInfo({id:tId.value}).then(res => {
  71. info.value = res.data;
  72. imgList.value = res.data.base64List;
  73. }).finally(() => {
  74. isLoading.value = false;
  75. })
  76. }
  77. async function previewBase64Image(base64Data) {
  78. try {
  79. // 关键步骤:将 Base64 字符串转换为本地临时路径
  80. // 此处以使用 image-tools 的 base64ToPath 为例
  81. const localPath = await base64ToPath(base64Data);
  82. // 调用 UniApp 的图片预览 API
  83. uni.previewImage({
  84. urls: [localPath], // 注意:urls 参数需要是数组,即使只预览一张图
  85. current: 0, // 当前显示图片在 urls 数组中的索引
  86. });
  87. } catch (error) {
  88. // 如果出现错误(如转换失败),隐藏加载提示并告知用户
  89. console.error('预览失败:', error);
  90. uni.showToast({
  91. title: '预览失败',
  92. icon: 'none'
  93. });
  94. }
  95. }
  96. function handleGoLishi() {
  97. uni.redirectTo({
  98. url: '/pages/admin/Hetong/HetongList'
  99. })
  100. }
  101. function handleQianming() {
  102. popupRef.value.open()
  103. }
  104. const handleQM = throttleAdvanced((img) => {
  105. uni.showToast({
  106. title: "签名提交中...",
  107. mask: true,
  108. })
  109. httpApi.getHetongQianming({
  110. id: info.value.id,
  111. yifangBase64: img.replace(/^data:image\/\w+;base64,/, ''), // 当前接口,只有唯一yifangBase64 + id
  112. }).then(res => {
  113. if (res.data) {
  114. uni.showToast({
  115. title: "签名成功",
  116. duration: 2000,
  117. mask: true,
  118. success() {
  119. timer1.value = setTimeout(() => uni.navigateBack(),2000)
  120. }
  121. })
  122. }
  123. })
  124. })
  125. function getBase64(img) {
  126. if (!img) {
  127. uni.showToast({
  128. title: '签名异常'
  129. })
  130. return;
  131. }
  132. handleQM(img)
  133. }
  134. function goback2() {
  135. popupRef.value.close()
  136. }
  137. </script>
  138. <style>
  139. </style>