HetongInfo.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view class="phone-hetong-page">
  3. <!-- 导航区域 -->
  4. <customNavbarVue title="合同" :show-back-btn="true" @back="handleGoLishi"></customNavbarVue>
  5. <template v-if="tId">
  6. <view class="pdf-box">
  7. <img v-for="item in imgList" mode="aspectFit" :src="`data:image/png;base64,${item}`"
  8. @click="previewBase64Image(`data:image/png;base64,${item}`)" class="pdf-img" />
  9. </view>
  10. <!-- 加载提示 -->
  11. <view class="pdf-tip-box" v-if="isLoading">
  12. <view class="tip-img-box">
  13. <view :style="{ backgroundImage: 'url(' + imgsArr.loadingIcon + ')' }" class="tip-icon"/>
  14. <view class="tip-text">加载中...</view>
  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" class="phone-green-btn ht-btn"
  22. type="default">我已阅读</button>
  23. <uni-popup ref="popupRef" type="top" background-color="#fff" :is-mask-click="false" :mask-click="false">
  24. <view class="ht-qm-popup">
  25. <customNavbarVue title="签名" :show-back-btn="true" @back="goback2"></customNavbarVue>
  26. <writeSign @getBase64="getBase64"></writeSign>
  27. </view>
  28. </uni-popup>
  29. </view>
  30. </template>
  31. <script setup>
  32. import {
  33. ref,reactive
  34. } from "vue";
  35. import * as httpApi from "@/api/khHetong.js"
  36. import cacheManager from '@/utils/cacheManager.js'
  37. import customNavbarVue from "@/components/custom-navbar/custom-navbar.vue";
  38. import {
  39. onLoad
  40. } from "@dcloudio/uni-app"
  41. import writeSign from "@/components/writeSign/index.vue"
  42. import {
  43. throttleAdvanced
  44. } from "@/utils/common.js"
  45. import {
  46. base64ToPath
  47. } from "image-tools";
  48. const tId = ref(null)
  49. const info = ref({})
  50. const show = ref(false)
  51. const popupRef = ref(null)
  52. const imgList = ref([])
  53. const isLoading = ref(true)
  54. const timer1 = ref(null)
  55. const imgsArr = reactive({
  56. loadingIcon: '',
  57. })
  58. onLoad((options) => {
  59. tId.value = options.id;
  60. const auth = cacheManager.get('auth');
  61. imgsArr.loadingIcon = cacheManager.get('projectImg').loading_icon;
  62. init();
  63. })
  64. function handleQianming() {
  65. popupRef.value.open()
  66. }
  67. function init() {
  68. if (!tId.value) {
  69. uni.showToast({
  70. title: '请确认地址参数完整性'
  71. })
  72. return;
  73. }
  74. httpApi.getHetongPreview({
  75. id: tId.value
  76. }).then(res => {
  77. info.value = res.data;
  78. imgList.value = res.data.base64List;
  79. }).finally(() => {
  80. isLoading.value = false;
  81. })
  82. }
  83. async function previewBase64Image(base64Data) {
  84. try {
  85. // 关键步骤:将 Base64 字符串转换为本地临时路径
  86. // 此处以使用 image-tools 的 base64ToPath 为例
  87. const localPath = await base64ToPath(base64Data);
  88. // 调用 UniApp 的图片预览 API
  89. uni.previewImage({
  90. urls: [localPath], // 注意:urls 参数需要是数组,即使只预览一张图
  91. current: 0, // 当前显示图片在 urls 数组中的索引
  92. });
  93. } catch (error) {
  94. // 如果出现错误(如转换失败),隐藏加载提示并告知用户
  95. console.error('预览失败:', error);
  96. uni.showToast({
  97. title: '预览失败',
  98. icon: 'none'
  99. });
  100. }
  101. }
  102. function goUpPage() {
  103. uni.navigateBack()
  104. clearTimeout(timer1.value);
  105. timer1.value = null;
  106. }
  107. const handleQM = throttleAdvanced((img) => {
  108. uni.showToast({
  109. title: "签名提交中...",
  110. mask: true,
  111. })
  112. httpApi.getHetongQianming({
  113. id: tId.value,
  114. qianmingBase64: img.replace(/^data:image\/\w+;base64,/, '')
  115. }).then(res => {
  116. if (res.data) {
  117. uni.showToast({
  118. title: "签名成功",
  119. duration: 2000,
  120. mask: true,
  121. success() {
  122. timer1.value = setTimeout(() => goUpPage(), 2000)
  123. }
  124. })
  125. }
  126. })
  127. })
  128. function getBase64(img) {
  129. if (!img) {
  130. uni.showToast({
  131. title: '签名异常'
  132. })
  133. return;
  134. }
  135. handleQM(img)
  136. }
  137. function handleGoLishi() {
  138. uni.navigateBack()
  139. }
  140. function goback2() {
  141. popupRef.value.close()
  142. }
  143. </script>
  144. <style scoped>
  145. </style>