addressManage.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. let arr = data.detail.split(',')
  103. let len = arr.length - 1
  104. this.addressLocation.name = arr[0]
  105. this.addressLocation.latitude = data.latitude
  106. this.addressLocation.longitude = data.longitude
  107. this.addressData = {
  108. name: data.real_name,
  109. mobile: data.phone,
  110. address: {
  111. province: data.province,
  112. city: data.city,
  113. district: data.district
  114. },
  115. area: data.detail.split(',')[len],
  116. default: data.is_default == 1,
  117. id: data.id
  118. };
  119. this.addressDetail = data.province + data.city + data.district;
  120. }
  121. this.manageType = option.type;
  122. uni.setNavigationBarTitle({
  123. title
  124. });
  125. },
  126. methods: {
  127. // 选中经纬度
  128. clickMap() {
  129. uni.showLoading({
  130. title: '加载中'
  131. });
  132. let obj = this;
  133. // #ifndef APP-PLUS
  134. uni.chooseLocation({
  135. type: 'gcj02',
  136. success: function(res) {
  137. obj.addressLocation.name = res.name;
  138. console.log('位置名称:' + res.name);
  139. console.log('详细地址:' + res.address);
  140. console.log('纬度:' + res.latitude);
  141. console.log('经度:' + res.longitude);
  142. obj.addressLocation.latitude = res.latitude;
  143. obj.addressLocation.longitude = res.longitude;
  144. }
  145. });
  146. // #endif
  147. // #ifdef APP-PLUS
  148. uni.hideLoading();
  149. uni.getLocation({
  150. type: 'gcj02',
  151. success(e) {
  152. uni.chooseLocation({
  153. latitude: e.latitude,
  154. longitude: e.longitude,
  155. success(e) {
  156. obj.addressLocation = e;
  157. console.log(e,"123456")
  158. },
  159. fail(e) {
  160. uni.showModal({
  161. title:'地址选择错误',
  162. content:JSON.parse(e)
  163. })
  164. console.log(e);
  165. }
  166. });
  167. },fail(e) {
  168. uni.showModal({
  169. title:'定位错误',
  170. content:JSON.parse(e)
  171. })
  172. }
  173. });
  174. // uni.chooseLocation()
  175. // #endif
  176. },
  177. // 选中城市切换
  178. onCityClick({ data }) {
  179. let address = this.addressData.address;
  180. address.province = data[0];
  181. address.city = data[1];
  182. address.district = data[2];
  183. this.addressDetail = data.join(',');
  184. },
  185. // 选择地址
  186. cityChange:function(e) {
  187. console.log(e)
  188. let address = this.addressData.address;
  189. let type1 = e.detail.value[0];
  190. let type2 = e.detail.value[1];
  191. let type3 = e.detail.value[2];
  192. address.province = this.arrDate[0][type1];
  193. console.log(address.province)
  194. address.city = this.arrDate[1][type2];
  195. console.log(address.city)
  196. address.district = this.arrDate[2][type3];
  197. console.log(address.district)
  198. this.addressDetail = address.province + ' ' + address.city + ' ' + address.district;
  199. },
  200. // 设置是否为默认地址
  201. switchChange(e) {
  202. this.addressData.default = e.value;
  203. },
  204. //提交
  205. confirm() {
  206. let obj = this;
  207. let data = this.addressData;
  208. if (!data.name) {
  209. this.$api.msg('请填写收货人姓名');
  210. return;
  211. }
  212. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)) {
  213. this.$api.msg('请输入正确的手机号码');
  214. return;
  215. }
  216. if (!data.address) {
  217. this.$api.msg('请在地图选择所在位置');
  218. return;
  219. }
  220. if (!data.area) {
  221. this.$api.msg('请填写门牌号信息');
  222. return;
  223. }
  224. if(data.area.length<4){
  225. this.$api.msg('请填写具体信息精确到门牌号');
  226. return;
  227. }
  228. if(obj.addressLocation.longitude == '') {
  229. this.$api.msg('请选择正确的定位地址');
  230. return;
  231. }
  232. if(obj.addressLocation.latitude == '') {
  233. this.$api.msg('请选择正确的定位地址');
  234. return;
  235. }
  236. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  237. addressEdit({
  238. type: 1,
  239. real_name: data.name,
  240. phone: data.mobile,
  241. address: {
  242. province: data.address.province,
  243. city: data.address.city,
  244. district: data.address.district
  245. },
  246. detail: obj.addressLocation.name + ',' + data.area,
  247. is_default: data.default,
  248. id: data.id || '',
  249. longitude: obj.addressLocation.longitude,
  250. latitude: obj.addressLocation.latitude,
  251. }).then(function(e) {
  252. uni.showToast({
  253. title: '提交成功',
  254. duration: 2000,
  255. icon: 'none'
  256. });
  257. setTimeout(function() {
  258. console.log('返回');
  259. uni.navigateBack();
  260. }, 800);
  261. obj.$api.prePage().refreshList();
  262. });
  263. }
  264. }
  265. };
  266. </script>
  267. <style lang="scss">
  268. page {
  269. background: $page-color-base;
  270. padding-top: 16rpx;
  271. }
  272. .row {
  273. display: flex;
  274. align-items: center;
  275. position: relative;
  276. padding: 0 30rpx;
  277. height: 110rpx;
  278. background: #fff;
  279. .tit {
  280. flex-shrink: 0;
  281. width: 120rpx;
  282. font-size: 30rpx;
  283. color: $font-color-dark;
  284. }
  285. .input {
  286. flex: 1;
  287. font-size: 30rpx;
  288. color: $font-color-dark;
  289. }
  290. .iconlocation {
  291. font-size: 36rpx;
  292. color: $font-color-light;
  293. }
  294. }
  295. .default-row {
  296. margin-top: 16rpx;
  297. .tit {
  298. flex: 1;
  299. }
  300. switch {
  301. transform: translateX(16rpx) scale(0.9);
  302. }
  303. }
  304. .add-btn {
  305. display: flex;
  306. align-items: center;
  307. justify-content: center;
  308. width: 690rpx;
  309. height: 80rpx;
  310. margin: 60rpx auto;
  311. font-size: $font-lg;
  312. color: #fff;
  313. background-color: $base-color;
  314. border-radius: 10rpx;
  315. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  316. }
  317. .alert-box {
  318. background-color: #ffffff;
  319. }
  320. </style>