AddShippingAddress.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view class="detail-view">
  3. <u-form label-width="140" :model="add_form" ref="uForm">
  4. <view class="form-model-view">
  5. <u-form-item required label="收货人" prop="name">
  6. <u-input type="text" v-model="add_form.name" placeholder="收货人名称" />
  7. </u-form-item>
  8. <u-form-item required label="收货地址">
  9. <u-input v-model='area' class="dis-input" @click="region_show = true" disabled
  10. placeholder="请选择所属区域" />
  11. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  12. </u-form-item>
  13. <u-form-item required label-position="top" label="详细地址" prop="address">
  14. <u-input v-model="add_form.address" type="textarea" placeholder="详细地址,例如楼牌,门号" />
  15. </u-form-item>
  16. <u-form-item required label="联系电话">
  17. <u-input v-model="add_form.mobile" type="number" placeholder="填写收货人联系电话" />
  18. </u-form-item>
  19. </view>
  20. </u-form>
  21. <view class="detail-bottom">
  22. <view class="handel-btn" @click="addSupplier">提交</view>
  23. </view>
  24. <RegionSel v-model="region_show" @confirm="confirm" @cancel="region_show = false" />
  25. </view>
  26. </template>
  27. <script>
  28. import RegionSel from '@/components/region/RegionSel.vue';
  29. export default {
  30. components: {
  31. RegionSel
  32. },
  33. data() {
  34. return {
  35. area: '',
  36. add_form: {
  37. name: '',
  38. provinceCode: '',
  39. cityCode: '',
  40. districtCode: '',
  41. address: '',
  42. mobile: '',
  43. },
  44. region_show: false,
  45. rules: {
  46. name: [{
  47. required: true,
  48. message: "请填写收货人",
  49. trigger: "blur"
  50. }, ],
  51. address: [{
  52. required: true,
  53. message: "请输入详细地址",
  54. trigger: "blur"
  55. }, ],
  56. },
  57. customerId: ''
  58. };
  59. },
  60. onLoad(options) {
  61. if (options.customerId) {
  62. this.customerId = options.customerId
  63. }
  64. },
  65. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  66. onReady() {
  67. this.$refs.uForm.setRules(this.rules);
  68. },
  69. methods: {
  70. addSupplier() {
  71. if (!this.add_form.name.trim() ||
  72. !this.area.trim() ||
  73. !this.add_form.mobile.trim() ||
  74. !this.add_form.address.trim()) {
  75. this.$u.toast('必填项不能为空')
  76. return
  77. }
  78. if (!this.$u.test.mobile(this.add_form.mobile)) {
  79. this.$u.toast('手机号格式有误,请重新输入!')
  80. return
  81. }
  82. this.$u.api.addShippingAddress({
  83. name: this.add_form.name,
  84. mobile: this.add_form.mobile,
  85. provinceCode: this.add_form.provinceCode,
  86. cityCode: this.add_form.cityCode,
  87. districtCode: this.add_form.districtCode,
  88. address: this.add_form.address,
  89. defaultStatus: 5,
  90. customerId: this.customerId,
  91. }).then(res => {
  92. this.$u.toast('新增成功')
  93. setTimeout(() => {
  94. uni.navigateBack()
  95. }, 500)
  96. })
  97. },
  98. confirm(val) {
  99. this.add_form.provinceCode = val[0].value;
  100. this.add_form.cityCode = val[1].value;
  101. this.add_form.districtCode = val[2].value;
  102. let name = '';
  103. val.forEach(item => {
  104. name += item.label;
  105. });
  106. this.area = name;
  107. },
  108. }
  109. }
  110. </script>
  111. <style lang="scss">
  112. </style>