Commit d4f78866 authored by dragondean@qq.com's avatar dragondean@qq.com

海运价格设置的阶梯价适配成空运一样的

parent 17f3f7db
......@@ -103,22 +103,64 @@
<!--如果是阶梯价-->
<template v-if="form.stepPrice">
<div v-for="(item, index) in form.priceStepList" :key="index">
<sea-step
<!--全包价-->
<template v-if="form.priceType==1" >
<div v-for="(item, index) in form.fullPriceStepList" :key="index">
<price-step
ref="stepPrice"
:index="index"
:price-type="form.priceType"
:currency-list="currencyList"
:unit-list="unitList"
:show-add="index === form.priceStepList.length -1 && !readonly"
field-prefix="all"
:price-name="$t('全包价')"
:show-add="index === form.fullPriceStepList.length -1 && !readonly"
:value="item"
:readonly="readonly"
@add="handleAddPrice($event)"
@delete="handleDeletePrice($event)"
@changeUnit="handleUnitChange(index, $event)"
></sea-step>
@add="handleAddPrice('fullPriceStepList', $event)"
@delete="handleDeletePrice('fullPriceStepList', $event)"
@changeUnit="handleUnitChange(form.fullPriceStepList, index, ...$event)"
></price-step>
</div>
</template>
<el-row v-else :gutter="20" class="mt-20">
<el-col :span="12">
<div v-for="(item, index) in form.freightPriceStepList" :key="index">
<price-step
ref="stepPrice"
:index="index"
:currency-list="currencyList"
:unit-list="unitList"
field-prefix="transport"
:price-name="$t('运费')"
:show-add="index === form.freightPriceStepList.length -1 && !readonly"
:value="item"
:readonly="readonly"
@add="handleAddPrice('freightPriceStepList', $event)"
@delete="handleDeletePrice('freightPriceStepList', $event)"
@changeUnit="handleUnitChange(form.freightPriceStepList, index, ...$event)"
></price-step>
</div>
</el-col>
<el-col :span="12">
<div v-for="(item, index) in form.clearancePriceStepList" :key="index">
<price-step
ref="stepPrice"
:index="index"
:currency-list="currencyList"
:unit-list="unitList"
field-prefix="clearance"
:price-name="$t('清关费')"
:show-add="index === form.clearancePriceStepList.length -1 && !readonly"
:value="item"
:readonly="readonly"
@add="handleAddPrice('clearancePriceStepList', $event)"
@delete="handleDeletePrice('clearancePriceStepList', $event)"
@changeUnit="handleUnitChange(form.clearancePriceStepList, index, ...$event)"
></price-step>
</div>
</el-col>
</el-row>
</template>
<template v-else>
<sea-price
ref="seaPrice"
......@@ -127,7 +169,7 @@
:unit-list="unitList"
:value="form"
:readonly="readonly"
@changeUnit="handleFormUniChange($event)"
@changeUnit="handleFormUnitChange($event)"
></sea-price>
</template>
......@@ -211,6 +253,7 @@ import Logs from "@/views/ecw/productPrice/components/Logs.vue";
import SeaStep from "@/views/ecw/productPrice/components/SeaStep.vue";
import Template from "@/views/cms/template/index.vue";
import SeaPrice from "@/views/ecw/productPrice/components/SeaPrice.vue";
import PriceStep from "@/views/ecw/productPrice/components/PriceStep.vue";
const DEFAULT_PRICE_UNIT = 1
const DEFAULT_VOLUME_UNIT = 7
......@@ -218,6 +261,7 @@ const DEFAULT_WEIGHT_UNIT = 7
export default {
components: {
PriceStep,
SeaPrice,
Template, Logs, QuickSet, PackagingType, RoutersSelector, ProductSelector, Selector, Inputor, SeaStep },
filters: {parseTime},
......@@ -320,15 +364,17 @@ export default {
},
'form.priceType'(priceType){
if(this.form.stepPrice === 1){
this.initStepPrice()
}
},
'form.needBook'(val){
if(val) this.$set(this.form, 'dayLimit', 10000)
else delete this.form.dayLimit
},
'form.stepPrice'(stepPrice){
if(stepPrice == 1 && !this.form.priceStepList?.length){
this.handleAddPrice("priceStepList")
if(this.form.stepPrice === 1){
this.initStepPrice()
}
this.stepPrice = !!stepPrice
},
......@@ -489,44 +535,35 @@ export default {
})
},
methods: {
handleAddPrice(){
if(!this.form.priceStepList){
this.$set(this.form, 'priceStepList', [])
}
let allPriceUnit = DEFAULT_PRICE_UNIT
let allVolumeUnit = DEFAULT_VOLUME_UNIT
let transportPriceUnit = DEFAULT_PRICE_UNIT
let transportVolumeUnit = DEFAULT_VOLUME_UNIT
let clearancePriceUnit = DEFAULT_PRICE_UNIT
let clearanceVolumeUnit = DEFAULT_VOLUME_UNIT
handleAddPrice(field, fieldPrefix){
if(!this.form[field]){
this.$set(this.form, field, [])
}
let priceUnit = DEFAULT_PRICE_UNIT
let volumeUnit = DEFAULT_VOLUME_UNIT
let weightUnit = DEFAULT_WEIGHT_UNIT
if(this.form.priceStepList?.length){
const first = this.form.priceStepList[0]
allPriceUnit = first.allPriceUnit
allVolumeUnit = first.allVolumeUnit
transportPriceUnit = first.transportPriceUnit
transportVolumeUnit = first.transportVolumeUnit
clearancePriceUnit = first.clearancePriceUnit
clearanceVolumeUnit = first.clearanceVolumeUnit
if(this.form[field].length){
const first = this.form[field][0]
priceUnit = first[`${fieldPrefix}PriceUnit`]
volumeUnit = first[`${fieldPrefix}VolumeUnit`]
weightUnit = first.weightUnit
}
this.form.priceStepList.push({
allPriceUnit,
allVolumeUnit,
transportPriceUnit,
transportVolumeUnit,
clearancePriceUnit,
clearanceVolumeUnit,
console.log("添加价格的默认单位", {
priceUnit,
volumeUnit,
weightUnit
})
this.form[field].push({
[`${fieldPrefix}PriceUnit`]: priceUnit,
[`${fieldPrefix}VolumeUnit`]: volumeUnit,
weightUnit: weightUnit,
specialList:[]
})
},
handleDeletePrice(index){
this.form.priceStepList.splice(index, 1)
handleDeletePrice(field, index){
this.form[field].splice(index, 1)
},
// 阶梯价更新单位
handleUnitChange(index, data){
handleUnitChange(stepPriceList, index, data){
console.log('handleUnitChange', ...arguments)
if(index > 0) return
......@@ -534,8 +571,13 @@ export default {
if(data.field === 'weightUnit' && data.type != 'clearance'){
this.form.minWeightUnit = data.value
}
this.form.priceStepList.forEach(item => {
stepPriceList.forEach(item => {
item[data.field] = data.value
if(item.packagingList?.length){
item.packagingList.forEach(p => {
p[data.field] = data.value
})
}
if(item.specialList?.length){
item.specialList.forEach(p => {
p[data.field] = data.value
......@@ -543,14 +585,42 @@ export default {
}
})
},
// 获得用语提交的阶梯价副本
getPriceList(stepList){
if(!stepList?.length) return []
let stepPriceList = JSON.parse(JSON.stringify(stepList))
stepPriceList.forEach((item, index) => {
item.rankNum = index + 1
item.packagingList = item.packagingList.filter(p => !!p.packagingTypes?.length)
item.packagingList = item.packagingList.map( p => {
p.packagingTypes = p.packagingTypes.join(",")
return p
})
})
return stepPriceList
},
// 非阶梯价格更新单位
handleFormUniChange(data){
handleFormUnitChange(data){
if(this.form.specialList?.length){
this.form.specialList.forEach(p => {
p[data.field] = data.value
})
}
},
initStepPrice(){
if(this.form.priceType == 1 && !this.form.fullPriceStepList?.length){
this.handleAddPrice("fullPriceStepList", 'all')
}
if(this.form.priceType === 0){
if(!this.form.freightPriceStepList?.length){
this.handleAddPrice('freightPriceStepList', 'transport')
}
if(!this.form.clearancePriceStepList?.length){
this.handleAddPrice('clearancePriceStepList', 'clearance')
}
}
},
// force 为是否强制提交,在价格过期的时候需要确认后强制提交
submitForm(force = false) {
this.$refs["form"].validate(async (valid) => {
......@@ -572,39 +642,22 @@ export default {
// specialList: this.specialProducts,
isAllProduct: 0
})
if(this.form.stepPrice != 1){
// data.priceStepList = this.priceStepList
delete data.priceStepList
// 非阶梯价格判断是否运费(全包价是否为空)
if((this.form.priceType == 0 && !this.form.transportPrice) || (this.form.priceType == 1 && !this.form.allPrice)){
return this.$message.error(this.$t('运费/全包价不能为0'))
let isValid = true
for (let stepPrice of this.$refs.stepPrice){
if(!stepPrice.validate()){
isValid = false
break
}
}else{
// 全包价 的阶段 设置和运费(全包价)不能为空
let stepPriceEmpty = []
this.form.priceStepList.forEach((item, index) => {
let notEmptyFields = ['endNum', 'weightUnit']
// 第一条阶梯的起始值可以是0,其他的不能为0
if(index){
notEmptyFields.push('startNum')
}
notEmptyFields.forEach(field => {
// 第一个阶梯的起始值不判断0
if(index === 0 && field == 'startNum' && item[field] == 0) return
if(!isValid)return
if(!item[field] || item[field].toString().trim() == ''){
stepPriceEmpty.push({index, field})
}
})
if((this.form.priceType == 0 && !item.transportPrice) || (this.form.priceType == 1 && !item.allPrice)){
stepPriceEmpty.push({index, field: !item.transportPrice ? 'transportPrice' : 'allPrice'})
}
})
if(stepPriceEmpty.length){
console.log('stepPriceEmpty', stepPriceEmpty)
return this.$message.error(this.$t('阶梯和价格设置不能留空'))
}
// 全包价
if(this.form.priceType == 1) {
data.fullPriceStepList = this.getPriceList(this.form.fullPriceStepList)
}else{
data.clearancePriceStepList = this.getPriceList(this.form.clearancePriceStepList)
data.freightPriceStepList = this.getPriceList(this.form.freightPriceStepList)
}
// 设置了有效期,且已过期则给提示
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment