Commit 3d3d1771 authored by lanbaoming's avatar lanbaoming

批量改价单价模式必填校验2024-04-12

parent 3f8c9038
<template> <template>
<div class="app-container"> <div class="app-container">
<el-form ref="form" :model="form" :rules="rules" label-width="150px"> <el-form ref="form" :model="form" :rules="rules" label-width="150px">
<products-selector ref="productSelector" v-model="form.productIdList" show-all @setall="isAllProduct=$event" :default-ids="form.productIdList" enable-filtered @setFiltered="isAllFilteredProduct=$event" class="mb-20" /> <products-selector
ref="productSelector"
v-model="form.productIdList"
show-all
@setall="isAllProduct = $event"
:default-ids="form.productIdList"
enable-filtered
@setFiltered="isAllFilteredProduct = $event"
class="mb-20"
/>
<routers-selector v-model="selectedRoutes" :type="type" /> <routers-selector v-model="selectedRoutes" :type="type" />
<el-card style="margin-bottom: 10px"> <el-card style="margin-bottom: 10px">
<div slot="header" style="font-size:20px;"> <div slot="header" style="font-size: 20px">
{{$t('价格设置')}} {{ $t("价格设置") }}
<!--空运只有阶梯价格,不显示阶梯价格勾选--> <!--空运只有阶梯价格,不显示阶梯价格勾选-->
<span v-if="type != 'air'"> <span v-if="type != 'air'">
<el-checkbox label="" @change="form.stepPrice=$event ? 1 : 0">{{$t('阶梯价格')}}</el-checkbox> <el-checkbox label="" @change="form.stepPrice = $event ? 1 : 0">{{
$t("阶梯价格")
}}</el-checkbox>
</span> </span>
</div> </div>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="12"> <el-col :span="12">
<el-form-item :label="$t('预付')" prop="needPay" > <el-form-item :label="$t('预付')" prop="needPay">
<el-radio-group v-model="form.needPay"> <el-radio-group v-model="form.needPay">
<el-radio :label="1">{{ $t('预付') }}</el-radio> <el-radio :label="1">{{ $t("预付") }}</el-radio>
<el-radio :label="0">{{ $t('均可') }}</el-radio> <el-radio :label="0">{{ $t("均可") }}</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<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" formatter='number' /> <dict-selector
:type="DICT_TYPE.ECW_PRICE_TYPE"
v-model="form.priceType"
form-type="radio"
formatter="number"
/>
</el-form-item> </el-form-item>
<el-form-item <el-form-item :label="$t('最小起计量')" :prop="`minWeight`">
:label="$t('最小起计量')" <el-input-number
:prop="`minWeight`" v-model="form.minWeight"
> class="w-100"
<el-input-number v-model="form.minWeight" class="w-100" :min="0" :controls="false"/> :min="0"
/ <selector v-model="form.minWeightUnit" :options="unitList" :label-field="$l(null, 'title')" value-field="id" class="w-100" disabled /> :controls="false"
/>
/
<selector
v-model="form.minWeightUnit"
:options="unitList"
:label-field="$l(null, 'title')"
value-field="id"
class="w-100"
disabled
/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<quick-set :unit-list="unitList" :currency-list="currencyList" :value="form" type="sea"></quick-set> <quick-set
:unit-list="unitList"
:currency-list="currencyList"
:value="form"
type="sea"
></quick-set>
</el-col> </el-col>
</el-row> </el-row>
<template v-if="form.stepPrice"> <template v-if="form.stepPrice">
<!--全包价--> <!--全包价-->
<template v-if="form.priceType==1" > <template v-if="form.priceType == 1">
<div v-for="(item, index) in form.fullPriceStepList" :key="index"> <div v-for="(item, index) in form.fullPriceStepList" :key="index">
<price-step <price-step
ref="stepPrice" ref="stepPrice"
...@@ -48,17 +79,22 @@ ...@@ -48,17 +79,22 @@
:unit-list="unitList" :unit-list="unitList"
field-prefix="all" field-prefix="all"
:price-name="$t('全包价')" :price-name="$t('全包价')"
:show-add="index === form.fullPriceStepList.length -1" :show-add="index === form.fullPriceStepList.length - 1"
:value="item" :value="item"
@add="handleAddPrice('fullPriceStepList', $event)" @add="handleAddPrice('fullPriceStepList', $event)"
@delete="handleDeletePrice('fullPriceStepList', $event)" @delete="handleDeletePrice('fullPriceStepList', $event)"
@changeUnit="handleUnitChange(form.fullPriceStepList, index, ...$event)" @changeUnit="
handleUnitChange(form.fullPriceStepList, index, ...$event)
"
></price-step> ></price-step>
</div> </div>
</template> </template>
<el-row v-else :gutter="20" class="mt-20"> <el-row v-else :gutter="20" class="mt-20">
<el-col :span="12"> <el-col :span="12">
<div v-for="(item, index) in form.freightPriceStepList" :key="index"> <div
v-for="(item, index) in form.freightPriceStepList"
:key="index"
>
<price-step <price-step
ref="stepPrice" ref="stepPrice"
:index="index" :index="index"
...@@ -66,16 +102,25 @@ ...@@ -66,16 +102,25 @@
:unit-list="unitList" :unit-list="unitList"
field-prefix="transport" field-prefix="transport"
:price-name="$t('运费')" :price-name="$t('运费')"
:show-add="index === form.freightPriceStepList.length -1" :show-add="index === form.freightPriceStepList.length - 1"
:value="item" :value="item"
@add="handleAddPrice('freightPriceStepList', $event)" @add="handleAddPrice('freightPriceStepList', $event)"
@delete="handleDeletePrice('freightPriceStepList', $event)" @delete="handleDeletePrice('freightPriceStepList', $event)"
@changeUnit="handleUnitChange(form.freightPriceStepList, index, ...$event)" @changeUnit="
handleUnitChange(
form.freightPriceStepList,
index,
...$event
)
"
></price-step> ></price-step>
</div> </div>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<div v-for="(item, index) in form.clearancePriceStepList" :key="index"> <div
v-for="(item, index) in form.clearancePriceStepList"
:key="index"
>
<price-step <price-step
ref="stepPrice" ref="stepPrice"
:index="index" :index="index"
...@@ -83,11 +128,17 @@ ...@@ -83,11 +128,17 @@
:unit-list="unitList" :unit-list="unitList"
field-prefix="clearance" field-prefix="clearance"
:price-name="$t('清关费')" :price-name="$t('清关费')"
:show-add="index === form.clearancePriceStepList.length -1" :show-add="index === form.clearancePriceStepList.length - 1"
:value="item" :value="item"
@add="handleAddPrice('clearancePriceStepList', $event)" @add="handleAddPrice('clearancePriceStepList', $event)"
@delete="handleDeletePrice('clearancePriceStepList', $event)" @delete="handleDeletePrice('clearancePriceStepList', $event)"
@changeUnit="handleUnitChange(form.clearancePriceStepList, index, ...$event)" @changeUnit="
handleUnitChange(
form.clearancePriceStepList,
index,
...$event
)
"
></price-step> ></price-step>
</div> </div>
</el-col> </el-col>
...@@ -134,71 +185,116 @@ ...@@ -134,71 +185,116 @@
</el-row> </el-row>
</template> </template>
<el-form-item :label="$t('价格有效期')"> <el-form-item :label="$t('价格有效期')">
<el-date-picker v-model="form.validateStartDate" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker> <el-date-picker
v-model="form.validateStartDate"
value-format="yyyy-MM-dd HH:mm:ss"
></el-date-picker>
- -
<el-date-picker v-model="form.validateEndDate" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker> <el-date-picker
v-model="form.validateEndDate"
value-format="yyyy-MM-dd HH:mm:ss"
></el-date-picker>
</el-form-item> </el-form-item>
</el-card> </el-card>
<el-card> <el-card>
<div slot="header" style="font-size:20px;"> <div slot="header" style="font-size: 20px">
{{$t('基础信息')}} {{ $t("基础信息") }}
</div> </div>
<el-form-item :label="$t('是否预约入仓')" prop="needBook"> <el-form-item :label="$t('是否预约入仓')" prop="needBook">
<el-radio v-model.number="form.needBook" :label="1">{{$t('是')}}</el-radio> <el-radio v-model.number="form.needBook" :label="1">{{
<el-radio v-model.number="form.needBook" :label="0">{{$t('否')}}</el-radio> $t("是")
}}</el-radio>
<el-radio v-model.number="form.needBook" :label="0">{{
$t("否")
}}</el-radio>
</el-form-item> </el-form-item>
<!--下面几个字段只有批量设置海运才需要--> <!--下面几个字段只有批量设置海运才需要-->
<template v-if="type == 'sea'"> <template v-if="type == 'sea'">
<el-form-item :label="$t('每日入仓上限')" prop="dayLimit" v-if="form.needBook == 1"> <el-form-item
<el-input v-model.number="form.dayLimit" type="number" class="w-100" />{{$t('立方米')}} :label="$t('每日入仓上限')"
prop="dayLimit"
v-if="form.needBook == 1"
>
<el-input
v-model.number="form.dayLimit"
type="number"
class="w-100"
/>{{ $t("立方米") }}
</el-form-item> </el-form-item>
<el-form-item :label="$t('货柜位置')" prop="containerLocation"> <el-form-item :label="$t('货柜位置')" prop="containerLocation">
<dict-selector :type="DICT_TYPE.ECW_CONTAINER_LOCATION" v-model="form.containerLocation" /> <dict-selector
:type="DICT_TYPE.ECW_CONTAINER_LOCATION"
v-model="form.containerLocation"
/>
</el-form-item> </el-form-item>
<el-form-item :label="$t('订单方数上限')" prop="square"> <el-form-item :label="$t('订单方数上限')" prop="square">
<el-input v-model.number="form.square" type="number" style="width:200px" /> <el-input
v-model.number="form.square"
type="number"
style="width: 200px"
/>
</el-form-item> </el-form-item>
</template> </template>
<el-form-item :label="$t('是否单询')" prop="inquiry"> <el-form-item :label="$t('是否单询')" prop="inquiry">
<dict-selector :type="DICT_TYPE.NEED_ORDER_INQUIRY" v-model="form.needOrderInquiry" form-type="radio" formatter="number"></dict-selector> <dict-selector
:type="DICT_TYPE.NEED_ORDER_INQUIRY"
v-model="form.needOrderInquiry"
form-type="radio"
formatter="number"
></dict-selector>
</el-form-item> </el-form-item>
</el-card> </el-card>
</el-form> </el-form>
<div style="margin: 20px 0"> <div style="margin: 20px 0">
<el-button @click="submitForm" type="primary" :loading="loading">{{$t('确认提交')}}</el-button> <el-button @click="submitForm" type="primary" :loading="loading">{{
<el-button type="default" @click="$router.back()">{{$t('返回上一页')}}</el-button> $t("确认提交")
}}</el-button>
<el-button type="default" @click="$router.back()">{{
$t("返回上一页")
}}</el-button>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import RoutersSelector from '@/components/RoutersSelector' import RoutersSelector from "@/components/RoutersSelector";
import {batchUpdateProductPrice, getProductPrice} from "@/api/ecw/productPrice"; import {
import { getCurrencyList } from '@/api/ecw/currency'; batchUpdateProductPrice,
import { getUnitList } from '@/api/ecw/unit'; getProductPrice,
import ProductsSelector from '@/components/ProductsSelector' } from "@/api/ecw/productPrice";
import Selector from '@/components/Selector' import { getCurrencyList } from "@/api/ecw/currency";
import Inputor from '@/components/Inputor' import { getUnitList } from "@/api/ecw/unit";
import Decimal from 'decimal.js' import ProductsSelector from "@/components/ProductsSelector";
import {getProduct} from "@/api/ecw/product"; import Selector from "@/components/Selector";
import Inputor from "@/components/Inputor";
import Decimal from "decimal.js";
import { getProduct } from "@/api/ecw/product";
import QuickSet from "@/views/ecw/productPrice/components/QuickSet.vue"; import QuickSet from "@/views/ecw/productPrice/components/QuickSet.vue";
import PriceStep from "@/views/ecw/productPrice/components/PriceStep.vue"; import PriceStep from "@/views/ecw/productPrice/components/PriceStep.vue";
import SeaPrice from "@/views/ecw/productPrice/components/SeaPrice.vue"; import SeaPrice from "@/views/ecw/productPrice/components/SeaPrice.vue";
import Template from "@/views/cms/template/index.vue"; import Template from "@/views/cms/template/index.vue";
const DEFAULT_PRICE_UNIT = 1 const DEFAULT_PRICE_UNIT = 1;
const DEFAULT_VOLUME_UNIT = 7 const DEFAULT_VOLUME_UNIT = 7;
const DEFAULT_WEIGHT_UNIT = 7 const DEFAULT_WEIGHT_UNIT = 7;
export default { export default {
components: {Template, SeaPrice, PriceStep, QuickSet, RoutersSelector, ProductsSelector, Selector, Inputor }, components: {
Template,
SeaPrice,
PriceStep,
QuickSet,
RoutersSelector,
ProductsSelector,
Selector,
Inputor,
},
data() { data() {
return { return {
checkList: [], checkList: [],
...@@ -221,7 +317,11 @@ export default { ...@@ -221,7 +317,11 @@ export default {
specialProducts: [], specialProducts: [],
// priceStepList: [{},{}], // 阶梯价格 // priceStepList: [{},{}], // 阶梯价格
// specialList:[], // 特殊需求,默认四个 // specialList:[], // 特殊需求,默认四个
rules: {}, rules() {
return {
priceType: [{ required: true, message: this.$t("请选择单价模式") }],
};
},
product: null, product: null,
/* productType: null, */ /* productType: null, */
currencyList: [], currencyList: [],
...@@ -231,103 +331,111 @@ export default { ...@@ -231,103 +331,111 @@ export default {
lineList: [], //路线数组 lineList: [], //路线数组
loading: false, loading: false,
// 批量加价/减价 // 批量加价/减价
quickForm:{} quickForm: {},
} };
}, },
computed: { computed: {
// 类型,默认海运sea,air表示空运 // 类型,默认海运sea,air表示空运
type(){ type() {
let type = this.$route.path.split(/[-_]/).pop() let type = this.$route.path.split(/[-_]/).pop();
if(type == 'air' || type == 'sea') return type if (type == "air" || type == "sea") return type;
return null return null;
}, },
// 默认运费的货币和体积单位 // 默认运费的货币和体积单位
currencyAndUnit(){ currencyAndUnit() {
let currency = null, unit = null, fields = null let currency = null,
unit = null,
fields = null;
// 如果是阶梯价格则取第一阶梯,否则就取form中的字段 // 如果是阶梯价格则取第一阶梯,否则就取form中的字段
let obj = this.form.stepPrice == 1 ? this.form.priceStepList[0] : this.form let obj =
this.form.stepPrice == 1 ? this.form.priceStepList[0] : this.form;
// 全包价 // 全包价
if(this.form.priceType == 1){ if (this.form.priceType == 1) {
currency = obj.allPriceUnit currency = obj.allPriceUnit;
unit = obj.allVolumeUnit unit = obj.allVolumeUnit;
}else{ } else {
currency = obj.transportPriceUnit currency = obj.transportPriceUnit;
unit = obj.transportVolumeUnit unit = obj.transportVolumeUnit;
} }
return {currency, unit} return { currency, unit };
}, },
// 判断是否空值 // 判断是否空值
isEmpty(){ isEmpty() {
return (content) => { return (content) => {
return !content && content !== 0 && content !== '0' return !content && content !== 0 && content !== "0";
} };
}, },
}, },
watch: { watch: {
checkList() { //选择路线 checkList() {
//选择路线
if (this.checkList.length > 0) { if (this.checkList.length > 0) {
this.form.lineChannelList = this.checkList.map(item => { this.form.lineChannelList = this.checkList.map((item) => {
return { lineId: item, shippingChannelId: 0 } return { lineId: item, shippingChannelId: 0 };
}) });
} else { } else {
this.form.lineChannelList = [] this.form.lineChannelList = [];
} }
}, },
product() { product() {
this.$set(this.form, 'productType', this.product.typeId) this.$set(this.form, "productType", this.product.typeId);
}, },
'form.stepPrice'(stepPrice){ "form.stepPrice"(stepPrice) {
if(this.form.stepPrice === 1){ if (this.form.stepPrice === 1) {
this.initStepPrice() this.initStepPrice();
} }
this.syncMinWeightUnit() this.syncMinWeightUnit();
}, },
'form.priceType'(priceType){ "form.priceType"(priceType) {
if(this.form.stepPrice === 1){ if (this.form.stepPrice === 1) {
this.initStepPrice() this.initStepPrice();
} }
this.syncMinWeightUnit() this.syncMinWeightUnit();
}, },
'form.needBook'(val){ "form.needBook"(val) {
if(val) this.$set(this.form, 'dayLimit', 10000) if (val) this.$set(this.form, "dayLimit", 10000);
else delete this.form.dayLimit else delete this.form.dayLimit;
}, },
}, },
async created() { async created() {
this.currencyList = (await getCurrencyList())?.data || [] this.currencyList = (await getCurrencyList())?.data || [];
this.unitList = (await getUnitList())?.data || [] this.unitList = (await getUnitList())?.data || [];
await this.$nextTick() await this.$nextTick();
// 如果是复制,则获取数据并填充,先复制,然后填充特需,避免数据的特需不全导致部分不显示 // 如果是复制,则获取数据并填充,先复制,然后填充特需,避免数据的特需不全导致部分不显示
if(this.$route.query.templateId){ if (this.$route.query.templateId) {
await this.getTemplateDetail(this.$route.query.templateId) await this.getTemplateDetail(this.$route.query.templateId);
} }
// 从价格中获取特需的默认单位 // 从价格中获取特需的默认单位
this.getDictDatas(this.DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS).forEach(item => { this.getDictDatas(this.DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS).forEach(
(item) => {
// 没有的才push,已有的可能是从复制模板携带过来的数据 // 没有的才push,已有的可能是从复制模板携带过来的数据
if(!this.form.specialList.find(special => special.specialDictType == item.value)) { if (
console.log('特需push', item.value) !this.form.specialList.find(
(special) => special.specialDictType == item.value
)
) {
console.log("特需push", item.value);
this.form.specialList.push({ this.form.specialList.push({
"clearancePrice": null, clearancePrice: null,
"clearancePriceUnit": DEFAULT_PRICE_UNIT, clearancePriceUnit: DEFAULT_PRICE_UNIT,
"clearanceVolumeUnit": DEFAULT_VOLUME_UNIT, clearanceVolumeUnit: DEFAULT_VOLUME_UNIT,
"specialDictType": item.value, specialDictType: item.value,
"transportPrice": null, transportPrice: null,
"transportPriceUnit": DEFAULT_PRICE_UNIT, transportPriceUnit: DEFAULT_PRICE_UNIT,
"transportVolumeUnit": DEFAULT_VOLUME_UNIT, transportVolumeUnit: DEFAULT_VOLUME_UNIT,
}) });
}else console.log('已存在特需', item.value) } else console.log("已存在特需", item.value);
}) }
);
}, },
methods: { methods: {
// 获取模板数据(复制的源路线价格信息) // 获取模板数据(复制的源路线价格信息)
async getTemplateDetail(id){ async getTemplateDetail(id) {
const res = await getProductPrice(id) const res = await getProductPrice(id);
// 填充商品、线路、价格信息、出货渠道(空运) // 填充商品、线路、价格信息、出货渠道(空运)
// this.form.productIdList = [res.data.productId] // this.form.productIdList = [res.data.productId]
/* 23-11-07要求不复制商品和线路 https://zentao.test.jdshangmen.com/bug-view-5145.html /* 23-11-07要求不复制商品和线路 https://zentao.test.jdshangmen.com/bug-view-5145.html
...@@ -359,8 +467,8 @@ export default { ...@@ -359,8 +467,8 @@ export default {
needPay, needPay,
freightPriceStepList, freightPriceStepList,
clearancePriceStepList, clearancePriceStepList,
fullPriceStepList fullPriceStepList,
} = res.data } = res.data;
const data = { const data = {
allPrice, allPrice,
...@@ -383,14 +491,14 @@ export default { ...@@ -383,14 +491,14 @@ export default {
needPay, needPay,
freightPriceStepList, freightPriceStepList,
clearancePriceStepList, clearancePriceStepList,
fullPriceStepList fullPriceStepList,
} };
// 海运需要填充货柜位置和订单方数上限 // 海运需要填充货柜位置和订单方数上限
if(this.type == 'sea'){ if (this.type == "sea") {
data.containerLocation = res.data.containerLocation data.containerLocation = res.data.containerLocation;
data.square = res.data.square data.square = res.data.square;
} }
this.$set(this, 'form', Object.assign({}, this.form, data)) this.$set(this, "form", Object.assign({}, this.form, data));
// 产品选择器默认选择的商品 // 产品选择器默认选择的商品
/* 23-11-07要求不复制商品和线路 https://zentao.test.jdshangmen.com/bug-view-5145.html /* 23-11-07要求不复制商品和线路 https://zentao.test.jdshangmen.com/bug-view-5145.html
...@@ -399,150 +507,164 @@ export default { ...@@ -399,150 +507,164 @@ export default {
})*/ })*/
}, },
// 设置最小起计量单位 // 设置最小起计量单位
syncMinWeightUnit(){ syncMinWeightUnit() {
// 如果是阶梯价 // 如果是阶梯价
if(this.form.stepPrice){ if (this.form.stepPrice) {
const field = this.form.priceType === 1 ? "fullPriceStepList" : "freightPriceStepList" const field =
const stepPriceList = this.form[field] this.form.priceType === 1
if(stepPriceList?.length){ ? "fullPriceStepList"
this.form.minWeightUnit = stepPriceList[0]?.weightUnit || DEFAULT_WEIGHT_UNIT : "freightPriceStepList";
}else { const stepPriceList = this.form[field];
this.form.minWeightUnit = DEFAULT_WEIGHT_UNIT if (stepPriceList?.length) {
this.form.minWeightUnit =
stepPriceList[0]?.weightUnit || DEFAULT_WEIGHT_UNIT;
} else {
this.form.minWeightUnit = DEFAULT_WEIGHT_UNIT;
} }
}else{ } else {
this.form.minWeightUnit = this.form[this.form.priceType === 1 ? 'allVolumeUnit' : 'transportVolumeUnit'] || DEFAULT_WEIGHT_UNIT this.form.minWeightUnit =
this.form[
this.form.priceType === 1 ? "allVolumeUnit" : "transportVolumeUnit"
] || DEFAULT_WEIGHT_UNIT;
} }
}, },
handleAddPrice(field, fieldPrefix){ handleAddPrice(field, fieldPrefix) {
if(!this.form[field]){ if (!this.form[field]) {
this.$set(this.form, field, []) this.$set(this.form, field, []);
} }
let priceUnit = DEFAULT_PRICE_UNIT let priceUnit = DEFAULT_PRICE_UNIT;
let volumeUnit = DEFAULT_VOLUME_UNIT let volumeUnit = DEFAULT_VOLUME_UNIT;
let weightUnit = DEFAULT_WEIGHT_UNIT let weightUnit = DEFAULT_WEIGHT_UNIT;
if(this.form[field].length){ if (this.form[field].length) {
const first = this.form[field][0] const first = this.form[field][0];
priceUnit = first[`${fieldPrefix}PriceUnit`] priceUnit = first[`${fieldPrefix}PriceUnit`];
volumeUnit = first[`${fieldPrefix}VolumeUnit`] volumeUnit = first[`${fieldPrefix}VolumeUnit`];
weightUnit = first.weightUnit weightUnit = first.weightUnit;
} }
console.log("添加价格的默认单位", { console.log("添加价格的默认单位", {
priceUnit, priceUnit,
volumeUnit, volumeUnit,
weightUnit weightUnit,
}) });
this.form[field].push({ this.form[field].push({
[`${fieldPrefix}PriceUnit`]: priceUnit, [`${fieldPrefix}PriceUnit`]: priceUnit,
[`${fieldPrefix}VolumeUnit`]: volumeUnit, [`${fieldPrefix}VolumeUnit`]: volumeUnit,
weightUnit: weightUnit, weightUnit: weightUnit,
specialList:[] specialList: [],
}) });
}, },
handleDeletePrice(field, index){ handleDeletePrice(field, index) {
this.form[field].splice(index, 1) this.form[field].splice(index, 1);
}, },
handleUnitChange(stepPriceList, index, data){ handleUnitChange(stepPriceList, index, data) {
console.log('handleUnitChange', ...arguments) console.log("handleUnitChange", ...arguments);
if(index > 0) return if (index > 0) return;
const isVolumeUnit = data.field.indexOf("VolumeUnit") > -1 const isVolumeUnit = data.field.indexOf("VolumeUnit") > -1;
// 如果是重量单位,且不是清关费想换的,则需要同步最小起计量单位 // 如果是重量单位,且不是清关费想换的,则需要同步最小起计量单位
if(isVolumeUnit && data.type != 'clearance'){ if (isVolumeUnit && data.type != "clearance") {
this.form.minWeightUnit = data.value this.form.minWeightUnit = data.value;
} }
stepPriceList.forEach(item => { stepPriceList.forEach((item) => {
item[data.field] = data.value item[data.field] = data.value;
// 如果是设置体积单位,则还需要同步到阶梯重量单位 // 如果是设置体积单位,则还需要同步到阶梯重量单位
if(isVolumeUnit){ if (isVolumeUnit) {
item['weightUnit'] = data.value item["weightUnit"] = data.value;
} }
if(item.packagingList?.length){ if (item.packagingList?.length) {
item.packagingList.forEach(p => { item.packagingList.forEach((p) => {
if(data.field.indexOf("PriceUnit") > -1){ if (data.field.indexOf("PriceUnit") > -1) {
p['packagingPriceUnit'] = data.value p["packagingPriceUnit"] = data.value;
} }
if(data.field.indexOf("VolumeUnit") > -1){ if (data.field.indexOf("VolumeUnit") > -1) {
p['packagingVolumeUnit'] = data.value p["packagingVolumeUnit"] = data.value;
} }
}) });
} }
if(item.specialList?.length){ if (item.specialList?.length) {
item.specialList.forEach(p => { item.specialList.forEach((p) => {
p[data.field] = data.value p[data.field] = data.value;
}) });
} }
}) });
}, },
// 获得用语提交的阶梯价副本 // 获得用语提交的阶梯价副本
getPriceList(stepList, prefix){ getPriceList(stepList, prefix) {
if(!stepList?.length) return [] if (!stepList?.length) return [];
let stepPriceList = JSON.parse(JSON.stringify(stepList)) let stepPriceList = JSON.parse(JSON.stringify(stepList));
stepPriceList.forEach((item, index) => { stepPriceList.forEach((item, index) => {
item.rankNum = index + 1 item.rankNum = index + 1;
item.packagingList = item.packagingList.filter(p => !!p.packagingTypes?.length) item.packagingList = item.packagingList.filter(
item.packagingList = item.packagingList.map( p => { (p) => !!p.packagingTypes?.length
p.packagingTypes = p.packagingTypes.join(",") );
return p item.packagingList = item.packagingList.map((p) => {
}) p.packagingTypes = p.packagingTypes.join(",");
}) return p;
});
});
// 240121应老王要求,未设置价格的不提交 // 240121应老王要求,未设置价格的不提交
return stepPriceList.filter(item => { return stepPriceList.filter((item) => {
return !!item[`${prefix}Price`] return !!item[`${prefix}Price`];
}) });
}, },
// 格式化包装类型费用 // 格式化包装类型费用
getPackingPrice(packging){ getPackingPrice(packging) {
if(!packging?.length) return if (!packging?.length) return;
packging = JSON.parse(JSON.stringify(packging)) packging = JSON.parse(JSON.stringify(packging));
return packging.filter(item => !!item.packagingTypes).map(item => { return packging
item.packagingTypes = item.packagingTypes?.join(",") || "" .filter((item) => !!item.packagingTypes)
return item .map((item) => {
}) item.packagingTypes = item.packagingTypes?.join(",") || "";
return item;
});
}, },
// 非阶梯价格更新单位 // 非阶梯价格更新单位
handleFormUnitChange(data){ handleFormUnitChange(data) {
console.log("handleFormUnitChange", {...data}) console.log("handleFormUnitChange", { ...data });
// 海运非阶梯价没有重量单位,所以按照体积单位同步最小起计量单位 // 海运非阶梯价没有重量单位,所以按照体积单位同步最小起计量单位
if(data.field === 'transportVolumeUnit' || data.field == 'allVolumeUnit'){ if (
this.form.minWeightUnit = data.value data.field === "transportVolumeUnit" ||
data.field == "allVolumeUnit"
) {
this.form.minWeightUnit = data.value;
} }
if(this.form.specialList?.length){ if (this.form.specialList?.length) {
this.form.specialList.forEach(p => { this.form.specialList.forEach((p) => {
p[data.field] = data.value p[data.field] = data.value;
}) });
} }
// 同步包装的单位 // 同步包装的单位
let packingField = { let packingField = {
transportVolumeUnit: 'freightPricePackagingList', transportVolumeUnit: "freightPricePackagingList",
clearanceVolumeUnit: 'clearancePricePackagingList', clearanceVolumeUnit: "clearancePricePackagingList",
allVolumeUnit: 'fullPricePackagingList', allVolumeUnit: "fullPricePackagingList",
transportPriceUnit: 'freightPricePackagingList', transportPriceUnit: "freightPricePackagingList",
clearancePriceUnit: 'clearancePricePackagingList' clearancePriceUnit: "clearancePricePackagingList",
}[data.field] }[data.field];
if(!this.form[packingField]?.length){ if (!this.form[packingField]?.length) {
return false return false;
} }
this.form[packingField].forEach(item => { this.form[packingField].forEach((item) => {
if(data.field.indexOf("PriceUnit") > -1){ if (data.field.indexOf("PriceUnit") > -1) {
item['packagingPriceUnit'] = data.value item["packagingPriceUnit"] = data.value;
} }
if(data.field.indexOf("VolumeUnit") > -1){ if (data.field.indexOf("VolumeUnit") > -1) {
item['packagingVolumeUnit'] = data.value item["packagingVolumeUnit"] = data.value;
} }
}) });
}, },
initStepPrice(){ initStepPrice() {
if(this.form.priceType == 1 && !this.form.fullPriceStepList?.length){ if (this.form.priceType == 1 && !this.form.fullPriceStepList?.length) {
this.handleAddPrice("fullPriceStepList", 'all') this.handleAddPrice("fullPriceStepList", "all");
} }
if(this.form.priceType === 0){ if (this.form.priceType === 0) {
if(!this.form.freightPriceStepList?.length){ if (!this.form.freightPriceStepList?.length) {
this.handleAddPrice('freightPriceStepList', 'transport') this.handleAddPrice("freightPriceStepList", "transport");
} }
if(!this.form.clearancePriceStepList?.length){ if (!this.form.clearancePriceStepList?.length) {
this.handleAddPrice('clearancePriceStepList', 'clearance') this.handleAddPrice("clearancePriceStepList", "clearance");
} }
} }
}, },
...@@ -553,15 +675,18 @@ export default { ...@@ -553,15 +675,18 @@ export default {
} }
// 只有新增的时候做判断 // 只有新增的时候做判断
if (!this.$route.query.ids && (!this.selectedRoutes || !this.selectedRoutes.length)) { if (
this.$message.error(this.$t('请选择线路')); !this.$route.query.ids &&
(!this.selectedRoutes || !this.selectedRoutes.length)
) {
this.$message.error(this.$t("请选择线路"));
return; return;
} }
let data = Object.assign({}, this.form, { let data = Object.assign({}, this.form, {
// lineChannelList: this.selectedRoutes, // lineChannelList: this.selectedRoutes,
// specialList: this.specialProducts, // specialList: this.specialProducts,
isAllProduct: this.isAllProduct ? 1:0, isAllProduct: this.isAllProduct ? 1 : 0,
// 阶梯价 // 阶梯价
freightPriceStepList: [], freightPriceStepList: [],
clearancePriceStepList: [], clearancePriceStepList: [],
...@@ -569,15 +694,19 @@ export default { ...@@ -569,15 +694,19 @@ export default {
// 非阶梯价包装类型 // 非阶梯价包装类型
freightPricePackagingList: [], freightPricePackagingList: [],
clearancePricePackagingList: [], clearancePricePackagingList: [],
fullPricePackagingList: [] fullPricePackagingList: [],
}) });
// 如果是勾選了全部篩選商品,則獲取商品ID // 如果是勾選了全部篩選商品,則獲取商品ID
if(this.isAllFilteredProduct){ if (this.isAllFilteredProduct) {
data.productIdList = await this.$refs.productSelector.getFilteredIds() data.productIdList =
await this.$refs.productSelector.getFilteredIds();
} }
if(!data.isAllProduct && (!data.productIdList || !data.productIdList.length)){ if (
return this.$message.error('请选择商品') !data.isAllProduct &&
(!data.productIdList || !data.productIdList.length)
) {
return this.$message.error("请选择商品");
} }
// 阶梯价校验 // 阶梯价校验
...@@ -592,63 +721,94 @@ export default { ...@@ -592,63 +721,94 @@ export default {
} }
if(!isValid)return if(!isValid)return
} */ } */
if(data.stepPrice){ if (data.stepPrice) {
// 全包价 // 全包价
if(this.form.priceType == 1) { if (this.form.priceType == 1) {
data.fullPriceStepList = this.getPriceList(this.form.fullPriceStepList, 'all') data.fullPriceStepList = this.getPriceList(
}else{ this.form.fullPriceStepList,
data.clearancePriceStepList = this.getPriceList(this.form.clearancePriceStepList, 'clearance') "all"
data.freightPriceStepList = this.getPriceList(this.form.freightPriceStepList, 'transport') );
} else {
data.clearancePriceStepList = this.getPriceList(
this.form.clearancePriceStepList,
"clearance"
);
data.freightPriceStepList = this.getPriceList(
this.form.freightPriceStepList,
"transport"
);
} }
} }
// 非阶梯价则需要提交包装类型 // 非阶梯价则需要提交包装类型
else{ else {
if(this.form.priceType == 1){ if (this.form.priceType == 1) {
data.fullPricePackagingList = this.getPackingPrice(this.form.fullPricePackagingList) data.fullPricePackagingList = this.getPackingPrice(
}else{ this.form.fullPricePackagingList
data.freightPricePackagingList = this.getPackingPrice(this.form.freightPricePackagingList) );
data.clearancePricePackagingList = this.getPackingPrice(this.form.clearancePricePackagingList) } else {
data.freightPricePackagingList = this.getPackingPrice(
this.form.freightPricePackagingList
);
data.clearancePricePackagingList = this.getPackingPrice(
this.form.clearancePricePackagingList
);
} }
} }
data.lineChannelList = this.selectedRoutes;
data.lineChannelList = this.selectedRoutes if (data.lineChannelList.length < 1) {
return this.$message.error(this.$t("请选择需要修改的路线"));
if(data.lineChannelList.length < 1){
return this.$message.error(this.$t('请选择需要修改的路线'))
} }
await this.$confirm(this.$t('已选择{route}条路线,{product}个商品;确认提交修改?', { await this.$confirm(
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
this.loading = true : data.productIdList.length,
console.log('提交批量修改', data) })
batchUpdateProductPrice(data).then(response => { );
this.loading = true;
console.log("提交批量修改", data);
batchUpdateProductPrice(data)
.then((response) => {
this.$modal.msgSuccess(this.$t("修改成功")); this.$modal.msgSuccess(this.$t("修改成功"));
this.$router.replace('/lineProject/product-price?' + (new URLSearchParams(this.$route.query)).toString()) this.$router.replace(
"/lineProject/product-price?" +
new URLSearchParams(this.$route.query).toString()
);
}) })
.finally(res => this.loading = false) .finally((res) => (this.loading = false));
}); });
}, },
// 快捷设置,只更新默认运费 // 快捷设置,只更新默认运费
quickSet(){ quickSet() {
// 字段,根据是否全包价来取 // 字段,根据是否全包价来取
let field = this.form.priceType == 1 ? 'allPrice' : 'transportPrice' let field = this.form.priceType == 1 ? "allPrice" : "transportPrice";
// 取得要加的数额(减少则是负数) // 取得要加的数额(减少则是负数)
let amount = Decimal(this.quickForm.plus || -this.quickForm.minus) let amount = Decimal(this.quickForm.plus || -this.quickForm.minus);
this.form.priceStepList.forEach(item => { this.form.priceStepList.forEach((item) => {
// 加上对应的价格,但是不能小于0 // 加上对应的价格,但是不能小于0
this.$set(item, field, Math.max(0, Decimal(item[field] || 0).plus(amount).toNumber())) this.$set(
}) item,
} field,
} Math.max(
} 0,
Decimal(item[field] || 0)
.plus(amount)
.toNumber()
)
);
});
},
},
};
</script> </script>
<style scoped> <style scoped>
.w100{ .w100 {
width: 100px; width: 100px;
} }
.mr10{ .mr10 {
margin-right: 10px; margin-right: 10px;
} }
</style> </style>
<template> <template>
<div class="app-container"> <div class="app-container">
<el-form ref="form" :model="form" :rules="rules" label-width="150px"> <el-form ref="form" :model="form" :rules="rules" label-width="150px">
<products-selector ref="productSelector" v-model="form.productIdList" show-all @setall="isAllProduct=$event" :default-ids="form.productIdList" enable-filtered @setFiltered="isAllFilteredProduct=$event" class="mb-20" /> <products-selector
ref="productSelector"
v-model="form.productIdList"
show-all
@setall="isAllProduct = $event"
:default-ids="form.productIdList"
enable-filtered
@setFiltered="isAllFilteredProduct = $event"
class="mb-20"
/>
<routers-selector v-model="selectedRoutes" type="air" /> <routers-selector v-model="selectedRoutes" type="air" />
<el-card style="margin-bottom: 10px"> <el-card style="margin-bottom: 10px">
<div slot="header" style="font-size:20px;"> <div slot="header" style="font-size: 20px">
{{$t('价格设置')}} {{ $t("价格设置") }}
</div> </div>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="12"> <el-col :span="12">
<el-form-item :label="$t('预付')" prop="needPay" > <el-form-item :label="$t('预付')" prop="needPay">
<el-radio-group v-model="form.needPay"> <el-radio-group v-model="form.needPay">
<el-radio :label="1">{{ $t('预付') }}</el-radio> <el-radio :label="1">{{ $t("预付") }}</el-radio>
<el-radio :label="0">{{ $t('均可') }}</el-radio> <el-radio :label="0">{{ $t("均可") }}</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<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" formatter='number' /> <dict-selector
:type="DICT_TYPE.ECW_PRICE_TYPE"
v-model="form.priceType"
form-type="radio"
formatter="number"
/>
</el-form-item> </el-form-item>
<el-form-item <el-form-item :label="$t('最小起计量')" :prop="`minWeight`">
:label="$t('最小起计量')" <el-input-number
:prop="`minWeight`" v-model="form.minWeight"
> :controls="false"
<el-input-number v-model="form.minWeight" :controls="false" class="w-100"/> class="w-100"
/ <selector v-model="form.minWeightUnit" :options="unitList" :label-field="$l(null, 'title')" value-field="id" defaultable2 class="w-100" disabled /> />
/
<selector
v-model="form.minWeightUnit"
:options="unitList"
:label-field="$l(null, 'title')"
value-field="id"
defaultable2
class="w-100"
disabled
/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<quick-set :unit-list="unitList" :currency-list="currencyList" :value="form"></quick-set> <quick-set
:unit-list="unitList"
:currency-list="currencyList"
:value="form"
></quick-set>
</el-col> </el-col>
</el-row> </el-row>
<!--全包价--> <!--全包价-->
<template v-if="form.priceType==1" > <template v-if="form.priceType == 1">
<div v-for="(item, index) in form.fullPriceStepList" :key="index"> <div v-for="(item, index) in form.fullPriceStepList" :key="index">
<price-step <price-step
ref="stepPrice" ref="stepPrice"
...@@ -43,17 +71,22 @@ ...@@ -43,17 +71,22 @@
:unit-list="unitList" :unit-list="unitList"
field-prefix="all" field-prefix="all"
:price-name="$t('全包价')" :price-name="$t('全包价')"
:show-add="index === form.fullPriceStepList.length -1" :show-add="index === form.fullPriceStepList.length - 1"
:value="item" :value="item"
@add="handleAddPrice('fullPriceStepList', $event)" @add="handleAddPrice('fullPriceStepList', $event)"
@delete="handleDeletePrice('fullPriceStepList', $event)" @delete="handleDeletePrice('fullPriceStepList', $event)"
@changeUnit="handleUnitChange(form.fullPriceStepList, index, ...$event)" @changeUnit="
handleUnitChange(form.fullPriceStepList, index, ...$event)
"
></price-step> ></price-step>
</div> </div>
</template> </template>
<el-row v-else :gutter="20" class="mt-20"> <el-row v-else :gutter="20" class="mt-20">
<el-col :span="12"> <el-col :span="12">
<div v-for="(item, index) in form.freightPriceStepList" :key="index"> <div
v-for="(item, index) in form.freightPriceStepList"
:key="index"
>
<price-step <price-step
ref="stepPrice" ref="stepPrice"
:index="index" :index="index"
...@@ -61,16 +94,21 @@ ...@@ -61,16 +94,21 @@
:unit-list="unitList" :unit-list="unitList"
field-prefix="transport" field-prefix="transport"
:price-name="$t('运费')" :price-name="$t('运费')"
:show-add="index === form.freightPriceStepList.length -1" :show-add="index === form.freightPriceStepList.length - 1"
:value="item" :value="item"
@add="handleAddPrice('freightPriceStepList', $event)" @add="handleAddPrice('freightPriceStepList', $event)"
@delete="handleDeletePrice('freightPriceStepList', $event)" @delete="handleDeletePrice('freightPriceStepList', $event)"
@changeUnit="handleUnitChange(form.freightPriceStepList, index, ...$event)" @changeUnit="
handleUnitChange(form.freightPriceStepList, index, ...$event)
"
></price-step> ></price-step>
</div> </div>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<div v-for="(item, index) in form.clearancePriceStepList" :key="index"> <div
v-for="(item, index) in form.clearancePriceStepList"
:key="index"
>
<price-step <price-step
ref="stepPrice" ref="stepPrice"
:index="index" :index="index"
...@@ -78,84 +116,127 @@ ...@@ -78,84 +116,127 @@
:unit-list="unitList" :unit-list="unitList"
field-prefix="clearance" field-prefix="clearance"
:price-name="$t('清关费')" :price-name="$t('清关费')"
:show-add="index === form.clearancePriceStepList.length -1" :show-add="index === form.clearancePriceStepList.length - 1"
:value="item" :value="item"
@add="handleAddPrice('clearancePriceStepList', $event)" @add="handleAddPrice('clearancePriceStepList', $event)"
@delete="handleDeletePrice('clearancePriceStepList', $event)" @delete="handleDeletePrice('clearancePriceStepList', $event)"
@changeUnit="handleUnitChange(form.clearancePriceStepList, index, ...$event)" @changeUnit="
handleUnitChange(
form.clearancePriceStepList,
index,
...$event
)
"
></price-step> ></price-step>
</div> </div>
</el-col> </el-col>
</el-row> </el-row>
<el-form-item :label="$t('价格有效期')"> <el-form-item :label="$t('价格有效期')">
<el-date-picker v-model="form.validateStartDate" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker> <el-date-picker
v-model="form.validateStartDate"
value-format="yyyy-MM-dd HH:mm:ss"
></el-date-picker>
- -
<el-date-picker v-model="form.validateEndDate" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker> <el-date-picker
v-model="form.validateEndDate"
value-format="yyyy-MM-dd HH:mm:ss"
></el-date-picker>
</el-form-item> </el-form-item>
</el-card> </el-card>
<el-card> <el-card>
<div slot="header" style="font-size:20px;"> <div slot="header" style="font-size: 20px">
{{$t('基础信息')}} {{ $t("基础信息") }}
</div> </div>
<el-form-item :label="$t('是否预约入仓')" prop="needBook"> <el-form-item :label="$t('是否预约入仓')" prop="needBook">
<el-radio v-model.number="form.needBook" :label="1">{{$t('是')}}</el-radio> <el-radio v-model.number="form.needBook" :label="1">{{
<el-radio v-model.number="form.needBook" :label="0">{{$t('否')}}</el-radio> $t("是")
}}</el-radio>
<el-radio v-model.number="form.needBook" :label="0">{{
$t("否")
}}</el-radio>
</el-form-item> </el-form-item>
<el-form-item :label="$t('是否单询')" prop="inquiry"> <el-form-item :label="$t('是否单询')" prop="inquiry">
<dict-selector :type="DICT_TYPE.NEED_ORDER_INQUIRY" v-model="form.needOrderInquiry" form-type="radio" formatter="number"></dict-selector> <dict-selector
:type="DICT_TYPE.NEED_ORDER_INQUIRY"
v-model="form.needOrderInquiry"
form-type="radio"
formatter="number"
></dict-selector>
</el-form-item> </el-form-item>
<el-form-item :label="$t('线路重量上限') + `(kg)`" prop="square"> <el-form-item :label="$t('线路重量上限') + `(kg)`" prop="square">
<el-input-number v-model="form.weightLimit" type="number" style="width:200px" :controls="false" /> <el-input-number
v-model="form.weightLimit"
type="number"
style="width: 200px"
:controls="false"
/>
</el-form-item> </el-form-item>
</el-card> </el-card>
</el-form> </el-form>
<div style="margin: 20px 0"> <div style="margin: 20px 0">
<el-button @click="submitForm" type="primary" :loading="loading">{{$t('确认提交')}}</el-button> <el-button @click="submitForm" type="primary" :loading="loading">{{
<el-button type="default" @click="$router.back()">{{$t('返回上一页')}}</el-button> $t("确认提交")
}}</el-button>
<el-button type="default" @click="$router.back()">{{
$t("返回上一页")
}}</el-button>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import RoutersSelector from '@/components/RoutersSelector' import RoutersSelector from "@/components/RoutersSelector";
import {batchUpdateProductPrice, batchUpdateProductPriceAir, getProductPrice} from "@/api/ecw/productPrice"; import {
import { getCurrencyList } from '@/api/ecw/currency'; batchUpdateProductPrice,
import { getUnitList } from '@/api/ecw/unit'; batchUpdateProductPriceAir,
import ProductsSelector from '@/components/ProductsSelector' getProductPrice,
import Selector from '@/components/Selector' } from "@/api/ecw/productPrice";
import Inputor from '@/components/Inputor' import { getCurrencyList } from "@/api/ecw/currency";
import Decimal from 'decimal.js' import { getUnitList } from "@/api/ecw/unit";
import {getProduct} from "@/api/ecw/product"; import ProductsSelector from "@/components/ProductsSelector";
import Selector from "@/components/Selector";
import Inputor from "@/components/Inputor";
import Decimal from "decimal.js";
import { getProduct } from "@/api/ecw/product";
import QuickSet from "@/views/ecw/productPrice/components/QuickSet.vue"; import QuickSet from "@/views/ecw/productPrice/components/QuickSet.vue";
import PriceStep from "@/views/ecw/productPrice/components/PriceStep.vue"; import PriceStep from "@/views/ecw/productPrice/components/PriceStep.vue";
import {getProductTypeList} from "@/api/ecw/productType"; import { getProductTypeList } from "@/api/ecw/productType";
// 定义默认的价格单位和体积单位 // 定义默认的价格单位和体积单位
const DEFAULT_PRICE_UNIT = 1 const DEFAULT_PRICE_UNIT = 1;
const DEFAULT_VOLUME_UNIT = 6 const DEFAULT_VOLUME_UNIT = 6;
const DEFAULT_WEIGHT_UNIT = 6 const DEFAULT_WEIGHT_UNIT = 6;
export default { export default {
components: {PriceStep, QuickSet, RoutersSelector, ProductsSelector, Selector, Inputor }, components: {
PriceStep,
QuickSet,
RoutersSelector,
ProductsSelector,
Selector,
Inputor,
},
data() { data() {
return { return {
checkList: [], checkList: [],
selectedRoutes: [], // 勾选的路线渠道 selectedRoutes: [], // 勾选的路线渠道
form: { form: {
stepPrice: 0, stepPrice: 0,
priceType: null priceType: null,
}, },
isAllProduct: false, // 是否全部商品 isAllProduct: false, // 是否全部商品
isAllFilteredProduct: false, // 是否勾選全部搜索結果 isAllFilteredProduct: false, // 是否勾選全部搜索結果
specialProducts: [], specialProducts: [],
rules: {}, rules() {
return {
priceType: [{ required: true, message: this.$t("请选择单价模式") }],
};
},
product: null, product: null,
currencyList: [], currencyList: [],
unitList: [], unitList: [],
...@@ -163,63 +244,64 @@ export default { ...@@ -163,63 +244,64 @@ export default {
productDisabled: true, productDisabled: true,
lineList: [], //路线数组 lineList: [], //路线数组
loading: false, loading: false,
} };
}, },
computed: { computed: {
// 判断是否空值 // 判断是否空值
isEmpty() { isEmpty() {
return (content) => { return (content) => {
return !content && content !== 0 && content !== '0' return !content && content !== 0 && content !== "0";
} };
}, },
}, },
watch: { watch: {
checkList() { //选择路线 checkList() {
//选择路线
if (this.checkList.length > 0) { if (this.checkList.length > 0) {
this.form.lineChannelList = this.checkList.map(item => { this.form.lineChannelList = this.checkList.map((item) => {
return { lineId: item, shippingChannelId: 0 } return { lineId: item, shippingChannelId: 0 };
}) });
} else { } else {
this.form.lineChannelList = [] this.form.lineChannelList = [];
} }
}, },
product() { product() {
this.$set(this.form, 'productType', this.product.typeId) this.$set(this.form, "productType", this.product.typeId);
}, },
// 价格类型切换,需要初始化对应的字段 // 价格类型切换,需要初始化对应的字段
'form.priceType'(priceType){ "form.priceType"(priceType) {
if(priceType == 1 && !this.form.fullPriceStepList?.length){ if (priceType == 1 && !this.form.fullPriceStepList?.length) {
this.handleAddPrice('fullPriceStepList', 'all') this.handleAddPrice("fullPriceStepList", "all");
} }
if(priceType == 0){ if (priceType == 0) {
if(!this.form.freightPriceStepList?.length){ if (!this.form.freightPriceStepList?.length) {
this.handleAddPrice('freightPriceStepList', 'transport') this.handleAddPrice("freightPriceStepList", "transport");
} }
if(!this.form.clearancePriceStepList?.length){ if (!this.form.clearancePriceStepList?.length) {
this.handleAddPrice('clearancePriceStepList', 'clearance') this.handleAddPrice("clearancePriceStepList", "clearance");
} }
} }
}, },
'form.needBook'(val){ "form.needBook"(val) {
if(val) this.$set(this.form, 'dayLimit', 10000) if (val) this.$set(this.form, "dayLimit", 10000);
else delete this.form.dayLimit else delete this.form.dayLimit;
}, },
}, },
async created() { async created() {
this.currencyList = (await getCurrencyList())?.data || [] this.currencyList = (await getCurrencyList())?.data || [];
this.unitList = (await getUnitList())?.data || [] this.unitList = (await getUnitList())?.data || [];
this.$set(this.form, 'stepPrice', 1) this.$set(this.form, "stepPrice", 1);
// 如果是复制,则获取数据并填充,先复制,然后填充特需,避免数据的特需不全导致部分不显示 // 如果是复制,则获取数据并填充,先复制,然后填充特需,避免数据的特需不全导致部分不显示
if(this.$route.query.templateId){ if (this.$route.query.templateId) {
await this.getTemplateDetail(this.$route.query.templateId) await this.getTemplateDetail(this.$route.query.templateId);
} }
}, },
methods: { methods: {
// 获取模板数据(复制的源路线价格信息) // 获取模板数据(复制的源路线价格信息)
async getTemplateDetail(id){ async getTemplateDetail(id) {
const res = await getProductPrice(id) const res = await getProductPrice(id);
// 要复制过来的字段 // 要复制过来的字段
const { const {
allPrice, allPrice,
...@@ -242,8 +324,8 @@ export default { ...@@ -242,8 +324,8 @@ export default {
needPay, needPay,
freightPriceStepList, freightPriceStepList,
clearancePriceStepList, clearancePriceStepList,
fullPriceStepList fullPriceStepList,
} = res.data } = res.data;
const data = { const data = {
allPrice, allPrice,
...@@ -266,9 +348,9 @@ export default { ...@@ -266,9 +348,9 @@ export default {
needPay, needPay,
freightPriceStepList, freightPriceStepList,
clearancePriceStepList, clearancePriceStepList,
fullPriceStepList fullPriceStepList,
} };
this.$set(this, 'form', Object.assign({}, this.form, data)) this.$set(this, "form", Object.assign({}, this.form, data));
// 产品选择器默认选择的商品 // 产品选择器默认选择的商品
/* 23-11-07要求不复制商品和线路 https://zentao.test.jdshangmen.com/bug-view-5145.html /* 23-11-07要求不复制商品和线路 https://zentao.test.jdshangmen.com/bug-view-5145.html
...@@ -277,82 +359,84 @@ export default { ...@@ -277,82 +359,84 @@ export default {
})*/ })*/
}, },
handleAddPrice(field, fieldPrefix){ handleAddPrice(field, fieldPrefix) {
if(!this.form[field]){ if (!this.form[field]) {
this.$set(this.form, field, []) this.$set(this.form, field, []);
} }
let priceUnit = DEFAULT_PRICE_UNIT let priceUnit = DEFAULT_PRICE_UNIT;
let volumeUnit = DEFAULT_VOLUME_UNIT let volumeUnit = DEFAULT_VOLUME_UNIT;
let weightUnit = DEFAULT_WEIGHT_UNIT let weightUnit = DEFAULT_WEIGHT_UNIT;
if(this.form[field].length){ if (this.form[field].length) {
const first = this.form[field][0] const first = this.form[field][0];
priceUnit = first[`${fieldPrefix}PriceUnit`] priceUnit = first[`${fieldPrefix}PriceUnit`];
volumeUnit = first[`${fieldPrefix}VolumeUnit`] volumeUnit = first[`${fieldPrefix}VolumeUnit`];
weightUnit = first.weightUnit weightUnit = first.weightUnit;
} }
console.log("添加价格的默认单位", { console.log("添加价格的默认单位", {
priceUnit, priceUnit,
volumeUnit, volumeUnit,
weightUnit weightUnit,
}) });
this.form[field].push({ this.form[field].push({
[`${fieldPrefix}PriceUnit`]: priceUnit, [`${fieldPrefix}PriceUnit`]: priceUnit,
[`${fieldPrefix}VolumeUnit`]: volumeUnit, [`${fieldPrefix}VolumeUnit`]: volumeUnit,
weightUnit: weightUnit, weightUnit: weightUnit,
specialList:[] specialList: [],
}) });
}, },
handleDeletePrice(field, index){ handleDeletePrice(field, index) {
this.form[field].splice(index, 1) this.form[field].splice(index, 1);
}, },
handleUnitChange(stepPriceList, index, data){ handleUnitChange(stepPriceList, index, data) {
console.log('handleUnitChange', ...arguments) console.log("handleUnitChange", ...arguments);
if(index > 0) return if (index > 0) return;
const isVolumeUnit = data.field.indexOf("VolumeUnit") > -1 const isVolumeUnit = data.field.indexOf("VolumeUnit") > -1;
// 如果是重量单位,且不是清关费想换的,则需要同步最小起计量单位 // 如果是重量单位,且不是清关费想换的,则需要同步最小起计量单位
if(isVolumeUnit && data.type != 'clearance'){ if (isVolumeUnit && data.type != "clearance") {
this.form.minWeightUnit = data.value this.form.minWeightUnit = data.value;
} }
stepPriceList.forEach(item => { stepPriceList.forEach((item) => {
item[data.field] = data.value item[data.field] = data.value;
// 如果是设置体积单位,则还需要同步到阶梯重量单位 // 如果是设置体积单位,则还需要同步到阶梯重量单位
if(isVolumeUnit){ if (isVolumeUnit) {
item['weightUnit'] = data.value item["weightUnit"] = data.value;
} }
if(item.packagingList?.length){ if (item.packagingList?.length) {
item.packagingList.forEach(p => { item.packagingList.forEach((p) => {
if(data.field.indexOf("PriceUnit") > -1){ if (data.field.indexOf("PriceUnit") > -1) {
p['packagingPriceUnit'] = data.value p["packagingPriceUnit"] = data.value;
} }
if(data.field.indexOf("VolumeUnit") > -1){ if (data.field.indexOf("VolumeUnit") > -1) {
p['packagingVolumeUnit'] = data.value p["packagingVolumeUnit"] = data.value;
} }
}) });
} }
if(item.specialList?.length){ if (item.specialList?.length) {
item.specialList.forEach(p => { item.specialList.forEach((p) => {
p[data.field] = data.value p[data.field] = data.value;
}) });
} }
}) });
}, },
// 获得用语提交的阶梯价副本 // 获得用语提交的阶梯价副本
getPriceList(stepList, prefix){ getPriceList(stepList, prefix) {
if(!stepList?.length) return [] if (!stepList?.length) return [];
let stepPriceList = JSON.parse(JSON.stringify(stepList)) let stepPriceList = JSON.parse(JSON.stringify(stepList));
stepPriceList.forEach((item, index) => { stepPriceList.forEach((item, index) => {
item.rankNum = index + 1 item.rankNum = index + 1;
item.packagingList = item.packagingList.filter(p => !!p.packagingTypes?.length) item.packagingList = item.packagingList.filter(
item.packagingList = item.packagingList.map( p => { (p) => !!p.packagingTypes?.length
p.packagingTypes = p.packagingTypes.join(",") );
return p item.packagingList = item.packagingList.map((p) => {
}) p.packagingTypes = p.packagingTypes.join(",");
}) return p;
});
});
// 240121应老王要求,未设置价格的不提交 // 240121应老王要求,未设置价格的不提交
return stepPriceList.filter(item => { return stepPriceList.filter((item) => {
return !!item[`${prefix}Price`] return !!item[`${prefix}Price`];
}) });
}, },
submitForm() { submitForm() {
...@@ -362,24 +446,31 @@ export default { ...@@ -362,24 +446,31 @@ export default {
} }
// 只有新增的时候做判断 // 只有新增的时候做判断
if (!this.$route.query.ids && (!this.selectedRoutes || !this.selectedRoutes.length)) { if (
this.$message.error(this.$t('请选择线路')); !this.$route.query.ids &&
(!this.selectedRoutes || !this.selectedRoutes.length)
) {
this.$message.error(this.$t("请选择线路"));
return; return;
} }
let data = Object.assign({}, this.form, { let data = Object.assign({}, this.form, {
isAllProduct: this.isAllProduct ? 1:0 isAllProduct: this.isAllProduct ? 1 : 0,
}) });
// 如果是勾選了全部篩選商品,則獲取商品ID // 如果是勾選了全部篩選商品,則獲取商品ID
if(this.isAllFilteredProduct){ if (this.isAllFilteredProduct) {
data.productIdList = await this.$refs.productSelector.getFilteredIds() data.productIdList =
await this.$refs.productSelector.getFilteredIds();
} }
if(!data.isAllProduct && (!data.productIdList || !data.productIdList.length)){ if (
return this.$message.error('请选择商品') !data.isAllProduct &&
(!data.productIdList || !data.productIdList.length)
) {
return this.$message.error("请选择商品");
} }
data.lineChannelList = this.selectedRoutes data.lineChannelList = this.selectedRoutes;
/* let isValid = true /* let isValid = true
for (let stepPrice of this.$refs.stepPrice){ for (let stepPrice of this.$refs.stepPrice){
...@@ -391,39 +482,56 @@ export default { ...@@ -391,39 +482,56 @@ export default {
if(!isValid)return */ if(!isValid)return */
// 全包价 // 全包价
if(this.form.priceType == 1) { if (this.form.priceType == 1) {
data.fullPriceStepList = this.getPriceList(this.form.fullPriceStepList, 'all') data.fullPriceStepList = this.getPriceList(
delete data.clearancePriceStepList this.form.fullPriceStepList,
delete data.freightPriceStepList "all"
}else{ );
data.clearancePriceStepList = this.getPriceList(this.form.clearancePriceStepList, 'clearance') delete data.clearancePriceStepList;
data.freightPriceStepList = this.getPriceList(this.form.freightPriceStepList, 'transport') delete data.freightPriceStepList;
delete data.fullPriceStepList } else {
data.clearancePriceStepList = this.getPriceList(
this.form.clearancePriceStepList,
"clearance"
);
data.freightPriceStepList = this.getPriceList(
this.form.freightPriceStepList,
"transport"
);
delete data.fullPriceStepList;
} }
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}个商品;确认提交修改?', { await this.$confirm(
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
this.loading = true : data.productIdList.length,
batchUpdateProductPriceAir(data).then(response => { })
);
this.loading = true;
batchUpdateProductPriceAir(data)
.then((response) => {
this.$modal.msgSuccess(this.$t("修改成功")); this.$modal.msgSuccess(this.$t("修改成功"));
this.$router.replace('/lineProject/product-price?' + (new URLSearchParams(this.$route.query)).toString()) this.$router.replace(
"/lineProject/product-price?" +
new URLSearchParams(this.$route.query).toString()
);
}) })
.finally(res => this.loading = false) .finally((res) => (this.loading = false));
}); });
} },
} },
} };
</script> </script>
<style scoped> <style scoped>
.w100{ .w100 {
width: 100px; width: 100px;
} }
.mr10{ .mr10 {
margin-right: 10px; margin-right: 10px;
} }
</style> </style>
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