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

编辑空运价格,还没测完

parent 23a160e8
......@@ -9,6 +9,14 @@ export function createProductPrice(data) {
})
}
export function createProductPriceAir(data) {
return request({
url: '/ecw/product-price/createAir',
method: 'post',
data: data
})
}
// 更新产品价格
export function updateProductPrice(data) {
return request({
......@@ -18,6 +26,15 @@ export function updateProductPrice(data) {
})
}
// 更新空运价格
export function updateProductPriceAir(data) {
return request({
url: '/ecw/product-price/updateAir',
method: 'put',
data: data
})
}
// 删除产品价格
export function deleteProductPrice(id) {
return request({
......
<script>
import Selector from "@/components/Selector/index.vue";
import Inputor from "@/components/Inputor/index.vue";
import Template from "@/views/cms/template/index.vue";
import {DICT_TYPE, getDictDatas} from "@/utils/dict";
export default {
name: "PriceStep",
components: {Inputor, Selector},
components: {Template, Inputor, Selector},
props:{
index: Number,
priceName: String,
......@@ -17,6 +19,8 @@ export default {
type: Array,
default: []
},
showAdd: Boolean,
readonly: Boolean,
value:{
type: Object,
default: () => {
......@@ -26,9 +30,91 @@ export default {
}
}
},
created() {
if(!this.value.packagingList){
this.addPackage()
}
this.initSpecialPrice()
},
data(){
return {
form: {}
}
},
computed:{
packagingList(){
return getDictDatas(DICT_TYPE.ECW_PACKAGING_TYPE).filter(dict => {
let enable = true
this.value.packagingList.forEach(item => {
if(item.packagingTypes?.length && item.packagingTypes.indexOf(dict.value) > -1){
enable = false
}
})
return enable
})
}
},
methods:{
getDictDatas,
// 初始化特需加价
initSpecialPrice(){
if(!this.value.specialList){
this.$set(this.value, 'specialList', [])
}
this.getDictDatas(this.DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS).forEach(item => {
if(!this.value.specialList.find(special => special.specialDictType == item.value)){
this.value.specialList.push({
[`${this.fieldPrefix}Price`]: 0, // 新建默认给0,否则默认是null
[`${this.fieldPrefix}PriceUnit`]: this.value[`${this.fieldPrefix}PriceUnit`],
[`${this.fieldPrefix}VolumeUnit`]: this.value[`${this.fieldPrefix}VolumeUnit`],
"specialDictType": item.value
})
}
})
},
// 添加包装类型运费
addPackage(){
if(!this.value.packagingList){
this.$set(this.value, 'packagingList', [])
}
this.value.packagingList.push({
packagingPrice: undefined,
packagingPriceUnit : this.value[`${this.fieldPrefix}PriceUnit`],
packagingVolumeUnit : this.value[`${this.fieldPrefix}VolumeUnit`],
})
},
// 删除包装类型运费
deletePackage(index){
this.value.packagingList.splice(index, 1)
},
// 校验
validate(){
let valid = true
const index = this.index
// 区间设置检查
if(index > 0 && !this.value.startNum){
valid = false
this.$message.error(`请设置第${index+1}阶段的起始值`)
}
if(!this.value.endNum){
valid = false
this.$message.error(`请设置第${index+1}阶段的结束值`)
}
// 价格检查
if(!this.value[`${this.fieldPrefix}Price`]){
valid = false
this.$message.error(`请设置第${index+1}阶段的${this.priceName}`)
}
// 包装价格检查
if(this.value.packagingList?.length){
this.value.packagingList.forEach((item, i) => {
if(item.packagingTypes?.length && !item.packagingPrice){
valid = false
this.$message.error(`请设置第${index+1}阶段的包装类型${i+1}${this.priceName}`)
}
})
}
return valid
}
}
}
......@@ -36,21 +122,110 @@ export default {
<template>
<div>
<el-form-item :label="$t('第{index}阶梯', {index})">
<div class="bold text-lg">{{$t('空运{type}设置', {type: priceName})}}</div>
<div style="font-size:14px; margin:10px 0">
{{$t('第{index}阶梯定价方案', {index: index+1})}}
<template v-if="showAdd">
<el-link type="primary" @click.native="$emit('add', fieldPrefix)">{{$t('添加区间')}}</el-link>
<el-divider direction="vertical"></el-divider>
<el-link type="danger" @click.native="$emit( 'delete', index)">{{$t('删除')}}</el-link>
</template>
</div>
<el-form-item :label="$t('第{index}阶梯', {index: index+1})">
<el-input-number v-model="value.startNum" :controls="false" class="w-100"></el-input-number>
-
<el-input-number v-model="value.endNum" :controls="false" class="w-100"></el-input-number>
/
<selector :disabled="index > 0" v-model="value.weightUnit" :options="unitList" :label-field="$l(null, 'title')" value-field="id" class="w-100" />
<selector
:disabled="index>0"
v-model="value.weightUnit"
:options="unitList"
:label-field="$l(null, 'title')"
@input="$emit('changeUnit', {
value: $event,
field: 'weightUnit'
})"
value-field="id"
class="w-100" />
</el-form-item>
<el-form-item :label="$t('默认') + priceName">
<el-input-number v-model="value[`${fieldPrefix}Price`]" :placeholder="$t('整数或者两位小数')" :precision="2" :controls="false" class="w-100 mr-10"/>
<selector :disabled="index > 1" v-model="value[`${fieldPrefix}PriceUnit`]" :options="currencyList" :label-field="$l(null, 'title')" value-field="id" class="w-100" />
/ <selector :disabled="index > 1" v-model="value[`${fieldPrefix}VolumeUnit`]" :options="unitList" :label-field="$l(null, 'title')" value-field="id" class="w-100" />
<selector
:disabled="index>0"
v-model="value[`${fieldPrefix}PriceUnit`]"
:options="currencyList"
:label-field="$l(null, 'title')"
@input="$emit('changeUnit', {
value: $event,
field: `${fieldPrefix}PriceUnit`
})"
value-field="id"
class="w-100" />
/
<selector
:disabled="index>0"
v-model="value[`${fieldPrefix}VolumeUnit`]"
:options="unitList"
:label-field="$l(null, 'title')"
@input="$emit('changeUnit', {
value: $event,
field: `${fieldPrefix}VolumeUnit`
})"
value-field="id"
class="w-100" />
</el-form-item>
<!--特性加价-->
<template v-for="(special, specialIndex) in value.specialList">
<el-form-item
:label="getDictDataLabel(DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS, special.specialDictType) + priceName"
:key="specialIndex + 'transport'"
>
<el-input-number v-model.number="special[`${fieldPrefix}Price`]" :controls="false" :min="0" :placeholder="$t('整数或者两位小数')" class="w-100 mr-10" />
<selector disabled v-model="special[`${fieldPrefix}PriceUnit`]" :options="currencyList" :label-field="$l(null, 'title')" value-field="id" defaultable2 class="w-100 mr-10" />
<span class="mr-10">/</span>
<selector disabled v-model="special[`${fieldPrefix}VolumeUnit`]" :options="unitList" :label-field="$l(null, 'title')" value-field="id" defaultable2 class="w-100" />
</el-form-item>
</template>
<!--包装类型价格-->
<template v-for="(item, i) in value.packagingList">
<el-form-item :label="$t('包装类型') + priceName + (i+1)">
<template #label>
<div class="el-form-item__label" style="width: 150px;">{{$t('包装类型') + priceName + (i+1)}}</div>
</template>
<el-select v-model="item.packagingTypes" multiple placeholder="请选择" style="width: 100%; max-width: 450px; margin-bottom: 5px; display: block">
<el-option
v-for="item in packagingList"
:key="item.value"
:label="$l(item, 'label')"
:value="item.value"
>
</el-option>
</el-select>
<el-input-number v-model="item.packagingPrice" :controls="false" :min="0" :placeholder="$t('整数或者两位小数')" class="w-100 mr-10" />
<selector disabled v-model="item.packagingPriceUnit" :options="currencyList" :label-field="$l(null, 'title')" value-field="id" defaultable2 class="w-100 mr-10" />
<span class="mr-10">/</span>
<selector disabled v-model="item.packagingVolumeUnit" :options="unitList" :label-field="$l(null, 'title')" value-field="id" defaultable2 class="w-100" />
<template v-if="i == value.packagingList.length -1 && !readonly">
<el-link type="primary" @click.native="addPackage" class="ml-5">{{$t('添加')}}</el-link>
<el-divider direction="vertical"></el-divider>
<el-link type="danger" @click.native="deletePackage(i)">{{$t('删除')}}</el-link>
</template>
<div v-if="!item.packagingTypes || !item.packagingTypes.length" class="tips">{{$t('未选择包装类型,将被忽略')}}</div>
</el-form-item>
</template>
</div>
</template>
<style scoped lang="scss">
.bold {
font-weight: bold;
}
.text-lg{
font-size: 1.3rem;
}
.tips{
font-size: 1rem; color: red;
}
</style>
......@@ -32,7 +32,7 @@ export default {
</script>
<template>
<dv>
<div>
<h2>{{$t('快捷设置')}}</h2>
<div class="flex items-center">
{{$t('批量加价')}}+
......@@ -51,7 +51,7 @@ export default {
<div class="mt-10">
<el-button @click="$emit('confirm', quickForm)" type="primary" :disabled="!quickForm.plus && !quickForm.minus">{{$t('确定')}}</el-button>
</div>
</dv>
</div>
</template>
<style scoped lang="scss">
......
<template>
<div class="app-container">
<el-form ref="form" :model="form" :rules="rules" label-width="150px" :disabled="readonly">
<el-form ref="form" :model="form" label-width="150px" :disabled="readonly">
<el-form-item :label="$t('商品类型')" prop="productType">
<el-select v-model="form.productType" :disabled="!!$route.query.action">
......@@ -53,12 +53,12 @@
</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item v-if="type === 'air'" :label="$t('出货渠道')">
<el-form-item :label="$t('出货渠道')">
{{channel ? $l(channel, 'name') : '/'}}
</el-form-item>
</template>
<!--有路线则不显示路线选择器-->
<routers-selector v-else v-model="selectedRoutes" :option="routerOption" :type="type" />
<routers-selector v-else v-model="selectedRoutes" :option="routerOption" type="air" />
<el-card style="margin-bottom: 10px">
<div slot="header" style="font-size:20px;">
......@@ -68,7 +68,7 @@
</span>
</div>
<el-row :gutter="20">
<el-col :span="12">
<el-col :span="form.priceType === 1 ? 12 : 24">
<el-form-item :label="$t('预付')" prop="needPay" v-if="$route.query.action == 'batchUpdate'" >
<el-radio-group v-model="form.needPay">
<el-radio :label="1">{{$t('预付')}}</el-radio>
......@@ -82,112 +82,71 @@
:label="$t('最小起计量')"
:prop="`minWeight`"
>
<inputor default2="0" v-model.number="form.minWeight" type="number" class="w-100" :rules="{validator: priceValidator, trigger: 'blur', message: '数量错误'}"/>
<el-input-number :min="0" v-model="form.minWeight" :controls="false" class="w-100"/>
/ <selector v-model="form.minWeightUnit" :options="unitList" :label-field="$l(null, 'title')" value-field="id" defaultable2 class="w-100" disabled />
</el-form-item>
<!--全包价-->
<template v-if="form.priceType==1" >
<div v-for="(item, index) in form.fullPriceStepList" :key="index">
<div class="bold text-lg">{{$t('空运全包价设置')}}</div>
<div style="font-size:14px; margin:10px 0">
{{$t('第{index}阶梯定价方案', {index: index+1})}}
<template v-if="index == form.fullPriceStepList.length - 1 && !readonly">
<el-link type="primary" @click.native="addStepPrice('fullPriceStepList')">{{$t('添加区间')}}</el-link>
<el-divider direction="vertical"></el-divider>
<el-link type="danger" @click.native="form.fullPriceStepList.splice(index, 1)">{{$t('删除')}}</el-link>
</template>
</div>
<price-step
:index="index+1"
ref="stepPrice"
:index="index"
:currency-list="currencyList"
:unit-list="unitList"
field-prefix="all"
:price-name="$t('全包价')"
:value="item"></price-step>
:show-add="index === form.fullPriceStepList.length -1 && !readonly"
:value="item"
:readonly="readonly"
@add="handleAddPrice('fullPriceStepList', $event)"
@delete="handleDeletePrice('fullPriceStepList', $event)"
@changeUnit="handleUnitChange(form.fullPriceStepList, index, ...$event)"
></price-step>
</div>
</template>
<template v-if="form.priceType!=1" >
<div v-for="(item, index) in form.freightPriceStepList" :key="index">
<div class="bold text-lg">{{$t('空运运费价格设置')}}</div>
<div style="font-size:14px; margin:10px 0">
{{$t('第{index}阶梯定价方案', {index: index+1})}}
<template v-if="index == form.freightPriceStepList.length - 1 && !readonly">
<el-link type="primary" @click.native="addStepPrice('freightPriceStepList')">{{$t('添加区间')}}</el-link>
<el-divider direction="vertical"></el-divider>
<el-link type="danger" @click.native="form.freightPriceStepList.splice(index, 1)">{{$t('删除')}}</el-link>
</template>
<el-row v-else :gutter="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>
<price-step
:index="index+1"
:currency-list="currencyList"
:unit-list="unitList"
field-prefix="transport"
:price-name="$t('运费')"
:value="item"></price-step>
</div>
</template>
<template v-if="form.priceType!=1" >
<div v-for="(item, index) in form.clearancePriceStepList" :key="index">
<div class="bold text-lg">{{$t('空运清关费价格设置')}}</div>
<div style="font-size:14px; margin:10px 0">
{{$t('第{index}阶梯定价方案', {index: index+1})}}
<template v-if="index == form.clearancePriceStepList.length - 1 && !readonly">
<el-link type="primary" @click.native="addStepPrice('clearancePriceStepList')">{{$t('添加区间')}}</el-link>
<el-divider direction="vertical"></el-divider>
<el-link type="danger" @click.native="form.clearancePriceStepList.splice(index, 1)">{{$t('删除')}}</el-link>
</template>
</el-col>
<el-col :span="12">
<quick-set v-if="!readonly" :currency-and-unit="currencyAndUnit" :unit-list="unitList" :currency-list="currencyList" @confirm="quickSet"></quick-set>
<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>
<price-step
:index="index+1"
:currency-list="currencyList"
:unit-list="unitList"
field-prefix="clearance"
:price-name="$t('清关费')"
:value="item"></price-step>
</div>
</template>
</el-col>
</el-row>
<!--特需-->
<template v-if="form.priceType==1">
<el-form-item
v-for="(special, specialIndex) in this.form.specialList"
:label="getDictDataLabel(DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS, special.specialDictType) + $t('全包价')"
:key="specialIndex + 'transport'"
:prop="`specialList.${specialIndex}`.allPrice"
:rules="{validator: priceValidator, trigger: 'blur', message: '价格错误'}"
>
<selector disabled v-model="special.allPriceUnit" :options="currencyList" :label-field="$l(null, 'title')" value-field="id" defaultable2 class="w-100 mr-10" />
<inputor default2="0" v-model.number="special.allPrice" type="number" :placeholder="$t('整数或者两位小数')" class="w-100 mr-10" />
<span class="mr-10">/</span>
<selector disabled v-model="special.allVolumeUnit" :options="unitList" :label-field="$l(null, 'title')" value-field="id" defaultable2 class="w-100" />
</el-form-item>
</template>
<template v-else v-for="(special, specialIndex) in this.form.specialList">
<el-form-item
:label="getDictDataLabel(DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS, special.specialDictType) + $t('运费')"
:key="specialIndex + 'transport'"
:prop="`specialList.${specialIndex}.transportPrice`"
:rules="{validator: priceValidator, trigger: 'blur', message: '价格错误'}"
>
<selector disabled v-model="special.transportPriceUnit" :options="currencyList" :label-field="$l(null, 'title')" value-field="id" defaultable2 class="w-100 mr-10" />
<inputor default2="0" v-model.number="special.transportPrice" type="number" :placeholder="$t('整数或者两位小数')" class="w-100 mr-10" />
<span class="mr-10">/</span>
<selector disabled v-model="special.transportVolumeUnit" :options="unitList" :label-field="$l(null, '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'"
:prop="`specialList.${specialIndex}.clearancePrice`"
:rules="{validator: priceValidator, trigger: 'blur', message: '价格错误'}"
>
<selector disabled v-model="special.clearancePriceUnit" :options="currencyList" :label-field="$l(null, 'title')" value-field="id" defaultable2 class="w-100 mr-10" />
<inputor default2="0" v-model.number="special.clearancePrice" type="number" :placeholder="$t('整数或者两位小数')" class="w-100 mr-10" />
<span class="mr-10">/</span>
<selector disabled v-model="special.clearanceVolumeUnit" :options="unitList" :label-field="$l(null, 'title')" value-field="id" defaultable2 class="w-100" />
</el-form-item>
</template>
<el-form-item :label="$t('价格有效期')">
<el-date-picker v-model="form.validateStartDate" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
-
......@@ -196,7 +155,7 @@
</el-col>
<!--编辑的时候右侧显示快捷设置,查看的时候空运显示商品清关费-->
<el-col :span="12" v-if="!readonly">
<el-col :span="12" v-if="!readonly && form.priceType == 1">
<quick-set :currency-and-unit="currencyAndUnit" :unit-list="unitList" :currency-list="currencyList" @confirm="quickSet"></quick-set>
</el-col>
......@@ -217,6 +176,9 @@
<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>
</el-form-item>
<el-form-item :label="$t('线路重量上限')" prop="inquiry">
<el-input-number v-model="form.weightLimit" :min="0" :controls="false"></el-input-number>
</el-form-item>
</el-card>
</el-form>
......@@ -241,7 +203,15 @@
</template>
<script>
import RoutersSelector from '@/components/RoutersSelector'
import { createProductPrice, updateProductPrice, batchUpdateProductPrice, getProductPrice, getProductPriceList, getPriceSnapshotList } from "@/api/ecw/productPrice";
import {
createProductPrice,
updateProductPrice,
batchUpdateProductPrice,
getProductPrice,
getProductPriceList,
getPriceSnapshotList,
updateProductPriceAir, createProductPriceAir
} from "@/api/ecw/productPrice";
import { getProductType, getProductTypeList } from '@/api/ecw/productType'
import { getCurrencyList } from '@/api/ecw/currency';
import { getUnitList } from '@/api/ecw/unit';
......@@ -258,6 +228,12 @@ import {getStatusName} from './util'
import QuickSet from "./components/QuickSet.vue"
import Logs from "@/views/ecw/productPrice/components/Logs.vue";
import PriceStep from "@/views/ecw/productPrice/components/PriceStep.vue";
// 定义默认的价格单位和体积单位
const DEFAULT_PRICE_UNIT = 1
const DEFAULT_VOLUME_UNIT = 6
const DEFAULT_WEIGHT_UNIT = 6
export default {
components: {PriceStep, Logs, QuickSet, PackagingType, RoutersSelector, ProductSelector, Selector, Inputor },
filters: {parseTime},
......@@ -273,17 +249,7 @@ export default {
needOrderInquiry: '0'
},
needPay: false, // 是否需要预付
stepPrice: false, // 是否阶梯订单
// specialProducts: [],
// priceStepList: [{},{}], // 阶梯价格
// specialList:[], // 特殊需求,默认四个
rules: {
transportPrice: [{ required: true, message: this.$t("海运费不能为空"), trigger: "blur" }],
clearancePrice: [{ required: true, message: this.$t("清关费不能为空"), trigger: "blur" }],
advanceStatus: [{ required: true, message: this.$t("是否预付不能为空"), trigger: "blur" }]
},
product: null,
/* productType: null, */
currencyList: [],
unitList: [],
productTypeList: [],
......@@ -291,11 +257,6 @@ export default {
readonly: false,
lineList: [], //路线数组
loading: false,
// showLogsDialog: false, // 显示价格日志弹层
// logs: [],
// 批量加价/减价
// quickForm:{}, // 快速加价/减价表单
// 渠道信息
channel: null
}
},
......@@ -322,32 +283,21 @@ export default {
},
// 默认运费的货币和体积单位
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
let currency = null, unit = null
if(this.form.priceType == 1 && this.form.fullPriceStepList?.length){
currency = this.form.fullPriceStepList[0].allPriceUnit
unit = this.form.fullPriceStepList[0].allVolumeUnit
}
if(this.form.priceType == 1 && this.form.freightPriceStepList?.length){
currency = this.form.freightPriceStepList[0].allPriceUnit
unit = this.form.freightPriceStepList[0].allVolumeUnit
}
return {currency, unit}
},
// 类型,默认海运sea,air表示空运
type(){
return this.$route.path.split(/[-_]/).pop()
},
},
watch: {
showLogsDialog(showLogsDialog){
if(showLogsDialog){
this.laodLogs()
}
},
checkList() { //选择路线
if (this.checkList.length > 0) {
this.form.lineChannelList = this.checkList.map(item => {
......@@ -371,60 +321,26 @@ export default {
}
},
form(val) {
if (!val) return
// 特殊需求回显
if (val.specialList) {
val.specialList.forEach(item => {
let index = this.form.specialList.findIndex(special => special.specialDictType == item.specialDictType)
if(index > -1)this.form.specialList[index] = item
})
}
},
// 价格类型切换,需要初始化对应的字段
'form.priceType'(priceType){
// 切换全包价的时候给默认货币单位,如果是回填则不需要给默认值
if(priceType == 1 && !this.form.allPrice){
this.$set(this.form, 'allPriceUnit', 1)
if(priceType == 1 && !this.form.fullPriceStepList?.length){
this.handleAddPrice('fullPriceStepList', 'all')
}
if(priceType == 0){
if(!this.form.freightPriceStepList?.length){
this.handleAddPrice('freightPriceStepList', 'transport')
}
if(!this.form.clearancePriceStepList?.length){
this.handleAddPrice('clearancePriceStepList', 'clearance')
}
}
this.syncAllUnit('watch:form.priceType')
},
'form.minWeightUnit'(minWeightUnit){
console.log('最小起计量单位', minWeightUnit)
},
'form.transportVolumeUnit'(transportVolumeUnit){
// 最小其计量
this.$set(this.form, 'minWeightUnit', transportVolumeUnit)
this.syncSpecialUnit({transportVolumeUnit})
this.form.clearanceVolumeUnit = transportVolumeUnit // 清关费体积单位同步运费体积单位
},
'form.clearanceVolumeUnit'(clearanceVolumeUnit){
this.syncSpecialUnit({clearanceVolumeUnit})
},
'form.transportPriceUnit'(transportPriceUnit){
this.syncSpecialUnit({transportPriceUnit})
},
'form.clearancePriceUnit'(clearancePriceUnit){
this.syncSpecialUnit({clearancePriceUnit})
},
'form.allPriceUnit'(allPriceUnit){
this.syncSpecialUnit({allPriceUnit})
},
'form.allVolumeUnit'(allVolumeUnit){
// 最小起计量
this.$set(this.form, 'minWeightUnit', allVolumeUnit)
this.syncSpecialUnit({allVolumeUnit})
},
'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 || !this.form.priceStepList.length)){
this.$set(this.form, 'priceStepList', [{},{}])
}
this.syncAllUnit('watch:form.stepPrice')
this.stepPrice = !!stepPrice
},
needPay(val){
this.$set(this.form, 'needPay', val ? 1 : 0)
},
......@@ -451,53 +367,22 @@ export default {
if(this.$route.query.readonly){
this.readonly = true
}
if(this.type == 'air'){
this.stepPrice = true
}
const defaultVolumeUnit = this.type === 'air' ? 6 : 7
const defaultPriceUnit = 1
this.currencyList = (await getCurrencyList())?.data || []
this.unitList = (await getUnitList())?.data || []
this.productTypeList = (await getProductTypeList())?.data || []
// action=batchUpdate 表示批量修改单个商品的价格(一条或者多条),如果没有ids显示路线选择组件,否则不显示路线组件
// action=update 表示修改单个商品的单条路线价格,需要回显
if(this.$route.query.action == 'update'){
let res = await getProductPrice(this.$route.query.id)
this.$set(this, 'form', res.data)
if(this.form.needPay){
this.needPay = true
}
if(this.form.stepPrice == 1){
this.stepPrice = true
}
if(res.data.validateStartDate){
this.form.validateStartDate = parseTime(res.data.validateStartDate)
}
if(res.data.validateEndDate){
this.form.validateEndDate = parseTime(res.data.validateEndDate)
}
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}])
}
await this.initUpdate()
}
// action=batchUpdate且ids不为空
if(this.$route.query.action == 'batchUpdate'){
delete this.form.needBook
}
// 同时修改多条线路
if (this.$route.query.ids) {
let query = {
ids: this.$route.query.ids
......@@ -515,21 +400,34 @@ export default {
this.productDisabled = false
}
// 获取类型列表
getProductTypeList().then(res => this.productTypeList = res.data)
// 没有操作标识的就是新建,给有效期默认值
if(!this.$route.query.action){
await this.initCreate()
}
if (this.$route.query.product_type) {
this.$set(this.form, 'productType', +this.$route.query.product_type)
}
if (this.$route.query.product_id) {
this.$set(this.form, 'productId', +this.$route.query.product_id)
}
// 显示渠道(修改或者从异常处理等进入携带了渠道参数)
if(this.form.shippingChannelId){
this.channel = (await getChannel(this.form.shippingChannelId))?.data || {}
}
},
methods: {
// 新建的初始化
async initCreate(){
this.form = {
priceType: 0,
// 空运则默认是阶梯价格
stepPrice: this.type == 'air' ? 1 : 0,
stepPrice: 1,
advanceStatus: 0,
needBook: 0,
specialList: [],
priceStepList: this.type === 'air' ? [{},{}] : [],
// dayLimit: 10000,
clearancePriceStepList: [],
freightPriceStepList: [],
fullPriceStepList: [],
validateEndDate: undefined,
validateStartDate: undefined,
clearancePrice: 0,
......@@ -537,7 +435,9 @@ export default {
minWeight: 0,
minWeightUnit: null,
// 是否单询,默认否
needOrderInquiry: 0
needOrderInquiry: 0,
needPay: 0,
weightLimit: undefined
}
this.form.validateStartDate = parseTime(Date.now())
......@@ -563,121 +463,101 @@ export default {
// 后面会根据这个渠道ID获取渠道信息
this.form.shippingChannelId = this.$route.query.channelId
}
}
if(!this.$route.query.action || this.$route.query.action == 'batchUpdate'){
this.$nextTick(() => {
// 默认体积单位,空运为千克,海运为立方米
console.log('指定默认单位', this.type === 'air' ? 6 : 7)
this.setDefaultVolumeUnit(this.type === 'air' ? 6 : 7)
// 默认货币单位(美元)
this.setDefaultPriceUnit(1)
// 空运默认的阶梯重量单位是千克
if(this.type === 'air'){
this.$set(this.form.priceStepList[0], 'weightUnit', 6)
}
})
}
if (this.$route.query.product_type) {
this.$set(this.form, 'productType', +this.$route.query.product_type)
}
if (this.$route.query.product_id) {
this.$set(this.form, 'productId', +this.$route.query.product_id)
}
// 显示渠道(修改或者从异常处理等进入携带了渠道参数)
if(this.form.shippingChannelId && this.type == 'air'){
getChannel(this.form.shippingChannelId).then(res => {
this.channel = res.data
})
}
},
async initUpdate(){
let res = await getProductPrice(this.$route.query.id)
this.$set(this, 'form', res.data)
getCurrencyList().then(res => this.currencyList = res.data)
getUnitList().then(res => this.unitList = res.data)
this.getDictDatas(this.DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS).forEach(item => {
if(!this.form.specialList.find(special => special.specialDictType == item.value)){
this.form.specialList.push({
"clearancePrice": !this.$route.query.action ? 0 : null, // 新建默认给0,否则默认是null
"clearancePriceUnit": null,
"clearanceVolumeUnit": null,
"specialDictType": item.value,
"transportPrice": !this.$route.query.action ? 0 : null, // 新建默认给0,否则默认是null
"transportPriceUnit": null,
"transportVolumeUnit": null,
})
if(this.form.needPay){
this.needPay = true
}
})
},
methods: {
// 同步全部单位
syncAllUnit(from){
let obj = this.form.stepPrice == 1 ? this.form.priceStepList[0] : this.form
let fields = {}
// 全包价
if(this.form.priceType == 1){
fields = {
allPriceUnit: obj['allPriceUnit'],
allVolumeUnit: obj['allVolumeUnit']
if(res.data.validateStartDate){
this.form.validateStartDate = parseTime(res.data.validateStartDate)
}
if(res.data.validateEndDate){
this.form.validateEndDate = parseTime(res.data.validateEndDate)
}
this.lineList = [res.data]
// 如果没有对应的阶梯价字段,则初始化一个
await this.$nextTick()
if(this.form.priceType === 1){
if(!this.form.fullPriceStepList?.length){
this.handleAddPrice("fullPriceStepList", "all")
}
}else{
fields = {
transportPriceUnit: obj.transportPriceUnit,
transportVolumeUnit: obj.transportVolumeUnit,
clearancePriceUnit: obj.clearancePriceUnit,
clearanceVolumeUnit: obj.transportVolumeUnit, // 清关费和运费的体积单位同步
if(!this.form.clearancePriceStepList?.length){
this.handleAddPrice("clearancePriceStepList", "clearance")
}
if(!this.form.freightPriceStepList?.length){
this.handleAddPrice("freightPriceStepList", "transport")
}
}
// 阶梯价还需要同步阶梯的重量单位
if(this.form.stepPrice == 1){
fields['weightUnit'] = obj.weightUnit
}
console.log('-> 同步特需单位', fields, {from})
this.syncSpecialUnit(fields)
},
// 同步特需的货币单位和体积单位
syncSpecialUnit(obj){
console.log('syncSpecialUnit', obj)
if(!obj) return
// 同步特需单位
this.form.specialList.forEach(item => {
Object.assign(item, obj)
})
// 如果是阶梯价则需要同步其他阶梯
if(this.form.stepPrice == 1 && this.form.priceStepList){
this.form.priceStepList.forEach((item, index) => {
this.$set(this.form.priceStepList, index, Object.assign(item, obj))
})
handleAddPrice(field, fieldPrefix){
if(!this.form[field]){
this.$set(this.form, field, [])
}
// 不是阶梯价需要 同步最小起计量
if(obj['transportVolumeUnit'] || obj['allVolumeUnit']){
this.$set(this.form, 'minWeightUnit', obj['transportVolumeUnit'] || obj['allVolumeUnit'])
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:[]
})
},
priceValidator(rule, value, callback){
if(!value || value == '') return callback()
value = parseFloat(value)
if(!value || value < 0){
return callback(new Error('价格错误'))
}
callback()
handleDeletePrice(){
},
setDefaultVolumeUnit(unit){
console.log('设置默认体积单位', unit)
this.$set(this.form, 'transportVolumeUnit', unit)
this.$set(this.form, 'clearanceVolumeUnit', unit)
this.$set(this.form, 'allVolumeUnit', unit)
handleUnitChange(stepPriceList, index, data){
console.log('handleUnitChange', ...arguments)
if(index > 0) return
// 如果是重量单位,则需要同步最小起计量单位
if(data.field === 'weightUnit'){
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
})
}
})
},
setDefaultPriceUnit(priceUnit){
console.log('设置默认价格单位', priceUnit)
this.$set(this.form, 'transportPriceUnit', priceUnit)
this.$set(this.form, 'clearancePriceUnit', priceUnit)
this.$set(this.form, 'allPriceUnit', priceUnit)
// 获得用语提交的阶梯价副本
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
},
// force 为是否强制提交,在价格过期的时候需要确认后强制提交
submitForm(force = false) {
......@@ -686,58 +566,34 @@ export default {
return;
}
// 只有修改单条路线的时候,不需要选择路线
/* if (this.$route.query.action !== 'update' && (!this.selectedRoutes || !this.selectedRoutes.length)) {
this.$message.error('请选择线路');
return;
} */
if(!this.lineList.length && (!this.selectedRoutes || !this.selectedRoutes.length)) {
this.$message.error(this.$t('请选择线路'));
return;
}
let data = Object.assign({}, this.form, {
// lineChannelList: this.selectedRoutes,
// 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)
}
// 设置了有效期,且已过期则给提示
if(this.form.validateEndDate && force !== true){
let validateEndDate = new Date(this.form.validateEndDate)
if(data.validateEndDate && force !== true){
let validateEndDate = new Date(data.validateEndDate)
if(validateEndDate.getTime() < Date.now()){
return this.$confirm('您设置的线路价格已过期,确定提交吗?', '提示', {
confirmButtonText: '确认提交',
......@@ -752,7 +608,7 @@ export default {
// 修改单条路线
if (this.$route.query.action == 'update') {
this.loading = true
return updateProductPrice(data).then(res => {
return updateProductPriceAir(data).then(res => {
this.$modal.msgSuccess(this.$t("请求成功"));
this.$tab.closePage()
}).finally(res => this.loading = false)
......@@ -804,24 +660,13 @@ export default {
data.lineChannelList = this.lineList.length ? this.lineList : this.selectedRoutes
await this.$confirm(this.$t("已选择{route}条路线,确认提交?", {route: data.lineChannelList.length}))
// 空运且不是全包价的清关费用0填充
if(this.type == 'air' && this.form.priceType == 0){
// 根据是否全包价确定字段
data.priceStepList.forEach(item => {
item.clearancePrice = item.clearancePrice || 0
})
}
this.loading = true
createProductPrice(data).then(response => {
createProductPriceAir(data).then(response => {
this.$modal.msgSuccess(this.$t("请求成功"));
this.$router.replace('/lineProject/product-price?' + (new URLSearchParams(this.$route.query)).toString())
}).finally(res => this.loading = false);
});
},
closeLogsDialog(){
this.showLogsDialog = false
},
// 快捷设置,只更新默认运费
quickSet(data){
......@@ -834,8 +679,9 @@ export default {
this.$set(item, field, Math.max(0, Decimal(item[field] || 0).plus(amount).toNumber()))
})
},
// 添加区间价,field是阶梯价字段,fieldPrefix是价格字段前缀
/*// 添加区间价,field是阶梯价字段,fieldPrefix是价格字段前缀
addStepPrice(field, fieldPrefix){
console.log('addPrice', field, fieldPrefix)
let fields = {}
if(!this.form[field]) this.$set(this.form, field, [])
const obj = this.form[field][0] || {}
......@@ -844,7 +690,7 @@ export default {
fields[fieldPrefix + 'Price'] = obj[fieldPrefix + 'Price']
this.form[field].push(fields)
},
},*/
showLogs(){
if(!this.$refs.logs){
return this.$message.error("未找到组件")
......@@ -861,10 +707,4 @@ export default {
.mr10{
margin-right: 10px;
}
.bold {
font-weight: bold;
}
.text-lg{
font-size: 1.3rem;
}
</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