Commit 3cc874a1 by cen

fix: 修复订单弹窗和策略组件中的逻辑错误

- 修改 env.js 中的 index 值以确保正确的默认订单类型
- 在 OrderPopup 组件中添加 hideFooter 属性以控制底部显示
- 更新 CreateOrder 组件中的 popupType 逻辑,确保在未找到对应类型时输出错误信息
- 在多个组件中增强订单策略验证逻辑,确保在订单类型切换时重置策略配置
- 优化价格计算逻辑,确保在订单提交时进行有效性检查
1 parent 61140f45
...@@ -383,6 +383,7 @@ const componentConfig = { ...@@ -383,6 +383,7 @@ const componentConfig = {
name: 'OrderTypePopup', name: 'OrderTypePopup',
title: '订单类型', title: '订单类型',
hideSearch: true, hideSearch: true,
hideFooter: false,
// 绑定 CreateOrder 中的字段名 // 绑定 CreateOrder 中的字段名
idKey: 'djOrderType', idKey: 'djOrderType',
cacheData: [], cacheData: [],
......
<template> <template>
<view class="order-popup"> <view class="order-popup">
<popup <popup :position="position" :animation="animation" ref="popup" @onConfirm="confirm" @onCancel="cancel" @onReset="reset" :showReset="popupType === 15" :hideFooter="componentObject[popupType] && componentObject[popupType].hideFooter" :popupStyle="(componentObject[popupType] && componentObject[popupType].popupStyle) || ''">
:position="position"
:animation="animation"
ref="popup"
@onConfirm="confirm"
@onCancel="cancel"
@onReset="reset"
:showReset="popupType === 15"
:hideFooter="componentObject[popupType].hideFooter"
:popupStyle="componentObject[popupType].popupStyle || ''"
>
<view class="popup-title flex"> <view class="popup-title flex">
{{ title }} {{ title }}
<view <view class="popup-close flex" @click="close">
class="popup-close flex" <uni-icons type="closeempty" size="16"></uni-icons>
@click="close"
>
<uni-icons
type="closeempty"
size="16"
></uni-icons>
</view> </view>
</view> </view>
<template v-if="!componentObject[popupType].hideSearch"> <template v-if="componentObject[popupType] && !componentObject[popupType].hideSearch">
<view class="popup-search"> <view class="popup-search">
<input <input class="input" type="text" :placeholder="(componentObject[popupType] && componentObject[popupType].placeholder) || '请输入'" placeholder-class="placeholder" v-model="componentObject[popupType].searchValue" confirm-type="search" @confirm="handleSearch" />
class="input" <view class="clear flex" @click="clear">
type="text" <uni-icons type="closeempty" size="16" v-if="componentObject[popupType] && componentObject[popupType].searchValue"></uni-icons>
:placeholder="componentObject[popupType].placeholder || '请输入'"
placeholder-class="placeholder"
v-model="componentObject[popupType].searchValue"
confirm-type="search"
@confirm="handleSearch"
/>
<view
class="clear flex"
@click="clear"
>
<uni-icons
type="closeempty"
size="16"
v-if="componentObject[popupType].searchValue"
></uni-icons>
</view> </view>
</view> </view>
</template> </template>
<view :class="['popup-body', <view v-if="componentObject[popupType]" :class="['popup-body', { 'hide-footer': componentObject[popupType].hideFooter }, { 'hide-search': componentObject[popupType].hideSearch }, { 'hide-footer-search': componentObject[popupType].hideFooter && componentObject[popupType].hideSearch }]">
{'hide-footer': componentObject[popupType].hideFooter }, <scroll-view scroll-y :class="['popup-scroll-view', { show: componentObject[popupType].loadComplete }]">
{'hide-search': componentObject[popupType].hideSearch }, <component :is="componentObject[popupType].name" :params.sync="componentObject[popupType]" :data="data" :dataKey="dataKey" :isDefeatOrder="isDefeatOrder" :defaultTime="defaultTime" :positionTypeList="positionTypeList" ref="componentRef" @choose="chooseContent = $event" @openSkuPopup="openSkuPopup" @onComplete="componentObject[popupType].loadComplete = true" @confirm="confirm"></component>
{'hide-footer-search':componentObject[popupType].hideFooter && componentObject[popupType].hideSearch }
]">
<scroll-view
scroll-y
:class="['popup-scroll-view', { show: componentObject[popupType].loadComplete }]"
>
<component
:is="componentObject[popupType].name"
:params.sync="componentObject[popupType]"
:data="data"
:dataKey="dataKey"
:isDefeatOrder="isDefeatOrder"
:defaultTime="defaultTime"
:positionTypeList="positionTypeList"
ref="componentRef"
@choose="chooseContent = $event"
@openSkuPopup="openSkuPopup"
@onComplete="componentObject[popupType].loadComplete = true"
@confirm="confirm"
></component>
<template v-if="componentObject[popupType].noData"> <template v-if="componentObject[popupType].noData">
<view class="nothing flex">暂无数据</view> <view class="nothing flex">暂无数据</view>
</template> </template>
</scroll-view> </scroll-view>
<image <image v-if="!componentObject[popupType].loadComplete" class="loading" src="../../assets/images/common/loadding.gif" />
v-if="!componentObject[popupType].loadComplete"
class="loading"
src="../../assets/images/common/loadding.gif"
/>
</view> </view>
</popup> </popup>
<sku-popup <sku-popup ref="skuPopupRef" @onConfirm="skuConfirm"></sku-popup>
ref="skuPopupRef"
@onConfirm="skuConfirm"
></sku-popup>
</view> </view>
</template> </template>
...@@ -239,17 +181,25 @@ export default { ...@@ -239,17 +181,25 @@ export default {
}, },
initPopupData () { initPopupData () {
this.chooseContent = null this.chooseContent = null
if (!this.componentObject[this.popupType]) {
console.error(`Popup type ${this.popupType} not found in config`)
return
}
let componentRef = this.componentRef() let componentRef = this.componentRef()
if (!componentRef) setTimeout(this.initPopupData, .1e3) if (!componentRef) setTimeout(this.initPopupData, .1e3)
else componentRef.getList && componentRef.getList(this.componentObject[this.popupType].searchValue) else componentRef.getList && componentRef.getList(this.componentObject[this.popupType].searchValue || '')
}, },
handleSearch () { handleSearch () {
if (!this.componentObject[this.popupType]) {
console.error(`Popup type ${this.popupType} not found in config`)
return
}
let componentRef = this.componentRef() let componentRef = this.componentRef()
if (!componentRef) uni.showToast({ if (!componentRef) uni.showToast({
title: '请稍后再试', title: '请稍后再试',
icon: 'none' icon: 'none'
}) })
else componentRef.handleSearch(this.componentObject[this.popupType].searchValue) else componentRef.handleSearch(this.componentObject[this.popupType].searchValue || '')
}, },
confirm (autoClose) { confirm (autoClose) {
try { try {
......
const target = ['ip', 'dev', 'uat', 'prod', 'beta'] const target = ['ip', 'dev', 'uat', 'prod', 'beta']
const index = 2 const index = 1
/** /**
* *
0本地 0本地
......
...@@ -436,10 +436,19 @@ export default { ...@@ -436,10 +436,19 @@ export default {
handleCell(val) { handleCell(val) {
console.log(val, this.orderObj) console.log(val, this.orderObj)
// 获取当前选中的popupType // 获取当前选中的popupType
this.popupType = Object.keys(this.popupTypeEnum).find(key => this.popupTypeEnum[key].key === val.value) * 1 const foundKey = Object.keys(this.popupTypeEnum).find(key => this.popupTypeEnum[key].key === val.value)
if (!foundKey) {
console.error(`Popup type not found for value: ${val.value}`)
return
}
this.popupType = foundKey * 1
// 获取对应的list字段 // 获取对应的list字段
const popupConfig = this.popupTypeEnum[this.popupType] const popupConfig = this.popupTypeEnum[this.popupType]
if (popupConfig && popupConfig.list) { if (!popupConfig) {
console.error(`Popup config not found for popupType: ${this.popupType}`)
return
}
if (popupConfig.list) {
this.externalData = this[popupConfig.list] || [] this.externalData = this[popupConfig.list] || []
} else { } else {
this.externalData = [] this.externalData = []
...@@ -451,7 +460,12 @@ export default { ...@@ -451,7 +460,12 @@ export default {
this.externalData = utils.deepClone(this.goodsList) this.externalData = utils.deepClone(this.goodsList)
} }
console.log(this.popupType, this.externalData, '-------------') console.log(this.popupType, this.externalData, '-------------')
this.$refs.orderPopup.open() // 确保 orderPopup 引用存在后再调用 open 方法
if (this.$refs.orderPopup && this.$refs.orderPopup.open) {
this.$refs.orderPopup.open()
} else {
console.error('OrderPopup ref is not available')
}
}, },
// 单选框change事件 // 单选框change事件
radioChange(e, val) { radioChange(e, val) {
...@@ -492,6 +506,12 @@ export default { ...@@ -492,6 +506,12 @@ export default {
// 订单类型 // 订单类型
this.$set(this.orderObj, 'djOrderType', chooseContent.name) this.$set(this.orderObj, 'djOrderType', chooseContent.name)
this.$set(this.orderObj, 'orderTypeCode', chooseContent.value) this.$set(this.orderObj, 'orderTypeCode', chooseContent.value)
// 订单类型切换时,清除已选商品
const productFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof', 'package', 'skuGoods']
productFields.forEach(field => {
this.$set(this.orderObj, field, null)
})
this.changeTotalPrice()
} else if (productFields.includes(_typeValue.key)) { } else if (productFields.includes(_typeValue.key)) {
if (_typeValue.key == 'skuGoods') { if (_typeValue.key == 'skuGoods') {
if (!this.orderObj[_typeValue.key]) { if (!this.orderObj[_typeValue.key]) {
...@@ -616,6 +636,141 @@ export default { ...@@ -616,6 +636,141 @@ export default {
return true return true
}, },
// 验证订单策略和总价
checkOrderStrategyAndTotal() {
const orderTypeCode = String(this.orderObj.orderTypeCode || '')
const labelFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof', 'package', 'skuGoods']
let allGoods = []
// 收集所有商品
labelFields.forEach(field => {
const goodsList = this.orderObj[field]
if (Array.isArray(goodsList) && goodsList.length > 0) {
allGoods = allGoods.concat(goodsList)
}
})
// 检查订单总价
const total = parseFloat(this.totalPrice || 0)
if (total < 0.01) {
uni.showToast({
title: '商品总价不可小于0.01,请修改商品价格后提交',
icon: 'none'
})
return false
}
// 如果是打折策略(2)、买赠策略(3)、组合付款(5),需要验证策略配置
if (orderTypeCode === '2') {
// 打折策略:至少存在一项SKU为"比例折扣"或"折扣金额"
let hasDiscount = false
allGoods.forEach(item => {
let goods = null
if (item.goods) {
goods = item.goods
} else if (item.packageGoods && item.packageGoods.goodsList) {
// 套餐商品,检查套餐内的商品
item.packageGoods.goodsList.forEach(g => {
const strategyConfig = g.strategyConfig || {}
if (strategyConfig.mode === 'ratio' && strategyConfig.discountRatio) {
hasDiscount = true
} else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) {
hasDiscount = true
}
})
} else if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods) {
goods = item.multipleSpecificationsGoods.goods
}
if (goods) {
const strategyConfig = goods.strategyConfig || {}
if (strategyConfig.mode === 'ratio' && strategyConfig.discountRatio) {
hasDiscount = true
} else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) {
hasDiscount = true
}
}
})
if (!hasDiscount) {
uni.showToast({
title: '至少存在一项SKU为"比例折扣"或"折扣金额"',
icon: 'none'
})
return false
}
} else if (orderTypeCode === '3') {
// 买赠策略:至少存在一项SKU为"赠品"
let hasGift = false
allGoods.forEach(item => {
let goods = null
if (item.goods) {
goods = item.goods
} else if (item.packageGoods && item.packageGoods.goodsList) {
// 套餐商品,检查套餐内的商品
item.packageGoods.goodsList.forEach(g => {
const strategyConfig = g.strategyConfig || {}
if (strategyConfig.isGift === '1') {
hasGift = true
}
})
} else if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods) {
goods = item.multipleSpecificationsGoods.goods
}
if (goods) {
const strategyConfig = goods.strategyConfig || {}
if (strategyConfig.isGift === '1') {
hasGift = true
}
}
})
if (!hasGift) {
uni.showToast({
title: '至少存在一项SKU为"赠品"',
icon: 'none'
})
return false
}
} else if (orderTypeCode === '5') {
// 组合付款:至少存在一项SKU为"抵扣金额"
let hasDeduct = false
allGoods.forEach(item => {
let goods = null
if (item.goods) {
goods = item.goods
} else if (item.packageGoods && item.packageGoods.goodsList) {
// 套餐商品,检查套餐内的商品
item.packageGoods.goodsList.forEach(g => {
const strategyConfig = g.strategyConfig || {}
if (strategyConfig.mode === 'deduct' && strategyConfig.deductAmount) {
hasDeduct = true
}
})
} else if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods) {
goods = item.multipleSpecificationsGoods.goods
}
if (goods) {
const strategyConfig = goods.strategyConfig || {}
if (strategyConfig.mode === 'deduct' && strategyConfig.deductAmount) {
hasDeduct = true
}
}
})
if (!hasDeduct) {
uni.showToast({
title: '至少存在一项SKU为"抵扣金额"',
icon: 'none'
})
return false
}
}
return true
},
// 提交 // 提交
async submit() { async submit() {
...@@ -635,6 +790,11 @@ export default { ...@@ -635,6 +790,11 @@ export default {
} }
} }
// 验证订单策略和总价
if (!this.checkOrderStrategyAndTotal()) {
return
}
if (!(await this.checkDailyReport())) { if (!(await this.checkDailyReport())) {
const { orderCreateType } = this const { orderCreateType } = this
const obj = utils.deepClone(this.orderObj) const obj = utils.deepClone(this.orderObj)
......
...@@ -165,15 +165,54 @@ export default { ...@@ -165,15 +165,54 @@ export default {
} }
}, },
watch: { watch: {
// 策略类型变化时,重置 mode 为 'none'
strategyType: {
handler(newType, oldType) {
// 当策略类型改变时(从其他类型切换到 combined 或 discount),重置 mode 为 'none'
if ((newType === 'combined' || newType === 'discount') && oldType && oldType !== newType) {
this.$nextTick(() => {
this.localState.mode = 'none'
})
}
},
immediate: false
},
// 外部 v-model -> 内部 state // 外部 v-model -> 内部 state
value: { value: {
handler(val) { handler(val) {
if (!val) return if (!val || Object.keys(val).length === 0) {
// 如果 value 为空,确保 mode 为 'none'(对于组合付款和打折策略)
if (this.strategyType === 'combined' || this.strategyType === 'discount') {
this.localState.mode = 'none'
}
return
}
// 先更新所有存在的字段
Object.keys(this.localState).forEach(key => { Object.keys(this.localState).forEach(key => {
if (val[key] !== undefined) { if (val[key] !== undefined) {
this.localState[key] = val[key] this.localState[key] = val[key]
} }
}) })
// 对于组合付款和打折策略,确保 mode 字段正确设置
if (this.strategyType === 'combined' || this.strategyType === 'discount') {
// 如果 value 中有 mode 字段,检查它是否与当前策略类型匹配
if (val.mode !== undefined) {
// 如果 strategyType 是 'discount',但 mode 是 'deduct'(组合付款的值),重置为 'none'
if (this.strategyType === 'discount' && val.mode === 'deduct') {
this.localState.mode = 'none'
}
// 如果 strategyType 是 'combined',但 mode 是 'ratio' 或 'amount'(打折策略的值),重置为 'none'
else if (this.strategyType === 'combined' && (val.mode === 'ratio' || val.mode === 'amount')) {
this.localState.mode = 'none'
}
// 否则使用 value 中的 mode
else {
this.localState.mode = val.mode
}
} else {
this.localState.mode = 'none'
}
}
}, },
deep: true, deep: true,
immediate: true immediate: true
...@@ -324,8 +363,15 @@ export default { ...@@ -324,8 +363,15 @@ export default {
onDiscountTabChange(mode) { onDiscountTabChange(mode) {
this.localState.mode = mode this.localState.mode = mode
if (mode === 'none') { if (mode === 'none') {
// 无折扣:清空所有输入框
this.localState.discountRatio = '' this.localState.discountRatio = ''
this.localState.discountAmount = '' this.localState.discountAmount = ''
} else if (mode === 'ratio') {
// 切换到折扣比例:清空折扣金额
this.localState.discountAmount = ''
} else if (mode === 'amount') {
// 切换到折扣金额:清空折扣比例
this.localState.discountRatio = ''
} }
}, },
onCombinedTabChange(mode) { onCombinedTabChange(mode) {
......
...@@ -355,29 +355,41 @@ export default { ...@@ -355,29 +355,41 @@ export default {
initStrategyConfig() { initStrategyConfig() {
if (!this.list || this.list.length === 0) return if (!this.list || this.list.length === 0) return
const strategyType = this.getStrategyType({}) const strategyType = this.getStrategyType({})
if (!strategyType) return if (!strategyType) {
// 订单类型切换时,重置所有商品的策略配置
this.list.forEach(item => {
if (!item.packageGoods || !item.packageGoods.goodsList) return
item.packageGoods.goodsList.forEach(goods => {
if (goods.strategyConfig) {
goods.strategyConfig = {}
}
goods.discountType = null
goods.discountValue = null
goods.finalPrice = null
})
})
return
}
this.list.forEach(item => { this.list.forEach(item => {
if (!item.packageGoods || !item.packageGoods.goodsList) return if (!item.packageGoods || !item.packageGoods.goodsList) return
item.packageGoods.goodsList.forEach(goods => { item.packageGoods.goodsList.forEach(goods => {
// 如果还没有 strategyConfig,初始化一个默认值 // 无论 strategyConfig 是否存在,都根据新的策略类型重新初始化
if (!goods.strategyConfig) { if (strategyType === 'discount') {
if (strategyType === 'discount') { this.$set(goods, 'strategyConfig', {
this.$set(goods, 'strategyConfig', { mode: 'none',
mode: 'none', discountRatio: '',
discountRatio: '', discountAmount: ''
discountAmount: '' })
}) } else if (strategyType === 'gift') {
} else if (strategyType === 'gift') { this.$set(goods, 'strategyConfig', {
this.$set(goods, 'strategyConfig', { isGift: '0'
isGift: '0' })
}) } else if (strategyType === 'combined') {
} else if (strategyType === 'combined') { this.$set(goods, 'strategyConfig', {
this.$set(goods, 'strategyConfig', { mode: 'none',
mode: 'none', deductAmount: ''
deductAmount: '' })
})
}
} }
}) })
}) })
......
...@@ -188,28 +188,38 @@ export default { ...@@ -188,28 +188,38 @@ export default {
initStrategyConfig() { initStrategyConfig() {
if (!this.list || this.list.length === 0) return if (!this.list || this.list.length === 0) return
const strategyType = this.getStrategyType({}) const strategyType = this.getStrategyType({})
if (!strategyType) return if (!strategyType) {
// 订单类型切换时,重置所有商品的策略配置
this.list.forEach(item => {
if (!item.goods) return
if (item.goods.strategyConfig) {
item.goods.strategyConfig = {}
}
item.goods.discountType = null
item.goods.discountValue = null
item.goods.finalPrice = null
})
return
}
this.list.forEach(item => { this.list.forEach(item => {
if (!item.goods) return if (!item.goods) return
// 如果还没有 strategyConfig,初始化一个默认值 // 无论 strategyConfig 是否存在,都根据新的策略类型重新初始化
if (!item.goods.strategyConfig) { if (strategyType === 'discount') {
if (strategyType === 'discount') { this.$set(item.goods, 'strategyConfig', {
this.$set(item.goods, 'strategyConfig', { mode: 'none',
mode: 'none', discountRatio: '',
discountRatio: '', discountAmount: ''
discountAmount: '' })
}) } else if (strategyType === 'gift') {
} else if (strategyType === 'gift') { this.$set(item.goods, 'strategyConfig', {
this.$set(item.goods, 'strategyConfig', { isGift: '0'
isGift: '0' })
}) } else if (strategyType === 'combined') {
} else if (strategyType === 'combined') { this.$set(item.goods, 'strategyConfig', {
this.$set(item.goods, 'strategyConfig', { mode: 'none',
mode: 'none', deductAmount: ''
deductAmount: '' })
})
}
} }
}) })
}, },
......
...@@ -418,7 +418,27 @@ export default { ...@@ -418,7 +418,27 @@ export default {
initStrategyConfig() { initStrategyConfig() {
if (!this.list || this.list.length === 0) return if (!this.list || this.list.length === 0) return
const strategyType = this.getStrategyType({}) const strategyType = this.getStrategyType({})
if (!strategyType) return if (!strategyType) {
// 订单类型切换时,重置所有商品的策略配置
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) {
if (goods.strategyConfig) {
goods.strategyConfig = {}
}
goods.discountType = null
goods.discountValue = null
goods.finalPrice = null
}
})
return
}
this.list.forEach(item => { this.list.forEach(item => {
let goods = null let goods = null
...@@ -430,24 +450,22 @@ export default { ...@@ -430,24 +450,22 @@ export default {
if (!goods) return if (!goods) return
// 如果还没有 strategyConfig,初始化一个默认值 // 无论 strategyConfig 是否存在,都根据新的策略类型重新初始化
if (!goods.strategyConfig) { if (strategyType === 'discount') {
if (strategyType === 'discount') { this.$set(goods, 'strategyConfig', {
this.$set(goods, 'strategyConfig', { mode: 'none',
mode: 'none', discountRatio: '',
discountRatio: '', discountAmount: ''
discountAmount: '' })
}) } else if (strategyType === 'gift') {
} else if (strategyType === 'gift') { this.$set(goods, 'strategyConfig', {
this.$set(goods, 'strategyConfig', { isGift: '0'
isGift: '0' })
}) } else if (strategyType === 'combined') {
} else if (strategyType === 'combined') { this.$set(goods, 'strategyConfig', {
this.$set(goods, 'strategyConfig', { mode: 'none',
mode: 'none', deductAmount: ''
deductAmount: '' })
})
}
} }
}) })
} }
......
...@@ -165,15 +165,54 @@ export default { ...@@ -165,15 +165,54 @@ export default {
} }
}, },
watch: { watch: {
// 策略类型变化时,重置 mode 为 'none'
strategyType: {
handler(newType, oldType) {
// 当策略类型改变时(从其他类型切换到 combined 或 discount),重置 mode 为 'none'
if ((newType === 'combined' || newType === 'discount') && oldType && oldType !== newType) {
this.$nextTick(() => {
this.localState.mode = 'none'
})
}
},
immediate: false
},
// 外部 v-model -> 内部 state // 外部 v-model -> 内部 state
value: { value: {
handler(val) { handler(val) {
if (!val) return if (!val || Object.keys(val).length === 0) {
// 如果 value 为空,确保 mode 为 'none'(对于组合付款和打折策略)
if (this.strategyType === 'combined' || this.strategyType === 'discount') {
this.localState.mode = 'none'
}
return
}
// 先更新所有存在的字段
Object.keys(this.localState).forEach(key => { Object.keys(this.localState).forEach(key => {
if (val[key] !== undefined) { if (val[key] !== undefined) {
this.localState[key] = val[key] this.localState[key] = val[key]
} }
}) })
// 对于组合付款和打折策略,确保 mode 字段正确设置
if (this.strategyType === 'combined' || this.strategyType === 'discount') {
// 如果 value 中有 mode 字段,检查它是否与当前策略类型匹配
if (val.mode !== undefined) {
// 如果 strategyType 是 'discount',但 mode 是 'deduct'(组合付款的值),重置为 'none'
if (this.strategyType === 'discount' && val.mode === 'deduct') {
this.localState.mode = 'none'
}
// 如果 strategyType 是 'combined',但 mode 是 'ratio' 或 'amount'(打折策略的值),重置为 'none'
else if (this.strategyType === 'combined' && (val.mode === 'ratio' || val.mode === 'amount')) {
this.localState.mode = 'none'
}
// 否则使用 value 中的 mode
else {
this.localState.mode = val.mode
}
} else {
this.localState.mode = 'none'
}
}
}, },
deep: true, deep: true,
immediate: true immediate: true
...@@ -324,8 +363,15 @@ export default { ...@@ -324,8 +363,15 @@ export default {
onDiscountTabChange(mode) { onDiscountTabChange(mode) {
this.localState.mode = mode this.localState.mode = mode
if (mode === 'none') { if (mode === 'none') {
// 无折扣:清空所有输入框
this.localState.discountRatio = '' this.localState.discountRatio = ''
this.localState.discountAmount = '' this.localState.discountAmount = ''
} else if (mode === 'ratio') {
// 切换到折扣比例:清空折扣金额
this.localState.discountAmount = ''
} else if (mode === 'amount') {
// 切换到折扣金额:清空折扣比例
this.localState.discountRatio = ''
} }
}, },
onCombinedTabChange(mode) { onCombinedTabChange(mode) {
......
...@@ -607,23 +607,22 @@ export default { ...@@ -607,23 +607,22 @@ export default {
// 如果是套餐商品,需要初始化套餐内所有商品的策略配置 // 如果是套餐商品,需要初始化套餐内所有商品的策略配置
if (item.goodsFlag == 3 && item.packageGoods && item.packageGoods.goodsList) { if (item.goodsFlag == 3 && item.packageGoods && item.packageGoods.goodsList) {
item.packageGoods.goodsList.forEach(goods => { item.packageGoods.goodsList.forEach(goods => {
if (!goods.strategyConfig) { // 无论 strategyConfig 是否存在,都根据新的策略类型重新初始化
if (strategyType === 'discount') { if (strategyType === 'discount') {
this.$set(goods, 'strategyConfig', { this.$set(goods, 'strategyConfig', {
mode: 'none', mode: 'none',
discountRatio: '', discountRatio: '',
discountAmount: '' discountAmount: ''
}) })
} else if (strategyType === 'gift') { } else if (strategyType === 'gift') {
this.$set(goods, 'strategyConfig', { this.$set(goods, 'strategyConfig', {
isGift: '0' isGift: '0'
}) })
} else if (strategyType === 'combined') { } else if (strategyType === 'combined') {
this.$set(goods, 'strategyConfig', { this.$set(goods, 'strategyConfig', {
mode: 'none', mode: 'none',
deductAmount: '' deductAmount: ''
}) })
}
} }
}) })
return return
...@@ -639,24 +638,22 @@ export default { ...@@ -639,24 +638,22 @@ export default {
if (!goods) return if (!goods) return
// 如果还没有 strategyConfig,初始化一个默认值 // 无论 strategyConfig 是否存在,都根据新的策略类型重新初始化
if (!goods.strategyConfig) { if (strategyType === 'discount') {
if (strategyType === 'discount') { this.$set(goods, 'strategyConfig', {
this.$set(goods, 'strategyConfig', { mode: 'none',
mode: 'none', discountRatio: '',
discountRatio: '', discountAmount: ''
discountAmount: '' })
}) } else if (strategyType === 'gift') {
} else if (strategyType === 'gift') { this.$set(goods, 'strategyConfig', {
this.$set(goods, 'strategyConfig', { isGift: '0'
isGift: '0' })
}) } else if (strategyType === 'combined') {
} else if (strategyType === 'combined') { this.$set(goods, 'strategyConfig', {
this.$set(goods, 'strategyConfig', { mode: 'none',
mode: 'none', deductAmount: ''
deductAmount: '' })
})
}
} }
}) })
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!