HetongInfo.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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="tId && info.status == 0">
  21. 请务必仔细阅读上述内容,确认已完全理解所有条款后,点击【我已阅读】按钮完成签字确认。
  22. </view>
  23. <button @click="handleQianming" v-if="tId && info.status == 0" class="phone-green-btn ht-btn"
  24. type="default">我已阅读</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 {
  46. throttleAdvanced
  47. } from "@/utils/common.js"
  48. import {
  49. base64ToPath
  50. } from "image-tools";
  51. const tId = ref(null)
  52. const info = ref({})
  53. const show = ref(false)
  54. const popupRef = ref(null)
  55. const imgList = ref([])
  56. const isLoading = ref(true)
  57. const timer1 = ref(null)
  58. onLoad((options) => {
  59. tId.value = options.id;
  60. init();
  61. })
  62. function handleQianming() {
  63. popupRef.value.open()
  64. }
  65. function init() {
  66. httpApi.getHetongInfo({
  67. id: tId.value
  68. }).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 goUpPage() {
  95. uni.navigateBack()
  96. clearTimeout(timer1.value);
  97. timer1.value = null;
  98. }
  99. const handleQM = throttleAdvanced((img) => {
  100. uni.showToast({
  101. title: "签名提交中...",
  102. mask: true,
  103. })
  104. httpApi.getHetongQianming({
  105. id: tId.value,
  106. yifangBase64: img.replace(/^data:image\/\w+;base64,/, '')
  107. }).then(res => {
  108. if (res.data) {
  109. uni.showToast({
  110. title: "签名成功",
  111. duration: 2000,
  112. mask: true,
  113. success() {
  114. timer1.value = setTimeout(() => goUpPage(), 2000)
  115. }
  116. })
  117. }
  118. })
  119. })
  120. function getBase64(img) {
  121. if (!img) {
  122. uni.showToast({
  123. title: '签名异常'
  124. })
  125. return;
  126. }
  127. handleQM(img)
  128. }
  129. function handleGoLishi() {
  130. uni.redirectTo({
  131. url: '/pages/admin/Hetong/HetongList'
  132. })
  133. }
  134. function goback2() {
  135. popupRef.value.close()
  136. }
  137. </script>
  138. <style scoped>
  139. </style>