consignee-edit.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <view class="form-wrap">
  4. <!-- 姓名 -->
  5. <view class="form-row">
  6. <text class="form-label">收货人姓名</text>
  7. <input
  8. v-model="form.name"
  9. class="form-input"
  10. placeholder="请输入姓名"
  11. maxlength="30"
  12. />
  13. </view>
  14. <!-- 手机号 -->
  15. <view class="form-row">
  16. <text class="form-label">手机号</text>
  17. <input
  18. v-model="form.phone"
  19. class="form-input"
  20. placeholder="请输入手机号"
  21. type="number"
  22. maxlength="11"
  23. />
  24. </view>
  25. <!-- 身份证号 -->
  26. <view class="form-row">
  27. <text class="form-label">身份证号</text>
  28. <input
  29. v-model="form.idCard"
  30. class="form-input"
  31. placeholder="请输入身份证号(选填)"
  32. maxlength="18"
  33. />
  34. </view>
  35. <!-- 民族 -->
  36. <view class="form-row">
  37. <text class="form-label">民族</text>
  38. <input
  39. v-model="form.ethnicity"
  40. class="form-input"
  41. placeholder="请输入民族(选填)"
  42. maxlength="10"
  43. />
  44. </view>
  45. <!-- 血型 -->
  46. <view class="form-row">
  47. <text class="form-label">血型</text>
  48. <picker mode="selector" :range="bloodTypes" @change="onBloodTypeChange">
  49. <view class="picker-value">
  50. <text v-if="form.bloodType">{{ form.bloodType }}</text>
  51. <text v-else class="placeholder">请选择血型(选填)</text>
  52. </view>
  53. </picker>
  54. </view>
  55. <!-- 手签名:独立横屏签名页(去签名 → navigateTo → eventChannel 回传;选填语义不变) -->
  56. <view class="form-row form-row-signature">
  57. <text class="form-label">手签名</text>
  58. <view class="signature-cell">
  59. <text v-if="form.handSignature" class="signature-set">已设置手签名</text>
  60. <text v-else class="placeholder">选填,点击「去签名」手写</text>
  61. </view>
  62. </view>
  63. <view v-if="form.handSignature" class="signature-block sig-preview-block">
  64. <image class="signature-preview-img" :src="form.handSignature" mode="widthFix" />
  65. </view>
  66. <view class="signature-block">
  67. <button class="btn-sign-entry" @click="goSignature">{{ form.handSignature ? '重新签名' : '去签名' }}</button>
  68. </view>
  69. <!-- 设为默认 -->
  70. <view class="form-row form-row-switch">
  71. <text class="form-label">设为默认收货人</text>
  72. <switch :checked="form.isDefault === 1" @change="onDefaultChange" :color="switchColor" />
  73. </view>
  74. <!-- Save -->
  75. <button
  76. :class="['save-btn', saving ? 'disabled' : '']"
  77. :disabled="saving"
  78. @click="handleSave"
  79. >
  80. {{ saving ? '保存中...' : '保存' }}
  81. </button>
  82. </view>
  83. </view>
  84. </template>
  85. <script>
  86. import { BrandColors } from '@/utils/brand-colors.js'
  87. import { consigneeDetail, consigneeSave } from '../../../utils/api.js'
  88. import { setSignaturePrefill } from '@/utils/signature-bus.js'
  89. import fontScaleMixin from '@/mixins/font-scale.js'
  90. export default {
  91. mixins: [fontScaleMixin],
  92. data() {
  93. return {
  94. switchColor: BrandColors.indigoPeriwinkle,
  95. form: {
  96. name: '',
  97. phone: '',
  98. idCard: '',
  99. ethnicity: '',
  100. bloodType: '',
  101. handSignature: '',
  102. isDefault: 0
  103. },
  104. bloodTypes: ['A型', 'B型', 'O型', 'AB型', '其他'],
  105. saving: false,
  106. isEdit: false
  107. }
  108. },
  109. onLoad(options) {
  110. if (options && options.id) {
  111. this.isEdit = true
  112. this.loadDetail(options.id)
  113. uni.setNavigationBarTitle({ title: '编辑收货人' })
  114. }
  115. },
  116. methods: {
  117. async loadDetail(id) {
  118. try {
  119. const res = await consigneeDetail(id)
  120. if (res.code === 200 && res.data) {
  121. this.form = {
  122. id: res.data.id,
  123. name: res.data.name || '',
  124. phone: res.data.phone || '',
  125. idCard: res.data.idCard || '',
  126. ethnicity: res.data.ethnicity || '',
  127. bloodType: res.data.bloodType || '',
  128. handSignature: res.data.handSignature || '',
  129. isDefault: res.data.isDefault || 0
  130. }
  131. }
  132. } catch (e) {
  133. console.error(e)
  134. }
  135. },
  136. onBloodTypeChange(e) {
  137. this.form.bloodType = this.bloodTypes[e.detail.value]
  138. },
  139. onDefaultChange(e) {
  140. this.form.isDefault = e.detail.value ? 1 : 0
  141. },
  142. // 跳转独立横屏签名页;base64 过长经 signature-bus 传初始值,结果经 eventChannel 回传
  143. goSignature() {
  144. setSignaturePrefill(this.form.handSignature || '')
  145. uni.navigateTo({
  146. url: '/pages/signature/signature?requireAgree=1&agreeText=' + encodeURIComponent('我已阅读并同意,本人确认以上信息真实、准确'),
  147. events: {
  148. signatureConfirm: (dataUrl) => {
  149. this.form.handSignature = dataUrl || ''
  150. }
  151. }
  152. })
  153. },
  154. async handleSave() {
  155. if (!this.form.name || !this.form.name.trim()) {
  156. uni.showToast({ title: '请输入收货人姓名', icon: 'none' })
  157. return
  158. }
  159. if (!this.form.phone || this.form.phone.length < 11) {
  160. uni.showToast({ title: '请输入正确的手机号', icon: 'none' })
  161. return
  162. }
  163. this.saving = true
  164. try {
  165. const res = await consigneeSave(this.form)
  166. if (res.code === 200) {
  167. uni.showToast({ title: '保存成功', icon: 'success' })
  168. setTimeout(function() {
  169. uni.navigateBack()
  170. }, 1000)
  171. }
  172. } catch (e) {
  173. console.error(e)
  174. } finally {
  175. this.saving = false
  176. }
  177. }
  178. }
  179. }
  180. </script>
  181. <style scoped lang="scss">
  182. .container {
  183. min-height: 100vh;
  184. background: $app-bg;
  185. padding: 20rpx;
  186. }
  187. .form-wrap {
  188. background: $app-surface;
  189. border-radius: 16rpx;
  190. padding: $uni-space-page;
  191. }
  192. .form-row {
  193. display: flex;
  194. align-items: center;
  195. padding: 24rpx 0;
  196. border-bottom: 1rpx solid $facade-fill-2;
  197. }
  198. .form-row:last-child {
  199. border-bottom: none;
  200. }
  201. .form-label {
  202. font-size: calc(28rpx * var(--font-scale, 1));
  203. color: $facade-text-strong;
  204. width: 180rpx;
  205. flex-shrink: 0;
  206. }
  207. .form-input {
  208. flex: 1;
  209. font-size: calc(28rpx * var(--font-scale, 1));
  210. color: $facade-text-strong;
  211. text-align: right;
  212. padding: 8rpx 0;
  213. }
  214. .picker-value {
  215. flex: 1;
  216. text-align: right;
  217. font-size: calc(28rpx * var(--font-scale, 1));
  218. color: $facade-text-strong;
  219. padding: 8rpx 0;
  220. }
  221. .picker-value .placeholder {
  222. color: $facade-text-ghost;
  223. }
  224. .form-row-switch {
  225. justify-content: space-between;
  226. }
  227. .form-row-switch .form-label {
  228. width: auto;
  229. }
  230. .form-row-signature {
  231. border-bottom: none;
  232. }
  233. .signature-cell {
  234. flex: 1;
  235. text-align: right;
  236. font-size: calc(28rpx * var(--font-scale, 1));
  237. color: $facade-text-strong;
  238. padding: 8rpx 0;
  239. }
  240. .signature-set {
  241. color: $el-success;
  242. }
  243. .signature-block {
  244. padding: 0 0 24rpx;
  245. }
  246. .sig-preview-block {
  247. margin-bottom: 8rpx;
  248. }
  249. .signature-preview-img {
  250. width: 100%;
  251. height: auto;
  252. background: $app-surface;
  253. border: 2rpx dashed $facade-text-ghost;
  254. border-radius: 16rpx;
  255. }
  256. .btn-sign-entry {
  257. width: 100%;
  258. height: 80rpx;
  259. line-height: 80rpx;
  260. padding: 0;
  261. background: linear-gradient(135deg, $accent-indigo, $accent-indigo-deep);
  262. color: $app-surface;
  263. border: none;
  264. border-radius: 24rpx;
  265. font-size: calc(28rpx * var(--font-scale, 1));
  266. text-align: center;
  267. }
  268. .btn-sign-entry::after {
  269. border: none;
  270. }
  271. .save-btn {
  272. width: 100%;
  273. margin-top: 40rpx;
  274. background: linear-gradient(135deg, $accent-indigo, $accent-indigo-deep);
  275. color: $app-surface;
  276. border-radius: 24rpx;
  277. font-size: calc(30rpx * var(--font-scale, 1));
  278. padding: 24rpx;
  279. line-height: 1.5;
  280. }
  281. .save-btn.disabled {
  282. opacity: 0.6;
  283. }
  284. </style>