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.

141 lines
3.6 KiB
Vue

<template>
<div class="qyjgAddBox">
<el-dialog
class="qyjgAddDialogBox"
:title="title"
:visible.sync="qyjgDialogshow"
width="520px"
>
<el-form
label-position="left"
ref="formInfo"
label-width="104px"
:rules="rules"
:model="formInfo"
>
<el-form-item label="名称:" prop="mc">
<el-input v-model="formInfo.mc"></el-input>
</el-form-item>
<el-form-item label="所属电站:">
<el-select v-model="formInfo.bdzid">
<el-option
v-for="item in bdzOptions"
:key="item.id"
:label="item.mc"
:value="item.id"
></el-option>
</el-select>
</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 { areaAddApi, areaUpdateApi, bdzListAllApi } from "@/utils/api/index";
export default {
props: ["title"],
data() {
return {
qyjgDialogshow: false,
formInfo: {
bdzid: "",
mc: "",
},
rules: {
mc: [{ required: true, message: "请输入名称", trigger: "blur" }],
},
bdzOptions: [],
};
},
created() {},
mounted() {},
watch: {},
methods: {
//判断
getdataform(val) {
console.log(val);
this.formInfo = JSON.parse(JSON.stringify(val));
},
submitForm() {
this.$refs.formInfo.validate((valid) => {
if (valid) {
if (this.title == "添加区域") {
console.log(this.formInfo);
areaAddApi(this.formInfo)
.then((res) => {
if (res.success) {
this.$message({
duration: 1500,
showClose: true,
message: "添加成功",
type: "success",
});
this.hide();
this.$parent.getAreaAllList(); //刷新
}
})
.catch((err) => {});
} else {
areaUpdateApi(this.formInfo)
.then((res) => {
if (res.success) {
this.$message({
duration: 1500,
showClose: true,
message: "修改成功",
type: "success",
});
this.hide();
this.$parent.getAreaAllList(); //刷新
}
})
.catch((err) => {});
}
} else {
console.log("error submit!!");
return false;
}
});
},
//获取所有电站列表
getbdzListAll() {
bdzListAllApi()
.then((res) => {
console.log(res);
this.bdzOptions = res.data;
console.log(this.title);
if (this.title == "添加区域") {
console.log(this.formInfo);
this.formInfo.bdzid = this.bdzOptions[0].id;
this.formInfo.mc = "";
}
})
.catch((err) => {
console.log(err); //代码错误、请求失败捕获
});
},
display() {
this.qyjgDialogshow = true;
this.getbdzListAll();
},
hide() {
this.qyjgDialogshow = false;
this.$refs.formInfo.resetFields(); // 重置表单字段值
},
},
};
</script>
<style lang="less">
.qyjgAddBox {
.qyjgAddDialogBox {
.el-select {
width: 376px;
}
}
}
</style>