Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

277 linhas
6.7 KiB

  1. <template>
  2. <view class="page">
  3. <!-- 协议内容 -->
  4. <view class="section">
  5. <view class="doc-title">{{ docTitle }}</view>
  6. <rich-text class="doc-body" :nodes="docContent" />
  7. </view>
  8. <!-- 收入金额(仅income类型) -->
  9. <view class="section" v-if="signType === 'income'">
  10. <view class="form-label">请填写您的个人年可支配收入(元)</view>
  11. <view class="amount-wrap">
  12. <text class="amount-prefix">¥</text>
  13. <u-input v-model="incomeAmount" type="number" placeholder="请输入金额" border="none" maxlength="7" />
  14. </view>
  15. </view>
  16. <!-- 监护人信息(仅privacy_jhr类型) -->
  17. <view class="section" v-if="signType === 'privacy_jhr'">
  18. <view class="form-label">监护人信息</view>
  19. <view class="form-row">
  20. <text class="row-label">监护人姓名</text>
  21. <u-input v-model="guardianName" placeholder="请输入监护人姓名" border="surround" maxlength="20" />
  22. </view>
  23. <view class="form-row">
  24. <text class="row-label">监护人身份证</text>
  25. <u-input v-model="guardianIdCard" placeholder="请输入监护人身份证号" border="surround" maxlength="18" />
  26. </view>
  27. <view class="form-row">
  28. <text class="row-label">与患者关系</text>
  29. <u-input v-model="guardianRelation" placeholder="如:父亲、母亲" border="surround" maxlength="10" />
  30. </view>
  31. </view>
  32. <!-- 签名区域 -->
  33. <view class="section">
  34. <view class="sign-label">请在下方签名确认</view>
  35. <view class="canvas-wrap" @tap="goSignature">
  36. <image v-if="signImageUrl" class="sign-preview" :src="signImageUrl" mode="aspectFit" />
  37. <view v-else class="canvas-placeholder">
  38. <u-icon name="edit-pen" size="28" color="#ccc" />
  39. <text>点击此处去签名</text>
  40. </view>
  41. </view>
  42. <view v-if="signImageUrl" class="sign-actions">
  43. <view class="clear-btn" @tap="goSignature">重新签名</view>
  44. </view>
  45. </view>
  46. <!-- 底部按钮 -->
  47. <view class="btn-wrap">
  48. <u-button text="确认签署" :loading="submitting" @click="confirmSign" color="#0E63E3" size="large" />
  49. </view>
  50. </view>
  51. </template>
  52. <script setup>
  53. import { ref, onBeforeUnmount } from 'vue'
  54. import { onLoad } from '@dcloudio/uni-app'
  55. import { get, post } from '@/utils/request.js'
  56. const signType = ref('')
  57. const docTitle = ref('')
  58. const docContent = ref('')
  59. const incomeAmount = ref('')
  60. const guardianName = ref('')
  61. const guardianIdCard = ref('')
  62. const guardianRelation = ref('')
  63. const signImageUrl = ref('')
  64. const submitting = ref(false)
  65. const onSignatureResult = (data) => {
  66. if (data.url) signImageUrl.value = data.url
  67. }
  68. onLoad((options) => {
  69. signType.value = options.type || 'privacy'
  70. uni.$on('signatureResult', onSignatureResult)
  71. loadContent()
  72. })
  73. onBeforeUnmount(() => {
  74. uni.$off('signatureResult', onSignatureResult)
  75. })
  76. const loadContent = async () => {
  77. try {
  78. const key = 'sign_' + signType.value
  79. const res = await get('/api/content', { key })
  80. docTitle.value = res.data.title || ''
  81. docContent.value = res.data.content || ''
  82. } catch (e) {}
  83. }
  84. const goSignature = () => {
  85. uni.navigateTo({ url: '/pages/sign/signature' })
  86. }
  87. const confirmSign = async () => {
  88. if (!signImageUrl.value) {
  89. return uni.showToast({ title: '请先签名', icon: 'none' })
  90. }
  91. if (signType.value === 'income' && (!incomeAmount.value || Number(incomeAmount.value) <= 0)) {
  92. return uni.showToast({ title: '请填写有效的收入金额', icon: 'none' })
  93. }
  94. if (signType.value === 'privacy_jhr') {
  95. if (!guardianName.value.trim()) return uni.showToast({ title: '请输入监护人姓名', icon: 'none' })
  96. if (!guardianIdCard.value.trim()) return uni.showToast({ title: '请输入监护人身份证号', icon: 'none' })
  97. if (!/^\d{17}[\dXx]$/.test(guardianIdCard.value)) return uni.showToast({ title: '监护人身份证格式不正确', icon: 'none' })
  98. if (!guardianRelation.value.trim()) return uni.showToast({ title: '请输入与患者关系', icon: 'none' })
  99. }
  100. submitting.value = true
  101. try {
  102. const params = {
  103. type: signType.value,
  104. signImage: signImageUrl.value,
  105. amount: signType.value === 'income' ? incomeAmount.value : undefined,
  106. guardianName: signType.value === 'privacy_jhr' ? guardianName.value.trim() : undefined,
  107. guardianIdCard: signType.value === 'privacy_jhr' ? guardianIdCard.value.trim() : undefined,
  108. guardianRelation: signType.value === 'privacy_jhr' ? guardianRelation.value.trim() : undefined
  109. }
  110. const res = await post('/api/mp/sign', params)
  111. uni.$emit('signResult', {
  112. type: signType.value,
  113. url: res.data.url,
  114. amount: signType.value === 'income' ? incomeAmount.value : undefined
  115. })
  116. uni.showToast({ title: '签署成功', icon: 'success' })
  117. setTimeout(() => uni.navigateBack(), 1000)
  118. } catch (e) {
  119. if (e && e.msg) uni.showToast({ title: e.msg, icon: 'none' })
  120. } finally {
  121. submitting.value = false
  122. }
  123. }
  124. </script>
  125. <style lang="scss" scoped>
  126. .page {
  127. min-height: 100vh;
  128. background: #f4f4f5;
  129. padding: 24rpx;
  130. padding-bottom: calc(140rpx + env(safe-area-inset-bottom));
  131. }
  132. .section {
  133. background: #fff;
  134. margin-bottom: 24rpx;
  135. border-radius: 10rpx;
  136. padding: 32rpx;
  137. border: 1rpx solid #ebeef5;
  138. }
  139. .doc-title {
  140. font-size: 32rpx;
  141. font-weight: 600;
  142. text-align: center;
  143. margin-bottom: 32rpx;
  144. color: #222;
  145. }
  146. .doc-body {
  147. font-size: 28rpx;
  148. color: #555;
  149. line-height: 1.8;
  150. }
  151. .form-label {
  152. font-size: 28rpx;
  153. color: #333;
  154. font-weight: 600;
  155. margin-bottom: 16rpx;
  156. }
  157. .amount-wrap {
  158. display: flex;
  159. align-items: center;
  160. border: 1rpx solid #ddd;
  161. border-radius: 12rpx;
  162. overflow: hidden;
  163. gap: 12rpx;
  164. }
  165. .amount-prefix {
  166. padding: 20rpx 24rpx;
  167. font-size: 28rpx;
  168. color: #999;
  169. background: #f8f8f8;
  170. }
  171. .form-row {
  172. margin-bottom: 20rpx;
  173. &:last-child {
  174. margin-bottom: 0;
  175. }
  176. }
  177. .row-label {
  178. font-size: 26rpx;
  179. color: #555;
  180. margin-bottom: 12rpx;
  181. display: block;
  182. }
  183. .sign-label {
  184. font-size: 28rpx;
  185. color: #333;
  186. font-weight: 600;
  187. margin-bottom: 16rpx;
  188. }
  189. .canvas-wrap {
  190. position: relative;
  191. border: 2rpx dashed #ddd;
  192. border-radius: 12rpx;
  193. overflow: hidden;
  194. min-height: 300rpx;
  195. display: flex;
  196. align-items: center;
  197. justify-content: center;
  198. background: #fafafa;
  199. }
  200. .sign-preview {
  201. width: 100%;
  202. height: 300rpx;
  203. }
  204. .canvas-placeholder {
  205. display: flex;
  206. flex-direction: column;
  207. align-items: center;
  208. gap: 12rpx;
  209. padding: 40rpx 0;
  210. text {
  211. color: #ccc;
  212. font-size: 28rpx;
  213. }
  214. }
  215. .sign-actions {
  216. display: flex;
  217. justify-content: flex-end;
  218. margin-top: 16rpx;
  219. }
  220. .clear-btn {
  221. padding: 12rpx 32rpx;
  222. border: 1rpx solid #ccc;
  223. border-radius: 12rpx;
  224. font-size: 26rpx;
  225. color: #666;
  226. &:active {
  227. border-color: #0e63e3;
  228. color: #0e63e3;
  229. }
  230. }
  231. .btn-wrap {
  232. position: fixed;
  233. bottom: 0;
  234. left: 0;
  235. right: 0;
  236. background: #fff;
  237. padding: 20rpx 32rpx;
  238. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  239. box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.06);
  240. z-index: 100;
  241. }
  242. </style>