address-edit.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <template>
  2. <app-layout>
  3. <view class="app-view">
  4. <!-- 自动识别功能 -->
  5. <!-- <view class="automatic dir-left-nowrap cross-center main-between">
  6. <input type="text" v-model="automatic" placeholder-class="place-automatic"
  7. placeholder="复制收货信息(姓名前后请输入空格)" @confirm="getAddress">
  8. <button @click="getAddress">自动识别</button>
  9. </view> -->
  10. <view class="app-line app-border main-between cross-center">
  11. <text class="app-text box-grow-0">参训人</text>
  12. <input class="address-input" type="text" v-model="form.name" />
  13. </view>
  14. <view class="app-line app-border main-between cross-center">
  15. <text class="app-text box-grow-0">性别</text>
  16. <input class="address-input" type="text" v-model="form.name" />
  17. </view>
  18. <view class="app-line app-border main-between cross-center">
  19. <text class="app-text box-grow-0">联系电话</text>
  20. <input class="address-input" type="number" v-model="form.mobile" />
  21. </view>
  22. <view class="app-line app-border main-between cross-center">
  23. <text class="app-text box-grow-0">年龄</text>
  24. <input class="address-input" type="number" v-model="form.mobile" />
  25. </view>
  26. <view class="app-line app-border main-between cross-center">
  27. <text class="app-text box-grow-0">体重</text>
  28. <input class="address-input" type="number" v-model="form.mobile" />
  29. </view>
  30. <view class="app-line app-border main-between cross-center">
  31. <text class="app-text box-grow-0">身高</text>
  32. <input class="address-input" type="number" v-model="form.mobile" />
  33. </view>
  34. <view class="app-line app-border main-between cross-center">
  35. <text class="app-text box-grow-0">身份证号码</text>
  36. <input class="address-input" type="number" v-model="form.mobile" />
  37. </view>
  38. <!-- <view class="app-line app-border main-between cross-center">
  39. <text class="app-text box-grow-0">所在地区</text>
  40. <view class="box-grow-1 area-left">
  41. <app-area-picker v-if="tt_area_show"
  42. @customevent="areaEvent"
  43. :ids="[form.province_id,form.city_id,form.district_id]"></app-area-picker>
  44. </view>
  45. </view> -->
  46. <!-- #ifndef MP-TOUTIAO -->
  47. <!-- <view v-if="is_refund_address == 0" class="app-line app-border main-between cross-center">
  48. <text class="app-text box-grow-0">定位地址</text>
  49. <view class="h-100 main-right dir-left-nowrap cross-center box-grow-1" @click="getChooseLocation">
  50. <view class="box-grow-0 c-address">{{form.location}}</view>
  51. <icon class="box-grow-0 icon-arrow-image"></icon>
  52. </view>
  53. </view> -->
  54. <!-- #endif -->
  55. <!-- <view class="app-line main-between cross-center">
  56. <text class="app-text box-grow-0">详细地址</text>
  57. <input class="address-input" type="text" :focus="focus" @blur="focus = false" v-model="form.detail" />
  58. </view>
  59. <view class="tip" @click="detailFocus">请输入具体门牌号以便配送</view> -->
  60. </view>
  61. <view class="app-button">
  62. <app-button @click="submit" :theme="theme" arrangement="row" type="important" round width="90%">
  63. <!-- <text class="app-text">保存地址</text> -->
  64. <text class="app-text">保存信息</text>
  65. </app-button>
  66. </view>
  67. </app-layout>
  68. </template>
  69. <script>
  70. import {mapState} from 'vuex';
  71. import appLayout from "../../components/basic-component/app-layout/app-layout.vue";
  72. import appAreaPicker from '../../components/page-component/app-area-picker/app-area-picker.vue';
  73. import addressParse from './address-parse.js';
  74. import appTextArea from '../../components/basic-component/app-textarea/app-textarea.vue';
  75. export default {
  76. name: "address-edit",
  77. data() {
  78. return {
  79. form: {
  80. location: '',
  81. latitude: '',
  82. longitude: '',
  83. id: '',
  84. name: '',
  85. mobile: '',
  86. address: '',
  87. province_id: 0,
  88. city_id: 0,
  89. district_id: 0,
  90. detail: '',
  91. },
  92. is_refund_address: 0,
  93. detail_url: '',
  94. list: [],
  95. submit_status: false,
  96. tt_area_show: false,
  97. automatic: '',
  98. provinceString: '',
  99. cityString: '',
  100. areaString: '',
  101. focus: false,
  102. }
  103. },
  104. computed: {
  105. ...mapState({
  106. theme: state => state.mallConfig.theme,
  107. }),
  108. },
  109. components: {appLayout, appAreaPicker, appTextArea},
  110. onLoad: function (options) {
  111. this.getAutoInfo();
  112. this.is_refund_address = options.is_refund_address ? options.is_refund_address : 0;
  113. if (options.is_refund_address > 0) {
  114. this.detail_url = this.$api.app_admin.refund_address_edit;
  115. uni.setNavigationBarTitle({
  116. title: '编辑退货地址'
  117. });
  118. } else {
  119. this.detail_url = this.$api.user.address_detail;
  120. }
  121. if (options.form) {
  122. this.form = JSON.parse(options.form);
  123. }
  124. if (options.id > 0) {
  125. this.$showLoading({title: `加载中`});
  126. this.$request({
  127. url: this.detail_url,
  128. data: options
  129. }).then(info => {
  130. this.$hideLoading();
  131. if (info.code === 0) {
  132. if (options.is_refund_address > 0) {
  133. const detail = info.data.detail;
  134. this.getInfo(Object.assign({detail: detail.address_detail}, detail));
  135. } else {
  136. this.form = info.data.list;
  137. }
  138. } else {
  139. uni.showToast({title: info.msg, icon: 'none'});
  140. }
  141. this.tt_area_show = true;
  142. }).catch(() => {
  143. this.$hideLoading();
  144. this.tt_area_show = true;
  145. });
  146. } else {
  147. this.tt_area_show = true;
  148. }
  149. },
  150. methods: {
  151. outputData(data) {
  152. console.log(data);
  153. },
  154. async getAutoInfo() {
  155. const res = await this.$request({
  156. url: this.$api.user.auto_address_info,
  157. method: 'get'
  158. });
  159. if (res.code === 0) {
  160. let autoInfo = JSON.parse(res.data);
  161. const provinces = autoInfo.reduce((per, cur) => {
  162. const {children, ...others} = cur;
  163. return per.concat(others);
  164. }, []);
  165. const cities = autoInfo.reduce((per, cur) => {
  166. return per.concat(cur.children.map(({children, ...others}) => ({...others, provinceCode: cur.code})));
  167. }, []);
  168. const areas = autoInfo.reduce((per, cur) => {
  169. const provinceCode = cur.code;
  170. return per.concat(cur.children.reduce((p, c) => {
  171. const cityCode = c.code;
  172. return p.concat(c.children.map(({children, ...others}) => ({...others, cityCode, provinceCode,})));
  173. }, []));
  174. }, []);
  175. this.provinceString = JSON.stringify(provinces);
  176. this.cityString = JSON.stringify(cities);
  177. this.areaString = JSON.stringify(areas);
  178. }
  179. },
  180. // #ifndef MP-TOUTIAO
  181. async getChooseLocation() {
  182. const self = this;
  183. const [err, res] = await uni.chooseLocation();
  184. if (res) {
  185. self.form.location = res.name;
  186. self.form.latitude = res.latitude;
  187. self.form.longitude = res.longitude;
  188. }
  189. if (err) {
  190. const setting = () => {
  191. uni.showModal({
  192. title: '授权权限',
  193. content: '请先授权地理位置权限',
  194. success(res) {
  195. if (res.confirm) {
  196. uni.openSetting({
  197. success(settingdata) {
  198. if (settingdata.authSetting['scope.userLocation']) {
  199. uni.chooseLocation({
  200. success: function (res) {
  201. self.form.location = res.name;
  202. self.form.latitude = res.latitude;
  203. self.form.longitude = res.longitude;
  204. },
  205. });
  206. } else {
  207. uni.showToast({
  208. title: '授权失败',
  209. icon: 'none'
  210. });
  211. }
  212. }
  213. })
  214. }
  215. }
  216. })
  217. };
  218. //#ifdef MP-BAIDU
  219. if (err.errCode === 1003) {
  220. setting();
  221. }
  222. //#endif
  223. //#ifdef MP-WEIXIN
  224. if (err.errMsg === `chooseLocation:fail auth deny`) {
  225. setting();
  226. }
  227. //#endif
  228. }
  229. },
  230. // #endif
  231. getInfo(detail) {
  232. this.$request({
  233. url: this.$api.user.wechat_district,
  234. data: {
  235. province_name: detail.address[0],
  236. city_name: detail.address[1],
  237. county_name: detail.address[2],
  238. },
  239. }).then(info => {
  240. if (info.code === 0) {
  241. const {province, city, district} = info.data.district;
  242. detail.province_id = province.id;
  243. detail.city_id = city.id;
  244. detail.district_id = district.id;
  245. this.form = detail;
  246. }
  247. }).catch(() => {
  248. uni.showToast({
  249. title: '网络异常',
  250. icon: 'none',
  251. });
  252. })
  253. },
  254. areaEvent(data) {
  255. if (data) {
  256. this.form.province_id = data.province.id;
  257. this.form.city_id = data.city.id;
  258. this.form.district_id = data.district.id;
  259. this.list = [data.province.name, data.city.name, data.district.name];
  260. }
  261. },
  262. async submit() {
  263. try {
  264. if (this.submit_status) return;
  265. let content;
  266. if (!this.form.detail) {
  267. content = '详细地址不能为空';
  268. }
  269. if (!this.form.province_id) {
  270. content = '地区不能为空';
  271. }
  272. if (!this.form.mobile) {
  273. content = '联系方式不能为空';
  274. }
  275. if (!this.form.name) {
  276. content = '姓名不能为空';
  277. }
  278. if (content) {
  279. uni.showToast({
  280. title: content,
  281. icon: 'none'
  282. });
  283. return;
  284. }
  285. this.submit_status = true;
  286. let url = this.$api.user.address_save;
  287. let para = this.form;
  288. if (this.is_refund_address > 0) {
  289. url = this.$api.app_admin.refund_address_edit;
  290. let {id, name, mobile, detail} = this.form;
  291. para = {
  292. form: JSON.stringify({
  293. id,
  294. name,
  295. mobile,
  296. address_detail: detail,
  297. address: this.list,
  298. is_default: 0,
  299. remark: ''
  300. })
  301. }
  302. }
  303. const info = await this.$request({
  304. url: url,
  305. data: para,
  306. method: 'POST',
  307. });
  308. this.submit_status = false;
  309. if (info.code === 0) {
  310. uni.showToast({title: info.msg, icon: 'none'});
  311. uni.navigateBack({delta: 1});
  312. } else {
  313. uni.showToast({title: info.msg, icon: 'none'});
  314. }
  315. } catch (e) {
  316. this.submit_status = false;
  317. throw new Error(e);
  318. }
  319. },
  320. getAddress() {
  321. let data = addressParse(this.automatic, {} ,this.provinceString, this.cityString, this.areaString);
  322. if (Object.keys(data).length === 0) return;
  323. const district = uni.getStorageSync("_DISTRICT");
  324. let {name, province, city, area, phone, detail} = data;
  325. for (let i = 0; i < district.length; i++) {
  326. if (district[i].name === province) {
  327. for (let j = 0; j < district[i].list.length; j++) {
  328. if (district[i].list[j].name === city) {
  329. for (let k = 0; k < district[i].list[j].list.length; k++) {
  330. if (district[i].list[j].list[k].name === area) {
  331. this.form.province_id = district[i].id;
  332. this.form.city_id = district[i].list[j].id;
  333. this.form.district_id = district[i].list[j].list[k].id;
  334. break;
  335. }
  336. }
  337. break;
  338. }
  339. }
  340. break;
  341. }
  342. }
  343. this.form.name = name;
  344. this.form.detail = `${detail}`;
  345. this.form.mobile = phone;
  346. },
  347. detailFocus() {
  348. console.log(22);
  349. this.focus = true;
  350. }
  351. }
  352. }
  353. </script>
  354. <style scoped lang="scss">
  355. // 自动识别功能
  356. .automatic {
  357. height: #{100upx};
  358. margin-bottom: #{20upx};
  359. padding: #{0 32upx 0 24upx};
  360. background-color: #ffffff;
  361. button {
  362. width: #{150upx};
  363. height: #{60upx};
  364. padding: 0;
  365. line-height: #{58upx};
  366. border-radius: #{5upx};
  367. border: #{1upx} solid #ff4544;
  368. font-size: #{26upx};
  369. color: #ff4544;
  370. background-color: transparent;
  371. margin: 0;
  372. text-align: center;
  373. }
  374. input {
  375. width: calc(100% - #{182upx});
  376. font-size: #{28upx};
  377. color:#353535;
  378. }
  379. .place-automatic {
  380. font-size: #{26upx};
  381. color: #999999;
  382. }
  383. }
  384. .popup {
  385. position: fixed;
  386. background: rgba(0, 0, 0, 0.5);
  387. padding: #{50rpx};
  388. top: 0;
  389. left: 0;
  390. right: 0;
  391. bottom: 0;
  392. z-index: 2000;
  393. .textarea {
  394. width: 100%;
  395. background: #fff;
  396. border: #{1rpx} solid #ccc;
  397. z-index: 1;
  398. padding: #{24rpx};
  399. border-radius: #{5rpx};
  400. }
  401. .c {
  402. position: fixed;
  403. left: 0;
  404. top: 0;
  405. right: 0;
  406. bottom: 0;
  407. z-index: 0;
  408. }
  409. }
  410. .h-100 {
  411. height: 100%;
  412. }
  413. .app-button {
  414. margin: #{40rpx} #{24rpx};
  415. }
  416. .address-input {
  417. width: #{580rpx};
  418. font-size: #{28rpx};
  419. color: #353535;
  420. }
  421. .area-left {
  422. padding-left: #{32rpx};
  423. text-align: right;
  424. margin-left: auto;
  425. }
  426. .app-view {
  427. background: #f7f7f7;
  428. .app-line {
  429. background-color: #ffffff;
  430. height: #{99rpx};
  431. line-height: #{99rpx};
  432. padding: #{0 24upx};
  433. text.app-text {
  434. font-size: #{28rpx};
  435. color: $uni-important-color-black;
  436. // width: #{124rpx};
  437. width: #{150rpx};
  438. }
  439. }
  440. .app-border {
  441. border-bottom: #{1rpx} solid $uni-weak-color-one;
  442. }
  443. .c-address {
  444. padding-right: #{24rpx};
  445. font-size: #{28rpx};
  446. color: #353535;
  447. }
  448. .icon-arrow-image {
  449. width: #{12rpx};
  450. height: #{24rpx};
  451. background-image: url("../../static/image/icon/arrow-right.png");
  452. background-size: 100% auto;
  453. background-repeat: no-repeat;
  454. }
  455. .tip {
  456. padding: #{0 24rpx 24rpx 24rpx};
  457. background: #ffffff;
  458. color: #b7b7b7;
  459. }
  460. }
  461. </style>