addressManage.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <view :class="['qn-page-' + theme]" class="content">
  3. <view class="row b-b">
  4. <text class="tit">联系人</text>
  5. <input class="input" type="text" v-model="addressData.name" placeholder="收货人姓名" placeholder-class="placeholder" />
  6. </view>
  7. <view class="row b-b">
  8. <text class="tit">手机号</text>
  9. <!-- #ifdef MP -->
  10. <input class="input" type="number" @input="mobileInput" :value="addressData.mobile" placeholder="收货人手机号码" placeholder-class="placeholder" />
  11. <!-- #endif -->
  12. <!-- #ifdef APP-PLUS -->
  13. <input class="input" type="number" v-model="addressData.mobile" placeholder="收货人手机号码" placeholder-class="placeholder" />
  14. <!-- #endif -->
  15. </view>
  16. <!-- <view class="row b-b">
  17. <text class="tit">地址</text>
  18. <text @click="chooseLocation" class="input">
  19. {{addressData.addressName}}
  20. </text>
  21. <text class="yticon icon-shouhuodizhi"></text>
  22. </view> -->
  23. <RegionSel @getRegionName="getRegionName" @pickerRegionChange="pickerRegionChange" :provinceCode="provinceCode" :cityCode="cityCode" :districtCode="districtCode">
  24. <view class="row b-b clearfix" style="border-bottom:1rpx solid #E4E7ED;">
  25. <view class="tit float_left">地址</view>
  26. <view class="float_right">
  27. <span v-if="region_name" style="font-size: 28rpx;">{{ region_name }}</span>
  28. <span v-else style="color: #999;font-size: 28rpx;">请选择</span>
  29. </view>
  30. </view>
  31. </RegionSel>
  32. <view class="row b-b">
  33. <text class="tit">门牌号</text>
  34. <input class="input" type="button" v-model="addressData.address" placeholder="楼号、门牌" placeholder-class="placeholder" />
  35. </view>
  36. <view class="row default-row">
  37. <text class="tit">设为默认</text>
  38. <switch :checked="defaule" color="#45A418" @change="switchChange" />
  39. </view>
  40. <button class="add-btn primary-bg" @click="confirm">提交</button>
  41. </view>
  42. </template>
  43. <script>
  44. import RegionSel from '../components/region/RegionSel.vue';
  45. export default {
  46. components: {
  47. RegionSel
  48. },
  49. data() {
  50. return {
  51. provinceCode: 0,
  52. cityCode: 0,
  53. districtCode: 0,
  54. region_name: '',
  55. // 地址部分
  56. height: '500px',
  57. address: [],
  58. defaule: false,
  59. // 修改地址的id
  60. coustrom_id: '',
  61. manageType: '', //路由地址
  62. addressData: {
  63. name: '',
  64. mobile: '',
  65. defaultStatus: 4,
  66. provinceCode: '',
  67. cityCode: '',
  68. districtCode: '',
  69. addressName: '',
  70. address: '',
  71. area: ''
  72. }
  73. };
  74. },
  75. onLoad(option) {
  76. // 获取当前是增加页面还是编辑
  77. this.manageType = option.type;
  78. if (this.manageType != 'add') {
  79. this.coustrom_id = this.manageType;
  80. this.getShippingAddressInfo();
  81. uni.setNavigationBarTitle({
  82. title: '修改地址'
  83. });
  84. } else {
  85. uni.setNavigationBarTitle({
  86. title: '新增地址'
  87. });
  88. }
  89. },
  90. methods: {
  91. mobileInput(e) {
  92. // #ifdef MP
  93. let val = e.detail.value;
  94. if (val.length === 3 || val.length === 8) {
  95. val += ' ';
  96. }
  97. this.$nextTick(() => {
  98. this.addressData.mobile = val;
  99. });
  100. // #endif
  101. },
  102. switchChange(val) {
  103. // 添加地址传
  104. this.defaule = val.detail.value;
  105. if (this.defaule) {
  106. this.addressData.defaultStatus = 5;
  107. } else {
  108. this.addressData.defaultStatus = 4;
  109. }
  110. },
  111. getRegionName(name) {
  112. this.region_name = name;
  113. },
  114. pickerRegionChange(row) {
  115. this.addressData.provinceCode = row[0].value;
  116. this.addressData.cityCode = row[1].value || '';
  117. this.addressData.districtCode = row[2].value || '';
  118. this.region_name = row[0].label + (row[1].label ? '-' + row[1].label + (row[2].label ? '-' + row[2].label : '') : '');
  119. },
  120. // 点击提交Annie
  121. confirm() {
  122. if (this.coustrom_id) {
  123. this.updateShippingAddress();
  124. } else {
  125. this.addShippingAddress();
  126. }
  127. },
  128. //添加
  129. addShippingAddress() {
  130. if (!this.addressData.name) {
  131. this.$api.msg('请填写收货人姓名');
  132. return;
  133. }
  134. const mobile = this.$_utils.mobileRe(this.addressData.mobile);
  135. if (!/(^1[3|4|5|6|7|8|9][0-9]{9}$)/.test(mobile)) {
  136. this.$api.msg('请输入正确的手机号码');
  137. return;
  138. }
  139. if (!this.addressData.address) {
  140. this.$api.msg('请填写门牌号信息');
  141. return;
  142. }
  143. // 发送请求
  144. this.$u.api
  145. .addShippingAddress({
  146. ...this.addressData,
  147. mobile: mobile,
  148. defaultStatus: this.defaule ? 5 : 4
  149. })
  150. .then(res => {
  151. this.$api.msg('添加成功');
  152. setTimeout(function() {
  153. uni.navigateBack();
  154. }, 800);
  155. });
  156. },
  157. // 获取地址的详情
  158. getShippingAddressInfo() {
  159. this.$u.api.getShippingAddressInfo(this.coustrom_id).then(data => {
  160. this.addressData = data.data;
  161. this.addressData.mobile = this.$_utils.mobileFormat(data.data.mobile);
  162. this.provinceCode = this.addressData.provinceCode;
  163. this.cityCode = this.addressData.cityCode;
  164. this.districtCode = this.addressData.districtCode;
  165. // 获取地址显示页面
  166. this.defaule = data.data.defaultStatus === 5;
  167. });
  168. },
  169. // 修改地址
  170. updateShippingAddress() {
  171. if (!this.addressData.name) {
  172. this.$api.msg('请填写收货人姓名');
  173. return;
  174. }
  175. const mobile = this.$_utils.mobileRe(this.addressData.mobile);
  176. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(mobile)) {
  177. this.$api.msg('请输入正确的手机号码');
  178. return;
  179. }
  180. // if(!addressData.addressName){
  181. // this.$api.msg('请选择所在位置');
  182. // return;
  183. // }
  184. if (!this.addressData.address) {
  185. this.$api.msg('请填写门牌号信息');
  186. return;
  187. }
  188. this.$u.api
  189. .updateShippingAddress(this.coustrom_id, {
  190. name: this.addressData.name,
  191. mobile: mobile,
  192. provinceCode: this.addressData.provinceCode,
  193. cityCode: this.addressData.cityCode,
  194. districtCode: this.addressData.districtCode,
  195. address: this.addressData.address,
  196. defaultStatus: this.addressData.defaultStatus
  197. })
  198. .then(res => {
  199. this.$api.msg('修改成功');
  200. setTimeout(function() {
  201. uni.navigateBack();
  202. }, 800);
  203. });
  204. }
  205. }
  206. };
  207. </script>
  208. <style lang="scss">
  209. page {
  210. background: $page-color-base;
  211. padding-top: 16upx;
  212. }
  213. .row {
  214. display: flex;
  215. align-items: center;
  216. position: relative;
  217. padding: 0 30upx;
  218. height: 110upx;
  219. background: #fff;
  220. .tit {
  221. flex-shrink: 0;
  222. width: 120upx;
  223. font-size: 30upx;
  224. color: $font-color-dark;
  225. }
  226. .input {
  227. flex: 1;
  228. font-size: 30upx;
  229. color: $font-color-dark;
  230. }
  231. .icon-shouhuodizhi {
  232. font-size: 36upx;
  233. color: $font-color-light;
  234. }
  235. }
  236. .default-row {
  237. margin-top: 16upx;
  238. .tit {
  239. flex: 1;
  240. }
  241. switch {
  242. transform: translateX(16upx) scale(0.9);
  243. }
  244. }
  245. .add-btn {
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. width: 690upx;
  250. height: 80upx;
  251. margin: 60upx auto;
  252. font-size: $font-lg;
  253. color: #fff;
  254. border-radius: 10upx;
  255. }
  256. .add-btn:after {
  257. border: 0 none;
  258. }
  259. </style>