add.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view class="content bg-drak ft-main">
  3. <use-tabbar :tabbar="false"></use-tabbar>
  4. <view class="gap"></view>
  5. <view class="row dflex padding-lr">
  6. <text class="tit">收货人</text>
  7. <input class="input" placeholder="请输入收货人姓名" maxlength="140" v-model="fetch.name"/>
  8. </view>
  9. <view class="row dflex padding-lr">
  10. <text class="tit">手机号</text>
  11. <input class="input" placeholder="请输入手机号码" maxlength="140" type="number" pattern="[0-9]*" v-model="fetch.phone"/>
  12. </view>
  13. <view class="row dflex padding-left">
  14. <text class="tit">所在地区</text>
  15. <view class="dflex-b flex1">
  16. <view class="flex1 input_t" @click="openAddress">{{ fetch.area_string }}</view>
  17. <sx-address-picker v-model="address" :selected="fetch.area" @confirm="addressConfirm"/>
  18. </view>
  19. </view>
  20. <view class="use-area margin-lr-sm">
  21. <view class="tit">详细地址</view>
  22. <textarea class="bg-drak w-full border-radius-sm margin-top-sm padding" placeholder="请输入详细地址" maxlength="120" style="min-height: 70px; height: auto;" v-model="fetch.address"/>
  23. </view>
  24. <view class="gap"></view>
  25. <view class="row dflex-b padding-lr">
  26. <u-subsection :list="type" :current="fetch.type" @change="setType" mode="button"></u-subsection>
  27. </view>
  28. <view class="padding w-full margin-top-big" @click="save">
  29. <view class="dflex-b border-radius-big">
  30. <view class="tac padding-tb-sm flex1 bg-base">提交</view>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. type: [],
  40. address:false,
  41. fetch: {
  42. id:-1,
  43. province_id:0,
  44. city_id:0,
  45. county_id:0,
  46. town_id:0,
  47. address:'',
  48. name:'',
  49. phone:'',
  50. type:0,
  51. area:['CN', '11', '1101', '110107', '110107005'],
  52. area_string: '请选择地址',
  53. }
  54. };
  55. },
  56. onLoad(options) {
  57. this.type = ['默认地址', '普通地址'];
  58. if (options) {
  59. if (options.temp == 1) {
  60. this.type.push('临时地址');
  61. }
  62. if (options.id) {
  63. this.fetch.id = options.id;
  64. }
  65. }
  66. this.loadData();
  67. },
  68. methods: {
  69. loadData() {
  70. this.DeverApi.get(this, 'address.getInfo', {id:this.fetch.id});
  71. },
  72. setType(index) {
  73. this.fetch.type = index;
  74. },
  75. save() {
  76. if (!this.fetch.name) {
  77. return this.Dever.alert('请输入收货人姓名');
  78. }
  79. if (!this.fetch.phone) {
  80. return this.Dever.alert('请输入手机号');
  81. }
  82. if (!/^1\d{10}$/.test(this.fetch.phone)) {
  83. return this.Dever.alert('请输入有效手机号');
  84. }
  85. if (!this.fetch.province_id) {
  86. return this.Dever.alert('请选择省份');
  87. }
  88. if (!this.fetch.city_id) {
  89. return this.Dever.alert('请选择城市');
  90. }
  91. if (!this.fetch.county_id) {
  92. return this.Dever.alert('请选择区县');
  93. }
  94. if (!this.fetch.town_id) {
  95. return this.Dever.alert('请选择街道');
  96. }
  97. if (!this.fetch.address) {
  98. return this.Dever.alert('请输入详细地址');
  99. }
  100. this.DeverApi.post('address.up', this.fetch, res => {
  101. this.Dever.success('提交成功', () => {
  102. this.Dever.back('user/address/list');
  103. });
  104. });
  105. },
  106. openAddress() {
  107. this.address = true
  108. },
  109. // 选择地址
  110. addressConfirm(res) {
  111. var name = [];
  112. res.forEach((item, index) => {
  113. if (index > 0) {
  114. if (name != '市辖区') {
  115. name.push(item.name)
  116. }
  117. if (index == 1) {
  118. this.fetch.province_id = item.code;
  119. } else if (index == 2) {
  120. this.fetch.city_id = item.code;
  121. } else if (index == 3) {
  122. this.fetch.county_id = item.code;
  123. } else if (index == 4) {
  124. this.fetch.town_id = item.code;
  125. }
  126. }
  127. });
  128. this.fetch.area_string = name.join('-')
  129. },
  130. }
  131. };
  132. </script>
  133. <style lang="scss">
  134. .row {
  135. background: #fff;
  136. position: relative;
  137. height: 104rpx;
  138. margin: 18rpx;
  139. border-radius: 18rpx;
  140. .input {
  141. flex: 1;
  142. font-size: 28rpx;
  143. padding-left: 0;
  144. }
  145. .tit {
  146. flex-shrink: 0;
  147. width: 144rpx;
  148. }
  149. }
  150. .use-area {
  151. border-radius: 18rpx;
  152. background: #fff;
  153. padding: 28rpx;
  154. margin-top: 18rpx;
  155. }
  156. </style>