consignee-edit.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <view class="container">
  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="#667eea" />
  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 { consigneeDetail, consigneeSave } from '../../../utils/api.js'
  91. import HandSignature from '@/components/hand-signature/hand-signature.vue'
  92. export default {
  93. components: { HandSignature },
  94. data() {
  95. return {
  96. form: {
  97. name: '',
  98. phone: '',
  99. idCard: '',
  100. ethnicity: '',
  101. bloodType: '',
  102. handSignature: '',
  103. isDefault: 0
  104. },
  105. bloodTypes: ['A型', 'B型', 'O型', 'AB型', '其他'],
  106. saving: false,
  107. isEdit: false
  108. }
  109. },
  110. onLoad(options) {
  111. if (options && options.id) {
  112. this.isEdit = true
  113. this.loadDetail(options.id)
  114. uni.setNavigationBarTitle({ title: '编辑收货人' })
  115. }
  116. },
  117. methods: {
  118. async loadDetail(id) {
  119. try {
  120. const res = await consigneeDetail(id)
  121. if (res.code === 200 && res.data) {
  122. this.form = {
  123. id: res.data.id,
  124. name: res.data.name || '',
  125. phone: res.data.phone || '',
  126. idCard: res.data.idCard || '',
  127. ethnicity: res.data.ethnicity || '',
  128. bloodType: res.data.bloodType || '',
  129. handSignature: res.data.handSignature || '',
  130. isDefault: res.data.isDefault || 0
  131. }
  132. }
  133. } catch (e) {
  134. console.error(e)
  135. }
  136. },
  137. onBloodTypeChange(e) {
  138. this.form.bloodType = this.bloodTypes[e.detail.value]
  139. },
  140. onHandSignatureConfirm(dataUrl) {
  141. this.form.handSignature = dataUrl || ''
  142. },
  143. onHandSignatureClear() {
  144. this.form.handSignature = ''
  145. },
  146. onHandSignatureAgreeChange(agreed) {
  147. // 取消勾选同意 → 作废已确认签名
  148. if (!agreed) this.form.handSignature = ''
  149. },
  150. onDefaultChange(e) {
  151. this.form.isDefault = e.detail.value ? 1 : 0
  152. },
  153. async handleSave() {
  154. if (!this.form.name || !this.form.name.trim()) {
  155. uni.showToast({ title: '请输入收货人姓名', icon: 'none' })
  156. return
  157. }
  158. if (!this.form.phone || this.form.phone.length < 11) {
  159. uni.showToast({ title: '请输入正确的手机号', icon: 'none' })
  160. return
  161. }
  162. this.saving = true
  163. try {
  164. const res = await consigneeSave(this.form)
  165. if (res.code === 200) {
  166. uni.showToast({ title: '保存成功', icon: 'success' })
  167. setTimeout(function() {
  168. uni.navigateBack()
  169. }, 1000)
  170. }
  171. } catch (e) {
  172. console.error(e)
  173. } finally {
  174. this.saving = false
  175. }
  176. }
  177. }
  178. }
  179. </script>
  180. <style scoped>
  181. .container {
  182. min-height: 100vh;
  183. background: #f5f7fa;
  184. padding: 20rpx;
  185. }
  186. .form-wrap {
  187. background: #fff;
  188. border-radius: 16rpx;
  189. padding: 30rpx;
  190. }
  191. .form-row {
  192. display: flex;
  193. align-items: center;
  194. padding: 24rpx 0;
  195. border-bottom: 1rpx solid #f5f5f5;
  196. }
  197. .form-row:last-child {
  198. border-bottom: none;
  199. }
  200. .form-label {
  201. font-size: 28rpx;
  202. color: #333;
  203. width: 180rpx;
  204. flex-shrink: 0;
  205. }
  206. .form-input {
  207. flex: 1;
  208. font-size: 28rpx;
  209. color: #333;
  210. text-align: right;
  211. padding: 8rpx 0;
  212. }
  213. .picker-value {
  214. flex: 1;
  215. text-align: right;
  216. font-size: 28rpx;
  217. color: #333;
  218. padding: 8rpx 0;
  219. }
  220. .picker-value .placeholder {
  221. color: #ccc;
  222. }
  223. .form-row-switch {
  224. justify-content: space-between;
  225. }
  226. .form-row-switch .form-label {
  227. width: auto;
  228. }
  229. .form-row-signature {
  230. border-bottom: none;
  231. }
  232. .signature-cell {
  233. flex: 1;
  234. text-align: right;
  235. font-size: 28rpx;
  236. color: #333;
  237. padding: 8rpx 0;
  238. }
  239. .signature-set {
  240. color: #67c23a;
  241. }
  242. .signature-block {
  243. padding: 0 0 24rpx;
  244. }
  245. .save-btn {
  246. width: 100%;
  247. margin-top: 40rpx;
  248. background: linear-gradient(135deg, #667eea, #764ba2);
  249. color: #fff;
  250. border-radius: 50rpx;
  251. font-size: 30rpx;
  252. padding: 24rpx;
  253. line-height: 1.5;
  254. }
  255. .save-btn.disabled {
  256. opacity: 0.6;
  257. }
  258. </style>