addressManage.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. <!-- <picker mode="multiSelector" :range="arrDate" @change="cityChange">
  14. <view>{{ addressDetail || '请选择地址(点击选择地址)' }}</view>
  15. </picker> -->
  16. <pickerAddress class="input" @change="onCityClick">{{ addressDetail || '请选择地址(点击选择地址)' }}</pickerAddress>
  17. </view>
  18. <view class="row b-b" @click="clickMap">
  19. <text class="tit">定位</text>
  20. <input class="input" type="text" v-model="addressLocation.name" disabled="disabled" placeholder="请在列表选择要定位的地址" placeholder-class="placeholder" />
  21. <text class="iconfont iconlocation"></text>
  22. </view>
  23. <view class="row b-b">
  24. <text class="tit">门牌号</text>
  25. <input class="input" type="text" v-model="addressData.area" placeholder="请填写精确地址方便快速送到" placeholder-class="placeholder" />
  26. </view>
  27. <uni-list class="margin-t-20">
  28. <uni-list-item
  29. title="设为默认"
  30. :switch-checked="addressData.default"
  31. :show-switch="true"
  32. :show-arrow="false"
  33. switch-color="#5dbc7c"
  34. @switchChange="switchChange"
  35. ></uni-list-item>
  36. </uni-list>
  37. <button class="add-btn" @click="confirm">提交</button>
  38. </view>
  39. </template>
  40. <script>
  41. import uniList from '@/components/uni-list/uni-list.vue';
  42. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  43. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  44. import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue';
  45. import { addressEdit } from '@/api/address.js';
  46. import { openMap } from '@/utils/rocessor.js';
  47. export default {
  48. components: {
  49. uniList,
  50. uniListItem,
  51. pickerAddress,
  52. uniPopup
  53. },
  54. data() {
  55. return {
  56. addressDetail: '',
  57. addressData: {
  58. name: '',
  59. mobile: '',
  60. address: {
  61. province: '',
  62. city: '',
  63. district: ''
  64. },
  65. area: '',
  66. default: false
  67. },
  68. // 定位地址
  69. addressLocation: {
  70. name: '',
  71. address: '',
  72. errMsg: 'chooseLocation:ok',
  73. latitude: '',
  74. longitude: '',
  75. name: '',
  76. // 判断是否地址选择页进入
  77. isIndex: false
  78. },
  79. arrDate:[
  80. ['浙江省'],
  81. ['台州市'],
  82. ['椒江区','黄岩区','路桥区','温岭市','临海市','玉环县'],
  83. ],
  84. };
  85. },
  86. onLoad(option) {
  87. let title = '新增收货地址';
  88. // #ifdef MP
  89. // 获取地图权限
  90. uni.authorize({
  91. scope: 'scope.userLocation',
  92. success: res => {}
  93. });
  94. // #endif
  95. if (option.isIndex == 3) {
  96. this.isIndex = true;
  97. }
  98. if (option.type === 'edit') {
  99. title = '编辑收货地址';
  100. let data = JSON.parse(option.data);
  101. console.log(data);
  102. this.addressData = {
  103. name: data.real_name,
  104. mobile: data.phone,
  105. address: {
  106. province: data.province,
  107. city: data.city,
  108. district: data.district
  109. },
  110. area: data.detail,
  111. default: data.is_default == 1,
  112. id: data.id
  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. clickMap() {
  124. uni.showLoading({
  125. title: '加载中'
  126. });
  127. let obj = this;
  128. // #ifndef APP-PLUS
  129. openMap().then(() => {
  130. uni.hideLoading();
  131. uni.getLocation({
  132. type: 'gcj02',
  133. success(e) {
  134. uni.chooseLocation({
  135. latitude: e.latitude,
  136. longitude: e.longitude,
  137. success(e) {
  138. obj.addressLocation = e;
  139. },
  140. fail(e) {
  141. uni.showModal({
  142. title:'地址选择错误',
  143. content:JSON.parse(e)
  144. })
  145. console.log(e);
  146. }
  147. });
  148. },fail(e) {
  149. uni.showModal({
  150. title:'定位错误',
  151. content:JSON.parse(e)
  152. })
  153. }
  154. });
  155. })
  156. .catch(e => {
  157. console.log(e)
  158. uni.hideLoading();
  159. uni.showModal({
  160. title: '提示',
  161. content: '您未授权无法调用地图定位功能!',
  162. showCancel: false
  163. });
  164. });
  165. // #endif
  166. // #ifdef APP-PLUS
  167. uni.hideLoading();
  168. uni.getLocation({
  169. type: 'gcj02',
  170. success(e) {
  171. uni.chooseLocation({
  172. latitude: e.latitude,
  173. longitude: e.longitude,
  174. success(e) {
  175. obj.addressLocation = e;
  176. },
  177. fail(e) {
  178. uni.showModal({
  179. title:'地址选择错误',
  180. content:JSON.parse(e)
  181. })
  182. console.log(e);
  183. }
  184. });
  185. },fail(e) {
  186. uni.showModal({
  187. title:'定位错误',
  188. content:JSON.parse(e)
  189. })
  190. }
  191. });
  192. // uni.chooseLocation()
  193. // #endif
  194. },
  195. // 选中城市切换
  196. onCityClick({ data }) {
  197. let address = this.addressData.address;
  198. address.province = data[0];
  199. address.city = data[1];
  200. address.district = data[2];
  201. this.addressDetail = data.join(',');
  202. },
  203. // 选择地址
  204. cityChange:function(e) {
  205. console.log(e)
  206. let address = this.addressData.address;
  207. let type1 = e.detail.value[0];
  208. let type2 = e.detail.value[1];
  209. let type3 = e.detail.value[2];
  210. address.province = this.arrDate[0][type1];
  211. console.log(address.province)
  212. address.city = this.arrDate[1][type2];
  213. console.log(address.city)
  214. address.district = this.arrDate[2][type3];
  215. console.log(address.district)
  216. this.addressDetail = address.province + ' ' + address.city + ' ' + address.district;
  217. },
  218. // 设置是否为默认地址
  219. switchChange(e) {
  220. this.addressData.default = e.value;
  221. },
  222. //提交
  223. confirm() {
  224. let obj = this;
  225. let data = this.addressData;
  226. if (!data.name) {
  227. this.$api.msg('请填写收货人姓名');
  228. return;
  229. }
  230. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)) {
  231. this.$api.msg('请输入正确的手机号码');
  232. return;
  233. }
  234. if (!data.address) {
  235. this.$api.msg('请在地图选择所在位置');
  236. return;
  237. }
  238. if (!data.area) {
  239. this.$api.msg('请填写门牌号信息');
  240. return;
  241. }
  242. if(data.area.length<4){
  243. this.$api.msg('请填写具体信息精确到门牌号');
  244. return;
  245. }
  246. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  247. addressEdit({
  248. type: 1,
  249. real_name: data.name,
  250. phone: data.mobile,
  251. address: {
  252. province: data.address.province,
  253. city: data.address.city,
  254. district: data.address.district
  255. },
  256. detail: obj.addressLocation.name + ',' + data.area,
  257. is_default: data.default,
  258. id: data.id || '',
  259. longitude: obj.addressLocation.longitude,
  260. latitude: obj.addressLocation.latitude,
  261. }).then(function(e) {
  262. uni.showToast({
  263. title: '提交成功',
  264. duration: 2000,
  265. icon: 'none'
  266. });
  267. setTimeout(function() {
  268. console.log('返回');
  269. uni.navigateBack();
  270. }, 800);
  271. obj.$api.prePage().refreshList();
  272. });
  273. }
  274. }
  275. };
  276. </script>
  277. <style lang="scss">
  278. page {
  279. background: $page-color-base;
  280. padding-top: 16rpx;
  281. }
  282. .row {
  283. display: flex;
  284. align-items: center;
  285. position: relative;
  286. padding: 0 30rpx;
  287. height: 110rpx;
  288. background: #fff;
  289. .tit {
  290. flex-shrink: 0;
  291. width: 120rpx;
  292. font-size: 30rpx;
  293. color: $font-color-dark;
  294. }
  295. .input {
  296. flex: 1;
  297. font-size: 30rpx;
  298. color: $font-color-dark;
  299. }
  300. .iconlocation {
  301. font-size: 36rpx;
  302. color: $font-color-light;
  303. }
  304. }
  305. .default-row {
  306. margin-top: 16rpx;
  307. .tit {
  308. flex: 1;
  309. }
  310. switch {
  311. transform: translateX(16rpx) scale(0.9);
  312. }
  313. }
  314. .add-btn {
  315. display: flex;
  316. align-items: center;
  317. justify-content: center;
  318. width: 690rpx;
  319. height: 80rpx;
  320. margin: 60rpx auto;
  321. font-size: $font-lg;
  322. color: #fff;
  323. background-color: $base-color;
  324. border-radius: 10rpx;
  325. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  326. }
  327. .alert-box {
  328. background-color: #ffffff;
  329. }
  330. </style>