addressManage.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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" @click="onLatlngClick">
  17. <text class="tit">经纬度</text>
  18. <text>{{ latlng || '请选择经纬度' }}</text>
  19. </view> -->
  20. <view class="row b-b">
  21. <text class="tit">详细地址</text>
  22. <input class="input" type="text" v-model="addressData.area" placeholder="街道、小区、楼号、门牌" placeholder-class="placeholder" />
  23. </view>
  24. <uni-list class="margin-t-20">
  25. <uni-list-item
  26. title="设为默认"
  27. :switch-checked="addressData.default"
  28. :show-switch="true"
  29. :show-arrow="false"
  30. switch-color="#ee2f72"
  31. @switchChange="switchChange"
  32. ></uni-list-item>
  33. </uni-list>
  34. <!-- <view class="del-btn" v-if="showDel"><text @click="delAddr">删除地址</text></view> -->
  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 } from '@/api/user.js';
  44. export default {
  45. components: {
  46. uniList,
  47. uniListItem,
  48. pickerAddress,
  49. uniPopup
  50. },
  51. data() {
  52. return {
  53. detail_address: '',
  54. addressDetail: '',
  55. addressData: {
  56. name: '',
  57. mobile: '',
  58. address: {
  59. province: '',
  60. city: '',
  61. district: ''
  62. },
  63. area: '',
  64. default: false,
  65. latitude: '',
  66. longitude: ''
  67. }
  68. };
  69. },
  70. computed: {
  71. latlng() {
  72. let str = '';
  73. if (this.addressData.latitude !== '' && this.addressData.longitude !== '') {
  74. str = this.addressData.latitude + ' , ' + this.addressData.longitude;
  75. }
  76. return str;
  77. }
  78. },
  79. onLoad(option) {
  80. let title = '新增收货地址';
  81. if (option.type === 'edit') {
  82. title = '编辑收货地址';
  83. let data = JSON.parse(option.data);
  84. console.log(data);
  85. this.addressData = {
  86. name: data.real_name,
  87. mobile: data.phone,
  88. address: {
  89. province: data.province,
  90. city: data.city,
  91. district: data.district
  92. },
  93. area: data.detail,
  94. default: data.is_default == 1,
  95. id: data.id,
  96. latitude: '',
  97. longitude: ''
  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({ data }) {
  109. let address = this.addressData.address;
  110. address.province = data[0];
  111. address.city = data[1];
  112. address.district = data[2];
  113. this.addressDetail = data.join('');
  114. },
  115. onLatlngClick() {
  116. let obj = this;
  117. console.log('选择经纬度');
  118. wx.chooseLocation({
  119. success(res) {
  120. console.log(res, '地图选择');
  121. if (res.address == '') {
  122. obj.$api.msg('请选择地址');
  123. } else {
  124. obj.$set(obj.addressData, 'latitude', res.latitude);
  125. obj.$set(obj.addressData, 'longitude', res.longitude);
  126. obj.$set(obj, 'detail_address', res.address);
  127. }
  128. }
  129. });
  130. },
  131. //地图选择地址
  132. chooseLocation() {
  133. uni.chooseLocation({
  134. success: data => {
  135. console.log(data);
  136. this.addressData.addressName = data.name;
  137. this.addressData.address = data.name;
  138. }
  139. });
  140. },
  141. // 设置是否为默认地址
  142. switchChange(e) {
  143. this.addressData.default = e.value;
  144. },
  145. //提交
  146. confirm() {
  147. let obj = this;
  148. let data = this.addressData;
  149. if (!data.name) {
  150. this.$api.msg('请填写收货人姓名');
  151. return;
  152. }
  153. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)) {
  154. this.$api.msg('请输入正确的手机号码');
  155. return;
  156. }
  157. if (!data.address) {
  158. this.$api.msg('请在地图选择所在位置');
  159. return;
  160. }
  161. if (!data.area) {
  162. this.$api.msg('请填写门牌号信息');
  163. return;
  164. }
  165. // if (!data.latitude || !data.longitude) {
  166. // this.$api.msg('请选择经纬度');
  167. // return;
  168. // }
  169. // if (obj.detail_address.indexOf(data.address.province) == -1) {
  170. // this.$api.msg('地址和经纬度不一致');
  171. // return;
  172. // }
  173. // if (obj.detail_address.indexOf(data.address.city) == -1) {
  174. // this.$api.msg('地址和经纬度不一致');
  175. // return;
  176. // }
  177. // if (obj.detail_address.indexOf(data.address.district) == -1) {
  178. // this.$api.msg('地址和经纬度不一致');
  179. // return;
  180. // }
  181. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  182. addressEdit({
  183. real_name: data.name,
  184. phone: data.mobile,
  185. address: {
  186. province: data.address.province,
  187. city: data.address.city,
  188. district: data.address.district
  189. },
  190. detail: data.area,
  191. is_default: data.default,
  192. id: data.id || '',
  193. type: 1,
  194. latitude: data.latitude,
  195. longitude: data.longitude
  196. }).then(function(e) {
  197. obj.$api.prePage().refreshList();
  198. uni.showToast({
  199. title: '提交成功',
  200. duration: 2000
  201. });
  202. setTimeout(function() {
  203. uni.navigateBack();
  204. }, 800);
  205. });
  206. }
  207. }
  208. };
  209. </script>
  210. <style lang="scss">
  211. page {
  212. background: $page-color-base;
  213. padding-top: 16rpx;
  214. }
  215. .row {
  216. display: flex;
  217. align-items: center;
  218. position: relative;
  219. padding: 0 30rpx;
  220. height: 110rpx;
  221. background: #fff;
  222. .tit {
  223. flex-shrink: 0;
  224. width: 140rpx;
  225. font-size: 30rpx;
  226. color: $font-color-dark;
  227. }
  228. .input {
  229. flex: 1;
  230. font-size: 30rpx;
  231. color: $font-color-dark;
  232. }
  233. .iconlocation {
  234. font-size: 36rpx;
  235. color: $font-color-light;
  236. }
  237. }
  238. .default-row {
  239. margin-top: 16rpx;
  240. .tit {
  241. flex: 1;
  242. }
  243. switch {
  244. transform: translateX(16rpx) scale(0.9);
  245. }
  246. }
  247. .del-btn {
  248. width: 750rpx;
  249. height: 99rpx;
  250. margin-top: 28rpx;
  251. font-size: 30rpx;
  252. font-weight: 500;
  253. color: #901b21;
  254. background-color: #fff;
  255. line-height: 99rpx;
  256. padding-left: 42rpx;
  257. }
  258. .add-btn {
  259. display: flex;
  260. align-items: center;
  261. justify-content: center;
  262. width: 690rpx;
  263. height: 80rpx;
  264. margin: 60rpx auto;
  265. font-size: $font-lg;
  266. color: #fff;
  267. background-color: $base-color;
  268. border-radius: 10rpx;
  269. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  270. }
  271. .alert-box {
  272. background-color: #ffffff;
  273. }
  274. </style>