HetongInfo.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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,index) in imgList" :key="index" 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" :style="{ top: `calc(42px + ${statusBarHeight}px );`}">
  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 v-if="showQianming" @getBase64="getBase64"></writeSign>
  27. </view>
  28. </uni-popup>
  29. </view>
  30. </template>
  31. <script setup>
  32. import {
  33. ref,reactive,onMounted,onUnmounted
  34. } from "vue";
  35. import * as httpApi from "@/api/jzHetong.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, toast
  44. } from "@/utils/common.js"
  45. import {
  46. base64ToPath
  47. } from "image-tools";
  48. const statusBarHeight = ref(0);
  49. const tId = ref(null)
  50. const info = ref({})
  51. const show = ref(false)
  52. const popupRef = ref(null)
  53. const showQianming = ref(false)
  54. const imgList = ref([])
  55. const isLoading = ref(true)
  56. const timer1 = ref(null)
  57. const imgsArr = reactive({
  58. loadingIcon: '',
  59. })
  60. const fromPage = ref('')
  61. const timer2 = ref(null);
  62. onMounted(() => {
  63. uni.getSystemInfo({
  64. success: (res) => {
  65. statusBarHeight.value = res.statusBarHeight;
  66. }
  67. });
  68. });
  69. onUnmounted(() => {
  70. clearTimeout(timer2.value);
  71. timer2.value = null;
  72. })
  73. onLoad((options) => {
  74. tId.value = options.id;
  75. fromPage.value = options.from;
  76. const auth = cacheManager.get('auth');
  77. imgsArr.loadingIcon = cacheManager.get('projectImg').loading_icon;
  78. init();
  79. })
  80. function handleQianming() {
  81. popupRef.value.open()
  82. setTimeout(() => {
  83. showQianming.value = true
  84. })
  85. }
  86. function init() {
  87. httpApi.getHetongPreview({
  88. id: tId.value
  89. }).then(res => {
  90. info.value = res.data;
  91. imgList.value = res.data.base64List;
  92. }).catch(err => {
  93. timer2.value = setTimeout(() => {
  94. handleGoLishi()
  95. },3000)
  96. }).finally(() => {
  97. isLoading.value = false;
  98. })
  99. }
  100. async function previewBase64Image(base64Data) {
  101. try {
  102. // 关键步骤:将 Base64 字符串转换为本地临时路径
  103. // 此处以使用 image-tools 的 base64ToPath 为例
  104. const localPath = await base64ToPath(base64Data);
  105. // 调用 UniApp 的图片预览 API
  106. uni.previewImage({
  107. urls: [localPath], // 注意:urls 参数需要是数组,即使只预览一张图
  108. current: 0, // 当前显示图片在 urls 数组中的索引
  109. });
  110. } catch (error) {
  111. // 如果出现错误(如转换失败),隐藏加载提示并告知用户
  112. console.error('预览失败:', error);
  113. uni.showToast({
  114. title: '预览失败',
  115. icon: 'none'
  116. });
  117. }
  118. }
  119. function goUpPage() {
  120. clearTimeout(timer1.value);
  121. timer1.value = null;
  122. handleGoLishi()
  123. }
  124. const handleQM = throttleAdvanced((img) => {
  125. uni.showToast({
  126. title: "签名提交中...",
  127. mask: true,
  128. })
  129. httpApi.getHetongQianming({
  130. id: tId.value,
  131. qianmingBase64: img.replace(/^data:image\/\w+;base64,/, '')
  132. }).then(res => {
  133. if (res.data) {
  134. uni.showToast({
  135. title: "签名成功",
  136. duration: 2000,
  137. mask: true,
  138. success() {
  139. timer1.value = setTimeout(() => goUpPage(), 2000)
  140. }
  141. })
  142. }
  143. })
  144. })
  145. function getBase64(img) {
  146. if (!img) {
  147. uni.showToast({
  148. title: '签名异常'
  149. })
  150. return;
  151. }
  152. handleQM(img)
  153. }
  154. function handleGoLishi() {
  155. if (fromPage.value == 'appcx') {
  156. uni.redirectTo({
  157. url: '/pages/client/ShouYe/shouye'
  158. })
  159. return;
  160. }
  161. uni.navigateBack()
  162. }
  163. function goback2() {
  164. popupRef.value.close()
  165. }
  166. </script>
  167. <style scoped>
  168. </style>