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.

160 lines
4.2 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> -->
<el-tree
:data="listnr"
show-checkbox
:props="defaultProps"
ref="tree"
node-key="id"
:default-expand-all="true"
></el-tree>
2 years ago
<div slot="footer" class="dialog-footer">
<el-button @click="getCheckedNodes"></el-button>
<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: "",
parmsList: [],
2 years ago
};
},
mounted() {
2 years ago
this.getlistnr();
2 years ago
},
methods: {
//判断
2 years ago
getdataform(val) {
this.selid = val.id;
2 years ago
// if (val==null) {
// return this.formdata = {}
2 years ago
// }
2 years ago
// this.formdata = val
// this.$set(this.formdata,'time',[val.startTime, val.endTime])
},
//获取所有通道
2 years ago
getlistnr() {
getScheduleRulelAccessList({})
.then((res) => {
this.listnr = res.data.list;
})
.catch((err) => {});
2 years ago
},
2 years ago
2 years ago
//获取所选值
getCheckedNodes() {
const checkedNodes = this.$refs.tree.getCheckedNodes(false, true); //若节点可被选择,则返回目前被选中的节点所组成的数组
//const checkedParam = []; //定义选中的数组
let index = -1;
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
if (item.bsManufacturer !== undefined) {
this.ruleid = item.id;
console.log(this.ruleid);
}
});
}
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() {
this.$refs.formInfo.validate((valid) => {
if (valid) {
setScheduleRulel({ ruleid: this.ruleid, list: this.parmsList })
2 years ago
.then((res) => {
this.isShow = false;
this.$message.success("添加成功");
this.$parent.deviceList();
})
.catch((err) => {
this.$message.error("添加失败");
});
2 years ago
} else {
console.log({ ruleid: this.ruleid, list: this.parmsList });
2 years ago
console.log("error submit!!");
return false;
}
});
},
display() {
2 years ago
this.isShow = true;
2 years ago
},
hide() {
2 years ago
this.isShow = false;
},
},
2 years ago
};
</script>