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

海运批量加价

parent d4f78866
...@@ -13,59 +13,85 @@ ...@@ -13,59 +13,85 @@
</div> </div>
<div :gutter="20"> <div :gutter="20">
<el-form-item :label="$t('单价模式')" prop="priceType"> <el-form-item :label="$t('单价模式')" prop="priceType">
<dict-selector :type="DICT_TYPE.ECW_PRICE_TYPE" v-model="form.priceType" form-type="radio" /> <dict-selector :type="DICT_TYPE.ECW_PRICE_TYPE" v-model="form.priceType" form-type="radio" formatter="number" />
<!--海运才需要是否含阶梯价的选项,空运只有阶梯价就不需要了--> <!--海运才需要是否含阶梯价的选项,空运只有阶梯价就不需要了-->
<div v-if="type == 'sea'"> <div v-if="type == 'sea'">
<el-checkbox v-model="form.stepPrice" :true-label="1" :false-label="0">{{$t('是否含阶梯价')}}</el-checkbox> <el-checkbox v-model="form.stepPrice" :true-label="1" :false-label="0">{{$t('是否含阶梯价')}}</el-checkbox>
</div> </div>
</el-form-item> </el-form-item>
<el-form-item :label="$t('默认全包价')" v-if="form.priceType == 1">
<inputor default2="0" v-model.number="form.allPrice" type="number" :placeholder="$t('整数或者两位小数')" class="w100 mr10" />
<selector v-model="form.allPriceUnit" @input="syncAllUnit" :options="currencyList" :label-field="$l('title')" value-field="id" defaultable2 class="w100" />
/ <selector v-model="form.allVolumeUnit" @input="syncAllUnit" :options="unitList" :label-field="$l('title')" value-field="id" defaultable2 class="w100" />
</el-form-item>
<template v-else>
<el-form-item :label="$t('默认运费')" prop="transportPrice">
<selector v-model="form.transportPriceUnit" @input="syncAllUnit" :options="currencyList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" />
<inputor default2="0" v-model.number="form.transportPrice" type="number" :placeholder="$t('整数或者两位小数')" class="w-100 ml-10 mr-10" />
/ <selector v-model="form.transportVolumeUnit" @input="syncAllUnit" :options="unitList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" />
</el-form-item>
<el-form-item :label="$t('默认清关费')" prop="clearancePrice" v-if="type != 'air'">
<selector v-model="form.clearancePriceUnit" @input="syncAllUnit" :options="currencyList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" />
<inputor default2="0" v-model.number="form.clearancePrice" type="number" :placeholder="$t('整数或者两位小数')" class="w-100 ml-10 mr-10" />
/ <selector v-model="form.clearanceVolumeUnit" @input="syncAllUnit" :options="unitList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" />
</el-form-item>
</template>
<!--特需--> <!--如果是阶梯价-->
<template v-if="form.priceType==1"> <template v-if="form.stepPrice">
<el-form-item <!--全包价-->
v-for="(special, specialIndex) in form.specialList" <template v-if="form.priceType==1" >
:label="getDictDataLabel(DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS, special.specialDictType) + $t('全包价')" <div v-for="(item, index) in form.fullPriceStepList" :key="index">
:key="specialIndex + 'transport'"> <price-step
<selector disabled v-model="special.allPriceUnit" :options="currencyList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" /> ref="stepPrice"
<inputor default2="0" v-model.number="special.allPrice" type="number" :placeholder="$t('整数或者两位小数')" class="w-100 ml-10 mr-10" /> :index="index"
/ <selector disabled v-model="special.allVolumeUnit" :options="unitList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" /> :currency-list="currencyList"
</el-form-item> :unit-list="unitList"
field-prefix="all"
:price-name="$t('全包价')"
:show-add="index === form.fullPriceStepList.length -1"
:value="item"
:step-tips="!isStepPriceValid(item) ? $t('区间设置不完整,将被忽略') : null"
@add="handleAddPrice('fullPriceStepList', $event)"
@delete="handleDeletePrice('fullPriceStepList', $event)"
@changeUnit="handleUnitChange(form.fullPriceStepList, index, ...$event)"
></price-step>
</div>
</template> </template>
<template v-else v-for="(special, specialIndex) in form.specialList"> <el-row v-else :gutter="20" class="mt-20">
<el-form-item <el-col :span="12">
:label="getDictDataLabel(DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS, special.specialDictType) + $t('运费')" <div v-for="(item, index) in form.freightPriceStepList" :key="index">
:key="specialIndex + 'transport'"> <price-step
<selector disabled v-model="special.transportPriceUnit" :options="currencyList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" /> ref="stepPrice"
<inputor default2="0" v-model.number="special.transportPrice" type="number" :placeholder="$t('整数或者两位小数')" class="w-100 ml-10 mr-10" /> :index="index"
/ <selector disabled v-model="special.transportVolumeUnit" :options="unitList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" /> :currency-list="currencyList"
</el-form-item> :unit-list="unitList"
<el-form-item field-prefix="transport"
v-if="type != 'air'" :price-name="$t('运费')"
:label="getDictDataLabel(DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS, special.specialDictType) + $t('清关费')" :show-add="index === form.freightPriceStepList.length -1"
:key="specialIndex + 'clearance'"> :value="item"
<selector disabled v-model="special.clearancePriceUnit" :options="currencyList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" /> :step-tips="!isStepPriceValid(item) ? $t('区间设置不完整,将被忽略') : null"
<inputor default2="0" v-model.number="special.clearancePrice" type="number" :placeholder="$t('整数或者两位小数')" class="w-100 ml-10 mr-10" /> @add="handleAddPrice('freightPriceStepList', $event)"
/ <selector disabled v-model="special.clearanceVolumeUnit" :options="unitList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" /> @delete="handleDeletePrice('freightPriceStepList', $event)"
</el-form-item> @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"
:value="item"
:step-tips="!isStepPriceValid(item) ? $t('区间设置不完整,将被忽略') : null"
@add="handleAddPrice('clearancePriceStepList', $event)"
@delete="handleDeletePrice('clearancePriceStepList', $event)"
@changeUnit="handleUnitChange(form.clearancePriceStepList, index, ...$event)"
></price-step>
</div>
</el-col>
</el-row>
</template> </template>
<template v-else>
<sea-price
ref="seaPrice"
:price-type="form.priceType"
:currency-list="currencyList"
:unit-list="unitList"
:value="form"
@changeUnit="handleFormUnitChange($event)"
></sea-price>
</template>
</div> </div>
</el-card> </el-card>
</el-form> </el-form>
...@@ -85,9 +111,16 @@ import ProductsSelector from '@/components/ProductsSelector' ...@@ -85,9 +111,16 @@ import ProductsSelector from '@/components/ProductsSelector'
import Selector from '@/components/Selector' import Selector from '@/components/Selector'
import Inputor from '@/components/Inputor' import Inputor from '@/components/Inputor'
import Decimal from 'decimal.js' import Decimal from 'decimal.js'
import SeaPrice from "@/views/ecw/productPrice/components/SeaPrice.vue";
import Template from "@/views/cms/template/index.vue";
import PriceStep from "@/views/ecw/productPrice/components/PriceStep.vue";
const DEFAULT_PRICE_UNIT = 1
const DEFAULT_VOLUME_UNIT = 7
const DEFAULT_WEIGHT_UNIT = 7
export default { export default {
components: { RoutersSelector, ProductsSelector, Selector, Inputor }, components: {PriceStep, Template, SeaPrice, RoutersSelector, ProductsSelector, Selector, Inputor },
data() { data() {
return { return {
checkList: [], checkList: [],
...@@ -117,23 +150,13 @@ export default { ...@@ -117,23 +150,13 @@ export default {
type(){ type(){
return this.$route.path.split(/[-_]/).pop() return this.$route.path.split(/[-_]/).pop()
}, },
// 默认运费的货币和体积单位 // 判断阶梯价是否有效
currencyAndUnit(){ isStepPriceValid(){
let currency = null, unit = null, fields = null return stepPrice => {
// 如果是阶梯价格则取第一阶梯,否则就取form中的字段 return stepPrice.startNum && stepPrice.endNum
let obj = this.form.stepPrice == 1 ? this.form.priceStepList[0] : this.form
// 全包价
if(this.form.priceType == 1){
currency = obj.allPriceUnit
unit = obj.allVolumeUnit
}else{
currency = obj.transportPriceUnit
unit = obj.transportVolumeUnit
}
return {currency, unit}
} }
}, },
},
watch: { watch: {
checkList() { //选择路线 checkList() { //选择路线
if (this.checkList.length > 0) { if (this.checkList.length > 0) {
...@@ -147,25 +170,21 @@ export default { ...@@ -147,25 +170,21 @@ export default {
product() { product() {
this.$set(this.form, 'productType', this.product.typeId) this.$set(this.form, 'productType', this.product.typeId)
}, },
selectedRoutes(routers) { 'form.priceType'(priceType){
let transportIds = [] if(this.form.stepPrice === 1){
routers.forEach(item => { this.initStepPrice()
item.shippingChannelId = item.channelId
transportIds.push(+item.transportId)
})
// 如果只选择了空运(3),则默认体积单位改成千克
transportIds = new Set(transportIds)
console.log(transportIds)
window.transportIds = transportIds
if(transportIds.size == 1 && transportIds.has(3)){
this.setDefaultVolumeUnit(6)
}else this.setDefaultVolumeUnit(7)
} }
}, },
'form.stepPrice'(stepPrice){
if(this.form.stepPrice === 1){
this.initStepPrice()
}
this.stepPrice = !!stepPrice
},
},
async created() { async created() {
getCurrencyList().then(res => this.currencyList = res.data) this.currencyList = (await getCurrencyList())?.data || []
getUnitList().then(res => this.unitList = res.data) this.unitList = (await getUnitList())?.data || []
this.$nextTick(async() => { this.$nextTick(async() => {
this.setDefaultVolumeUnit(this.type == 'air' ? 6 : 7) this.setDefaultVolumeUnit(this.type == 'air' ? 6 : 7)
...@@ -187,76 +206,91 @@ export default { ...@@ -187,76 +206,91 @@ export default {
}) })
}, },
methods: { methods: {
// 同步全部单位 handleAddPrice(field, fieldPrefix){
syncAllUnit(){ if(!this.form[field]){
let obj = this.form this.$set(this.form, field, [])
let fields = {}
// 全包价
if(this.form.priceType == 1){
fields = {
allPriceUnit: obj['allPriceUnit'],
allVolumeUnit: obj['allVolumeUnit']
}
}else{
fields = {
transportPriceUnit: obj.transportPriceUnit,
transportVolumeUnit: obj.transportVolumeUnit,
clearancePriceUnit: obj.clearancePriceUnit,
clearanceVolumeUnit: obj.clearanceVolumeUnit,
} }
let priceUnit = DEFAULT_PRICE_UNIT
let volumeUnit = DEFAULT_VOLUME_UNIT
let weightUnit = DEFAULT_WEIGHT_UNIT
if(this.form[field].length){
const first = this.form[field][0]
priceUnit = first[`${fieldPrefix}PriceUnit`]
volumeUnit = first[`${fieldPrefix}VolumeUnit`]
weightUnit = first.weightUnit
} }
console.log("添加价格的默认单位", {
priceUnit,
volumeUnit,
weightUnit
})
this.form[field].push({
[`${fieldPrefix}PriceUnit`]: priceUnit,
[`${fieldPrefix}VolumeUnit`]: volumeUnit,
weightUnit: weightUnit,
specialList:[]
})
},
handleDeletePrice(field, index){
this.form[field].splice(index, 1)
},
handleUnitChange(stepPriceList, index, data){
console.log('handleUnitChange', ...arguments)
if(index > 0) return
// 全包价还需要同步阶梯的重量单位 // 如果是重量单位,且不是清关费想换的,则需要同步最小起计量单位
if(this.form.stepPrice == 1){ if(data.field === 'weightUnit' && data.type != 'clearance'){
fields['weightUnit'] = obj.weightUnit this.form.minWeightUnit = data.value
} }
stepPriceList.forEach(item => {
this.syncSpecialUnit(fields) item[data.field] = data.value
}, if(item.packagingList?.length){
// 同步特需的货币单位和体积单位 item.packagingList.forEach(p => {
syncSpecialUnit(obj){ p[data.field] = data.value
console.log('syncSpecialUnit', obj)
if(!obj) return
// 同步特需单位
this.form.specialList.forEach(item => {
Object.assign(item, obj)
}) })
}
// 如果是阶梯价则需要同步其他阶梯 if(item.specialList?.length){
if(this.form.stepPrice == 1){ item.specialList.forEach(p => {
this.form.priceStepList.forEach((item, index) => { p[data.field] = data.value
this.$set(this.form.priceStepList, index, Object.assign(item, obj))
}) })
} }
})
},
// 不是阶梯价需要 同步最小起计量 // 获得用语提交的阶梯价副本
if(obj['transportVolumeUnit'] || obj['allVolumeUnit']){ getPriceList(stepList){
this.$set(this.form, 'minWeightUnit', obj['transportVolumeUnit'] || obj['allVolumeUnit']) 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.filter(this.isStepPriceValid)
}, },
// 价格校验器 // 非阶梯价格更新单位
priceValidator(rule, value, callback){ handleFormUnitChange(data){
if(!value || value == '') return callback() if(this.form.specialList?.length){
value = parseFloat(value) this.form.specialList.forEach(p => {
if(!value || value < 0){ p[data.field] = data.value
return callback(new Error('价格错误')) })
} }
callback()
}, },
setDefaultVolumeUnit(unit){ initStepPrice(){
this.$set(this.form, 'transportVolumeUnit', unit) if(this.form.priceType == 1 && !this.form.fullPriceStepList?.length){
this.$set(this.form, 'clearanceVolumeUnit', unit) this.handleAddPrice("fullPriceStepList", 'all')
this.$set(this.form, 'allVolumeUnit', unit) }
this.$set(this.form, 'minWeightUnit', unit) if(this.form.priceType === 0){
console.log(this.form.priceStepList, this.form.stepPrice) if(!this.form.freightPriceStepList?.length){
// 阶梯价 this.handleAddPrice('freightPriceStepList', 'transport')
if(this.form.stepPrice == 1 && this.form.priceStepList?.length){ }
this.form.priceStepList.forEach(item => { if(!this.form.clearancePriceStepList?.length){
this.$set(item, 'transportVolumeUnit', unit) this.handleAddPrice('clearancePriceStepList', 'clearance')
this.$set(item, 'clearanceVolumeUnit', unit) }
this.$set(item, 'allVolumeUnit', unit)
this.$set(item, 'weightUnit', unit)
})
} }
}, },
submitForm() { submitForm() {
...@@ -290,10 +324,39 @@ export default { ...@@ -290,10 +324,39 @@ export default {
if(data.lineChannelList.length < 1){ if(data.lineChannelList.length < 1){
return this.$message.error(this.$t('请选择需要修改的路线')) return this.$message.error(this.$t('请选择需要修改的路线'))
} }
await this.$confirm(this.$t('已选择{route}条路线,{product}个商品;确认提交修改?', {
data.fullPriceStepList= this.getPriceList(data.fullPriceStepList)
data.freightPriceStepList= this.getPriceList(data.freightPriceStepList)
data.clearancePriceStepList= this.getPriceList(data.clearancePriceStepList)
// 检查被忽略的阶梯价
let msgArr = [];
if(data.priceType){
const ignoreAll = data.fullPriceStepList.length != this.form.fullPriceStepList.length
if(ignoreAll){
msgArr.push(this.$t("{n}个全包阶梯价", {n: ignoreAll}))
}
}else{
const ignoreFreight = this.form.freightPriceStepList.length - data.freightPriceStepList.length
const ignoreClearance = this.form.clearancePriceStepList.length - data.clearancePriceStepList.length
if(ignoreFreight){
msgArr.push(this.$t("{n}个运费阶梯价", {n: ignoreFreight}))
}
if(ignoreClearance){
msgArr.push(this.$t("{n}个清关费阶梯价", {n: ignoreClearance}))
}
}
let msg = this.$t('已选择{route}条路线,{product}个商品', {
route: data.lineChannelList.length, route: data.lineChannelList.length,
product: this.isAllProduct ? this.$refs.productSelector.allTotal : data.productIdList.length product: this.isAllProduct ? this.$refs.productSelector.allTotal : data.productIdList.length
})) })
console.log(msgArr)
if(msgArr.length){
msg += ";" + msgArr.join(",") + "被忽略"
}
await this.$confirm(msg + this.$t(';确认提交修改?', ))
this.loading = true this.loading = true
batchAddPrice(data).then(async(response) => { batchAddPrice(data).then(async(response) => {
await this.$alert(this.$t("操作成功")); await this.$alert(this.$t("操作成功"));
......
...@@ -363,15 +363,15 @@ export default { ...@@ -363,15 +363,15 @@ export default {
} }
}, },
'form.needBook'(val){
if(val) this.$set(this.form, 'dayLimit', 10000)
else delete this.form.dayLimit
},
'form.priceType'(priceType){ 'form.priceType'(priceType){
if(this.form.stepPrice === 1){ if(this.form.stepPrice === 1){
this.initStepPrice() this.initStepPrice()
} }
}, },
'form.needBook'(val){
if(val) this.$set(this.form, 'dayLimit', 10000)
else delete this.form.dayLimit
},
'form.stepPrice'(stepPrice){ 'form.stepPrice'(stepPrice){
if(this.form.stepPrice === 1){ if(this.form.stepPrice === 1){
this.initStepPrice() this.initStepPrice()
...@@ -417,20 +417,6 @@ export default { ...@@ -417,20 +417,6 @@ export default {
} }
this.lineList = [res.data] this.lineList = [res.data]
// 如果是阶梯价格,但是一个阶梯价都没有(异常数据),则默认给两个阶梯价
if(this.form.stepPrice == 1 && (!this.form.priceStepList || !this.form.priceStepList.length)){
const defaultStep = this.form.priceType == 1 ? {
allPriceUnit: defaultPriceUnit,
allVolumeUnit: defaultVolumeUnit,
weightUnit: defaultVolumeUnit
} : {
transportVolumeUnit: defaultVolumeUnit,
transportPriceUnit: defaultPriceUnit,
weightUnit: defaultVolumeUnit
}
console.log('阶梯价没有阶梯信息,默认给两个', {...defaultStep})
this.$set(this.form, 'priceStepList', [{...defaultStep},{...defaultStep}])
}
} }
// action=batchUpdate且ids不为空 // action=batchUpdate且ids不为空
......
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