addressManage.vue 8.1 KB

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