HetongInfo.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. 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. httpApi.getHetongPreview({
  69. id: tId.value
  70. }).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 goUpPage() {
  97. uni.navigateBack()
  98. clearTimeout(timer1.value);
  99. timer1.value = null;
  100. }
  101. const handleQM = throttleAdvanced((img) => {
  102. uni.showToast({
  103. title: "签名提交中...",
  104. mask: true,
  105. })
  106. httpApi.getHetongQianming({
  107. id: tId.value,
  108. qianmingBase64: img.replace(/^data:image\/\w+;base64,/, '')
  109. }).then(res => {
  110. if (res.data) {
  111. uni.showToast({
  112. title: "签名成功",
  113. duration: 2000,
  114. mask: true,
  115. success() {
  116. timer1.value = setTimeout(() => goUpPage(), 2000)
  117. }
  118. })
  119. }
  120. })
  121. })
  122. function getBase64(img) {
  123. if (!img) {
  124. uni.showToast({
  125. title: '签名异常'
  126. })
  127. return;
  128. }
  129. handleQM(img)
  130. }
  131. function handleGoLishi() {
  132. uni.navigateBack()
  133. }
  134. function goback2() {
  135. popupRef.value.close()
  136. }
  137. </script>
  138. <style scoped>
  139. </style>