<template>
  <el-dialog class="addLineDialog" title="设置" :visible.sync="isShow" :close-on-click-modal="false" width="40%" >
    <el-form label-position="left" ref="formInfo" label-width="100px" :rules="rules" :model="formdata" >
      <el-form-item label="通道：" prop="name">
        <el-tree :data="listnr" show-checkbox :props="defaultProps" ref="tree" node-key="id" ></el-tree>
      </el-form-item>
    </el-form>
    <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>
import { setScheduleRulel,getScheduleRulelAccessList } from "@/utils/api/index";
export default {
  props: {
    title:String
  },
  data() {
    return {
      isShow: false,
      formdata: {},
      rules: {
        name: [
          { required: true, message: "请选择通道", trigger: "blur" },
        ],
      },
      listnr: [],
      defaultProps: {
        children: 'list',
        label: 'name'
      },
      selid:0
    };
  },
  mounted() {
    this.getlistnr()
  },
  methods: {
    //判断
    getdataform(val){
      this.selid = val.id
      // if (val==null) {
      //   return this.formdata = {}
      // } 
      // this.formdata = val
      // this.$set(this.formdata,'time',[val.startTime, val.endTime])
    },
    //获取所有通道
    getlistnr(){
      getScheduleRulelAccessList({}).then((res) => {
        this.listnr = res.data.list
      }).catch((err) => {});
    },
    //获取所选值
    getCheckedNodes() {
      console.log(this.$refs.tree.getCheckedNodes());
    },
    // 保存确定操作
    submitForm() {
      this.$refs.formInfo.validate((valid) => {
        if (valid) {
          setScheduleRulel({ list: formArr }).then((res) => {
            this.isShow = false
            this.$message.success("添加成功");
            this.$parent.deviceList()
          })
          .catch((err) => {
            this.$message.error("添加失败");
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    display() {
      this.isShow = true
    },
    hide() {
      this.isShow = false
    }
  }
};
</script>
