From 462c4bb9efa3b52da42b524343b7ac0cbf2ba121 Mon Sep 17 00:00:00 2001 From: hly <2783385703@qq.com> Date: Sun, 17 Aug 2025 17:50:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=AE=A2=E5=8D=95):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BC=B4=E5=AE=A0=E5=B8=88=E7=AD=89=E7=BA=A7?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E5=88=B0=E5=9F=BA=E7=A1=80=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将伴宠师等级价格和城市倍率合并到基础服务价格计算中 - 修改多次服务价格计算方式为基于基础价格乘以倍数 - 在价格明细中显示节假日/非节假日标识 - 移除单独显示的伴宠师等级价格项 --- main.js | 1 + pages/newOrder/confirmOrder.vue | 40 ++++++++++--------- pages/newOrder/petList.vue | 13 ++++++- pages/newOrder/serviceNew.vue | 21 +++++++++- pages/newOrder/serviceNew2.vue | 85 ++++++++++++++++++++++++----------------- 5 files changed, 103 insertions(+), 57 deletions(-) diff --git a/main.js b/main.js index 0f91aab..2a48931 100644 --- a/main.js +++ b/main.js @@ -78,6 +78,7 @@ Vue.prototype.initGlobalData = function() { totalPrice:0, needPreFamiliarize:[], distancePrice : 0, // 距离加价 + companionLevelPrice : 0, // 伴宠师等级价格 } } } diff --git a/pages/newOrder/confirmOrder.vue b/pages/newOrder/confirmOrder.vue index da3855e..157f9e8 100644 --- a/pages/newOrder/confirmOrder.vue +++ b/pages/newOrder/confirmOrder.vue @@ -158,10 +158,7 @@ 提前熟悉 ¥{{ price_config.preFamiliarize.price }} - - {{ buyInfo.teacher ? buyInfo.teacher.userName : companionLevelTitle }} - ¥{{ companionLevelPrice() }} - + 费用总计 ¥{{ parseFloat(originalTotalPrice).toFixed(2) }} @@ -557,13 +554,13 @@ unit: '只' }) } - // 当日多次服务次数 + // 当日多次服务次数 - 基础价格乘以倍数 let multServicesTotalCost = 0 const maxFeedCount = Math.max(...pets.map(pet => pet.feedCount)); if (maxFeedCount === 2) { - multServicesTotalCost += this.price_config.multiService.two.price; // 1天2次 + multServicesTotalCost += baseServiceCost * this.price_config.multiService.two.price; // 基础价格 × 2次倍数 } else if (maxFeedCount === 3) { - multServicesTotalCost += this.price_config.multiService.three.price; // 1天3次 + multServicesTotalCost += baseServiceCost * this.price_config.multiService.three.price; // 基础价格 × 3次倍数 } priceDetails.push({ name: '专业喂养', @@ -577,14 +574,14 @@ priceDetails.push({ name: '上门次数', item: [{ - itemName: '1天2次', - price: this.price_config.multiService.two.price, + itemName: `1天2次 (${this.isHoliday(date) ? '节假日' : '非节假日'})`, + price: baseServiceCost * this.price_config.multiService.two.price, quantity: maxFeedCount === 2 ? 1 : 0, unit: '天' }, { - itemName: '1天3次', - price: this.price_config.multiService.three.price, + itemName: `1天3次 (${this.isHoliday(date) ? '节假日' : '非节假日'})`, + price: baseServiceCost * this.price_config.multiService.three.price, quantity: maxFeedCount === 3 ? 1 : 0, unit: '天' }, @@ -677,11 +674,16 @@ initPriceConfig() { let priceConfig = this.$store.state.price_config console.log('价格配置:', priceConfig) + + // 获取伴宠师等级价格和城市倍率 + let companionPrice = this.$globalData.newOrderData.companionLevelPrice || 0 + let cityPriceRate = this.$globalData.newOrderData.cityPriceRate || 1 + if(priceConfig.basePrice && priceConfig.basePrice.holiday){ - this.holidayPrice = Number(priceConfig.basePrice.holiday * this.$store.state.memberRate).toFixed(2) + this.holidayPrice = Number((priceConfig.basePrice.holiday * this.$store.state.memberRate * cityPriceRate) + companionPrice).toFixed(2) } if(priceConfig.basePrice && priceConfig.basePrice.normal){ - this.normalPrice = Number(priceConfig.basePrice.normal * this.$store.state.memberRate).toFixed(2) + this.normalPrice = Number((priceConfig.basePrice.normal * this.$store.state.memberRate * cityPriceRate) + companionPrice).toFixed(2) } if(priceConfig.holidays && priceConfig.holidays.length > 0){ this.holidayDate = priceConfig.holidays @@ -689,7 +691,7 @@ this.holidayDate = [] } this.discountMemberText = (this.$store.state.memberRate * 10) - }, + }, // 判断是否为节假日 isHoliday(date) { return this.holidayDate.includes(date) @@ -823,8 +825,8 @@ //伴宠师等级名称 companionLevelTitle : this.companionLevelTitle, - //伴宠师等级加价 - companionLevelPrice: this.companionLevelPrice(), + //伴宠师等级加价(已合并到基础价格中) + companionLevelPrice: 0, } if(this.buyInfo.teacher){ @@ -872,12 +874,12 @@ const petOrderServices = currentPetsByDay.map(pet => { let price = this.isHoliday(pet.serviceDate) ? this.holidayPrice : this.normalPrice - // 当日多次服务次数 + // 当日多次服务次数 - 基础价格乘以倍数 let feedCountPrice = 0; if (pet.feedCount == 2) { - feedCountPrice += this.price_config.multiService.two.price; // 1天2次 + feedCountPrice += price * this.price_config.multiService.two.price; // 基础价格 × 2次倍数 } else if (pet.feedCount == 3) { - feedCountPrice += this.price_config.multiService.three.price; // 1天3次 + feedCountPrice += price * this.price_config.multiService.three.price; // 基础价格 × 3次倍数 } return { petId: pet.petId, diff --git a/pages/newOrder/petList.vue b/pages/newOrder/petList.vue index ca9081d..2565d86 100644 --- a/pages/newOrder/petList.vue +++ b/pages/newOrder/petList.vue @@ -133,6 +133,7 @@ import { getPetList, delPet } from "@/api/system/pet" import { getTeacherAddressList, } from "@/api/order/order" + import { mapState } from 'vuex' export default { mixins: [positionMixin], data() { @@ -157,16 +158,24 @@ export default { normalPrice : 75, } }, + computed: { + ...mapState(['price_config', 'buyInfo']) + }, onShow() { this.getPetList(); this.getOutDateList() let priceConfig = this.$store.state.price_config console.log(priceConfig) + + // 获取已保存的伴宠师等级价格和城市倍率 + let companionPrice = this.$globalData.newOrderData.companionLevelPrice || 0 + let cityPriceRate = this.$globalData.newOrderData.cityPriceRate || 1 + if(priceConfig.basePrice && priceConfig.basePrice.holiday){ - this.holidayPrice = (priceConfig.basePrice.holiday * this.$store.state.memberRate).toFixed(2) + this.holidayPrice = ((priceConfig.basePrice.holiday * this.$store.state.memberRate * cityPriceRate) + companionPrice).toFixed(2) } if(priceConfig.basePrice && priceConfig.basePrice.normal){ - this.normalPrice = (priceConfig.basePrice.normal * this.$store.state.memberRate).toFixed(2) + this.normalPrice = ((priceConfig.basePrice.normal * this.$store.state.memberRate * cityPriceRate) + companionPrice).toFixed(2) } if(priceConfig.holidays && priceConfig.holidays.length > 0){ this.holidayDate = priceConfig.holidays diff --git a/pages/newOrder/serviceNew.vue b/pages/newOrder/serviceNew.vue index e0d4f0b..6d1f242 100644 --- a/pages/newOrder/serviceNew.vue +++ b/pages/newOrder/serviceNew.vue @@ -242,7 +242,7 @@ } }, computed: { - ...mapState(['teacherLevelList']) + ...mapState(['teacherLevelList', 'buyInfo', 'price_config']) }, onLoad: function(option) { }, @@ -273,6 +273,11 @@ this.companionLevel = this.teacherLevelList[0] this.$globalData.newOrderData.companionLevel = this.companionLevel } + // 计算并保存伴宠师等级价格 + this.$globalData.newOrderData.companionLevelPrice = this.calculateCompanionLevelPrice(this.companionLevel) + + // 保存城市倍率 + this.$globalData.newOrderData.cityPriceRate = this.isAddPrice() this.$store.commit('getUserInfo') @@ -283,6 +288,14 @@ return price * this.$store.state.memberRate }, + // 计算伴宠师等级价格(用于保存到全局数据) + calculateCompanionLevelPrice(level) { + if (!level || !level.paramValueText) { + return 0 + } + let price = Number(level.paramValueText) * this.isAddPrice() + return price * this.$store.state.memberRate + }, //判断当前选中的地址是否加价 isAddPrice(){ let currentAddress = this.$globalData.newOrderData.currentAddress || {} @@ -322,6 +335,8 @@ this.companionLevel = level; // 将选择的伴宠师等级保存到全局数据 this.$globalData.newOrderData.companionLevel = level; + // 计算并保存伴宠师等级价格 + this.$globalData.newOrderData.companionLevelPrice = this.calculateCompanionLevelPrice(level); }, showCompanionInfo(level) { this.showLevelInfo = level @@ -392,6 +407,10 @@ return; } this.$globalData.newOrderData.needPreFamiliarize = this.needPreFamiliarize + + // 保存城市倍率 + this.$globalData.newOrderData.cityPriceRate = this.isAddPrice() + uni.navigateTo({ url: "/pages/newOrder/serviceNew2" }); diff --git a/pages/newOrder/serviceNew2.vue b/pages/newOrder/serviceNew2.vue index 962e736..49e2990 100644 --- a/pages/newOrder/serviceNew2.vue +++ b/pages/newOrder/serviceNew2.vue @@ -153,7 +153,7 @@ 额外服务费 - ¥{{ feedCount > 2 ? price_config.multiService.three.price : price_config.multiService.two.price }} + ¥{{ (feedCount > 2 ? (isHoliday(currentMonthDay.fullDate) ? holidayPrice : normalPrice) * price_config.multiService.three.price : (isHoliday(currentMonthDay.fullDate) ? holidayPrice : normalPrice) * price_config.multiService.two.price).toFixed(2) }} @@ -861,17 +861,20 @@ export default { this.petTypeCounts = petTypeCounts // 2.3 当日多次服务总价 - // 计算每日多次服务次数费用 + // 计算每日多次服务次数费用 - 基础价格乘以倍数 let multServicesTotalCost = 0 let oneDayTwoTimesDates = [] let oneDayThreeTimesDates = [] for (const date in dailyPets) { const maxFeedCount = Math.max(...dailyPets[date].map(pet => pet.feedCount)); + const isHolidayDate = this.isHoliday(date); + const dayPrice = isHolidayDate ? parseFloat(this.holidayPrice) : parseFloat(this.normalPrice); + if (maxFeedCount === 2) { - multServicesTotalCost += this.price_config.multiService.two.price; // 1天2次 + multServicesTotalCost += dayPrice * this.price_config.multiService.two.price; // 基础价格 × 2次倍数 oneDayTwoTimesDates.push(date) } else if (maxFeedCount === 3) { - multServicesTotalCost += this.price_config.multiService.three.price; // 1天3次 + multServicesTotalCost += dayPrice * this.price_config.multiService.three.price; // 基础价格 × 3次倍数 oneDayThreeTimesDates.push(date) } } @@ -903,7 +906,6 @@ export default { + Number(this.baseServiceTotalCost) + Number(this.additionalTotalCost) + Number(this.multServicesTotalCost) - + Number(this.companionLevelPrice()) + Number(this.customServicesTotalCost) + Number(moreOrderPrice); // 更新总价 @@ -963,18 +965,7 @@ export default { }) } - let companionLevel = this.$globalData.newOrderData.companionLevel - if (companionLevel) { - priceDetails.push({ - name: '伴宠师等级', - item: [{ - itemName: companionLevel.paramValue, - price: this.companionLevelPrice(), - quantity: 1, - unit: '位' - },] - }) - } + // 伴宠师等级价格已合并到基础服务价格中,不再单独显示 // 分别统计节假日和非节假日的天数 const uniqueDates = new Set(this.newOrderData.pets.map(item => item.serviceDate)); let holidayCount = 0; @@ -1012,21 +1003,40 @@ export default { }); } if (this.oneDayTwoTimesDates.length > 0 || this.oneDayThreeTimesDates.length > 0) { + const multiServiceItems = [] + + // 计算1天2次的价格明细 + this.oneDayTwoTimesDates.forEach(date => { + const isHolidayDate = this.isHoliday(date) + const dayPrice = isHolidayDate ? parseFloat(this.holidayPrice) : parseFloat(this.normalPrice) + multiServiceItems.push({ + itemName: `1天2次 (${isHolidayDate ? '节假日' : '非节假日'})`, + price: dayPrice * this.price_config.multiService.two.price, + quantity: 1, + unit: '天', + date: date + }) + }) + + // 计算1天3次的价格明细 + this.oneDayThreeTimesDates.forEach(date => { + const isHolidayDate = this.isHoliday(date) + const dayPrice = isHolidayDate ? parseFloat(this.holidayPrice) : parseFloat(this.normalPrice) + multiServiceItems.push({ + itemName: `1天3次 (${isHolidayDate ? '节假日' : '非节假日'})`, + price: dayPrice * this.price_config.multiService.three.price, + quantity: 1, + unit: '天', + date: date + }) + }) + + // 按日期排序 + multiServiceItems.sort((a, b) => new Date(a.date) - new Date(b.date)) + priceDetails.push({ name: '上门次数', - item: [{ - itemName: '1天2次', - price: this.price_config.multiService.two.price, - quantity: this.oneDayTwoTimesDates.length, - unit: '天' - }, - { - itemName: '1天3次', - price: this.price_config.multiService.three.price, - quantity: this.oneDayThreeTimesDates.length, - unit: '天' - }, - ] + item: multiServiceItems }) } // 过滤宠物类型数量>0的数组 @@ -1144,11 +1154,16 @@ export default { initPriceConfig() { let priceConfig = this.$store.state.price_config console.log('价格配置:', priceConfig) + + // 获取伴宠师等级价格和城市倍率 + let companionPrice = this.$globalData.newOrderData.companionLevelPrice || 0 + let cityPriceRate = this.$globalData.newOrderData.cityPriceRate || 1 + if(priceConfig.basePrice && priceConfig.basePrice.holiday){ - this.holidayPrice = (priceConfig.basePrice.holiday * this.$store.state.memberRate).toFixed(2) + this.holidayPrice = ((priceConfig.basePrice.holiday * this.$store.state.memberRate * cityPriceRate) + companionPrice).toFixed(2) } if(priceConfig.basePrice && priceConfig.basePrice.normal){ - this.normalPrice = (priceConfig.basePrice.normal * this.$store.state.memberRate).toFixed(2) + this.normalPrice = ((priceConfig.basePrice.normal * this.$store.state.memberRate * cityPriceRate) + companionPrice).toFixed(2) } if(priceConfig.holidays && priceConfig.holidays.length > 0){ this.holidayDate = priceConfig.holidays @@ -1284,13 +1299,13 @@ export default { bodyType: '大型', }) * largeDogCount) } - // 当日多次服务次数 + // 当日多次服务次数 - 基础价格乘以倍数 let multServicesTotalCost = 0 const maxFeedCount = Math.max(...currentDayPets.map(pet => pet.feedCount)); if (maxFeedCount === 2) { - multServicesTotalCost += this.price_config.multiService.two.price; // 1天2次 + multServicesTotalCost += baseServiceCost * this.price_config.multiService.two.price; // 基础价格 × 2次倍数 } else if (maxFeedCount === 3) { - multServicesTotalCost += this.price_config.multiService.three.price; // 1天3次 + multServicesTotalCost += baseServiceCost * this.price_config.multiService.three.price; // 基础价格 × 3次倍数 } // 所有宠物定制服务费用 const customServiceCost = currentDayPets.reduce((acc, pet) => acc + this.calculatePetCustomServiceCost(pet), 0)