addressManage.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. console.log(data);
  87. this.addressData = {
  88. name: data.real_name,
  89. mobile: data.phone,
  90. address: {
  91. province: data.province,
  92. city: data.city,
  93. district: data.district
  94. },
  95. area: data.detail,
  96. default: data.is_default == 1,
  97. id: data.id
  98. };
  99. this.addressDetail = data.province + data.city + data.district;
  100. }
  101. this.manageType = option.type;
  102. uni.setNavigationBarTitle({
  103. title
  104. });
  105. },
  106. methods: {
  107. // 选中城市切换
  108. onCityClick({
  109. data
  110. }) {
  111. let address = this.addressData.address;
  112. address.province = data[0];
  113. address.city = data[1];
  114. address.district = data[2];
  115. this.addressDetail = data.join('');
  116. },
  117. //地图选择地址
  118. chooseLocation() {
  119. uni.chooseLocation({
  120. success: data => {
  121. console.log(data);
  122. this.addressData.addressName = data.name;
  123. this.addressData.address = data.name;
  124. }
  125. });
  126. },
  127. // 设置是否为默认地址
  128. switchChange(e) {
  129. this.addressData.default = e.value;
  130. },
  131. //提交
  132. confirm() {
  133. let obj = this;
  134. let data = this.addressData;
  135. if (!data.name) {
  136. this.$api.msg('请填写收货人姓名');
  137. return;
  138. }
  139. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)) {
  140. this.$api.msg('请输入正确的手机号码');
  141. return;
  142. }
  143. if (!data.address) {
  144. this.$api.msg('请在地图选择所在位置');
  145. return;
  146. }
  147. if (!data.area) {
  148. this.$api.msg('请填写门牌号信息');
  149. return;
  150. }
  151. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  152. addressEdit({
  153. real_name: data.name,
  154. phone: data.mobile,
  155. address: {
  156. province: data.address.province,
  157. city: data.address.city,
  158. district: data.address.district
  159. },
  160. detail: data.area,
  161. is_default: data.default,
  162. id: data.id || "",
  163. type: 1
  164. }).then(function(e) {
  165. obj.$api.prePage().refreshList();
  166. uni.showToast({
  167. title: '提交成功',
  168. duration: 2000
  169. });
  170. setTimeout(function() {
  171. uni.navigateBack();
  172. }, 800);
  173. });
  174. }
  175. }
  176. };
  177. </script>
  178. <style lang="scss">
  179. page {
  180. background: $page-color-base;
  181. }
  182. .content{
  183. padding-top: 30rpx;
  184. }
  185. .listBox {
  186. margin: 0 $page-row-spacing;
  187. border-radius: 20rpx;
  188. overflow: hidden;
  189. background-color: #FFFFFF;
  190. }
  191. .list {
  192. .input {
  193. text-align: right;
  194. font-size: $font-base;
  195. color: $color-gray;
  196. width: 100%;
  197. flex-grow: 1;
  198. }
  199. .listItem {
  200. padding: 35rpx 40rpx;
  201. border-bottom: 1px solid $page-color-light;
  202. }
  203. .listIconImg {
  204. width: 36rpx;
  205. }
  206. .right {
  207. color: $font-color-light;
  208. font-size: $font-base;
  209. flex-grow: 1;
  210. .img {
  211. width: 26rpx;
  212. }
  213. .code {}
  214. }
  215. .titleBox {
  216. .title {
  217. color: $font-color-base;
  218. font-size: $font-base;
  219. }
  220. }
  221. }
  222. </style>