<template>
  <div class="siteManage-main watchDog">
    <!-- 筛选start -->
    <div class="filter-container mb-20">
      <a class="">【测试站点1】站点的所有监控设备</a>
      <!-- <el-button icon="el-icon-plus" type="success" @click="addItem()">新增</el-button > -->
      <div>
        <el-button type="primary">导入</el-button>
        <el-button type="primary">导出</el-button>
      </div>
    </div>
    <!-- 筛选end -->

    <!-- 表格start -->
    <el-table :data="tableData" border stripe :header-cell-style="headClass">
      <el-table-column
        fixed
        prop="watchStatus"
        label="状态"
        width="50"
        align="center"
      >
        <template #default>
          <el-avatar class="status"></el-avatar>
        </template>
      </el-table-column>
      <el-table-column prop="watchName" label="名称" width="">
      </el-table-column>
      <el-table-column prop="watchCode" label="编号" width="">
      </el-table-column>
      <el-table-column prop="ratedVoltage" label="额定电压" width="">
      </el-table-column>
      <el-table-column prop="ratedCurrent" label="额定电流" width="">
      </el-table-column>
      <el-table-column prop="fzlMx" label="电流负载率门限" width="">
      </el-table-column>
      <el-table-column prop="powerAnalysis" label="电能质量分析" width="">
      </el-table-column>
      <el-table-column prop="watchAddress" label="表计地址" width="">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="180">
        <template #default="scope">
          <el-button
            type="text"
            size="small"
            @click.prevent="editRow(scope.row)"
            >编辑</el-button
          >
          <el-button
            @click="handleDelete(scope.$index, scope.row)"
            type="text"
            size="small"
            class="delete-text"
            >删除</el-button
          >
        </template>
      </el-table-column>

      <el-table-column fixed="right" label="变量" width="180">
        <template #default="scope">
          <el-button type="text" size="small" @click="goVariableList">
            变量列表
          </el-button>
          <!-- 
           <router-link style="margin-right:15px;" :to="{ path:'variableList'}">
              变量列表
            </router-link> -->
          <el-button @click="cloneDialog(scope.row)" type="text" size="small"
            >克隆</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格end -->

    <!--弹框组件开始-----------------------start-->
    <dialog-component
      v-if="showDialog"
      ref="dialogComponent"
      :dialog-title="dialogTitle"
      :item-info="tableItem"
      @closeDialog="closeDialog"
    ></dialog-component>
    <!--弹框组件开始-----------------------end-->

    <!--克隆组件开始-----------------------start-->
    <clone
      v-if="showDialog"
      ref="cloneDialog"
      :dialog-title="dialogTitle"
      :item-info="tableItem"
      @closeDialog="closeDialog"
    ></clone>
    <!--克隆组件end-----------------------end-->
  </div>
</template>

<script>
import DialogComponent from "./dialogComponent";
import Clone from "./clone";

export default {
  name: "WatchDog",
  props: ['activeName'],
  components: { DialogComponent, Clone },

  data() {
    return {
      showDialog: false,

      input: "请输入状态",
      tableData: [
        {
          ratedVoltage: "10KV",
          watchName: "测试设备1",
          watchCode: "cssb1",
          ratedCurrent: "58A",
          fzlMx: "80%",
          powerAnalysis: "开启",
          watchAddress: "1",
        },
        {
          ratedVoltage: "10KV",
          watchName: "测试设备1",
          watchCode: "cssb1",
          ratedCurrent: "58A",
          fzlMx: "80%",
          powerAnalysis: "开启",
          watchAddress: "1",
        },
        {
          ratedVoltage: "10KV",
          watchName: "测试设备1",
          watchCode: "cssb1",
          ratedCurrent: "58A",
          fzlMx: "80%",
          powerAnalysis: "开启",
          watchAddress: "1",
        },
        {
          ratedVoltage: "10KV",
          watchName: "测试设备1",
          watchCode: "cssb1",
          ratedCurrent: "58A",
          fzlMx: "80%",
          powerAnalysis: "开启",
          watchAddress: "1",
        },
        {
          ratedVoltage: "10KV",
          watchName: "测试设备1",
          watchCode: "cssb1",
          ratedCurrent: "58A",
          fzlMx: "80%",
          powerAnalysis: "开启",
          watchAddress: "1",
        },  
        {
          ratedVoltage: "10KV",
          watchName: "测试设备1",
          watchCode: "cssb1",
          ratedCurrent: "58A",
          fzlMx: "80%",
          powerAnalysis: "开启",
          watchAddress: "1",
        },
        {
          ratedVoltage: "10KV",
          watchName: "测试设备1",
          watchCode: "cssb1",
          ratedCurrent: "58A",
          fzlMx: "80%",
          powerAnalysis: "开启",
          watchAddress: "1",
        },
        {
          ratedVoltage: "10KV",
          watchName: "测试设备1",
          watchCode: "cssb1",
          ratedCurrent: "58A",
          fzlMx: "80%",
          powerAnalysis: "开启",
          watchAddress: "1",
        },
      ],
    };
  },
  methods: {
    // 表头样式设置
    goVariableList() {
       this.$emit('func')
    },
   
    headClass() {
      return "background:#FAFAFA;";
    },

    // 克隆操作
    cloneDialog() {
      this.tableItem = {
        id: "",
        stationName: "",
        watchName: "",
        watchCode: "",
        siteList: [],
        done: "",
        guaZai: "",
        checked: true,
        resource: "",
      };
      this.dialogTitle = "变量克隆";
      this.showDialog = true;
      this.$nextTick(() => {
        this.$refs["cloneDialog"].showDialog = true;
      });
    },

    // 添加操作
    addItem() {
      this.tableItem = {
        id: "",
        stationName: "",
        watchName: "",
        watchCode: "",
        siteList: [],
        done: "",
        guaZai: "",
        checked: true,
      };
      this.dialogTitle = "新增";
      this.showDialog = true;
      this.$nextTick(() => {
        this.$refs["dialogComponent"].showDialog = true;
      });
    },
    // 编辑操作
    editRow(row) {
      console.log(row);
      this.tableItem = row;
      this.dialogTitle = "编辑";
      this.showDialog = true;
      this.$nextTick(() => {
        this.$refs["dialogComponent"].showDialog = true;
      });
    },
    // 关闭操作
    closeDialog(flag) {
      if (flag) {
        // 重新刷新表格内容
        this.fetchData();
      }
      this.showDialog = false;
    },

    //删除操作
    handleDelete(index, row) {
      console.log(index, row);
      alert(index);
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
