<template>
|
<div>
|
<a-card :bordered="false" style="margin-top:24px">
|
<div class="tableList">
|
<div class="tableListForm">
|
<a-form layout="horizontal">
|
<a-row :gutter="{ md: 8, lg: 24, xl: 48 }">
|
<a-button
|
icon="plus"
|
type="primary"
|
@click="() => this.handleModalVisible(true)"
|
style="margin-left: 25px;margin-bottom: 30px"
|
>新建</a-button>
|
|
|
</a-row>
|
</a-form>
|
</div>
|
|
<av-standard-table
|
:dataSource="dataSource"
|
:columns="columns"
|
:loading="tableLoading"
|
:paginationProps="pagination"
|
@tableChange="handlerTableChange"
|
></av-standard-table>
|
</div>
|
</a-card>
|
|
<a-modal
|
title="添加-单位转换"
|
destroyOnClose
|
:visible="visibleCreateModal"
|
@ok="handleCreateModalOk"
|
@cancel="handleCreateModalCancel"
|
okText="保存"
|
>
|
<a-form style="margin-top: 8px" :form="form">
|
<a-form-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="初始单位">
|
<a-select
|
placeholder="请选择初始单位"
|
v-decorator="['initialUnit', { rules: [{ required: true,message:'请选择初始单位!' }] }]"
|
>
|
<a-select-option v-for="(item,index) in unitHttp" :key="index">{{item}}</a-select-option>
|
</a-select>
|
</a-form-item>
|
|
<a-form-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="计算规则">
|
<span>
|
<a-select
|
v-decorator="['initialMath', {initialValue:'*', rules: [{ required: true }] }]"
|
style="width:60px"
|
>
|
<a-select-option value="+">加</a-select-option>
|
<a-select-option value="-">减</a-select-option>
|
<a-select-option value="*">乘</a-select-option>
|
<a-select-option value="/">除</a-select-option>
|
</a-select>
|
|
<a-input
|
v-decorator="['roleValue', {initialValue:1000 ,rules: [{ required: true}] },]"
|
placeholder="请输入数字"
|
style="width:100px;margin-left:10px;margin-right:10px"
|
></a-input>
|
<a-button @click="AddInputClick">+</a-button>
|
</span>
|
<span>
|
<a-input
|
v-decorator="['createFormula', { rules: [{ required: true }] }]"
|
placeholder="通过上面选择框添加规则"
|
style="width:200px;margin-right:10px"
|
disabled
|
></a-input>
|
<a-button @click="CancelInputClick">×</a-button>
|
</span>
|
</a-form-item>
|
|
<a-form-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="转换单位">
|
<a-select
|
placeholder="请选择转换单位"
|
v-decorator="['changeUnit', { rules: [{ required: true,message:'请选择转换单位!'}] }]"
|
>
|
<a-select-option v-for="(item,index) in unitHttp" :key="index">{{item}}</a-select-option>
|
</a-select>
|
</a-form-item>
|
|
<a-form-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="专用因子">
|
<a-select
|
placeholder="请选择专用因子"
|
v-decorator="['sensorKey', { rules: [{ required: false,message:'请选择转换单位!'}] }]"
|
allow-clear
|
>
|
<a-select-option v-for="(item,key,index) in specificSensorKey" :key="key">{{item}}</a-select-option>
|
</a-select>
|
</a-form-item>
|
</a-form>
|
</a-modal>
|
<!-- @ok="handleUpdateOk" -->
|
<update-task-form
|
:visible.sync="updateTaskFormVisible"
|
:record="updateRecord"
|
@updateData="loadRuleData(1)"
|
></update-task-form>
|
</div>
|
</template>
|
|
<script lang="tsx">
|
import { Component, Prop, Vue, Model, Watch } from "vue-property-decorator";
|
|
import { get, post } from "@/util/request";
|
|
import UpdateTaskForm from "./components/UpdateUnitRule.vue";
|
|
@Component({
|
components: {
|
UpdateTaskForm
|
}
|
})
|
export default class sensorChangeUnit extends Vue {
|
private pagination: any = {
|
total: 0,
|
current: 1,
|
pageSize: 5,
|
showSizeChanger: false,
|
showQuickJumper: false
|
};
|
|
private tableLoading: boolean = false;
|
|
private dataSource: any[] = [];
|
|
private defaultKey: any = null;
|
|
private visibleCreateModal: boolean = false;
|
|
private updateTaskFormVisible: boolean = false;
|
|
private updateRecord: any = {};
|
|
private unitHttp: any = {};
|
|
private form: any = {};
|
private sensorAll:any=[];
|
private specificSensorKey:any=[]
|
|
private columns: any[] = [
|
{
|
title: "初始单位",
|
dataIndex: "originalUnitName"
|
},
|
{
|
title: "公式",
|
dataIndex: "formula"
|
},
|
{
|
title: "转换单位",
|
dataIndex: "targetUnitName"
|
},
|
{
|
title: "专用因子",
|
dataIndex: "sensorName"
|
},
|
{
|
title: "操作",
|
customRender: this.opRender
|
}
|
];
|
|
// 存放字典表因子下拉数据
|
private sensors: any = []
|
//初始化,加载table
|
private created() {
|
this.form = this.$form.createForm(this, { name: "sensorChangeUnit" });
|
//初始加载字典表中默认配置专用因子
|
get("dict/data/query?type=specificSensorKey", {}).then(res => {
|
this.specificSensorKey = res.data.data;
|
this.loadRuleData(1);
|
})
|
.catch(err => {
|
console.log(err);
|
});
|
}
|
|
private selectAllSensor(dataSourceMiddle:any){
|
if(this.sensorAll){
|
get("sensor/getAllSensorWithoutPage", {})
|
.then(res => {
|
if (res.data.code != 0) {
|
this.$message.error(res.data.message);
|
} else {
|
this.sensorAll=res.data.data.sensors
|
this.computeSensorName(dataSourceMiddle);
|
}
|
})
|
.catch(err => {
|
console.log(err);
|
});
|
}
|
|
}
|
//添加公式进入input
|
private AddInputClick() {
|
this.form.validateFields((err: any, values: any) => {
|
//把值存到input框
|
this.form.setFieldsValue({
|
createFormula: values.createFormula
|
? "(" +
|
values.createFormula +
|
")" +
|
values.initialMath +
|
values.roleValue
|
: "初值" + values.initialMath + values.roleValue
|
});
|
});
|
}
|
|
//清除input框公式
|
private CancelInputClick() {
|
this.form.validateFields((err: any, values: any) => {
|
//把值存到input框
|
this.form.setFieldsValue({
|
createFormula: null
|
});
|
});
|
}
|
//新建 ,调取初始单位,转换单位
|
private handleModalVisible(isVisible: boolean): void {
|
this.defaultKey = 1000;
|
this.visibleCreateModal = isVisible;
|
get("dict/data/query?type=unit", {
|
headers: { token: this.$ss.get("token") }
|
})
|
.then(res => {
|
this.unitHttp = res.data.data;
|
})
|
.catch(err => {
|
console.log(err);
|
});
|
}
|
|
private handleUpdateModalVisible(visible: boolean, record: any): void {
|
this.updateTaskFormVisible = true;
|
this.updateRecord = record;
|
}
|
|
//新建保存
|
private handleCreateModalOk() {
|
this.form.validateFields((err: any, fieldsValue: any) => {
|
|
if (err) {
|
return;
|
}
|
//初始单位和转换单位相同
|
if (fieldsValue.initialUnit == fieldsValue.changeUnit) {
|
this.$message.error("单位相同");
|
return;
|
}
|
//修改公式 用占位符替代
|
let fm = fieldsValue.createFormula.replace("初值", "{0}");
|
post("unitConversion/insert",
|
{
|
originalUnitKey: fieldsValue.initialUnit,
|
targetUnitKey: fieldsValue.changeUnit,
|
formula: fm,
|
sensorCode:fieldsValue.sensorKey?fieldsValue.sensorKey:null
|
|
}
|
)
|
.then((res: any) => {
|
if (res.data.code !== 0) {
|
this.$message.error(res.data.message, 2);
|
return;
|
}else {
|
this.visibleCreateModal = false;
|
this.$message.success(res.data.message, 2);
|
this.loadRuleData(1);
|
}
|
})
|
.catch(err => {
|
console.log(err);
|
});
|
});
|
}
|
|
//切换页码触发
|
private handlerTableChange(pagination: any, filter: any, sorter: any): void {
|
this.loadRuleData(pagination.current);
|
}
|
private handleCreateModalCancel(): any {
|
this.visibleCreateModal = false;
|
}
|
|
private loadRuleData(pageCurrent: any) {
|
this.tableLoading = true;
|
get("unitConversion/query", {
|
page: pageCurrent,
|
size: 5,
|
orderType: 1,
|
order: "updateTime"
|
})
|
.then(res => {
|
this.pagination.total = res.data.data.total;
|
this.pagination.current = res.data.data.current;
|
this.pagination.pageSize = res.data.data.size;
|
if (res.data.data.unitConversions) {
|
for (let i = 0; i < res.data.data.unitConversions.length; i++) {
|
//修改公式占位符
|
res.data.data.unitConversions[
|
i
|
].formula = res.data.data.unitConversions[i].formula.replace(
|
"{0}",
|
"初值"
|
);
|
}
|
let dataSourceMiddle = res.data.data.unitConversions === undefined ? [] : res.data.data.unitConversions;
|
this.selectAllSensor(dataSourceMiddle);
|
this.tableLoading = false;
|
} else {
|
this.dataSource = []
|
this.tableLoading = false;
|
}
|
})
|
.catch(err => {
|
console.log(err);
|
});
|
}
|
|
//把sensorCode转成sensorName
|
private computeSensorName(dataSourceMiddle: any) {
|
if(this.sensorAll){
|
for(let i=0;i<dataSourceMiddle.length;i++){
|
if(dataSourceMiddle[i].sensorCode){
|
for(let j=0;j<this.sensorAll.length;j++){
|
if(dataSourceMiddle[i].sensorCode==this.sensorAll[j].code){
|
dataSourceMiddle[i].sensorName=this.sensorAll[j].name
|
}
|
}
|
}
|
}
|
this.dataSource=dataSourceMiddle
|
}
|
|
}
|
|
private deleteManageRole(record: any) {
|
post("unitConversion/delete",
|
{
|
id: record.id
|
}
|
)
|
.then(res => {
|
if (res.data.code === 0) {
|
this.$message.success(res.data.message)
|
if(res.data.data === null)
|
this.loadRuleData(1);
|
}else {
|
this.$message.warning(res.data.message)
|
}
|
})
|
.catch(function(error) {
|
console.log("删除失败");
|
});
|
}
|
|
private opRender(text: string, record: any, index: number) {
|
return (
|
<div>
|
<a onClick={() => this.handleUpdateModalVisible(true, record)}>
|
{" "}
|
编辑{" "}
|
</a>
|
<a-divider type="vertical" />
|
<a-popconfirm
|
title="确认删除吗?"
|
ok-text="确定"
|
cancel-text="取消"
|
onConfirm={() => this.deleteManageRole(record)}
|
>
|
<a href="#">删除</a>
|
</a-popconfirm>
|
</div>
|
);
|
}
|
}
|
</script>
|
|
<style lang="less">
|
.tableList {
|
.tableListOperator {
|
margin-bottom: 16px;
|
|
button {
|
margin-right: 8px;
|
}
|
}
|
}
|
</style>
|