Hetong.vue 3.9 KB

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