addressManage.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view 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. <input class="input" type="number" v-model="addressData.mobile" placeholder="收货人手机号码" placeholder-class="placeholder" />
  10. </view>
  11. <view class="row b-b">
  12. <text class="tit">地址</text>
  13. <pickerAddress class="input" @change="onCityClick">{{ addressDetail || '请选择地址' }}</pickerAddress>
  14. <text class="iconfont iconlocation"></text>
  15. </view>
  16. <view class="row b-b" v-if="addressDetail">
  17. <text class="tit">选择镇</text>
  18. <picker :range="twonlist" range-key="name" class="input" @change="onTwonClick">{{ twon || '请选择镇' }}</picker>
  19. <text class="iconfont iconlocation"></text>
  20. </view>
  21. <view class="row b-b">
  22. <text class="tit">门牌号</text>
  23. <input class="input" type="text" v-model="addressData.area" placeholder="楼号、门牌" placeholder-class="placeholder" />
  24. </view>
  25. <uni-list class="margin-t-20">
  26. <uni-list-item
  27. title="设为默认"
  28. :switch-checked="addressData.default"
  29. :show-switch="true"
  30. :show-arrow="false"
  31. switch-color="#5dbc7c"
  32. @switchChange="switchChange"
  33. ></uni-list-item>
  34. </uni-list>
  35. <button class="add-btn" @click="confirm">提交</button>
  36. </view>
  37. </template>
  38. <script>
  39. import uniList from '@/components/uni-list/uni-list.vue';
  40. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  41. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  42. import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue';
  43. import { addressEdit, city_lists } from '@/api/user.js';
  44. export default {
  45. components: {
  46. uniList,
  47. uniListItem,
  48. pickerAddress,
  49. uniPopup
  50. },
  51. data() {
  52. return {
  53. twon: '',
  54. twonlist: [],
  55. addressDetail: '',
  56. addressData: {
  57. name: '',
  58. mobile: '',
  59. address: {
  60. province: '',
  61. city: '',
  62. district: ''
  63. },
  64. area: '',
  65. default: false
  66. }
  67. };
  68. },
  69. onLoad(option) {
  70. let title = '新增收货地址';
  71. if (option.type === 'edit') {
  72. title = '编辑收货地址';
  73. let data = JSON.parse(option.data);
  74. console.log(data);
  75. this.addressData = {
  76. name: data.real_name,
  77. mobile: data.phone,
  78. address: {
  79. province: data.province,
  80. city: data.city,
  81. district: data.district
  82. },
  83. area: data.detail,
  84. default: data.is_default == 1,
  85. id: data.id
  86. };
  87. this.twon = data.town;
  88. this.chooseTwon(data.district);
  89. this.addressDetail = data.province + data.city + data.district;
  90. }
  91. this.manageType = option.type;
  92. uni.setNavigationBarTitle({
  93. title
  94. });
  95. },
  96. methods: {
  97. // 选中城市切换
  98. onCityClick({ data }) {
  99. let address = this.addressData.address;
  100. address.province = data[0];
  101. address.city = data[1];
  102. address.district = data[2];
  103. this.addressDetail = data.join('');
  104. this.chooseTwon(address.district);
  105. },
  106. onTwonClick(e) {
  107. this.twon = this.twonlist[e.detail.value].name;
  108. },
  109. chooseTwon(add) {
  110. city_lists({ address: add }).then(({ data }) => {
  111. this.twonlist = data;
  112. });
  113. },
  114. //地图选择地址
  115. chooseLocation() {
  116. uni.chooseLocation({
  117. success: data => {
  118. console.log(data);
  119. this.addressData.addressName = data.name;
  120. this.addressData.address = data.name;
  121. }
  122. });
  123. },
  124. // 设置是否为默认地址
  125. switchChange(e) {
  126. this.addressData.default = e.value;
  127. },
  128. //提交
  129. confirm() {
  130. let obj = this;
  131. let data = this.addressData;
  132. if (!data.name) {
  133. this.$api.msg('请填写收货人姓名');
  134. return;
  135. }
  136. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)) {
  137. this.$api.msg('请输入正确的手机号码');
  138. return;
  139. }
  140. if (!data.address) {
  141. this.$api.msg('请在地图选择所在位置');
  142. return;
  143. }
  144. if (!obj.twon) {
  145. this.$api.msg('请选择所在的镇');
  146. return;
  147. }
  148. if (!data.area) {
  149. this.$api.msg('请填写门牌号信息');
  150. return;
  151. }
  152. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  153. addressEdit({
  154. town: obj.twon,
  155. real_name: data.name,
  156. phone: data.mobile,
  157. address: {
  158. province: data.address.province,
  159. city: data.address.city,
  160. district: data.address.district
  161. },
  162. detail: data.area,
  163. is_default: data.default,
  164. id: data.id || '',
  165. type: 1
  166. }).then(function(e) {
  167. obj.$api.prePage().refreshList();
  168. uni.showToast({
  169. title: '提交成功',
  170. duration: 2000
  171. });
  172. setTimeout(function() {
  173. uni.navigateBack();
  174. }, 800);
  175. });
  176. }
  177. }
  178. };
  179. </script>
  180. <style lang="scss">
  181. page {
  182. background: $page-color-base;
  183. padding-top: 16rpx;
  184. }
  185. .row {
  186. display: flex;
  187. align-items: center;
  188. position: relative;
  189. padding: 0 30rpx;
  190. height: 110rpx;
  191. background: #fff;
  192. .tit {
  193. flex-shrink: 0;
  194. width: 120rpx;
  195. font-size: 30rpx;
  196. color: $font-color-dark;
  197. }
  198. .input {
  199. flex: 1;
  200. font-size: 30rpx;
  201. color: $font-color-dark;
  202. }
  203. .iconlocation {
  204. font-size: 36rpx;
  205. color: $font-color-light;
  206. }
  207. }
  208. .default-row {
  209. margin-top: 16rpx;
  210. .tit {
  211. flex: 1;
  212. }
  213. switch {
  214. transform: translateX(16rpx) scale(0.9);
  215. }
  216. }
  217. .add-btn {
  218. display: flex;
  219. align-items: center;
  220. justify-content: center;
  221. width: 690rpx;
  222. height: 80rpx;
  223. margin: 60rpx auto;
  224. font-size: $font-lg;
  225. color: #fff;
  226. background-color: $base-color;
  227. border-radius: 10rpx;
  228. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  229. }
  230. .alert-box {
  231. background-color: #ffffff;
  232. }
  233. </style>