You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
4.9 KiB
Vue

<template>
1 year ago
<div class="jcsbAddBox">
<el-dialog
1 year ago
class="jcsbAddDialogBox"
:title="title"
1 year ago
:visible.sync="jcsbDialogshow"
width="520px"
:close-on-click-modal="false"
>
<el-form
label-position="left"
ref="formInfo"
label-width="104px"
:rules="rules"
1 year ago
:model="formInfo"
>
<el-form-item label="主设备名称:" prop="zsbName">
<el-input v-model="formInfo.zsbName" :disabled="true"></el-input>
</el-form-item>
<el-form-item label="名称:" prop="name">
<el-input v-model="formInfo.name"></el-input>
</el-form-item>
<el-form-item label="相位:" prop="phase">
<el-input v-model="formInfo.phase"></el-input>
</el-form-item>
1 year ago
<el-form-item label="devId" prop="devId">
<el-input v-model="formInfo.devId"></el-input>
</el-form-item>
<el-form-item label="选择类型:">
<el-select v-model="formInfo.typeId" @change="changetypeId">
<el-option
v-for="item in tableOptions"
1 year ago
:key="item.id"
:label="item.mc"
:value="item.id"
>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="传感器代码:" prop="sensorCode">
<el-input v-model="formInfo.sensorCode"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="hide"> </el-button>
<el-button type="primary" @click="submitForm()"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {
1 year ago
modevAddApi,
modevUpdateApi,
modevtypeListAllApi,
} from "@/utils/api/index";
export default {
props: ["title"],
data() {
return {
1 year ago
jcsbDialogshow: false,
formInfo: {
zsbName: "",
name: "",
phase: "",
typeId: "",
devId: "",
sensorCode: "",
},
rules: {
1 year ago
name: [{ required: true, message: "请输入名称", trigger: "blur" }],
devId: [{ required: true, message: "请输入devId", trigger: "blur" }],
},
1 year ago
tableOptions: [],
zsbInfo: "",
};
},
created() {},
1 year ago
mounted() {
this.$nextTick(() => {
this.zsbInfo = JSON.parse(localStorage.getItem("zsbInfo"));
console.log(this.zsbInfo);
this.formInfo.zsbName = this.zsbInfo.mc;
});
},
watch: {},
methods: {
//判断
getdataform(val) {
console.log(val);
1 year ago
this.formInfo = JSON.parse(JSON.stringify(val));
},
submitForm() {
this.$refs.formInfo.validate((valid) => {
if (valid) {
if (this.title == "添加监测设备") {
console.log(this.formInfo);
this.$set(this.formInfo, "zsbId", this.formInfo.zsbId);
1 year ago
modevAddApi(this.formInfo)
.then((res) => {
if (res.success) {
this.$message({
duration: 1500,
showClose: true,
message: "添加成功",
type: "success",
});
this.hide();
this.$parent.getmonitoringAllList(); //刷新
}
})
.catch((err) => {});
} else {
this.$set(this.formInfo, "zsbId", this.formInfo.zsbId);
1 year ago
console.log(this.formInfo);
modevUpdateApi(this.formInfo)
.then((res) => {
if (res.success) {
this.$message({
duration: 1500,
showClose: true,
message: "修改成功",
type: "success",
});
this.hide();
this.$parent.getmonitoringAllList(); //刷新
}
})
.catch((err) => {});
}
} else {
console.log("error submit!!");
return false;
}
});
},
1 year ago
changetypeId(val) {
console.log(val);
this.formInfo.typeId = val;
},
//获取所有的设备类型管理
getTableListAll() {
modevtypeListAllApi()
.then((res) => {
console.log(res);
this.tableOptions = res.data;
console.log(this.title);
if (this.title == "添加监测设备") {
console.log(this.formInfo);
this.formInfo.typeId = this.tableOptions[0].id;
}
})
.catch((err) => {
console.log(err); //代码错误、请求失败捕获
});
},
display() {
1 year ago
this.jcsbDialogshow = true;
this.getTableListAll();
},
hide() {
1 year ago
this.jcsbDialogshow = false;
this.$refs.formInfo.resetFields(); // 重置表单字段值
},
},
};
</script>
<style lang="less">
1 year ago
.jcsbAddBox {
.jcsbAddDialogBox {
.el-select {
1 year ago
width: 376px;
}
}
}
</style>