Hetong.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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"
  21. class="phone-green-btn ht-btn" 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 {throttleAdvanced} from "@/utils/common.js"
  43. import {base64ToPath} from "image-tools";
  44. const tId = ref(null)
  45. const info = ref({})
  46. const show = ref(false)
  47. const popupRef = ref(null)
  48. const imgList = ref([])
  49. const isLoading = ref(true)
  50. const timer1 = ref(null)
  51. onLoad((options) => {
  52. tId.value = options.id;
  53. init();
  54. })
  55. function handleQianming() {
  56. popupRef.value.open()
  57. }
  58. function init() {
  59. httpApi.getHetongInfo({id: tId.value}).then(res => {
  60. info.value = res.data;
  61. imgList.value = res.data.base64List;
  62. }).finally(() => {
  63. isLoading.value = false;
  64. })
  65. }
  66. async function previewBase64Image(base64Data) {
  67. try {
  68. // 关键步骤:将 Base64 字符串转换为本地临时路径
  69. // 此处以使用 image-tools 的 base64ToPath 为例
  70. const localPath = await base64ToPath(base64Data);
  71. // 调用 UniApp 的图片预览 API
  72. uni.previewImage({
  73. urls: [localPath], // 注意:urls 参数需要是数组,即使只预览一张图
  74. current: 0, // 当前显示图片在 urls 数组中的索引
  75. });
  76. } catch (error) {
  77. // 如果出现错误(如转换失败),隐藏加载提示并告知用户
  78. console.error('预览失败:', error);
  79. uni.showToast({
  80. title: '预览失败',
  81. icon: 'none'
  82. });
  83. }
  84. }
  85. function goUpPage() {
  86. uni.navigateBack()
  87. clearTimeout(timer1.value);
  88. timer1.value = null;
  89. }
  90. const handleQM = throttleAdvanced((img) => {
  91. uni.showToast({
  92. title: "签名提交中...",
  93. mask: true,
  94. })
  95. httpApi.getHetongQianming({
  96. id: tId.value,
  97. yifangBase64: img.replace(/^data:image\/\w+;base64,/,'')
  98. }).then(res => {
  99. if (res.data) {
  100. uni.showToast({
  101. title: "签名成功",
  102. duration: 2000,
  103. mask: true,
  104. success() {
  105. timer1.value = setTimeout(() => goUpPage(),2000)
  106. }
  107. })
  108. }
  109. })
  110. })
  111. function getBase64(img) {
  112. if (!img) {
  113. uni.showToast({
  114. title: '签名异常'
  115. })
  116. return;
  117. }
  118. console.log(22222)
  119. handleQM(img)
  120. }
  121. function goback2() {
  122. popupRef.value.close()
  123. }
  124. </script>
  125. <style scoped>
  126. </style>