emis-frontend/src/views/emis/emisQuoteExpression/quoteExpressionPanel.vue
2024-05-11 09:38:06 +08:00

437 lines
14 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div >
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
icon="el-icon-plus"
plain
size="mini"
@click="handleAdd"
v-hasPermi="['emis:emisQuoteExpression:add']"
>新增计算规则</el-button>
</el-col>
<!-- <el-col :span="1.5">
<el-button
plain
size="mini"
:disabled="single"
@click="handleCopy"
v-hasPermi="['emis:emisQuoteExpression:add']"
>复制计算规则</el-button>
</el-col> -->
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['emis:emisQuoteExpression:remove']"
>删除</el-button>
</el-col>
</el-row>
<el-table size="mini" v-loading="loading" :data="emisQuoteExpressionList" border stripe @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<!-- <el-table-column label="序号" align="center" width="60">
<template slot-scope="scope">
<span v-text="getIndex(scope.$index)"> </span>
</template>
</el-table-column> -->
<!--
<el-table-column label="xxx" align="left" prop="xxx" min-width="180">
<template slot-scope="scope">
<div class="link-type" @click="handleView(scope.row)">{{scope.row.orderSn}}</div>
</template>
</el-table-column>
-->
<!-- <el-table-column label="报价序号" align="center" prop="quoteSequence" min-width="100" /> -->
<!-- <el-table-column label="使用站点代码" align="center" prop="useSiteCode" min-width="100" />
<el-table-column label="使用站点名称" align="center" prop="useSite" min-width="100" />
<el-table-column label="起始重量" align="center" prop="startWeight" min-width="100" />
<el-table-column label="结束重量" align="center" prop="endWeight" min-width="100" /> -->
<el-table-column label="序号" align="center" prop="quoteSequence" width="60" />
<el-table-column label="范围" align="center" prop="conditionExpression" width="150">
<template slot-scope="scope">
<div class="link-type" @click="handleUpdate(scope.row)">{{scope.row.startWeight}} < w <= {{scope.row.endWeight}}</div>
</template>
</el-table-column>
<el-table-column label="公式" align="center" prop="calculateExpression" width="100" />
<el-table-column label="首重(s)" align="center" prop="initialWeight" width="100" />
<el-table-column label="续重单价(d)" align="center" prop="additionalWeight" width="100" />
<!-- <el-table-column label="条件表达式" align="center" prop="conditionExpression" min-width="100" /> -->
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
@click="handleUpdate(scope.row)"
>编辑</el-button>
<el-button
size="mini"
type="text"
@click="handleCopy(scope.row)"
>复制</el-button>
<el-button
size="mini"
type="text"
@click.native.prevent="handleDelete(scope.row,scope.$index, emisQuoteExpressionList)"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- @click="handleDelete(scope.row)" -->
<!-- 添加或修改费用计算表达式对话框 -->
<el-dialog :title="title" :visible.sync="open" width="50%" :close-on-click-modal="false" append-to-body>
<el-row :gutter="0">
<el-form ref="form" size="mini" :model="form" :rules="rules" label-width="80px">
<el-col :span="24">
<el-alert
title="填写说明"
type="info"
description="计算公式中只能包含(s,w,d数字,+,.*,/).示例:0-1公斤 首重5元,1-3 公斤 每公斤2元加上首重,计算公式: 5+(w-1)*2"
show-icon
:closable="false"
style="margin-bottom: 10px;"
>
</el-alert>
</el-col>
<el-col :span="8">
<el-form-item label="计算范围" prop="endWeight">
<div style="display: inline-flex;">
<div><el-input v-model="form.startWeight" placeholder="" disabled></el-input></div>
<div style="width: 70px;font-size: 12px;text-align: center;font-weight: bold;"> <w<= </div>
<div><el-input v-model="form.endWeight" placeholder="" ></el-input></div>
</div>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="公式" prop="calculateExpression">
<el-input v-model="form.calculateExpression" placeholder="" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="序号" prop="quoteSequence">
<el-input v-model="form.quoteSequence" placeholder="" disabled />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="首重(s)" prop="initialWeight">
<el-input v-model="form.initialWeight" placeholder="" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="续重单价(d)" prop="additionalWeight" label-width="100px">
<el-input v-model="form.additionalWeight" placeholder="" />
</el-form-item>
</el-col>
</el-form>
</el-row>
<div slot="footer" class="dialog-footer" style="text-align: center;margin-bottom: 10px;">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listEmisQuoteExpression, getEmisQuoteExpression, delEmisQuoteExpression, addEmisQuoteExpression, updateEmisQuoteExpression } from "@/api/emis/emisQuoteExpression";
export default {
name: "emisQuoteExpression",
props:{
value:{
type:Array,
},
quoteId:{
type:Number
},
isCopy:{
type:Boolean
}
},
watch: {
value(newVal) {
},
quoteId(){
this.initData();
}
},
components: { },
dicts: [
],
data() {
return {
// 遮罩层
loading: false,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
// 总条数
total: 0,
// 费用计算表达式表格数据
emisQuoteExpressionList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
currentRow:{},
// 表单参数
form: {},
// 表单校验
rules: {
quoteSequence: [
{ required: true, message: "报价序号不能为空", trigger: "blur" }
],
startWeight: [
{ required: true, message: "起始重量不能为空", trigger: "blur" }
],
endWeight: [
{ required: true, message: "结束重量不能为空", trigger: "blur" }
],
// conditionExpression: [
// { required: true, message: "条件表达式不能为空", trigger: "blur" }
// ],
calculateExpression: [
{ required: true, message: "计算表达式不能为空", trigger: "blur" }
],
}
};
},
created() {
this.initData();
},
methods: {
initData() {
if(this.quoteId!=null){
// this.emisQuoteExpressionList = this.value;
this.getList();
}else{
this.emisQuoteExpressionList=[];
}
},
getList() {
let queryParams={
quoteId:this.quoteId,
}
listEmisQuoteExpression(queryParams).then(response => {
this.emisQuoteExpressionList = response.rows;
this.total = response.total;
this.loading = false;
});
},
onChage(){
this.$emit("input", this.emisQuoteExpressionList);
this.$emit("onChange",this.emisQuoteExpressionList);
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
id: null,
quoteId: this.quoteId,
quoteSequence: null,
useSiteCode: null,
useSite: null,
startWeight: 0,
endWeight: null,
initialWeight: 0,
additionalWeight: 0,
conditionExpression: null,
calculateExpression: null,
status: null,
remark: null,
};
this.resetForm("form");
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
this.currentRow = selection[0];
},
/** 新增按钮操作 */
handleAdd(row) {
this.reset();
this.open = true;
this.title = "新增公式";
const quoteSequence=this.emisQuoteExpressionList.length+1;
this.form.quoteSequence=quoteSequence;
if(quoteSequence>1){
// 获取上一条数据
const [lastData]= this.emisQuoteExpressionList.slice(-1);
console.log(lastData);
this.form.startWeight=lastData.endWeight;
this.form.endWeight='';
this.form.initialWeight=0;
this.form.additionalWeight=0;
if(quoteSequence==2){
this.form.calculateExpression='1+(w-1)*2';
}else{
this.form.calculateExpression='w*2';
}
}
},
handleCopy(row){
this.reset();
this.open = true;
this.title = "复制公式";
console.log(row)
const quoteSequence=this.emisQuoteExpressionList.length+1;
if(quoteSequence>1){
// 获取上一条数据
let newData =Object.assign({}, row);
console.log(newData)
this.form=newData;
this.form.quoteSequence=quoteSequence;
// this.form.startWeight=newData.endWeight;
// this.form.endWeight='';
// this.form.initialWeight=0;
// this.form.additionalWeight=0;
// this.form.calculateExpression=newData.calculateExpression;
}
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
if(this.quoteId != null && !this.isCopy){
this.handleUpdateByQuoteId(row);
}else{
this.currentRow = row;
this.form = row;
}
this.open = true;
this.title = "修改公式";
},
handleUpdateByQuoteId(row){
this.loading = true;
getEmisQuoteExpression(row.id).then(response => {
this.form = response.data;
this.loading = false;
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
// 如果是已经存在的报价,直接更新
if(this.quoteId != null && !this.isCopy){
this.submitFormByQuoteId()
}else{
this.submitFormByNew();
}
this.form={};
this.open = false;
}
});
},
submitFormByQuoteId(){
if (this.form.id != null) {
updateEmisQuoteExpression(this.form).then(response => {
// this.$modal.msgSuccess("修改成功");
// this.$emit("on-changed");
this.getList();
});
} else {
addEmisQuoteExpression(this.form).then(response => {
// this.$modal.msgSuccess("添加成功");
// this.$emit("on-changed");
this.getList();
});
}
},
submitFormByNew(){
// 新增的需要带回数据
if (this.form.id == null) {
let newItem = Object.assign({}, this.form);
newItem.id=-1;
// console.log("000=>"+JSON.stringify(newItem));
this.emisQuoteExpressionList.push(newItem);
}
this.onChage();
},
/** 删除按钮操作 */
handleDelete(row,index,list) {
if(this.quoteId != null && !this.isCopy){
this.handleDeleteQuoteId(row);
}else{
this.handleDeleteByNew(row,index,list);
}
},
// 从数据库中删除
handleDeleteQuoteId(row) {
const ids = row.id || this.ids;
this.$modal.confirm('是否确认删除').then(function() {
return delEmisQuoteExpression(ids);
}).then(() => {
this.getList();
// this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
handleDeleteByNew(row,index,list){
list.splice(index, 1);
// @click.native.prevent="deleteItem(scope.$index, list)"
// let arr = []
// const quoteSequence = row.id || this.ids[0]
// this.emisQuoteExpressionList.map(item=>{
// if (item.quoteSequence == quoteSequence) {
// this.form = item;
// }
// });
}
}
};
</script>
<style scoped>
.el-divider{
margin-top: 0px;
background: 0 0;
border-top: 1px solid #E6EBF5;
}
.el-divider__text {
color: #0955ee;
cursor: pointer;
}
.el-alert__title {
color: black!important;;
}
.el-alert__description {
color: black!important;;
}
</style>