addressManage.vue 5.1 KB

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