consignee-edit.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. <!-- 手签名 -->
  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 class="signature-block">
  64. <hand-signature
  65. :value="form.handSignature"
  66. :require-agree="true"
  67. agree-text="我已阅读并同意,本人确认以上信息真实、准确"
  68. @confirm="onHandSignatureConfirm"
  69. @clear="onHandSignatureClear"
  70. @agree-change="onHandSignatureAgreeChange"
  71. />
  72. </view>
  73. <!-- 设为默认 -->
  74. <view class="form-row form-row-switch">
  75. <text class="form-label">设为默认收货人</text>
  76. <switch :checked="form.isDefault === 1" @change="onDefaultChange" :color="switchColor" />
  77. </view>
  78. <!-- Save -->
  79. <button
  80. :class="['save-btn', saving ? 'disabled' : '']"
  81. :disabled="saving"
  82. @click="handleSave"
  83. >
  84. {{ saving ? '保存中...' : '保存' }}
  85. </button>
  86. </view>
  87. </view>
  88. </template>
  89. <script>
  90. import { BrandColors } from '@/utils/brand-colors.js'
  91. import { consigneeDetail, consigneeSave } from '../../../utils/api.js'
  92. import HandSignature from '@/components/hand-signature/hand-signature.vue'
  93. import fontScaleMixin from '@/mixins/font-scale.js'
  94. export default {
  95. mixins: [fontScaleMixin],
  96. components: { HandSignature },
  97. data() {
  98. return {
  99. switchColor: BrandColors.indigoPeriwinkle,
  100. form: {
  101. name: '',
  102. phone: '',
  103. idCard: '',
  104. ethnicity: '',
  105. bloodType: '',
  106. handSignature: '',
  107. isDefault: 0
  108. },
  109. bloodTypes: ['A型', 'B型', 'O型', 'AB型', '其他'],
  110. saving: false,
  111. isEdit: false
  112. }
  113. },
  114. onLoad(options) {
  115. if (options && options.id) {
  116. this.isEdit = true
  117. this.loadDetail(options.id)
  118. uni.setNavigationBarTitle({ title: '编辑收货人' })
  119. }
  120. },
  121. methods: {
  122. async loadDetail(id) {
  123. try {
  124. const res = await consigneeDetail(id)
  125. if (res.code === 200 && res.data) {
  126. this.form = {
  127. id: res.data.id,
  128. name: res.data.name || '',
  129. phone: res.data.phone || '',
  130. idCard: res.data.idCard || '',
  131. ethnicity: res.data.ethnicity || '',
  132. bloodType: res.data.bloodType || '',
  133. handSignature: res.data.handSignature || '',
  134. isDefault: res.data.isDefault || 0
  135. }
  136. }
  137. } catch (e) {
  138. console.error(e)
  139. }
  140. },
  141. onBloodTypeChange(e) {
  142. this.form.bloodType = this.bloodTypes[e.detail.value]
  143. },
  144. onHandSignatureConfirm(dataUrl) {
  145. this.form.handSignature = dataUrl || ''
  146. },
  147. onHandSignatureClear() {
  148. this.form.handSignature = ''
  149. },
  150. onHandSignatureAgreeChange(agreed) {
  151. // 取消勾选同意 → 作废已确认签名
  152. if (!agreed) this.form.handSignature = ''
  153. },
  154. onDefaultChange(e) {
  155. this.form.isDefault = e.detail.value ? 1 : 0
  156. },
  157. async handleSave() {
  158. if (!this.form.name || !this.form.name.trim()) {
  159. uni.showToast({ title: '请输入收货人姓名', icon: 'none' })
  160. return
  161. }
  162. if (!this.form.phone || this.form.phone.length < 11) {
  163. uni.showToast({ title: '请输入正确的手机号', icon: 'none' })
  164. return
  165. }
  166. this.saving = true
  167. try {
  168. const res = await consigneeSave(this.form)
  169. if (res.code === 200) {
  170. uni.showToast({ title: '保存成功', icon: 'success' })
  171. setTimeout(function() {
  172. uni.navigateBack()
  173. }, 1000)
  174. }
  175. } catch (e) {
  176. console.error(e)
  177. } finally {
  178. this.saving = false
  179. }
  180. }
  181. }
  182. }
  183. </script>
  184. <style scoped lang="scss">
  185. .container {
  186. min-height: 100vh;
  187. background: $app-bg;
  188. padding: 20rpx;
  189. }
  190. .form-wrap {
  191. background: $app-surface;
  192. border-radius: 16rpx;
  193. padding: $uni-space-page;
  194. }
  195. .form-row {
  196. display: flex;
  197. align-items: center;
  198. padding: 24rpx 0;
  199. border-bottom: 1rpx solid $facade-fill-2;
  200. }
  201. .form-row:last-child {
  202. border-bottom: none;
  203. }
  204. .form-label {
  205. font-size: calc(28rpx * var(--font-scale, 1));
  206. color: $facade-text-strong;
  207. width: 180rpx;
  208. flex-shrink: 0;
  209. }
  210. .form-input {
  211. flex: 1;
  212. font-size: calc(28rpx * var(--font-scale, 1));
  213. color: $facade-text-strong;
  214. text-align: right;
  215. padding: 8rpx 0;
  216. }
  217. .picker-value {
  218. flex: 1;
  219. text-align: right;
  220. font-size: calc(28rpx * var(--font-scale, 1));
  221. color: $facade-text-strong;
  222. padding: 8rpx 0;
  223. }
  224. .picker-value .placeholder {
  225. color: $facade-text-ghost;
  226. }
  227. .form-row-switch {
  228. justify-content: space-between;
  229. }
  230. .form-row-switch .form-label {
  231. width: auto;
  232. }
  233. .form-row-signature {
  234. border-bottom: none;
  235. }
  236. .signature-cell {
  237. flex: 1;
  238. text-align: right;
  239. font-size: calc(28rpx * var(--font-scale, 1));
  240. color: $facade-text-strong;
  241. padding: 8rpx 0;
  242. }
  243. .signature-set {
  244. color: $el-success;
  245. }
  246. .signature-block {
  247. padding: 0 0 24rpx;
  248. }
  249. .save-btn {
  250. width: 100%;
  251. margin-top: 40rpx;
  252. background: linear-gradient(135deg, $accent-indigo, $accent-indigo-deep);
  253. color: $app-surface;
  254. border-radius: 24rpx;
  255. font-size: calc(30rpx * var(--font-scale, 1));
  256. padding: 24rpx;
  257. line-height: 1.5;
  258. }
  259. .save-btn.disabled {
  260. opacity: 0.6;
  261. }
  262. </style>