HetongInfo.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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/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
  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. const fromPage = ref('')
  59. onLoad((options) => {
  60. tId.value = options.id;
  61. fromPage.value = options.from;
  62. const auth = cacheManager.get('auth');
  63. imgsArr.loadingIcon = cacheManager.get('projectImg').loading_icon;
  64. init();
  65. })
  66. function handleQianming() {
  67. popupRef.value.open()
  68. }
  69. function init() {
  70. httpApi.getHetongPreview({
  71. id: tId.value
  72. }).then(res => {
  73. info.value = res.data;
  74. imgList.value = res.data.base64List;
  75. }).finally(() => {
  76. isLoading.value = false;
  77. })
  78. }
  79. async function previewBase64Image(base64Data) {
  80. try {
  81. // 关键步骤:将 Base64 字符串转换为本地临时路径
  82. // 此处以使用 image-tools 的 base64ToPath 为例
  83. const localPath = await base64ToPath(base64Data);
  84. // 调用 UniApp 的图片预览 API
  85. uni.previewImage({
  86. urls: [localPath], // 注意:urls 参数需要是数组,即使只预览一张图
  87. current: 0, // 当前显示图片在 urls 数组中的索引
  88. });
  89. } catch (error) {
  90. // 如果出现错误(如转换失败),隐藏加载提示并告知用户
  91. console.error('预览失败:', error);
  92. uni.showToast({
  93. title: '预览失败',
  94. icon: 'none'
  95. });
  96. }
  97. }
  98. function goUpPage() {
  99. uni.navigateBack()
  100. clearTimeout(timer1.value);
  101. timer1.value = null;
  102. }
  103. const handleQM = throttleAdvanced((img) => {
  104. uni.showToast({
  105. title: "签名提交中...",
  106. mask: true,
  107. })
  108. httpApi.getHetongQianming({
  109. id: tId.value,
  110. qianmingBase64: img.replace(/^data:image\/\w+;base64,/, '')
  111. }).then(res => {
  112. if (res.data) {
  113. uni.showToast({
  114. title: "签名成功",
  115. duration: 2000,
  116. mask: true,
  117. success() {
  118. timer1.value = setTimeout(() => goUpPage(), 2000)
  119. }
  120. })
  121. }
  122. })
  123. })
  124. function getBase64(img) {
  125. if (!img) {
  126. uni.showToast({
  127. title: '签名异常'
  128. })
  129. return;
  130. }
  131. handleQM(img)
  132. }
  133. function handleGoLishi() {
  134. if (fromPage.value) {
  135. uni.redirectTo({
  136. url: '/pages/client/ShouYe/shouye'
  137. })
  138. return;
  139. }
  140. uni.navigateBack()
  141. }
  142. function goback2() {
  143. popupRef.value.close()
  144. }
  145. </script>
  146. <style scoped>
  147. </style>