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.

171 lines
4.5 KiB
Vue

2 years ago
<template>
<el-dialog
2 years ago
class="addtowerDialog"
2 years ago
:title="title"
:visible.sync="isShow"
:close-on-click-modal="false"
width="470px"
@close="handleClose"
>
<el-form
label-position="left"
ref="formInfo"
label-width="100px"
:rules="rules"
:model="formdata"
>
2 years ago
<el-form-item label="线路名称:" prop="lineId">
2 years ago
<el-select v-model="formdata.lineId" placeholder="请选择">
2 years ago
<el-option
v-for="item in lineOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
2 years ago
</el-select>
</el-form-item>
2 years ago
<el-form-item label="杆塔名称:" prop="name">
<el-input v-model="formdata.name" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="杆塔地址:" prop="address">
<el-input v-model="formdata.address" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="排序号:" prop="order">
<el-input-number
controls-position="right"
v-model="formdata.order"
:min="0"
></el-input-number>
</el-form-item>
2 years ago
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="isShow = false"> </el-button>
<el-button type="primary" @click="submitForm()"> </el-button>
</div>
</el-dialog>
</template>
<script>
import { getLineListApi, addTowerApi, updateTowerApi } from "@/utils/api/index";
export default {
props: {
title: String,
},
data() {
return {
isShow: false,
lineOptions: [],
formdata: {},
rules: {
name: [{ required: true, message: "请输入杆塔名称", trigger: "blur" }],
2 years ago
lineId: [
{ required: true, message: "请选择线路编号", trigger: "blur" },
],
order: [{ required: true, message: "请输入排序号", trigger: "blur" }],
2 years ago
},
};
},
mounted() {
2 years ago
this.getLineListdata();
2 years ago
},
methods: {
2 years ago
getLineListdata() {
getLineListApi({ pageindex: 1, pagesize: 100 })
.then((res) => {
this.lineOptions = res.data.list;
})
.catch((err) => {});
2 years ago
},
//判断
getdataform(val) {
if (val == null) {
return (this.formdata = {
order: 0,
});
2 years ago
}
//this.formdata = val;
this.formdata = JSON.parse(JSON.stringify(val));
2 years ago
},
// 保存确定操作
submitForm() {
this.$refs.formInfo.validate((valid) => {
if (valid) {
if (this.title == "新增") {
let formArr = [];
formArr.push(this.formdata);
console.log(this.formdata);
2 years ago
addTowerApi({ list: formArr })
.then((res) => {
this.isShow = false;
2 years ago
this.$message({
duration: 1500,
2 years ago
showClose: true,
message: "添加成功",
type: "success",
});
2 years ago
this.$parent.deviceList();
})
.catch((err) => {
2 years ago
this.$message({
duration: 1500,
2 years ago
showClose: true,
message: "添加失败",
type: "error",
});
2 years ago
});
} else {
console.log(this.formdata);
2 years ago
updateTowerApi(this.formdata)
.then((res) => {
this.isShow = false;
2 years ago
//this.$message.success("修改成功");
this.$message({
duration: 1500,
2 years ago
showClose: true,
message: "修改成功",
type: "success",
});
2 years ago
this.$parent.deviceList();
})
.catch((err) => {
2 years ago
//this.$message.error("修改失败");
this.$message({
duration: 1500,
2 years ago
showClose: true,
message: "修改失败",
type: "error",
});
2 years ago
});
}
} else {
console.log("error submit!!");
return false;
}
});
},
display() {
this.isShow = true;
},
hide() {
this.isShow = false;
},
2 years ago
handleClose() {
2 years ago
this.$parent.deviceList();
2 years ago
},
2 years ago
},
};
</script>
2 years ago
<style lang="less">
.addtowerDialog {
.el-select {
width: 100%;
}
.el-input-number {
width: 100%;
}
.el-input-number .el-input__inner {
text-align: left;
}
2 years ago
}
</style>