HetongInfo.vue 3.6 KB

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