<template>
  <div class="app-container">
    <el-row :gutter="28">
      <el-col :span="5" :xs="24">
        <div class="head-container">
          <el-input
            v-model="filterBoxName"
            placeholder="请输入电柜名称"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 20px"
          />
        </div>
        <div class="head-container">
          <div class="tree-container">
            <el-tree
              :data="InfoOptions"
              :props="props"
              :expand-on-click-node="false"
              :filter-node-method="filterNode"
              ref="tree"
              node-key="id"
              default-expand-all
              highlight-current
              @node-click="handleNodeClick"

            />

          </div>
        </div>
      </el-col>

      <el-col :span="19" :xs="24">
        <!-- 母排信息 -->
        <div>
          <el-form :model="queryParamsBusbar" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="母排编号" prop="busbarCode">
              <el-input
                v-model="queryParamsBusbar.busbarCode"
                placeholder="请输入母排编号"
                clearable
                @keyup.enter.native="handleQueryBusbar"
              />
            </el-form-item>
            <el-form-item label="母排别名" prop="busbarAlias">
              <el-input
                v-model="queryParamsBusbar.busbarAlias"
                placeholder="请输入母排别名"
                clearable
                @keyup.enter.native="handleQueryBusbar"
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryBusbar">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQueryBusbar">重置</el-button>
            </el-form-item>
          </el-form>
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handleAddBusbar"
                v-hasPermi="['base:baseBusbarInfo:add']"
              >新增</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="success"
                plain
                icon="el-icon-edit"
                size="mini"
                :disabled="singleBusbar"
                @click="handleUpdateBusbar"
                v-hasPermi="['base:baseBusbarInfo:edit']"
              >修改</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="danger"
                plain
                icon="el-icon-delete"
                size="mini"
                :disabled="multipleBusbar"
                @click="handleDeleteBusbar"
                v-hasPermi="['base:baseBusbarInfo:remove']"
              >删除</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="warning"
                plain
                icon="el-icon-download"
                size="mini"
                @click="handleExportBusbar"
                v-hasPermi="['base:baseBusbarInfo:export']"
              >导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getListBusbar"></right-toolbar>
          </el-row>
          <el-table v-loading="loadingBusbar" :data="baseBusbarInfoList" @selection-change="handleSelectionChangeBusbar">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="检测编号" align="center" prop="busbarCode" />

<!--            <el-table-column label="检测位置" align="center" prop="busbarAlias" />-->

            <el-table-column label="检测位置" align="center" prop="busbarAlias">
              <template slot-scope="scope">
                <el-button type="text" @click="showAlarmsForBusbar(scope.row)">
                  {{ scope.row.busbarAlias }}
                </el-button>
              </template>
            </el-table-column>

            <el-table-column label="所属电柜" align="center" prop="cabinetCode" />
            <el-table-column label="母排距离" align="center" prop="busbarDist" />
            <el-table-column label="是否检测" align="center" prop="isChecked">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.busbar_is_checked" :value="scope.row.isChecked"/>
              </template>
            </el-table-column>
            <el-table-column label="是否尾排" align="center" prop="isEnd">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.busbar_is_end" :value="scope.row.isEnd"/>
              </template>
            </el-table-column>
            <el-table-column label="是否拍照" align="center" prop="isPictures">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.is_pictures" :value="scope.row.isPictures"/>
              </template>
            </el-table-column>
            <el-table-column label="坐标P" align="center" prop="wPanPos" />
            <el-table-column label="坐标T" align="center" prop="wTiltPos" />
            <el-table-column label="坐标Z" align="center" prop="wZoomPos" />
            <el-table-column label="是否旋转" align="center" prop="isRotate">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.is_rotate" :value="scope.row.isRotate"/>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdateBusbar(scope.row)"
                  v-hasPermi="['base:baseBusbarInfo:edit']"
                >修改</el-button>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDeleteBusbar(scope.row)"
                  v-hasPermi="['base:baseBusbarInfo:remove']"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="totalBusbar>0"
            :total="totalBusbar"
            :page.sync="queryParamsBusbar.pageNum"
            :limit.sync="queryParamsBusbar.pageSize"
            @pagination="getListBusbar"
          />
        </div>

        <!-- 报警信息 -->
        <div style="margin-top: 20px;">
<!--          <el-form :model="queryParamsAlarm" ref="queryFormAlarm" size="small" :inline="true" v-show="showSearchAlarm" label-width="68px">
            <el-form-item label="母排编号" prop="busbarCode">
              <el-input
                v-model="queryParamsAlarm.busbarCode"
                placeholder="请输入母排编号"
                clearable
                @keyup.enter.native="handleQueryAlarm"
              />
            </el-form-item>
            <el-form-item label="报警别名" prop="alarmAlias">
              <el-input
                v-model="queryParamsAlarm.alarmAlias"
                placeholder="请输入报警别名"
                clearable
                @keyup.enter.native="handleQueryAlarm"
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryAlarm">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQueryAlarm">重置</el-button>
            </el-form-item>
          </el-form>-->
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handleAddAlarm"
                v-hasPermi="['base:baseAlarmInfo:add']"
              >新增</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="success"
                plain
                icon="el-icon-edit"
                size="mini"
                :disabled="singleAlarm"
                @click="handleUpdateAlarm"
                v-hasPermi="['base:baseAlarmInfo:edit']"
              >修改</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="danger"
                plain
                icon="el-icon-delete"
                size="mini"
                :disabled="multipleAlarm"
                @click="handleDeleteAlarm"
                v-hasPermi="['base:baseAlarmInfo:remove']"
              >删除</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="warning"
                plain
                icon="el-icon-download"
                size="mini"
                @click="handleExportAlarm"
                v-hasPermi="['base:baseAlarmInfo:export']"
              >导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearchAlarm" @queryTable="getListAlarm"></right-toolbar>
          </el-row>
          <el-table v-loading="loadingAlarm" :data="baseAlarmInfoList" @selection-change="handleSelectionChangeAlarm">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="标识" align="center" prop="objId" />
            <el-table-column label="母排编号" align="center" prop="busbarCode" />
            <el-table-column label="报警别名" align="center" prop="alarmAlias" />
            <el-table-column label="报警内容" align="center" prop="alarmContent" />
            <el-table-column label="报警类型" align="center" prop="alarmType">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.alarm_type" :value="scope.row.alarmType"/>
              </template>
            </el-table-column>
            <el-table-column label="报警阈值" align="center" prop="alarmValue" />
            <el-table-column label="判断方式" align="center" prop="judgMethod">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.judg_method" :value="scope.row.judgMethod"/>
              </template>
            </el-table-column>
            <el-table-column label="是否启用" align="center" prop="isFlag">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.is_flag" :value="scope.row.isFlag"/>
              </template>
            </el-table-column>
<!--            <el-table-column label="创建人" align="center" prop="createdBy" />
            <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="更新人" align="center" prop="updatedBy" />
            <el-table-column label="更新时间" align="center" prop="updatedTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.updatedTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>-->
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdateAlarm(scope.row)"
                  v-hasPermi="['base:baseAlarmInfo:edit']"
                >修改</el-button>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDeleteAlarm(scope.row)"
                  v-hasPermi="['base:baseAlarmInfo:remove']"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="totalAlarm>0"
            :total="totalAlarm"
            :page.sync="queryParamsAlarm.pageNum"
            :limit.sync="queryParamsAlarm.pageSize"
            @pagination="getListAlarm"
          />
        </div>
      </el-col>
    </el-row>



    <!-- 添加或修改母排信息对话框 -->
    <el-dialog :title="titleBusbar" :visible.sync="openBusbar" width="500px" append-to-body>
      <el-form ref="formBusbar" :model="formBusbar" :rules="rulesBusbar" label-width="80px">
        <el-form-item label="母排编号" prop="busbarCode">
          <el-input v-model="formBusbar.busbarCode" placeholder="请输入母排编号" />
        </el-form-item>
        <el-form-item label="母排别名" prop="busbarAlias">
          <el-input v-model="formBusbar.busbarAlias" placeholder="请输入母排别名" />
        </el-form-item>
        <el-form-item label="电柜编号" prop="cabinetCode" >
          <el-input v-model="formBusbar.cabinetCode" placeholder="请输入电柜编号" />
        </el-form-item>
        <el-form-item label="母排距离" prop="busbarDist">
          <el-input v-model="formBusbar.busbarDist" placeholder="请输入母排距离" />
        </el-form-item>
        <el-form-item label="是否检测" prop="isChecked">
          <el-radio-group v-model="formBusbar.isChecked">
            <el-radio
              v-for="dict in dict.type.is_checked"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否尾排" prop="isEnd">
          <el-radio-group v-model="formBusbar.isEnd">
            <el-radio
              v-for="dict in dict.type.busbar_is_end"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否启用" prop="isFlag">
          <el-radio-group v-model="formBusbar.isFlag">
            <el-radio
              v-for="dict in dict.type.busbar_is_flag"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否拍照" prop="isPictures">
          <el-radio-group v-model="formBusbar.isPictures">
            <el-radio
              v-for="dict in dict.type.is_pictures"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="坐标P" prop="wPanPos">
          <el-input v-model="formBusbar.wPanPos" placeholder="请输入坐标P" />
        </el-form-item>
        <el-form-item label="坐标T" prop="wTiltPos">
          <el-input v-model="formBusbar.wTiltPos" placeholder="请输入坐标T" />
        </el-form-item>
        <el-form-item label="坐标Z" prop="wZoomPos">
          <el-input v-model="formBusbar.wZoomPos" placeholder="请输入坐标Z" />
        </el-form-item>
        <el-form-item label="是否旋转" prop="isRotate">
          <el-radio-group v-model="formBusbar.isRotate">
            <el-radio
              v-for="dict in dict.type.is_rotate"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormBusbar">确 定</el-button>
        <el-button @click="cancelBusbar">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改报警信息对话框 -->
    <el-dialog :title="titleAlarm" :visible.sync="openAlarm" width="500px" append-to-body>
      <el-form ref="formAlarm" :model="formAlarm" :rules="rulesAlarm" label-width="80px">
        <el-form-item label="母排编号" prop="busbarCode">
          <el-input v-model="formAlarm.busbarCode" placeholder="请输入母排编号" />
        </el-form-item>
        <el-form-item label="报警别名" prop="alarmAlias">
          <el-input v-model="formAlarm.alarmAlias" placeholder="请输入报警别名" />
        </el-form-item>
        <el-form-item label="报警内容">
          <editor v-model="formAlarm.alarmContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="报警类型" prop="alarmType">
          <el-select v-model="formAlarm.alarmType" placeholder="请选择报警类型">
            <el-option
              v-for="dict in dict.type.alarm_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="报警阈值" prop="alarmValue">
          <el-input v-model="formAlarm.alarmValue" placeholder="请输入报警阈值" />
        </el-form-item>
        <el-form-item label="判断方式" prop="judgMethod">
          <el-radio-group v-model="formAlarm.judgMethod">
            <el-radio
              v-for="dict in dict.type.judg_method"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否启用" prop="isFlag">
          <el-radio-group v-model="formAlarm.isFlag">
            <el-radio
              v-for="dict in dict.type.is_flag"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
<!--        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="formAlarm.createdBy" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdTime">
          <el-date-picker clearable
            v-model="formAlarm.createdTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新人" prop="updatedBy">
          <el-input v-model="formAlarm.updatedBy" placeholder="请输入更新人" />
        </el-form-item>
        <el-form-item label="更新时间" prop="updatedTime">
          <el-date-picker clearable
            v-model="formAlarm.updatedTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormAlarm">确 定</el-button>
        <el-button @click="cancelAlarm">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBaseBusbarInfo, getBaseBusbarInfo, delBaseBusbarInfo, addBaseBusbarInfo, updateBaseBusbarInfo } from "@/api/base/baseBusbarInfo";
import { listBaseAlarmInfo, getBaseAlarmInfo, delBaseAlarmInfo, addBaseAlarmInfo, updateBaseAlarmInfo } from "@/api/base/baseAlarmInfo";
import { getBaseCabinetInfoTree } from "@/api/base/baseCabinetInfo";

export default {
  name: "BaseBusbarAndAlarmInfo",
  dicts: ['is_pictures', 'is_rotate', 'cabinet_is_checked', 'busbar_is_flag', 'busbar_is_end', 'judg_method', 'is_flag', 'alarm_type'],
  data() {
    return {
      selectedCabinetCode: null, // 保存当前选中的电柜编

/*      activeTab: 'busbar',*/
      // 电柜信息下拉树选项
      InfoOptions: [],
      // 左侧树结构筛选框
      filterBoxName: undefined,
      props: {
        children: 'children',
        label: 'label'
      },

      // 遮罩层
      loadingBusbar: true,
      loadingAlarm: false,
      // 选中数组
      idsBusbar: [],
      idsAlarm: [],
      // 非单个禁用
      singleBusbar: true,
      singleAlarm: true,
      // 非多个禁用
      multipleBusbar: true,
      multipleAlarm: true,
      // 显示搜索条件
      showSearch: true,
      showSearchBusbar: true,
      showSearchAlarm: true,
      // 总条数
      totalBusbar: 0,
      totalAlarm: 0,
      // 母排信息表格数据
      baseBusbarInfoList: [],
      // 报警信息表格数据
      baseAlarmInfoList: [],
      // 弹出层标题
      titleBusbar: "",
      titleAlarm: "",
      // 是否显示弹出层
      openBusbar: false,
      openAlarm: false,
      // 更新时间时间范围
      daterangeCreatedTimeBusbar: [],
      daterangeUpdatedTimeBusbar: [],
      daterangeCreatedTimeAlarm: [],
      daterangeUpdatedTimeAlarm: [],
      // 查询参数
      queryParams: {
        busbarCode: null,
        busbarAlias: null,
        cabinetCode: null,
        busbarDist: null,
        isChecked: null,
        isEnd: null,
        isFlag: null,
        isPictures: null,
        wPanPos: null,
        wTiltPos: null,
        wZoomPos: null,
        isRotate: null
      },
      queryParamsBusbar: {
        pageNum: 1,
        pageSize: 10,
        objId: null,
        busbarCode: null,
        busbarAlias: null,
        cabinetCode: null,
        busbarDist: null,
        isChecked: null,
        isEnd: null,
        isFlag: null,
        remark: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null,
        isPictures: null,
        wPanPos: null,
        wTiltPos: null,
        wZoomPos: null,
        isRotate: null
      },
      queryParamsAlarm: {
        pageNum: 1,
        pageSize: 10,
        busbarCode: null,
        alarmAlias: null,
        alarmContent: null,
        alarmType: null,
        alarmValue: null,
        judgMethod: null,
        isFlag: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null
      },
      // 表单参数
      formBusbar: {},
      formAlarm: {},
      // 表单校验
      rulesBusbar: {
        busbarCode: [
          { required: true, message: "母排编号不能为空", trigger: "blur" }
        ],
      },
      rulesAlarm: {
        busbarCode: [
          { required: true, message: "母排编号不能为空", trigger: "blur" }
        ],
        alarmAlias: [
/*          { required: true, message: "报警别名不能为空", trigger: "blur" }
        ],
        alarmType: [
          { required: true, message: "报警类型不能为空", trigger: "change" }
        ],
        alarmValue: [
          { required: true, message: "报警阈值不能为空", trigger: "blur" }
        ],
        judgMethod: [
          { required: true, message: "判断方式不能为空", trigger: "change" }
        ],
        isFlag: [
          { required: true, message: "是否启用不能为空", trigger: "change" }*/
        ]
      }
    };
  },
  created() {
    this.getTreeselect();
    this.getListBusbar();
  },
  watch: {
    filterBoxName(val){
      this.$refs.tree.filter(val)
    }
  },
  methods: {
    /** 查询母排信息列表 */
    getListBusbar() {
      this.loadingBusbar = true;
      this.queryParamsBusbar.params = {};
      this.queryParamsBusbar.params = {
        cabinetCode: this.queryParamsBusbar.cabinetCode
      };
      if (null != this.daterangeCreatedTimeBusbar && '' != this.daterangeCreatedTimeBusbar) {
        this.queryParamsBusbar.params["beginCreatedTime"] = this.daterangeCreatedTimeBusbar[0];
        this.queryParamsBusbar.params["endCreatedTime"] = this.daterangeCreatedTimeBusbar[1];
      }
      if (null != this.daterangeUpdatedTimeBusbar && '' != this.daterangeUpdatedTimeBusbar) {
        this.queryParamsBusbar.params["beginUpdatedTime"] = this.daterangeUpdatedTimeBusbar[0];
        this.queryParamsBusbar.params["endUpdatedTime"] = this.daterangeUpdatedTimeBusbar[1];
      }
      listBaseBusbarInfo(this.queryParamsBusbar).then(response => {
        this.baseBusbarInfoList = response.rows;
        this.totalBusbar = response.total;
        this.loadingBusbar = false;
      });
    },
    /** 点击检测位置按钮时显示相关报警信息 */
    showAlarmsForBusbar(row) {
      this.queryParamsAlarm.busbarCode = row.busbarCode;
      this.handleQueryAlarm();
    },
    /** 查询报警信息列表 */
    getListAlarm() {
      this.queryParamsAlarm.params = {};
      if (null != this.daterangeCreatedTimeAlarm && '' != this.daterangeCreatedTimeAlarm) {
        this.queryParamsAlarm.params["beginCreatedTime"] = this.daterangeCreatedTimeAlarm[0];
        this.queryParamsAlarm.params["endCreatedTime"] = this.daterangeCreatedTimeAlarm[1];
      }
      if (null != this.daterangeUpdatedTimeAlarm && '' != this.daterangeUpdatedTimeAlarm) {
        this.queryParamsAlarm.params["beginUpdatedTime"] = this.daterangeUpdatedTimeAlarm[0];
        this.queryParamsAlarm.params["endUpdatedTime"] = this.daterangeUpdatedTimeAlarm[1];
      }
      listBaseAlarmInfo(this.queryParamsAlarm).then(response => {
        this.baseAlarmInfoList = response.rows;
        this.totalAlarm = response.total;
        this.loadingAlarm = false;
      });
    },
    /** 搜索按钮操作 */
    handleQueryBusbar() {
      this.queryParamsBusbar.cabinetCode = this.selectedCabinetCode;
      this.queryParamsBusbar.pageNum = 1;
      this.getListBusbar();
    },
    handleQueryAlarm() {
      this.queryParamsAlarm.pageNum = 1;
      this.getListAlarm();
    },
    /** 重置按钮操作 */
    resetQueryBusbar() {
      this.resetForm("queryFormBusbar");
      this.handleQueryBusbar();
    },
    resetQueryAlarm() {
      this.resetForm("queryFormAlarm");
      this.handleQueryAlarm();
    },
    /** 新增按钮操作 */
    handleAddBusbar() {
      this.resetFormBusbar();
      this.openBusbar = true;
      this.formBusbar.cabinetCode = this.selectedCabinetCode; // 设置电柜编号
      this.titleBusbar = "添加母排信息";
    },
    handleAddAlarm() {
      this.resetFormAlarm();
      this.openAlarm = true;
      this.titleAlarm = "添加报警信息";
    },
    /** 修改按钮操作 */
    handleUpdateBusbar(row) {
      const id = row.objId || this.ids
      getBaseBusbarInfo(id).then(response => {
        this.formBusbar = response.data;
        this.openBusbar = true;
        this.titleBusbar = "修改母排信息";
      });
    },
    handleUpdateAlarm(row) {
      const id = row.objId || this.ids
      getBaseAlarmInfo(id).then(response => {
        this.formAlarm = response.data;
        this.openAlarm = true;
        this.titleAlarm = "修改报警信息";
      });
    },
    /** 提交按钮 */
    submitFormBusbar() {
      this.$refs["formBusbar"].validate(valid => {
        if (valid) {
          if (this.formBusbar.objId !== undefined) {
            updateBaseBusbarInfo(this.formBusbar).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openBusbar = false;
              this.getListBusbar();
            });
          } else {
            addBaseBusbarInfo(this.formBusbar).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openBusbar = false;
              this.getListBusbar();
            });
          }
        }
      });
    },
    submitFormAlarm() {
      this.$refs["formAlarm"].validate(valid => {
        if (valid) {
          if (this.formAlarm.objId !== undefined) {
            updateBaseAlarmInfo(this.formAlarm).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openAlarm = false;
              this.getListAlarm();
            });
          } else {
            addBaseAlarmInfo(this.formAlarm).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openAlarm = false;
              this.getListAlarm();
            });
          }
        }
      });
    },
    /** 取消按钮 */
    cancelBusbar() {
      this.openBusbar = false;
      this.resetFormBusbar();
    },
    cancelAlarm() {
      this.openAlarm = false;
      this.resetFormAlarm();
    },
    /** 删除按钮操作 */
    handleDeleteBusbar(row) {
      const ids = row.objId || this.idsBusbar;
      this.$modal.confirm('是否确认删除母排编号为"' + ids + '"的数据项？').then(function() {
        return delBaseBusbarInfo(ids);
      }).then(() => {
        this.getListBusbar();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    handleDeleteAlarm(row) {
      const ids = row.objId || this.idsAlarm;
      this.$modal.confirm('是否确认删除报警编号为"' + ids + '"的数据项？').then(function() {
        return delBaseAlarmInfo(ids);
      }).then(() => {
        this.getListAlarm();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 重置表单 */
    resetFormBusbar() {
      this.formBusbar = {
        objId: null,
        busbarCode: null,
        busbarAlias: null,
        cabinetCode: null,
        busbarDist: null,
        isChecked: null,
        isEnd: null,
        isFlag: null,
        remark: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null,
        isPictures: null,
        wPanPos: null,
        wTiltPos: null,
        wZoomPos: null,
        isRotate: null
      };
      this.resetForm("formBusbar");
    },
    resetFormAlarm() {
      this.formAlarm = {
        objId: null,
        busbarCode: null,
        alarmAlias: null,
        alarmContent: null,
        alarmType: null,
        alarmValue: null,
        judgMethod: null,
        isFlag: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null
      };
      this.resetForm("formAlarm");
    },

    /** 导出按钮操作 */
    handleExportBusbar() {
      this.download('base/baseBusbarInfo/export', {
        ...this.queryParams
      }, `baseBusbarInfo_${new Date().getTime()}.xlsx`)
    },

    /** 处理母排信息表格选择变化 */
    handleSelectionChangeBusbar(selection) {
      this.idsBusbar = selection.map(item => item.id);
      this.singleBusbar = selection.length !== 1;
      this.multipleBusbar = !selection.length;
    },


    /** 获取电柜信息树结构 */
    getTreeselect() {
      getBaseCabinetInfoTree({}).then(response => {
        this.InfoOptions = response.data;
      });
    },
    /** 树节点点击事件 */
    handleNodeClick(data) {
      this.queryParamsBusbar.cabinetCode = data.code
      this.selectedCabinetCode = data.code; // 保存选中的电柜编号
      /*      this.queryParamsAlarm.busbarCode = data.busbarCode;*/
      this.handleQueryBusbar()
      /*      this.getListAlarm();*/
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },

  }
};
</script>

<style scoped>
.tree-container {
  height: 666px; /* 设置固定高度 */
  overflow-y: auto; /* 添加垂直滚动条 */
}
</style>

