From 32526e5bddb7b14328b2467cd18783f480b33f3b Mon Sep 17 00:00:00 2001 From: xuxueyang <xuxy@fengyuntec.com> Date: 星期六, 31 八月 2024 01:51:53 +0800 Subject: [PATCH] update合伙人 --- pages/user/address/address.vue | 284 +++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 216 insertions(+), 68 deletions(-) diff --git a/pages/user/address/address.vue b/pages/user/address/address.vue index 75053a7..8b2c9e5 100644 --- a/pages/user/address/address.vue +++ b/pages/user/address/address.vue @@ -1,5 +1,5 @@ <template> - <!-- 收获地址列表 --> + <!-- 收货地址列表 --> <view class="p15 container-address"> <no-data v-if="!list||list.length==0" style="width: 100%;"></no-data> @@ -8,12 +8,16 @@ <view class="flex"> <view class="container-info"> <view class="flex"> - <view class="name">{{item.name || '-'}}</view> - <view class="tel">{{item.tel||'-'}}</view> + <view class="name">{{ item.name || '-' }}</view> + <view class="tel">{{ item.tel || '-' }}</view> </view> <view class="address"> - {{item.address}} - + {{ item['province'] || '' }}{{ item['city'] && ('/' + item['city']) || '' }}{{ + item['region'] && ('/' + item['region']) || '' + }} + </view> + <view class="address"> + {{ item.address }} </view> </view> <!-- <view class="h-line"></view> --> @@ -28,21 +32,13 @@ </view> <view class="v-line"></view> <view class="flex"> - <view class="flex" @click="changeDefaultAddress(item,index)"> - <!-- <label class="radio flex" > --> - <!-- <radio value="r1" :checked="item.defaulted" disabled - style="transform:scale(0.6)" v-if="item.defaulted" /> - <radio value="r1" - style="transform:scale(0.6)" :checked="item.defaulted" v-if="!item.defaulted" @change="changeDefaultAddress(item,index)"/> - --> - - <!-- </label> --> - <view class="radio m-t-2 m-r-10" :class="[item.defaulted?'select':'']"> + <!-- --> + <view class="flex"> + <view class="radio m-t-2 m-r-10" :class="[item.isDefault?'select':'']" + @click="changeDefaultAddress(item,index)"> </view> - <span class="desc">{{item.defaulted?'默认地址:':'当前地址:'}}{{item.schoolAreaStr||''}} - {{item.blockStr||''}} - {{item.room||''}}</span> + <span class="desc">{{ item.isDefault ? '默认地址:' : '当前地址:' }}{{ item.address || '' }}</span> <!-- 当前地址/默认地址勾选 --> </view> <view class="desc del t-red" @click="deleteAddress(item)"> @@ -57,20 +53,14 @@ <view style="height: 92rpx;width: 690rpx;"> </view> - <view class="button-green button-fixed-bottom" style="width: 690rpx;line-height: 92rpx;height: 92rpx;" @click=" ()=>{ - delete this.submitForm.id - this.submitForm['name'] = '' - this.submitForm['tel'] = '' - this.submitForm['tel'] = '' - this.submitForm['area'] = '' - - openAddressForm() - }">添加收货地址</view> + <view class="button-green button-fixed-bottom" style="width: 690rpx;line-height: 92rpx;height: 92rpx;" + @click="addAddress">添加收货地址 + </view> <uni-popup ref="popup_form" type="top" :mask-click="false"> <view class="popup-address-form"> <view class="close-parent"> - {{submitForm.id?'新增':'编辑'}}收货地址 + {{ submitForm.id ? '新增' : '编辑' }}收货地址 <uni-icons class="close" type="closeempty" @click="closeAddressForm"></uni-icons> </view> <!--收货人、手机号、校区、详细地址 --> @@ -85,12 +75,27 @@ </view> <view class="form-item"> <view class="form-item-label require"> - 请选择收获地址 + 手机号 </view> <view class="form-item-value"> - <input v-model="submitForm.room" placeholder="请选择收获地址" disabled class="form-input"></input> - <!-- todo 点击定位 --> + <input v-model="submitForm.tel" placeholder="请输入收货人手机号" class="form-input"></input> </view> + </view> + <view class="form-item"> + <view class="form-item-label require"> + 收货地址 + </view> + <view class="m-l-a m-r-0 flex " :class="[!dto['province']?'desc-gray':'']"> + <uni-data-picker :area="true" @change="(e)=>{PickArea(submitForm,e)}" placeholder="" + :localdata="regionDataPlus"> + {{ submitForm['province'] || '请选择' }}{{ submitForm['city'] && ('/' + submitForm['city']) || '' }}{{ + submitForm['region'] && ('/' + submitForm['region']) || '' + }} + </uni-data-picker> + <u-icon class="m-l-a" name="arrow-right"></u-icon> + </view> + + </view> <view class="form-item"> <view class="form-item-label require"> @@ -106,8 +111,8 @@ 是否默认 </view> <view class="form-item-value"> - <radio value="r1" :checked="submitForm.defaulted" - @click="submitForm.defaulted=!submitForm.defaulted" + <radio value="r1" :checked="submitForm.isDefault" + @click="submitForm.isDefault=!submitForm.isDefault" style="transform:scale(0.6);margin-top: -8rpx;" /> </view> </view> @@ -121,6 +126,12 @@ </template> <script> + // 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 @@ -130,8 +141,16 @@ async onLoad(options) { // this.list = [{}, {}] this.source = options.source || '' - this.listApi = '/api/address/customer/list' + this.listApi = '/api/address/list' await this.getList() + + }, + computed: { + ...mapState({ + address: state => { + return state.defaultaddress || {} + }, + }), }, data() { @@ -141,34 +160,154 @@ name: '', tel: '', address: '', - schoolArea: '', - block: '', - room: '', - defaulted: false + isDefault: false, + province: '', + city: '', + region: '', + }, + regionDataPlus: [], + list: [], }; }, methods: { + addAddress() { + delete this.submitForm.id + this.submitForm['name'] = '' + this.submitForm['tel'] = '' + this.submitForm['address'] = '' + this.submitForm['province'] = '' + this.submitForm['city'] = '' + this.submitForm['region'] = '' + this.submitForm['isDefault'] = false + this.openAddressForm() + }, + PickArea(item, e) { + console.log('PickArea', item, e) + if (e.detail.value) { + this.submitForm.province = '' + this.submitForm.city = '' + this.submitForm.region = '' + 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]) + this.submitForm.city = e.detail.value[1].value + if (!!e.detail.value[2]) + this.submitForm.region = e.detail.value[2].value + } else { + //说明有重复的 + var plusnum = e.detail.value.length - 3 + if (!!e.detail.value[plusnum + 0]) + this.submitForm.province = e.detail.value[plusnum + 0].value + if (!!e.detail.value[plusnum + 1]) + this.submitForm.city = e.detail.value[plusnum + 1].value + if (!!e.detail.value[plusnum + 2]) + this.submitForm.region = e.detail.value[plusnum + 2].value + } + + this.$forceUpdate() + console.log('submit forn', this.submitForm) + } + }, + async init_area() { + 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() { + //前往接口挑选位置 + const qqmapsdk = new qqmapwx({ + // 使用你在腾讯地图应用生成的key + key: lockey + }); + + uni.getLocation({ + type: 'wgs84', + success(res) { + //得到经纬度 + console.log(res); + qqmapsdk.reverseGeocoder({ + location: { + latitude: res.latitude, + longitude: res.longitude + }, + //成功后的回调 + success: (r) => { + // console.log('地址信息', r.result.address_component); + // result: {location: {lat: 31.26249, lng: 120.63212}, address: "江苏省苏州市吴中区太湖东路288号",…} + // ad_info: {nation_code: "156", adcode: "320506", phone_area_code: "0512", city_code: "156320500",…} + // address: "江苏省苏州市吴中区太湖东路288号" + // address_component: {nation: "中国", province: "江苏省", city: "苏州市", district: "吴中区", street: "太湖东路",…} + // address_reference: {,…} + // formatted_addresses: {recommend: "长桥苏州市吴中区人民政府(太湖东路北)", rough: "长桥苏州市吴中区人民政府(太湖东路北)"} + // location: {lat: 31.26249, lng: 120.63212} + // status: 0 + tmp.formcodes['LOC_ONE'][tmp.tmp_picker_lock_index].longitude = r + .result.location.lng + tmp.formcodes['LOC_ONE'][tmp.tmp_picker_lock_index].latitude = r + .result.location.lat + tmp.formcodes['LOC_ONE'][tmp.tmp_picker_lock_index].loc_desc = r + .result.address + tmp.formcodes['LOC_ONE'][tmp.tmp_picker_lock_index]._show = false + tmp.$forceUpdate() + tmp.tmp_picker_lock_index = -1 + + }, + fail: function(res) { + console.log(res); + tmp.tmp_picker_lock_index = -1 + }, + }); + } + }); + }, async changeDefaultAddress(item, index) { - if (item.defaulted) { + if (item.isDefault) { return } this.$nextTick(() => { - // item.defaulted = false - // this.$set(item,'defaulted',false) + this.$message.confirm('确定设置此地址为默认地址吗').then(async res => { this.$message.showLoading() var { code - } = await this.$http.request('post', '/api/address/customer/default/' + - item.id, {}) + } = await this.$http.request('post', '/api/address/set/default/' + item + .id, { + data: { + id: item.id + }, + params: { + id: item.id + } + }) this.$message.hideLoading() - if (code == 0) { + if (code === 0) { for (var dto of this.list) { - dto.defaulted = false + dto.isDefault = false } this.$message.showToast('设置成功') - item.defaulted = true + item.isDefault = true this.$store.commit('setDefaultAddress', { ...item }) @@ -176,7 +315,7 @@ } }, err => { this.$nextTick(() => { - this.list[index].defaulted = false + this.list[index].isDefault = false this.$forceUpdate() console.log('err', err, this.list[index]) }) @@ -186,7 +325,7 @@ }) }, async selectAddress(item) { - await this.$message.confirm('确定选择此地址作为收获地址吗') + await this.$message.confirm('确定选择此地址作为收货地址吗') //携带,然后返回 this.$store.commit('setDefaultAddress', { ...item @@ -198,10 +337,14 @@ this.$message.showLoading() var { code - } = await this.$http.request('get', '/api/address/customer/delete/' + item.id, {}) + } = await this.$http.request('get', '/api/address/delete?id=' + item.id, {}) this.$message.hideLoading() - if (code == 0) { + if (code === 0) { this.$message.showToast('删除成功') + if (this.address.id === item.id) { + //要清空地址了 + this.$store.commit('setDefaultAddress', {}) + } setTimeout(() => { this.page.current = 1 this.getList() @@ -209,11 +352,12 @@ } }, async openAddressForm() { + this.init_area() if (this.submitForm.id) { this.$message.showLoading() var { data - } = await this.$http.request('get', '/api/address/customer/get/' + this.submitForm.id, {}) + } = await this.$http.request('get', '/api/address/list/detail?id=' + this.submitForm.id, {}) if (data) { @@ -221,23 +365,20 @@ ...this.submitForm, ...data } - this.blockIndex = -1 - this.schoolIndex = -1 } 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: '', - schoolArea: '', - block: '', - room: '', - defaulted: false + isDefault: false, + province: '', + city: '', + region: '', } - this.schoolIndex = -1 - this.blockIndex = -1 - this.blocks = [] } this.$refs.popup_form.open() @@ -255,19 +396,26 @@ this.$message.showLoading() const { code - } = await this.$http.request('post', '/api/address/customer/' + (this.submitForm.id ? 'edit' : - 'new'), { + } = await this.$http.request('post', '/api/address/' + (this.submitForm.id ? 'update' : + 'add'), { data: this.submitForm }) this.$message.hideLoading() - if (code == 0) { + if (code === 0) { this.$refs.popup_form.close() this.$message.showToast(this.submitForm.id ? '修改成功' : '新增成功') - + + let tmp = this setTimeout(() => { - this.page.current = 1 - this.getList() + 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