address-edit.vue 22 KB

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