<template>
  <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" @close="handleClose" id="applyRules">
    <p>对应规则有冲突，请选择处理方式：</p>
    <div>
      <el-radio v-model="select" :label="'Old'">保留设备实例中人工维护的动态参数的值</el-radio>
    </div>
    <div>
      <el-radio v-model="select" :label="'New'">按照规则自动覆盖动态参数的值</el-radio>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="handleClose">取消</el-button>
      <el-button size="small" type="primary" @click="confirmClash">确认</el-button>
    </span>
  </el-dialog>
</template>
<script>

import {
  dynamicPromptobjs, //提示冲突
  dynamicClashConfirm, //冲突选择确认
  dynamicExecute, //执行规则
} from "@/api/scan/request";
import Vue from 'vue'
export default {
  data() {
    return {
      dialogVisible: false, //弹窗显示与隐藏
      tableData: [],
      activeName: "first", //当前所在tab页
      finished: false, //未处理所有冲突提示文字
      force: false, //请求冲突-默认false
      select: 'New'
    };
  },
  methods: {
    showDialog(force) {
      this.force = force
      if (this.tableData.length) {
        this.dialogVisible = true;
      } else {
        this.rulesConfirm()
      }
    },
    handleClose() {
      this.dialogVisible = false;
      this.$emit('cancel')
    },
    //查询是否有冲突
    getPromptobjs() {
      let param = {
        Force: this.force
      }
      dynamicPromptobjs(param, res => {
        this.tableData = res.Content;
        this.$emit('clash', this.tableData.length);
      })
    },
    //确认冲突
    confirmClash() {
      let selectedRows = this.tableData.map(t => {
        t.checked = this.select
        return t
      });
      let param = [];
      selectedRows.map(t => {
        let tempObj = {
          Objs: [t],
          Points: [t]
        }
        param.push(tempObj)
      })
      dynamicClashConfirm(param, res => {
        this.rulesConfirm();
      })
    },
    //执行规则
    rulesConfirm() {
      let param = {
        Force: this.force
      }
      dynamicExecute(param, res => {
        this.$message.success('执行成功');
        this.dialogVisible = false;
        let missionID = res.Content[0].Id
        this.$emit('refresh', missionID)
      })
    }
  },
  mounted() { },
  created() {
    this.getPromptobjs()
  }
};
</script>
<style lang="scss" scoped>
#applyRules {
  /deep/ td.bgf5 {
    background-color: #f5f7fa;
  }
  td p {
    text-align: center;
  }
  /deep/ .el-radio__input.is-checked + .el-radio__label {
    color: #000;
  }
}
</style>