Commit 227c81c1 by cen

feat: 添加订单策略组件及相关逻辑

- 在 OrderCard.vue 中新增支付方式和审批状态显示
- 在 CreateOrder.vue、Package.vue 和 SkuGoods.vue 中集成 OrderStrategy 组件,支持折扣、买赠和组合付款策略
- 更新价格计算逻辑以支持不同订单类型的策略
- 增强商品价格显示和策略配置的初始化逻辑
1 parent 5690aa84
...@@ -39,6 +39,23 @@ ...@@ -39,6 +39,23 @@
</view> </view>
</view> </view>
</view> </view>
<!-- 支付方式 -->
<view class="order-payType flex">
<view class="payType flex align-center">
<view class="payType-label">订单类型</view>
<view class="payType-value flex align-center">
{{ payType[orderCardDetail['selectPayType']] }}
</view>
</view>
<view class="order-price flex align-center">
<view class="order-price-label">审批状态</view>
<view class="price">
<text class="unit">¥</text>
{{ orderCardDetail.totalPrice }}
</view>
</view>
</view>
<view class="info-box"> <view class="info-box">
<view class="order-list align-center" v-for="(item, sindex) in orderCardDetail.deliveryUserId ? pointsMultiObj : orderObj" :key="sindex"> <view class="order-list align-center" v-for="(item, sindex) in orderCardDetail.deliveryUserId ? pointsMultiObj : orderObj" :key="sindex">
<view class="order flex align-center"> <view class="order flex align-center">
......
...@@ -26,14 +26,21 @@ ...@@ -26,14 +26,21 @@
</view> </view>
</view> </view>
</view> </view>
<!-- 折扣 / 买赠 / 组合付款策略组件 -->
<OrderStrategy v-if="getStrategyType(goods)" :strategyType="getStrategyType(goods)" v-model="goods.strategyConfig" :basePrice="getBasePrice(goods, item)" :displayPrice="getDisplayPrice(goods, item)" @priceChange="onPriceChange(goods, $event)" />
</view> </view>
</view> </view>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import OrderStrategy from './OrderStrategy.vue'
export default { export default {
name: 'Package', name: 'Package',
components: {
OrderStrategy
},
props: { props: {
list: { list: {
type: Array, type: Array,
...@@ -42,6 +49,10 @@ export default { ...@@ -42,6 +49,10 @@ export default {
positionTypeList: { positionTypeList: {
type: Array, type: Array,
default: [] default: []
},
orderTypeCode: {
type: [String, Number],
default: ''
} }
}, },
created() { created() {
...@@ -52,12 +63,22 @@ export default { ...@@ -52,12 +63,22 @@ export default {
mounted() { mounted() {
// 确保每次使用组件时都检查并设置number属性 // 确保每次使用组件时都检查并设置number属性
this.initProductNumbers() this.initProductNumbers()
// 根据订单类型初始化策略配置
this.initStrategyConfig()
}, },
updated() { updated() {
// 当组件数据更新时也检查number属性 // 当组件数据更新时也检查number属性
this.initProductNumbers() this.initProductNumbers()
console.log(this.list, 'Package-list2') console.log(this.list, 'Package-list2')
}, },
watch: {
orderTypeCode: {
handler() {
this.initStrategyConfig()
},
immediate: true
}
},
methods: { methods: {
// 初始化商品数量方法 // 初始化商品数量方法
initProductNumbers() { initProductNumbers() {
...@@ -173,6 +194,121 @@ export default { ...@@ -173,6 +194,121 @@ export default {
}) })
item.packageGoods.upgradePrice = total item.packageGoods.upgradePrice = total
return total.toFixed(2) return total.toFixed(2)
},
// 根据订单类型获取策略类型
getStrategyType(goods) {
const orderType = String(this.orderTypeCode || '')
// '1' 正常订单、'4' 冲量活动:不显示策略组件
if (orderType === '1' || orderType === '4') {
return null
}
// '2' 打折策略
if (orderType === '2') {
return 'discount'
}
// '3' 买赠策略
if (orderType === '3') {
return 'gift'
}
// '5' 组合付款
if (orderType === '5') {
return 'combined'
}
return null
},
// 计算基础价格(单价 * 数量)
getBasePrice(goods, item) {
if (!goods) return 0
const sellPrice = parseFloat(goods.sellPrice || 0)
const number = parseInt(item.packageGoods.number || 1)
const basePrice = sellPrice * number
// 四舍五入保留两位小数
return Math.round(basePrice * 100) / 100
},
// 计算最终显示价格
getDisplayPrice(goods, item) {
const basePrice = this.getBasePrice(goods, item)
if (!basePrice) return '¥0.00'
const orderType = String(this.orderTypeCode || '')
const strategyConfig = goods.strategyConfig || {}
// '2' 打折策略
if (orderType === '2') {
if (strategyConfig.mode === 'ratio' && strategyConfig.discountRatio) {
const ratio = parseFloat(strategyConfig.discountRatio)
if (ratio >= 1 && ratio <= 10) {
const finalPrice = basePrice * (ratio / 10)
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
}
} else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) {
const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0 && discountAmount <= basePrice) {
const finalPrice = basePrice - discountAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
}
}
return '¥' + basePrice.toFixed(2)
}
// '3' 买赠策略
if (orderType === '3') {
if (strategyConfig.isGift === '1') {
return '¥0.00'
}
return '¥' + basePrice.toFixed(2)
}
// '5' 组合付款
if (orderType === '5') {
if (strategyConfig.mode === 'deduct' && strategyConfig.deductAmount) {
const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0 && deductAmount <= basePrice) {
const finalPrice = basePrice - deductAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
}
}
return '¥' + basePrice.toFixed(2)
}
return '¥' + basePrice.toFixed(2)
},
// 价格变化回调
onPriceChange(goods, finalPrice) {
// 可以在这里更新商品的其他价格相关字段
this.$set(goods, 'finalPrice', finalPrice)
this.$emit('changeTotalPrice')
},
// 初始化策略配置
initStrategyConfig() {
if (!this.list || this.list.length === 0) return
const strategyType = this.getStrategyType({})
if (!strategyType) return
this.list.forEach(item => {
if (!item.packageGoods || !item.packageGoods.goodsList) return
item.packageGoods.goodsList.forEach(goods => {
// 如果还没有 strategyConfig,初始化一个默认值
if (!goods.strategyConfig) {
if (strategyType === 'discount') {
this.$set(goods, 'strategyConfig', {
mode: 'none',
discountRatio: '',
discountAmount: ''
})
} else if (strategyType === 'gift') {
this.$set(goods, 'strategyConfig', {
isGift: '0'
})
} else if (strategyType === 'combined') {
this.$set(goods, 'strategyConfig', {
mode: 'none',
deductAmount: ''
})
}
}
})
})
} }
} }
} }
......
...@@ -49,6 +49,8 @@ ...@@ -49,6 +49,8 @@
<view class="add" @click="increaseNumber(item)">+</view> <view class="add" @click="increaseNumber(item)">+</view>
</view> </view>
</view> </view>
<!-- 折扣 / 买赠 / 组合付款策略组件 -->
<OrderStrategy v-if="getStrategyType(item)" :strategyType="getStrategyType(item)" :value="getStrategyConfig(item)" :basePrice="getBasePrice(item)" :displayPrice="getDisplayPrice(item)" @input="onStrategyConfigChange(item, $event)" @priceChange="onPriceChange(item, $event)" />
</view> </view>
</view> </view>
</view> </view>
...@@ -56,8 +58,13 @@ ...@@ -56,8 +58,13 @@
</template> </template>
<script> <script>
import OrderStrategy from './OrderStrategy.vue'
export default { export default {
name: 'SkuGoods', name: 'SkuGoods',
components: {
OrderStrategy
},
props: { props: {
list: { list: {
type: Array, type: Array,
...@@ -74,6 +81,10 @@ export default { ...@@ -74,6 +81,10 @@ export default {
isDisabled: { isDisabled: {
type: Boolean, type: Boolean,
default: false default: false
},
orderTypeCode: {
type: [String, Number],
default: ''
} }
}, },
created() { created() {
...@@ -83,11 +94,21 @@ export default { ...@@ -83,11 +94,21 @@ export default {
mounted() { mounted() {
// 确保每次使用组件时都检查并设置number属性 // 确保每次使用组件时都检查并设置number属性
this.initProductNumbers() this.initProductNumbers()
// 根据订单类型初始化策略配置
this.initStrategyConfig()
}, },
updated() { updated() {
// 当组件数据更新时也检查number属性 // 当组件数据更新时也检查number属性
this.initProductNumbers() this.initProductNumbers()
}, },
watch: {
orderTypeCode: {
handler() {
this.initStrategyConfig()
},
immediate: true
}
},
methods: { methods: {
// 初始化商品数量方法 // 初始化商品数量方法
initProductNumbers() { initProductNumbers() {
...@@ -253,6 +274,154 @@ export default { ...@@ -253,6 +274,154 @@ export default {
deleteGoods(index) { deleteGoods(index) {
this.list.splice(index, 1) this.list.splice(index, 1)
this.$emit('changeTotalPrice') this.$emit('changeTotalPrice')
},
// 根据订单类型获取策略类型
getStrategyType(item) {
const orderType = String(this.orderTypeCode || '')
// '1' 正常订单、'4' 冲量活动:不显示策略组件
if (orderType === '1' || orderType === '4') {
return null
}
// '2' 打折策略
if (orderType === '2') {
return 'discount'
}
// '3' 买赠策略
if (orderType === '3') {
return 'gift'
}
// '5' 组合付款
if (orderType === '5') {
return 'combined'
}
return null
},
// 获取策略配置对象
getStrategyConfig(item) {
if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods) {
return item.multipleSpecificationsGoods.goods.strategyConfig || {}
}
return item.goods.strategyConfig || {}
},
// 策略配置变化回调
onStrategyConfigChange(item, config) {
if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods) {
this.$set(item.multipleSpecificationsGoods.goods, 'strategyConfig', config)
} else if (item.goods) {
this.$set(item.goods, 'strategyConfig', config)
}
},
// 计算基础价格(单价 * 数量)
getBasePrice(item) {
let sellPrice = 0
let number = 1
if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods) {
sellPrice = parseFloat(item.multipleSpecificationsGoods.goods.sellPrice || 0)
number = parseInt(item.multipleSpecificationsGoods.number || 1)
} else if (item.goods) {
sellPrice = parseFloat(item.goods.sellPrice || 0)
number = parseInt(item.goods.number || 1)
}
const basePrice = sellPrice * number
// 四舍五入保留两位小数
return Math.round(basePrice * 100) / 100
},
// 计算最终显示价格
getDisplayPrice(item) {
const basePrice = this.getBasePrice(item)
if (!basePrice) return '¥0.00'
const orderType = String(this.orderTypeCode || '')
const strategyConfig = this.getStrategyConfig(item)
// '2' 打折策略
if (orderType === '2') {
if (strategyConfig.mode === 'ratio' && strategyConfig.discountRatio) {
const ratio = parseFloat(strategyConfig.discountRatio)
if (ratio >= 1 && ratio <= 10) {
const finalPrice = basePrice * (ratio / 10)
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
}
} else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) {
const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0 && discountAmount <= basePrice) {
const finalPrice = basePrice - discountAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
}
}
return '¥' + basePrice.toFixed(2)
}
// '3' 买赠策略
if (orderType === '3') {
if (strategyConfig.isGift === '1') {
return '¥0.00'
}
return '¥' + basePrice.toFixed(2)
}
// '5' 组合付款
if (orderType === '5') {
if (strategyConfig.mode === 'deduct' && strategyConfig.deductAmount) {
const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0 && deductAmount <= basePrice) {
const finalPrice = basePrice - deductAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
}
}
return '¥' + basePrice.toFixed(2)
}
return '¥' + basePrice.toFixed(2)
},
// 价格变化回调
onPriceChange(item, finalPrice) {
// 可以在这里更新商品的其他价格相关字段
if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods) {
this.$set(item.multipleSpecificationsGoods.goods, 'finalPrice', finalPrice)
} else if (item.goods) {
this.$set(item.goods, 'finalPrice', finalPrice)
}
this.$emit('changeTotalPrice')
},
// 初始化策略配置
initStrategyConfig() {
if (!this.list || this.list.length === 0) return
const strategyType = this.getStrategyType({})
if (!strategyType) return
this.list.forEach(item => {
let goods = null
if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods) {
goods = item.multipleSpecificationsGoods.goods
} else if (item.goods) {
goods = item.goods
}
if (!goods) return
// 如果还没有 strategyConfig,初始化一个默认值
if (!goods.strategyConfig) {
if (strategyType === 'discount') {
this.$set(goods, 'strategyConfig', {
mode: 'none',
discountRatio: '',
discountAmount: ''
})
} else if (strategyType === 'gift') {
this.$set(goods, 'strategyConfig', {
isGift: '0'
})
} else if (strategyType === 'combined') {
this.$set(goods, 'strategyConfig', {
mode: 'none',
deductAmount: ''
})
}
}
})
} }
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!