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.

156 lines
4.1 KiB
Vue

2 years ago
<template>
2 years ago
<el-dialog
class="addLineDialog"
title="设置"
:visible.sync="isShow"
:close-on-click-modal="false"
width="40%"
>
<!-- <el-form
2 years ago
label-position="left"
ref="formInfo"
label-width="100px"
:rules="rules"
:model="formdata"
>
2 years ago
<el-form-item label="通道:" prop="name">
2 years ago
<el-tree
:data="listnr"
show-checkbox
:props="defaultProps"
ref="tree"
node-key="id"
:default-expand-all="true"
></el-tree>
2 years ago
</el-form-item>
</el-form> -->
2 years ago
<div class="flexnr">
<div class="w50">通道:</div>
<el-tree :data="listnr" show-checkbox :props="defaultProps" ref="tree" node-key="id" :default-expand-all="true"></el-tree>
</div>
2 years ago
<div slot="footer" class="dialog-footer">
2 years ago
<!-- <el-button @click="getCheckedNodes"></el-button> -->
2 years ago
<el-button @click="isShow = false"> </el-button>
<el-button type="primary" @click="submitForm()"> </el-button>
</div>
</el-dialog>
</template>
<script>
2 years ago
import {
setScheduleRulel,
getScheduleRulelAccessList,
} from "@/utils/api/index";
2 years ago
export default {
props: {
2 years ago
title: String,
2 years ago
},
data() {
return {
isShow: false,
formdata: {},
rules: {
2 years ago
name: [{ required: true, message: "请选择通道", trigger: "blur" }],
2 years ago
},
listnr: [],
defaultProps: {
2 years ago
children: "list",
label: "name",
2 years ago
},
2 years ago
selid: 0,
ruleid: "",
2 years ago
parmsList: [],//选中的通道
2 years ago
};
},
mounted() {
},
methods: {
//判断
2 years ago
getdataform(val) {
this.selid = val.id;
2 years ago
this.getlistnr()
2 years ago
},
//获取所有通道
2 years ago
getlistnr() {
getScheduleRulelAccessList({})
.then((res) => {
this.listnr = res.data.list;
})
.catch((err) => {});
2 years ago
},
2 years ago
2 years ago
//获取所选值
getCheckedNodes() {
2 years ago
this.parmsList = []
const checkedNodes = this.$refs.tree.getCheckedNodes(false, true); //若节点可被选择,则返回目前被选中的节点所组成的数组
//const checkedParam = []; //定义选中的数组
let index = -1;
2 years ago
// console.log(checkedNodes);
if (checkedNodes.length !== 0) {
checkedNodes.forEach((item) => {
// 父节点结构的情况 判断是否有list子节点如果有定义数组结构
if (item.list !== undefined) {
index++;
this.parmsList[index] = {
//name: item.name,
termid: item.id,
channelidlist: [],
};
} else {
//如果没有list 把子节点id push到 定义的数组channelidlist中
this.parmsList[index].channelidlist.push(item.id);
}
//通过bsManufacturer 判断是否是 线路 获取线路id
2 years ago
// if (item.bsManufacturer !== undefined) {
// this.ruleid = item.id;
// console.log(this.ruleid);
// }
});
}
2 years ago
// console.log(this.parmsList);
//遍历删除没有channelichilddlist的数据只留下通道
this.parmsList = this.parmsList
.filter((item) => item.channelidlist.length !== 0)
.map((item) => {
return {
termid: item.termid,
channelidlist: item.channelidlist,
};
});
console.log(this.parmsList);
return this.parmsList;
2 years ago
},
2 years ago
2 years ago
// 保存确定操作
submitForm() {
2 years ago
this.getCheckedNodes()
if (this.parmsList.length==0) return this.$message.error("通道不能为空");
setScheduleRulel({ list: this.parmsList, ruleid: this.selid })
.then((res) => {
this.isShow = false;
this.$message.success("添加成功");
this.$parent.deviceList();
})
.catch((err) => {
this.$message.error("添加失败");
});
2 years ago
},
display() {
2 years ago
this.isShow = true;
2 years ago
},
hide() {
2 years ago
this.isShow = false;
},
},
2 years ago
};
</script>
2 years ago
<style lang="less" scoped>
.flexnr {
display: flex;
align-items: start;
}
.w50{
width: 50px;
}
</style>