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

海运批量加价

parent d4f78866
......@@ -13,59 +13,85 @@
</div>
<div :gutter="20">
<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'">
<el-checkbox v-model="form.stepPrice" :true-label="1" :false-label="0">{{$t('是否含阶梯价')}}</el-checkbox>
</div>
</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">
<el-form-item
v-for="(special, specialIndex) in form.specialList"
:label="getDictDataLabel(DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS, special.specialDictType) + $t('全包价')"
:key="specialIndex + 'transport'">
<selector disabled v-model="special.allPriceUnit" :options="currencyList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" />
<inputor default2="0" v-model.number="special.allPrice" type="number" :placeholder="$t('整数或者两位小数')" class="w-100 ml-10 mr-10" />
/ <selector disabled v-model="special.allVolumeUnit" :options="unitList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" />
</el-form-item>
</template>
<template v-else v-for="(special, specialIndex) in form.specialList">
<el-form-item
:label="getDictDataLabel(DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS, special.specialDictType) + $t('运费')"
:key="specialIndex + 'transport'">
<selector disabled v-model="special.transportPriceUnit" :options="currencyList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" />
<inputor default2="0" v-model.number="special.transportPrice" type="number" :placeholder="$t('整数或者两位小数')" class="w-100 ml-10 mr-10" />
/ <selector disabled v-model="special.transportVolumeUnit" :options="unitList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" />
</el-form-item>
<el-form-item
v-if="type != 'air'"
:label="getDictDataLabel(DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS, special.specialDictType) + $t('清关费')"
:key="specialIndex + 'clearance'">
<selector disabled v-model="special.clearancePriceUnit" :options="currencyList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" />
<inputor default2="0" v-model.number="special.clearancePrice" type="number" :placeholder="$t('整数或者两位小数')" class="w-100 ml-10 mr-10" />
/ <selector disabled v-model="special.clearanceVolumeUnit" :options="unitList" :label-field="$l('title')" value-field="id" defaultable2 class="w-100" />
</el-form-item>
<!--如果是阶梯价-->
<template v-if="form.stepPrice">
<!--全包价-->
<template v-if="form.priceType==1" >
<div v-for="(item, index) in form.fullPriceStepList" :key="index">
<price-step
ref="stepPrice"
:index="index"
:currency-list="currencyList"
: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>
<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"
:value="item"
:step-tips="!isStepPriceValid(item) ? $t('区间设置不完整,将被忽略') : null"
@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"
: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 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>
</el-card>
</el-form>
......@@ -85,9 +111,16 @@ import ProductsSelector from '@/components/ProductsSelector'
import Selector from '@/components/Selector'
import Inputor from '@/components/Inputor'
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 {
components: { RoutersSelector, ProductsSelector, Selector, Inputor },
components: {PriceStep, Template, SeaPrice, RoutersSelector, ProductsSelector, Selector, Inputor },
data() {
return {
checkList: [],
......@@ -117,22 +150,12 @@ export default {
type(){
return this.$route.path.split(/[-_]/).pop()
},
// 默认运费的货币和体积单位
currencyAndUnit(){
let currency = null, unit = null, fields = null
// 如果是阶梯价格则取第一阶梯,否则就取form中的字段
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
// 判断阶梯价是否有效
isStepPriceValid(){
return stepPrice => {
return stepPrice.startNum && stepPrice.endNum
}
return {currency, unit}
}
},
},
watch: {
checkList() { //选择路线
......@@ -147,25 +170,21 @@ export default {
product() {
this.$set(this.form, 'productType', this.product.typeId)
},
selectedRoutes(routers) {
let transportIds = []
routers.forEach(item => {
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.priceType'(priceType){
if(this.form.stepPrice === 1){
this.initStepPrice()
}
},
'form.stepPrice'(stepPrice){
if(this.form.stepPrice === 1){
this.initStepPrice()
}
this.stepPrice = !!stepPrice
},
},
async created() {
getCurrencyList().then(res => this.currencyList = res.data)
getUnitList().then(res => this.unitList = res.data)
this.currencyList = (await getCurrencyList())?.data || []
this.unitList = (await getUnitList())?.data || []
this.$nextTick(async() => {
this.setDefaultVolumeUnit(this.type == 'air' ? 6 : 7)
......@@ -187,76 +206,91 @@ export default {
})
},
methods: {
// 同步全部单位
syncAllUnit(){
let obj = this.form
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,
}
handleAddPrice(field, fieldPrefix){
if(!this.form[field]){
this.$set(this.form, field, [])
}
// 全包价还需要同步阶梯的重量单位
if(this.form.stepPrice == 1){
fields['weightUnit'] = obj.weightUnit
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
}
this.syncSpecialUnit(fields)
},
// 同步特需的货币单位和体积单位
syncSpecialUnit(obj){
console.log('syncSpecialUnit', obj)
if(!obj) return
// 同步特需单位
this.form.specialList.forEach(item => {
Object.assign(item, obj)
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){
this.form.priceStepList.forEach((item, index) => {
this.$set(this.form.priceStepList, index, Object.assign(item, obj))
})
// 如果是重量单位,且不是清关费想换的,则需要同步最小起计量单位
if(data.field === 'weightUnit' && data.type != 'clearance'){
this.form.minWeightUnit = data.value
}
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
})
}
})
},
// 不是阶梯价需要 同步最小起计量
if(obj['transportVolumeUnit'] || obj['allVolumeUnit']){
this.$set(this.form, 'minWeightUnit', obj['transportVolumeUnit'] || obj['allVolumeUnit'])
}
// 获得用语提交的阶梯价副本
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.filter(this.isStepPriceValid)
},
// 价格校验器
priceValidator(rule, value, callback){
if(!value || value == '') return callback()
value = parseFloat(value)
if(!value || value < 0){
return callback(new Error('价格错误'))
// 非阶梯价格更新单位
handleFormUnitChange(data){
if(this.form.specialList?.length){
this.form.specialList.forEach(p => {
p[data.field] = data.value
})
}
callback()
},
setDefaultVolumeUnit(unit){
this.$set(this.form, 'transportVolumeUnit', unit)
this.$set(this.form, 'clearanceVolumeUnit', unit)
this.$set(this.form, 'allVolumeUnit', unit)
this.$set(this.form, 'minWeightUnit', unit)
console.log(this.form.priceStepList, this.form.stepPrice)
// 阶梯价
if(this.form.stepPrice == 1 && this.form.priceStepList?.length){
this.form.priceStepList.forEach(item => {
this.$set(item, 'transportVolumeUnit', unit)
this.$set(item, 'clearanceVolumeUnit', unit)
this.$set(item, 'allVolumeUnit', unit)
this.$set(item, 'weightUnit', unit)
})
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')
}
}
},
submitForm() {
......@@ -290,10 +324,39 @@ export default {
if(data.lineChannelList.length < 1){
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,
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
batchAddPrice(data).then(async(response) => {
await this.$alert(this.$t("操作成功"));
......
......@@ -363,15 +363,15 @@ 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.priceType'(priceType){
if(this.form.stepPrice === 1){
this.initStepPrice()
}
},
'form.stepPrice'(stepPrice){
if(this.form.stepPrice === 1){
this.initStepPrice()
......@@ -417,20 +417,6 @@ export default {
}
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不为空
......
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