addressManage.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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" @click="openAddress()">
  33. <text class="title">定位</text>
  34. </view>
  35. <view class="right flex" @click="openAddress()">
  36. <input class="input" type="text" v-model="addressData.locate_address" placeholder="请选择定位"
  37. placeholder-class="placeholder" />
  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. console.log('dakaiditu')
  135. uni.chooseLocation({
  136. latitude:uni.getStorageSync('CACHE_LATITUDE'),
  137. longitude: uni.getStorageSync('CACHE_LONGITUDE'),
  138. success: data => {
  139. console.log(data);
  140. this.addressData.area = data.name;
  141. this.addressData.locate_address = data.address;
  142. this.addressData.longitude = data.longitude;
  143. this.addressData.latitude = data.latitude;
  144. },
  145. fail(err) {
  146. cosole.log(err,'errr')
  147. }
  148. });
  149. },
  150. // 设置是否为默认地址
  151. switchChange(e) {
  152. this.addressData.default = e.detail.value?1:0;
  153. },
  154. //提交
  155. confirm() {
  156. let obj = this;
  157. let data = this.addressData;
  158. if (!data.name) {
  159. this.$api.msg('请填写收货人姓名');
  160. return;
  161. }
  162. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)) {
  163. this.$api.msg('请输入正确的手机号码');
  164. return;
  165. }
  166. if (!data.address) {
  167. this.$api.msg('请在地图选择所在位置');
  168. return;
  169. }
  170. if (!data.area) {
  171. this.$api.msg('请填写门牌号信息');
  172. return;
  173. }
  174. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  175. addressEdit({
  176. real_name: data.name,
  177. phone: data.mobile,
  178. address: {
  179. province: data.address.province,
  180. city: data.address.city,
  181. district: data.address.district
  182. },
  183. detail: data.area,
  184. is_default: data.default,
  185. id: data.id || "",
  186. type: 1,
  187. longitude: data.longitude, //经度
  188. latitude:data.latitude, //纬度
  189. locate_address:data.locate_address
  190. }).then(function(e) {
  191. obj.$api.prePage().refreshList();
  192. uni.showToast({
  193. title: '提交成功',
  194. duration: 2000
  195. });
  196. setTimeout(function() {
  197. uni.navigateBack();
  198. }, 800);
  199. });
  200. }
  201. }
  202. };
  203. </script>
  204. <style lang="scss">
  205. page {
  206. background: $page-color-base;
  207. }
  208. .content{
  209. padding-top: 30rpx;
  210. }
  211. .listBox {
  212. margin: 0 $page-row-spacing;
  213. border-radius: 20rpx;
  214. overflow: hidden;
  215. background-color: #FFFFFF;
  216. }
  217. .list {
  218. .input {
  219. text-align: right;
  220. font-size: $font-base;
  221. color: $color-gray;
  222. width: 100%;
  223. flex-grow: 1;
  224. }
  225. .listItem {
  226. padding: 35rpx 40rpx;
  227. border-bottom: 1px solid $page-color-light;
  228. }
  229. .listIconImg {
  230. width: 36rpx;
  231. }
  232. .right {
  233. color: $font-color-light;
  234. font-size: $font-base;
  235. flex-grow: 1;
  236. .img {
  237. width: 26rpx;
  238. }
  239. .code {}
  240. }
  241. .titleBox {
  242. margin-right: 10rpx;
  243. .title {
  244. color: $font-color-base;
  245. font-size: $font-base;
  246. }
  247. }
  248. }
  249. </style>