addPinkManage.vue 7.3 KB

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