HetongInfo.vue 4.7 KB

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