From 094f0526c153dbfcbd723780646f26f32a14ee9d Mon Sep 17 00:00:00 2001 From: 陶杰 <1378534974@qq.com> Date: 星期二, 24 九月 2024 18:52:24 +0800 Subject: [PATCH] 1.合伙人-首页-显示ID --- pages/user/address/address.vue | 81 ++++++++++++++++++++++++++++++++++++---- 1 files changed, 72 insertions(+), 9 deletions(-) diff --git a/pages/user/address/address.vue b/pages/user/address/address.vue index 9df16bb..c0fd7b2 100644 --- a/pages/user/address/address.vue +++ b/pages/user/address/address.vue @@ -78,7 +78,7 @@ 手机号 </view> <view class="form-item-value"> - <input v-model="submitForm.tel" placeholder="请输入收货人手机号" class="form-input"></input> + <input v-model="submitForm.tel" placeholder="请输入收货人手机号" class="form-input" @blur="validatePhoneNumber()" ></input> </view> </view> <view class="form-item"> @@ -129,7 +129,9 @@ // import qqmapwx from '@/plugins/qqmap-wx-jssdk.min.js'; // const lockey = 'VUHBZ-2AMLP-B7AD7-VUQZ7-D4TW5-MFFVN'; //使用在腾讯位置服务申请的key // const chooseLocation = requirePlugin('chooseLocation'); - + import { + mapState + } from 'vuex' export default { async onPullDownRefresh() { this.page.current = 0 @@ -141,6 +143,14 @@ this.source = options.source || '' this.listApi = '/api/address/list' await this.getList() + + }, + computed: { + ...mapState({ + address: state => { + return state.defaultaddress || {} + }, + }), }, data() { @@ -161,6 +171,16 @@ }; }, methods: { + validatePhoneNumber() { + + // 手机号码正则表达式,可以根据需要调整 + const phoneRegex = /^[1][3-9][0-9]{9}$/; + if (!phoneRegex.test(this.submitForm['tel'])) { + this.$message.showToast('请填写正确手机号码') + } + + }, + addAddress() { delete this.submitForm.id this.submitForm['name'] = '' @@ -178,7 +198,14 @@ this.submitForm.province = '' this.submitForm.city = '' this.submitForm.region = '' - if (e.detail.value.length <= 3) { + if (e.detail.value.length == 2) { + if (!!e.detail.value[0]) + this.submitForm.province = e.detail.value[0].value + if (!!e.detail.value[0]) + this.submitForm.city = e.detail.value[0].value + if (!!e.detail.value[1]) + this.submitForm.region = e.detail.value[1].value + } else if (e.detail.value.length <= 3) { if (!!e.detail.value[0]) this.submitForm.province = e.detail.value[0].value if (!!e.detail.value[1]) @@ -201,9 +228,22 @@ } }, async init_area() { - const res = await this.$http.request('get', '/api/pub/china/area/json') - this.regionDataPlus = res.data && JSON.parse(res.data.replaceAll('code', 'value').replaceAll('name', - 'text')) || [] + if (this.regionDataPlus && this.regionDataPlus.length > 0) { + + } else { + var a = this.$storage.getItem('cache_area') + if (a) { + this.regionDataPlus = JSON.parse(a) || [] + } else { + const res = await this.$http.request('get', '/api/pub/china/area/json') + // console.log('area', JSON.parse(res.data)) + this.regionDataPlus = res.data && JSON.parse(res.data.replaceAll('code', 'value').replaceAll( + 'name', + 'text')) || [] + this.$storage.setItem('cache_area', JSON.stringify(this.regionDataPlus)) + } + } + }, chooseLocation() { //前往接口挑选位置 @@ -311,7 +351,7 @@ this.$message.hideLoading() if (code === 0) { this.$message.showToast('删除成功') - if (item.isDefault) { + if (this.address.id === item.id) { //要清空地址了 this.$store.commit('setDefaultAddress', {}) } @@ -339,8 +379,10 @@ this.$message.hideLoading() } else { this.submitForm = { - name: this.currentInfo && this.currentInfo.nickName || '', - tel: this.currentInfo && this.currentInfo.tel || '', + // name: this.currentInfo && this.currentInfo.nickName || '', + // tel: this.currentInfo && this.currentInfo.tel || '', + name: '', + tel: '', address: '', isDefault: false, province: '', @@ -361,6 +403,20 @@ this.$message.showToast('字段未填写完整') return } + if(!this.submitForm['province']||!this.submitForm['province']||!this.submitForm['province']){ + this.$message.showToast('省市区未选择完整') + return + } + + // 手机号码正则表达式,可以根据需要调整 + const phoneRegex = /^[1][3-9][0-9]{9}$/; + if (!phoneRegex.test(this.submitForm['tel'])) { + this.$message.showToast('请填写正确手机号码') + return + } + + + this.$message.showLoading() const { code @@ -372,11 +428,18 @@ if (code === 0) { this.$refs.popup_form.close() this.$message.showToast(this.submitForm.id ? '修改成功' : '新增成功') + let tmp = this setTimeout(() => { tmp.page.current = 1 tmp.refreshList() }, 300) + //如果当前选择的地址是这个,需要更新一下数据 + if (this.address.id && this.submitForm.id === this.address.id) { + this.$store.commit('setDefaultAddress', { + ...this.submitForm + }) + } } }, -- Gitblit v1.9.3