Browse Source

feat(订单): 重构价格计算逻辑,合并伴宠师等级价格到基础服务费

- 将伴宠师等级价格和城市倍率合并到基础服务价格计算中
- 修改多次服务价格计算方式为基于基础价格乘以倍数
- 在价格明细中显示节假日/非节假日标识
- 移除单独显示的伴宠师等级价格项
master
前端-胡立永 3 weeks ago
parent
commit
462c4bb9ef
5 changed files with 103 additions and 57 deletions
  1. +1
    -0
      main.js
  2. +21
    -19
      pages/newOrder/confirmOrder.vue
  3. +11
    -2
      pages/newOrder/petList.vue
  4. +20
    -1
      pages/newOrder/serviceNew.vue
  5. +50
    -35
      pages/newOrder/serviceNew2.vue

+ 1
- 0
main.js View File

@ -78,6 +78,7 @@ Vue.prototype.initGlobalData = function() {
totalPrice:0,
needPreFamiliarize:[],
distancePrice : 0, // 距离加价
companionLevelPrice : 0, // 伴宠师等级价格
}
}
}


+ 21
- 19
pages/newOrder/confirmOrder.vue View File

@ -158,10 +158,7 @@
<view>提前熟悉 </view>
<view>¥{{ price_config.preFamiliarize.price }}</view>
</view>
<view v-if="companionLevelPrice()>0" class="total-cost">
<view> {{ buyInfo.teacher ? buyInfo.teacher.userName : companionLevelTitle }} </view>
<view>¥{{ companionLevelPrice() }}</view>
</view>
<!-- 伴宠师价格已合并到基础服务价格中不再单独显示 -->
<view class="total-cost">
<view>费用总计 </view>
<view>¥{{ parseFloat(originalTotalPrice).toFixed(2) }}</view>
@ -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; // 12
multServicesTotalCost += baseServiceCost * this.price_config.multiService.two.price; // × 2
} else if (maxFeedCount === 3) {
multServicesTotalCost += this.price_config.multiService.three.price; // 13
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; // 12
feedCountPrice += price * this.price_config.multiService.two.price; // × 2
} else if (pet.feedCount == 3) {
feedCountPrice += this.price_config.multiService.three.price; // 13
feedCountPrice += price * this.price_config.multiService.three.price; // × 3
}
return {
petId: pet.petId,


+ 11
- 2
pages/newOrder/petList.vue View File

@ -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


+ 20
- 1
pages/newOrder/serviceNew.vue View File

@ -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"
});


+ 50
- 35
pages/newOrder/serviceNew2.vue View File

@ -153,7 +153,7 @@
<view class="service-row-content">
<text class="service-name" style="color: #A94F20;">额外服务费</text>
<view class="service-price" style="color:#A94F20">
¥{{ 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) }}
</view>
</view>
</view>
@ -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; // 12
multServicesTotalCost += dayPrice * this.price_config.multiService.two.price; // × 2
oneDayTwoTimesDates.push(date)
} else if (maxFeedCount === 3) {
multServicesTotalCost += this.price_config.multiService.three.price; // 13
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 = []
// 12
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
})
})
// 13
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; // 12
multServicesTotalCost += baseServiceCost * this.price_config.multiService.two.price; // × 2
} else if (maxFeedCount === 3) {
multServicesTotalCost += this.price_config.multiService.three.price; // 13
multServicesTotalCost += baseServiceCost * this.price_config.multiService.three.price; // × 3
}
//
const customServiceCost = currentDayPets.reduce((acc, pet) => acc + this.calculatePetCustomServiceCost(pet), 0)


Loading…
Cancel
Save