consignee-edit.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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-switch">
  57. <text class="form-label">设为默认收货人</text>
  58. <switch :checked="form.isDefault === 1" @change="onDefaultChange" color="#667eea" />
  59. </view>
  60. <!-- Save -->
  61. <button
  62. :class="['save-btn', saving ? 'disabled' : '']"
  63. :disabled="saving"
  64. @click="handleSave"
  65. >
  66. {{ saving ? '保存中...' : '保存' }}
  67. </button>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import { consigneeDetail, consigneeSave } from '../../../utils/api.js'
  73. export default {
  74. data() {
  75. return {
  76. form: {
  77. name: '',
  78. phone: '',
  79. idCard: '',
  80. ethnicity: '',
  81. bloodType: '',
  82. isDefault: 0
  83. },
  84. bloodTypes: ['A型', 'B型', 'O型', 'AB型', '其他'],
  85. saving: false,
  86. isEdit: false
  87. }
  88. },
  89. onLoad(options) {
  90. if (options && options.id) {
  91. this.isEdit = true
  92. this.loadDetail(options.id)
  93. uni.setNavigationBarTitle({ title: '编辑收货人' })
  94. }
  95. },
  96. methods: {
  97. async loadDetail(id) {
  98. try {
  99. const res = await consigneeDetail(id)
  100. if (res.code === 200 && res.data) {
  101. this.form = {
  102. id: res.data.id,
  103. name: res.data.name || '',
  104. phone: res.data.phone || '',
  105. idCard: res.data.idCard || '',
  106. ethnicity: res.data.ethnicity || '',
  107. bloodType: res.data.bloodType || '',
  108. isDefault: res.data.isDefault || 0
  109. }
  110. }
  111. } catch (e) {
  112. console.error(e)
  113. }
  114. },
  115. onBloodTypeChange(e) {
  116. this.form.bloodType = this.bloodTypes[e.detail.value]
  117. },
  118. onDefaultChange(e) {
  119. this.form.isDefault = e.detail.value ? 1 : 0
  120. },
  121. async handleSave() {
  122. if (!this.form.name || !this.form.name.trim()) {
  123. uni.showToast({ title: '请输入收货人姓名', icon: 'none' })
  124. return
  125. }
  126. if (!this.form.phone || this.form.phone.length < 11) {
  127. uni.showToast({ title: '请输入正确的手机号', icon: 'none' })
  128. return
  129. }
  130. this.saving = true
  131. try {
  132. const res = await consigneeSave(this.form)
  133. if (res.code === 200) {
  134. uni.showToast({ title: '保存成功', icon: 'success' })
  135. setTimeout(function() {
  136. uni.navigateBack()
  137. }, 1000)
  138. }
  139. } catch (e) {
  140. console.error(e)
  141. } finally {
  142. this.saving = false
  143. }
  144. }
  145. }
  146. }
  147. </script>
  148. <style scoped>
  149. .container {
  150. min-height: 100vh;
  151. background: #f5f7fa;
  152. padding: 20rpx;
  153. }
  154. .form-wrap {
  155. background: #fff;
  156. border-radius: 16rpx;
  157. padding: 30rpx;
  158. }
  159. .form-row {
  160. display: flex;
  161. align-items: center;
  162. padding: 24rpx 0;
  163. border-bottom: 1rpx solid #f5f5f5;
  164. }
  165. .form-row:last-child {
  166. border-bottom: none;
  167. }
  168. .form-label {
  169. font-size: 28rpx;
  170. color: #333;
  171. width: 180rpx;
  172. flex-shrink: 0;
  173. }
  174. .form-input {
  175. flex: 1;
  176. font-size: 28rpx;
  177. color: #333;
  178. text-align: right;
  179. padding: 8rpx 0;
  180. }
  181. .picker-value {
  182. flex: 1;
  183. text-align: right;
  184. font-size: 28rpx;
  185. color: #333;
  186. padding: 8rpx 0;
  187. }
  188. .picker-value .placeholder {
  189. color: #ccc;
  190. }
  191. .form-row-switch {
  192. justify-content: space-between;
  193. }
  194. .form-row-switch .form-label {
  195. width: auto;
  196. }
  197. .save-btn {
  198. width: 100%;
  199. margin-top: 40rpx;
  200. background: linear-gradient(135deg, #667eea, #764ba2);
  201. color: #fff;
  202. border-radius: 50rpx;
  203. font-size: 30rpx;
  204. padding: 24rpx;
  205. line-height: 1.5;
  206. }
  207. .save-btn.disabled {
  208. opacity: 0.6;
  209. }
  210. </style>