addressManage.vue 6.0 KB

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