<template>
|
<a-form style="margin-top: 8px">
|
<a-modal
|
title="编辑-因子信息"
|
destroyOnClose
|
:visible="visible"
|
@cancel="handleCancel"
|
@ok="handleOk"
|
okText="保存"
|
>
|
<a-form style="margin-top: 8px" :form="form">
|
<a-form-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="名称">
|
<a-input
|
v-decorator="['sensorName', {initialValue:iSensorName,rules: [{ required: true,message:'请输入名称'}]}]"
|
placeholder="请输入名称"
|
/>
|
</a-form-item>
|
<a-form-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="code">
|
<!-- v-decorator="['initialUnit', { rules: [{ required: true,message:'请选择初始单位!' }] }]" -->
|
<a-input
|
v-decorator="['sensorCode', {initialValue:iSensorCode,rules: [{ required: true,message:'请输入code'}]}]"
|
placeholder="请输入code"
|
/>
|
</a-form-item>
|
|
<a-form-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="描述">
|
<a-input v-decorator="['sensorDesc',{initialValue:iSensorDesc} ]" placeholder="请输入描述" />
|
</a-form-item>
|
</a-form>
|
</a-modal>
|
</a-form>
|
</template>
|
|
<script lang="ts">
|
import {
|
Component,
|
Prop,
|
Vue,
|
Emit,
|
Model,
|
Watch
|
} from "vue-property-decorator";
|
import { State, Mutation, namespace } from "vuex-class";
|
|
import axios from "axios";
|
|
@Component({
|
components: {}
|
})
|
export default class UpdateDevicesVersion extends Vue {
|
private iSensorName: any = null;
|
private iSensorCode: any = null;
|
private iSensorDesc: any = null;
|
private id: any = null;
|
private form: any = {};
|
|
@Prop({
|
type: Boolean,
|
default: false
|
})
|
private visible!: boolean;
|
|
@Prop({
|
type: Object,
|
default() {
|
return {};
|
}
|
})
|
private record!: any;
|
|
private handleCancel(): void {
|
this.updateVisible(false);
|
}
|
|
private created() {
|
this.form = this.$form.createForm(this, { name: "UpdateSensorBasic" });
|
}
|
// 保存 更新数据库
|
private handleOk(): void {
|
this.form.validateFields((err: any, values: any) => {
|
if (err) {
|
return;
|
}
|
axios
|
.post(
|
"http://192.168.0.25:8082/sensor/updateSensor",
|
{
|
id: this.id,
|
name:values.sensorName == this.record.name ? null : values.sensorName,
|
code: values.sensorCode == this.record.code ? null : values.sensorCode,
|
desc: values.sensorDesc
|
},
|
{
|
headers: {
|
token: this.$ss.get("token")
|
}
|
}
|
)
|
.then(res => {
|
if (res.data.code != 0) {
|
this.$message.error(res.data.message);
|
} else {
|
//保存成功,组件刷新数据
|
this.$emit("updateData");
|
this.updateVisible(false);
|
}
|
})
|
.catch(err => {
|
console.log(err);
|
});
|
});
|
}
|
|
private updateVisible(visible: boolean): void {
|
this.$emit("update:visible", visible);
|
}
|
|
//监听编辑回调值
|
@Watch("record", {
|
immediate: true, //监听开始后是否立即调用该回调函数;
|
deep: true //深度监听
|
})
|
//监听编辑逻辑赋值
|
private recordChange(value: any, oldValue: any): void {
|
this.iSensorName = this.record.name;
|
this.iSensorCode = this.record.code;
|
if(this.record.desc){
|
this.iSensorDesc = this.record.desc;
|
}else{
|
this.iSensorDesc=null;
|
}
|
|
|
this.id = this.record.id;
|
|
}
|
}
|
</script>
|