Commit aa924e3b authored by 1483922988@qq.com's avatar 1483922988@qq.com

海运空运加价可以为负数,任务578

parent b4443768
......@@ -2,80 +2,89 @@
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";
import { DICT_TYPE, getDictDatas } from "@/utils/dict";
export default {
name: "SeaPrice",
components: {Inputor, Selector},
props:{
components: { Inputor, Selector },
props: {
// 字段前缀
fieldPrefix: String,
// 价格名称
priceName: String,
// 包装类型字段
packagingField: String,
unitList:{
unitList: {
type: Array,
default: []
default: [],
},
currencyList:{
currencyList: {
type: Array,
default: []
default: [],
},
readonly: Boolean,
value:{
value: {
type: Object,
default: () => {
return {}
}
}
return {};
},
computed:{
packagingList(){
const dicts = JSON.parse(JSON.stringify(getDictDatas(DICT_TYPE.ECW_PACKAGING_TYPE)))
return dicts.map(dict => {
dict.enable = true
this.value[this.packagingField]?.forEach(item => {
if(item.packagingTypes?.length && item.packagingTypes.indexOf(dict.value) > -1){
dict.enable = false
}
})
return dict
})
},
},
computed: {
packagingList() {
const dicts = JSON.parse(
JSON.stringify(getDictDatas(DICT_TYPE.ECW_PACKAGING_TYPE))
);
return dicts.map((dict) => {
dict.enable = true;
this.value[this.packagingField]?.forEach((item) => {
if (
item.packagingTypes?.length &&
item.packagingTypes.indexOf(dict.value) > -1
) {
dict.enable = false;
}
});
return dict;
});
},
},
created() {
this.initSpecialPrice()
this.initPackingPrice()
this.initSpecialPrice();
this.initPackingPrice();
},
data(){
return {
}
data() {
return {};
},
methods:{
methods: {
getDictDatas,
// 包装类型初始化
initPackingPrice(){
initPackingPrice() {
// 已有包装类型则处理字段,没有则初始化一个
if(this.value[this.packagingField]?.length){
this.value[this.packagingField].forEach(item => {
if(!item.packagingTypes){
this.$set(item, 'packagingTypes', [])
}else if(typeof item.packagingTypes == 'string'){
item.packagingTypes = item.packagingTypes.split(',')
if (this.value[this.packagingField]?.length) {
this.value[this.packagingField].forEach((item) => {
if (!item.packagingTypes) {
this.$set(item, "packagingTypes", []);
} else if (typeof item.packagingTypes == "string") {
item.packagingTypes = item.packagingTypes.split(",");
}
})
return
});
return;
}
this.addPackage()
this.addPackage();
},
// 初始化特需加价
initSpecialPrice(){
if(!this.value.specialList){
this.$set(this.value, 'specialList', [])
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.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({
allPrice: undefined, // 新建默认给0,否则默认是null
allPriceUnit: this.value[`allPriceUnit`],
......@@ -86,111 +95,174 @@ export default {
clearancePrice: undefined,
clearancePriceUnit: this.value[`clearancePriceUnit`],
clearanceVolumeUnit: this.value[`clearanceVolumeUnit`],
specialDictType: item.value
})
specialDictType: item.value,
});
}
})
});
},
// 添加包装类型运费
addPackage(){
if(!this.value[this.packagingField]){
this.$set(this.value, this.packagingField, [])
addPackage() {
if (!this.value[this.packagingField]) {
this.$set(this.value, this.packagingField, []);
}
this.value[this.packagingField]?.push({
packagingPrice: undefined,
packagingPriceUnit : this.value[`${this.fieldPrefix}PriceUnit`],
packagingVolumeUnit : this.value[`${this.fieldPrefix}VolumeUnit`],
})
packagingPriceUnit: this.value[`${this.fieldPrefix}PriceUnit`],
packagingVolumeUnit: this.value[`${this.fieldPrefix}VolumeUnit`],
});
},
// 删除包装类型运费
deletePackage(index){
this.value[this.packagingField]?.splice(index, 1)
deletePackage(index) {
this.value[this.packagingField]?.splice(index, 1);
},
// 校验
validate(){
let valid = true
validate() {
let valid = true;
// 价格检查
if(!this.validatePrice(this.value[`${this.fieldPrefix}Price`])){
valid = false
this.$message.error(this.$t("请设置{name}", {name: this.priceName}))
if (!this.validatePrice(this.value[`${this.fieldPrefix}Price`])) {
valid = false;
this.$message.error(this.$t("请设置{name}", { name: this.priceName }));
}
// 检查包装费
if(this.value[this.packagingField]?.length){
if (this.value[this.packagingField]?.length) {
this.value[this.packagingField]?.forEach((item, index) => {
if(!item.packagingTypes?.length) return
if(!this.validatePrice(item.packagingPrice)){
valid = false
this.$message.error(this.$t("请设置{name}的包装费{index}", {name: this.priceName, index: index+1}))
}
if (!item.packagingTypes?.length) return;
if (!this.validatePrice(item.packagingPrice)) {
valid = false;
this.$message.error(
this.$t("请设置{name}的包装费{index}", {
name: this.priceName,
index: index + 1,
})
);
}
});
}
return valid
return valid;
},
// 校验价格是否为空,可以是0
validatePrice(value){
if(value === undefined || value === null || value === ''){
return false
validatePrice(value) {
if (value === undefined || value === null || value === "") {
return false;
}
return true
return true;
},
}
}
},
};
</script>
<template>
<div>
<div class="page-title">{{$t('{name}价格设置', {name: this.priceName})}}</div>
<el-form-item :label="$t('默认{name}', {name: this.priceName})">
<el-input-number v-model="value[`${fieldPrefix}Price`]" :placeholder="$t('整数或者两位小数')" :controls="false":disabled="readonly" class="w-100 mr-10"/>
<div class="page-title">
{{ $t("{name}价格设置", { name: this.priceName }) }}
</div>
<el-form-item :label="$t('默认{name}', { name: this.priceName })">
<el-input-number
v-model="value[`${fieldPrefix}Price`]"
:placeholder="$t('整数或者两位小数')"
:controls="false"
:disabled="readonly"
class="w-100 mr-10"
/>
<selector
:disabled="readonly"
v-model="value[`${fieldPrefix}PriceUnit`]"
:options="currencyList"
:label-field="$l(null, 'title')"
@input="$emit('changeUnit', {
@input="
$emit('changeUnit', {
value: $event,
field: `${fieldPrefix}PriceUnit`
})"
field: `${fieldPrefix}PriceUnit`,
})
"
value-field="id"
class="w-100" />
class="w-100"
/>
/
<selector
:disabled="readonly"
v-model="value[`${fieldPrefix}VolumeUnit`]"
:options="unitList"
:label-field="$l(null, 'title')"
@input="$emit('changeUnit', {
@input="
$emit('changeUnit', {
value: $event,
field: `${fieldPrefix}VolumeUnit`
})"
field: `${fieldPrefix}VolumeUnit`,
})
"
value-field="id"
class="w-100" />
class="w-100"
/>
</el-form-item>
<!--特性加价-->
<template v-for="(special, specialIndex) in value.specialList">
<div :key="specialIndex + 'transport'">
<el-form-item
:label="getDictDataLabel(DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS, special.specialDictType) + priceName + $t('加价')"
:label="
getDictDataLabel(
DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS,
special.specialDictType
) +
priceName +
$t('加价')
"
>
<el-input-number v-model.number="special[`${fieldPrefix}Price`]" :controls="false" :min="0" :disabled="readonly" :placeholder="$t('整数或者两位小数')" class="w-100 mr-10" />
<selector disabled v-model="special[`${fieldPrefix}PriceUnit`]" :options="currencyList" :label-field="$l(null, 'title')" value-field="id" class="w-100 mr-10" />
<el-input-number
v-model.number="special[`${fieldPrefix}Price`]"
:controls="false"
:disabled="readonly"
:placeholder="$t('整数或者两位小数')"
class="w-100 mr-10"
/>
<selector
disabled
v-model="special[`${fieldPrefix}PriceUnit`]"
:options="currencyList"
:label-field="$l(null, 'title')"
value-field="id"
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" class="w-100" />
<selector
disabled
v-model="special[`${fieldPrefix}VolumeUnit`]"
:options="unitList"
:label-field="$l(null, 'title')"
value-field="id"
class="w-100"
/>
</el-form-item>
</div>
</template>
<!--包装类型价格-->
<template v-for="(item, i) in value[packagingField]">
<el-form-item :label="$t('包装类型') + priceName + (i+1)" :key="i">
<el-form-item :label="$t('包装类型') + priceName + (i + 1)" :key="i">
<template #label>
<div class="el-form-item__label" style="width: 150px;">{{$t('包装类型{name}加价', {name: priceName}) + (i+1)}}</div>
<div v-if="!item.packagingTypes || !item.packagingTypes.length" class="tips">{{$t('未选择包装类型将被忽略')}}</div>
<div class="el-form-item__label" style="width: 150px">
{{ $t("包装类型{name}加价", { name: priceName }) + (i + 1) }}
</div>
<div
v-if="!item.packagingTypes || !item.packagingTypes.length"
class="tips"
>
{{ $t("未选择包装类型将被忽略") }}
</div>
</template>
<el-select v-model="item.packagingTypes" multiple placeholder="请选择" style="width: 100%; max-width: 450px; margin-bottom: 5px; display: block">
<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"
......@@ -200,14 +272,40 @@ export default {
>
</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" />
<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[packagingField].length -1 && !readonly">
<el-link type="primary" @click.native="addPackage" class="ml-5">{{$t('添加')}}</el-link>
<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[packagingField].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>
<el-link type="danger" @click.native="deletePackage(i)">{{
$t("删除")
}}</el-link>
</template>
</el-form-item>
</template>
......@@ -218,10 +316,11 @@ export default {
.bold {
font-weight: bold;
}
.text-lg{
.text-lg {
font-size: 1.3rem;
}
.tips{
font-size: 1rem; color: red;
.tips {
font-size: 1rem;
color: red;
}
</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