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