hetong.vue 3.9 KB

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