diff --git a/pages/newOrder/address.vue b/pages/newOrder/address.vue index 262df18..faa9527 100644 --- a/pages/newOrder/address.vue +++ b/pages/newOrder/address.vue @@ -66,6 +66,7 @@ data(){ return{ loading:false, + needRelocate: false, // 是否需要重新定位 addressInfo:{ name:"", phone:"", @@ -88,6 +89,7 @@ }, onLoad(option) { this.optionType=option.optionType; + this.needRelocate = option.needRelocate === 'true'; // 是否需要重新定位 if(this.optionType=='edit'){ this.addressId=option.addressId; this.getAddressDetails(option.addressId); @@ -113,20 +115,31 @@ latitude, longitude, } = res; + + // 检查是否需要重新定位或缺少经纬度信息 + const needClearLocation = this.needRelocate || !latitude || !longitude; + this.addressInfo = { name, phone, emergencyPhone, - province, - city, - district, + province: needClearLocation ? '' : province, + city: needClearLocation ? '' : city, + district: needClearLocation ? '' : district, detailAddress, openId, isDefault, - latitude, - longitude, - selectAddress: `${province}${city}${district}`, + latitude: needClearLocation ? '' : latitude, + longitude: needClearLocation ? '' : longitude, + selectAddress: needClearLocation ? '' : `${province}${city}${district}`, }; + + // 如果需要重新定位,提示用户 + if(needClearLocation) { + setTimeout(() => { + this.$modal.showToast('请重新选择所在地区进行定位'); + }, 500); + } }else{ this.$modal.showToast('获取地址详情失败') } @@ -142,41 +155,27 @@ this.addressInfo.latitude = res.latitude this.addressInfo.longitude = res.longitude - - var reg = /.+?(省|市|自治区|自治州|县|区)/g; + // 获取完整地址 let address = '' - - if (!res.address && res.name) { //用户直接选择城市的逻辑 + if (!res.address && res.name) { address = res.name - } - if (res.address || res.name) { - address = res.address + res.name + } else if (res.address || res.name) { + address = (res.address || '') + (res.name || '') } if(!address){ return } - let arr = address.match(reg) - - this.addressInfo.province = arr[0] || '' - this.addressInfo.city = arr[1] || '' - this.addressInfo.district = arr[2] || '' - - let detail = arr[2] || arr[1] || arr[0] || '' - - this.addressInfo.detailAddress = address.substring(address.indexOf(detail) + detail.length) - - this.addressInfo.selectAddress = `${arr[0] || ''}${arr[1] || ''}${arr[2] || ''}` + // 解析地址信息 + const addressInfo = this.parseAddress(address); - // if (!res.address && res.name) { //用户直接选择城市的逻辑 - // return this.addressInfo.selectAddress = res.name - // } - // if (res.address || res.name) { - // return this.addressInfo.selectAddress = res.address + res.name - // } - // this.addressInfo.selectAddress = '' //用户啥都没选就点击勾选 + this.addressInfo.province = addressInfo.province + this.addressInfo.city = addressInfo.city + this.addressInfo.district = addressInfo.district + this.addressInfo.detailAddress = addressInfo.detailAddress + this.addressInfo.selectAddress = addressInfo.selectAddress }, fail(e) { console.log("获取位置信息失败!", e) @@ -299,6 +298,92 @@ console.log('groupChange', n); this.addressInfo.isDefault=+(!this.addressInfo.isDefault) }, + + // 智能解析地址信息 + parseAddress(address) { + if (!address) { + return { + province: '', + city: '', + district: '', + detailAddress: '', + selectAddress: '' + }; + } + + // 直辖市列表 + const municipalities = ['北京市', '上海市', '天津市', '重庆市']; + + // 省级行政区正则 + const provinceReg = /(.*?(?:省|自治区|特别行政区))/; + // 市级行政区正则 + const cityReg = /(.*?(?:市|自治州|地区|盟))/; + // 区县级行政区正则 + const districtReg = /(.*?(?:区|县|市|旗|自治县|自治旗))/; + + let province = ''; + let city = ''; + let district = ''; + let detailAddress = ''; + let remainingAddress = address; + + // 检查是否为直辖市 + const municipality = municipalities.find(m => address.includes(m)); + if (municipality) { + province = municipality; + city = municipality; + remainingAddress = address.substring(address.indexOf(municipality) + municipality.length); + + // 解析区县 + const districtMatch = remainingAddress.match(districtReg); + if (districtMatch) { + district = districtMatch[1]; + detailAddress = remainingAddress.substring(districtMatch[0].length).trim(); + } else { + detailAddress = remainingAddress.trim(); + } + } else { + // 非直辖市,按省市区县顺序解析 + + // 解析省份 + const provinceMatch = remainingAddress.match(provinceReg); + if (provinceMatch) { + province = provinceMatch[1]; + remainingAddress = remainingAddress.substring(provinceMatch[0].length); + } + + // 解析城市 + const cityMatch = remainingAddress.match(cityReg); + if (cityMatch) { + city = cityMatch[1]; + remainingAddress = remainingAddress.substring(cityMatch[0].length); + } + + // 解析区县 + const districtMatch = remainingAddress.match(districtReg); + if (districtMatch) { + district = districtMatch[1]; + remainingAddress = remainingAddress.substring(districtMatch[0].length); + } + + detailAddress = remainingAddress.trim(); + } + + // 如果没有解析到省份,但有城市,可能是省级市 + if (!province && city) { + province = city; + } + + const selectAddress = `${province}${city !== province ? city : ''}${district}`; + + return { + province, + city, + district, + detailAddress, + selectAddress + }; + } } } diff --git a/pages/newOrder/addressList.vue b/pages/newOrder/addressList.vue index 153c4bc..e717cf3 100644 --- a/pages/newOrder/addressList.vue +++ b/pages/newOrder/addressList.vue @@ -127,14 +127,16 @@ if(!params.latitude || !params.longitude) { uni.showModal({ title: '提示', - content: '该地址缺少位置信息,请先编辑地址完善位置信息', + content: '该地址缺少位置信息,需要重新定位,请点击确定重新选择位置', showCancel: true, cancelText: '取消', - confirmText: '去编辑', + confirmText: '重新定位', success: (res) => { if (res.confirm) { - // 用户点击确定,跳转到编辑地址页面 - this.editAddress(params); + // 用户点击确定,跳转到编辑地址页面并传递需要重新定位的标识 + uni.navigateTo({ + url: `/pages/newOrder/address?optionType=edit&addressId=${params.id}&needRelocate=true` + }); } } }); diff --git a/pages/newOrder/petList.vue b/pages/newOrder/petList.vue index 1fc24e9..541882f 100644 --- a/pages/newOrder/petList.vue +++ b/pages/newOrder/petList.vue @@ -193,6 +193,31 @@ export default { this.getCalendarDate(); }, methods: { + //判断当前选中的地址是否加价 + isAddPrice(){ + let currentAddress = this.$globalData.newOrderData.currentAddress || {} + + let defaultPrice = 1 + + try{ + defaultPrice = this.price_config.cityConfig.priceRates.default + }catch(e){ + defaultPrice = 1 + } + + if(!this.price_config.cityConfig || !currentAddress.province || !currentAddress.city){ + return defaultPrice + } + + let addressList = this.price_config.cityConfig.priceRates || [] + + for(let key in addressList){ + if((currentAddress.province + currentAddress.city).includes(key)){ + return addressList[key] + } + } + return defaultPrice + }, getPetList() { this.petList = [] getPetList().then(res => { diff --git a/pages/newOrder/serviceNew.vue b/pages/newOrder/serviceNew.vue index 6d1f242..80ca686 100644 --- a/pages/newOrder/serviceNew.vue +++ b/pages/newOrder/serviceNew.vue @@ -53,19 +53,19 @@ - 等级: - {{ showLevelInfo.paramValue }} + 等级: + {{ showLevelInfo.paramValue }} - 价格: - {{ companionLevelPrice() }} + 价格: + {{ (companionLevelPrice() + basePrice()).toFixed(2) }} - 分类标准: - 分类标准: + - + @@ -283,6 +283,13 @@ this.$store.commit('getUserInfo') }, methods:{ + basePrice(){ + let priceConfig = this.$store.state.price_config + let normal = priceConfig.basePrice && priceConfig.basePrice.normal + let normalNumber = normal * this.$store.state.memberRate * this.isAddPrice() + + return isNaN(normalNumber) ? 0 : normalNumber + }, companionLevelPrice(){ let price = Number(this.showLevelInfo.paramValueText) * this.isAddPrice() @@ -515,11 +522,13 @@ .companion-info-content { .companion-info-item { margin-bottom: 40rpx; + display: flex; .companion-info-label { font-size: 28rpx; color: #666; - margin-right: 10rpx; + width: 136rpx; + flex-shrink: 0; } .companion-info-value { diff --git a/store/index.js b/store/index.js index a1680dc..38528c4 100644 --- a/store/index.js +++ b/store/index.js @@ -90,6 +90,8 @@ const store = new Vuex.Store({ if (state.price_config && key) { state.memberRate = state.price_config.memberDiscount[key] || 1 + + console.log('state.memberRate', state.memberRate); } } }) diff --git a/utils/getUrl.js b/utils/getUrl.js index c24510d..7f40537 100644 --- a/utils/getUrl.js +++ b/utils/getUrl.js @@ -1,16 +1,16 @@ -let current ="trial"; +let current ="release"; const accountInfo = wx.getAccountInfoSync(); // current = accountInfo.miniProgram.envVersion; const api={ - develop:"http://127.0.0.1:8002", + develop:"http://127.0.0.1:8080", // develop:"http://h5.xzaiyp.top", // develop:"https://api.catmdogd.com/prod-api", // develop:"https://api-test.catmdogd.com/test-api", trial:"https://pet-admin.hhlm1688.com/api", - // release:"https://api.catmdogd.com", + release:"https://api.catmdogd.com/prod-api", } const currentUrl = api[current];