HetongInfo.vue 3.5 KB

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