<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item
        label="计量设备状态"
        label-width="100px"
        prop="monitorStatus"
      >
        <el-select
          v-model="queryParams.monitorStatus"
          placeholder="请选择计量设备状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.monitorStatus"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="是否虚拟" prop="isAmmeter">
        <el-select
          v-model="queryParams.isAmmeter"
          placeholder="请选择是否虚拟"
          clearable
        >
          <el-option
            v-for="dict in dict.type.isAmmeter"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="表具类型" prop="isAmmeter">
        <el-select
          v-model="queryParams.publicShareType"
          placeholder="请选择表具类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.public_share_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="表具层级" prop="monitorHierarchy">
        <el-select v-model="queryParams.monitorHierarchy" placeholder="请选择表具层级" clearable>
          <el-option
            v-for="dict in dict.type.monitor_hierarchy"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</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="handleAdd"
          v-hasPermi="['energy:ShuiMeasurement:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-sort"
          size="mini"
          @click="toggleExpandAll"
          >展开/折叠</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['energy:ShuiMeasurement:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        共{{list.length}}条
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-if="refreshTable"
      v-loading="loading"
      :data="ShuiMeasurementList"
      row-key="objid"
      :expand-row-keys="['1', '2']"
      :default-expand-all="isExpandAll"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <!-- <el-table-column label="父级编号" prop="parentId" v-if="false"/> -->
      <el-table-column
        label="计量设备编号"
        align="center"
        prop="monitorId"
        min-width="150"
      />
      <el-table-column label="计量设备名称" align="center" prop="monitorName" />
      <el-table-column label="计量设备位置" align="center" prop="monitorAddr" />
      <el-table-column label="计量设备类型" align="center" prop="monitorType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.energy_type"
            :value="scope.row.monitorType"
          />
        </template>
      </el-table-column>
      <el-table-column label="CBS房间编号" align="center" key="roomCode" prop="roomCode"  />
      <el-table-column label="CBS房间名称" align="center" key="roomName" prop="roomName"  />
      <el-table-column label="CBS物理编号" align="center" key="physicalCode" prop="physicalCode"  />
      <el-table-column label="计量设备状态" align="center" prop="monitorStatus">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.monitorStatus"
            :value="scope.row.monitorStatus"
          />
        </template>
      </el-table-column>
      <!--
      <el-table-column label="祖级列表" align="center" prop="ancestors" />
      <el-table-column label="等级" align="center" prop="grade" />
      <el-table-column label="建筑类型" align="center" prop="buildId" />
      <el-table-column label="分项类型" align="center" prop="subentryId" />
      <el-table-column label="业态类型" align="center" prop="businessId" />
      <el-table-column label="传感器仪表" align="center" prop="meterTypeId" />
      <el-table-column label="测量器具" align="center" prop="meterId" />
      <el-table-column label="修正值" align="center" prop="correctValue" />
      <el-table-column label="PT值" align="center" prop="pt" />
      <el-table-column label="CT值" align="center" prop="ct" /> -->
      <el-table-column label="是否虚拟" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.isAmmeter"
            :value="scope.row.isAmmeter"
          />
        </template>
      </el-table-column>
      <!-- <el-table-column label="通断复位" align="center" prop="isKeyMonitor" />
      <el-table-column label="是否断路" align="center" prop="isCircuit" />
      <el-table-column label="权限标识" align="center" prop="deptId" />
      <el-table-column label="权限标识" align="center" prop="userId" /> -->
      <el-table-column label="表具类型" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.public_share_type"
            :value="scope.row.publicShareType"
          />
        </template>
      </el-table-column>
      <el-table-column label="表具层级" align="center" prop="monitorHierarchy">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.monitor_hierarchy" :value="scope.row.monitorHierarchy"/>
        </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="handleUpdate(scope.row)"
            v-hasPermi="['energy:ShuiMeasurement:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleAdd(scope.row)"
            v-hasPermi="['energy:ShuiMeasurement:add']"
            >新增</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['energy:ShuiMeasurement:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加或修改计量设备信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="采集设备编号" prop="collectDeviceId">
          <el-row>
            <el-col :span="12">
              <el-input
                v-model="form.collectDeviceId"
                placeholder="请选择采集设备编号"
              />
            </el-col>
            <el-col :span="12">
              <el-button type="primary" @click="selectDevice"
                >选择采集设备</el-button
              >
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="父级编号" prop="parentId">
          <treeselect
            v-model="form.parentId"
            :options="ShuiMeasurementOptions"
            :normalizer="normalizer"
            placeholder="请选择父级编号"
          />
        </el-form-item>
        <el-form-item label="计量设备编号" prop="monitorId">
          <el-input v-model="form.monitorId" placeholder="请输入计量设备名称" />
        </el-form-item>
        <el-form-item label="计量设备名称" prop="monitorName">
          <el-input
            v-model="form.monitorName"
            placeholder="请输入计量设备名称"
          />
        </el-form-item>
        <el-form-item label="计量设备位置" prop="monitorAddr">
          <el-input
            v-model="form.monitorAddr"
            placeholder="请输入计量设备位置"
          />
        </el-form-item>
        <el-form-item label="类型" prop="monitorType" v-if="false">
          <el-input v-model="form.monitorType" />
        </el-form-item>
        <el-form-item label="CBS房间编号" prop="roomCode">
          <el-input v-model="form.roomCode" placeholder="请输入CBS房间编号" />
        </el-form-item>
        <el-form-item label="CBS房间名称" prop="roomName">
          <el-input v-model="form.roomName" placeholder="请输入房间名称" />
        </el-form-item>
        <el-form-item label="CBS物理编号" prop="physicalCode">
          <el-input v-model="form.physicalCode" placeholder="physicalCode" />
        </el-form-item>
        <el-form-item label="通讯地址" prop="addressCode">
          <el-input v-model="form.addressCode" placeholder="请填写通讯地址" />
        </el-form-item>
        <el-form-item label="计量设备状态" prop="monitorStatus">
          <el-radio-group v-model="form.monitorStatus">
            <el-radio
              v-for="dict in dict.type.monitorStatus"
              :key="dict.value"
              :label="parseInt(dict.value)"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <!--
        <el-form-item label="采集设备编号" prop="collectDeviceId">
          <el-input v-model="form.collectDeviceId" placeholder="请输入采集设备编号" />
        </el-form-item>

        <el-form-item label="等级" prop="grade">
          <el-input v-model="form.grade" placeholder="请输入等级" />
        </el-form-item>-->
        <el-form-item label="建筑类型" prop="buildId">
          <el-tree
            class="tree-border"
            :data="buildOptions"
            show-checkbox
            :check-strictly="true"
            :default-expanded-keys="twoKeys"
            ref="build"
            node-key="id"
            empty-text="加载中，请稍候"
            :props="defaultProps"
          ></el-tree>
        </el-form-item>
        <el-form-item label="分项类型" prop="subentryId">
          <el-tree
            class="tree-border"
            :data="subentryOptions"
            show-checkbox
            :check-strictly="true"
            :default-expanded-keys="twoKeys"
            ref="subentry"
            node-key="id"
            empty-text="加载中，请稍候"
            :props="defaultProps"
          ></el-tree>
        </el-form-item>
        <el-form-item label="业态类型" prop="businessId">
          <el-tree
            class="tree-border"
            :data="businessOptions"
            show-checkbox
            :default-expanded-keys="twoKeys"
            :check-strictly="true"
            ref="business"
            node-key="id"
            empty-text="加载中，请稍候"
            :props="defaultProps"
          ></el-tree>
        </el-form-item>
        <el-form-item label="传感器仪表" prop="meterTypeId">
          <el-input v-model="form.meterTypeId" placeholder="请输入传感器仪表" />
        </el-form-item>
        <el-form-item label="测量器具" prop="meterId">
          <el-input v-model="form.meterId" placeholder="请输入测量器具" />
        </el-form-item>
        <el-form-item label="修正值" prop="correctValue">
          <el-input v-model="form.correctValue" placeholder="请输入修正值" />
        </el-form-item>
        <el-form-item label="PT值" prop="pt">
          <el-input v-model="form.pt" placeholder="请输入PT值" />
        </el-form-item>
        <el-form-item label="CT值" prop="ct">
          <el-input v-model="form.ct" placeholder="请输入CT值" />
        </el-form-item>
        <el-form-item label="是否虚拟" label-width="100px" prop="isAmmeter">
          <el-radio v-model="form.isAmmeter" label="true">是</el-radio>
          <el-radio v-model="form.isAmmeter" label="false">否</el-radio>
        </el-form-item>
        <el-form-item label="公摊表类型" prop="publicShareType">
          <el-radio-group v-model="form.publicShareType">
            <el-radio
              v-for="dict in dict.type.public_share_type"
              :key="dict.value"
              :label="parseInt(dict.value)"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="表具层级" prop="monitorHierarchy">
          <el-select v-model="form.monitorHierarchy" placeholder="请选择表具层级">
            <el-option
              v-for="dict in dict.type.monitor_hierarchy"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <!--
        <el-form-item label="是否虚拟" prop="isAmmeter">
          <el-input v-model="form.isAmmeter" placeholder="请输入是否虚拟" />
        </el-form-item>

        <el-form-item label="通断复位" prop="isKeyMonitor">
          <el-input v-model="form.isKeyMonitor" placeholder="请输入通断复位" />
        </el-form-item>
        <el-form-item label="是否断路" prop="isCircuit">
          <el-input v-model="form.isCircuit" placeholder="请输入是否断路" />
        </el-form-item>
        <el-form-item label="权限标识" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入权限标识" />
        </el-form-item>
        <el-form-item label="权限标识" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入权限标识" />
        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 选择采集器对话框 -->
    <el-dialog
      :title="title1"
      :visible.sync="open1"
      width="800px"
      append-to-body
    >
      <el-form
        :model="queryParams1"
        ref="queryForm1"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="120px"
      >
        <el-form-item label="能源类型名称" prop="energyType">
          <el-select
            v-model="queryParams1.energyType"
            placeholder="能源类型名称"
            clearable
            style="width: 240px"
          >
            <el-option
              v-for="dict in dict.type.energy_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery1"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery1"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="deviceloading"
        :data="typeList"
        @selection-change="handleSelectionChange1"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column
          label="设备编号"
          align="center"
          prop="collectDeviceId"
        />
        <el-table-column
          label="设备名称"
          align="center"
          prop="collectDeviceName"
        />
        <el-table-column label="生产厂家" align="center" prop="manufacturer" />
        <el-table-column label="能源类型" align="center" prop="energyType">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.energy_type"
              :value="scope.row.energyType"
            />
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="devicetotal > 0"
        :total="devicetotal"
        :page.sync="queryParams1.pageNum"
        :limit.sync="queryParams1.pageSize"
        @pagination="getDeviceList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm1">确 定</el-button>
        <el-button @click="cancel1">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listShuiMeasurement,
  getShuiMeasurement,
  delShuiMeasurement,
  addShuiMeasurement,
  updateShuiMeasurement,
  buildTreeSelect,
  subentryTreeSelect,
  businessTreeSelect,
  treeselect,
} from "@/api/energy/energy/waterManagement/shuiMeasurement";
import { listInfo } from "@/api/energy/energy/base/info";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "ShuiMeasurement",
  dicts: ["isAmmeter", "monitorStatus", "energy_type", "public_share_type",'monitor_hierarchy'],
  components: {
    Treeselect,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 返回条数
      list: null,
      // 显示搜索条件
      showSearch: true,
      // 计量设备信息表格数据
      ShuiMeasurementList: [],
      // 计量设备信息树选项
      ShuiMeasurementOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否展开，默认全部展开
      isExpandAll: false,
      // 重新渲染表格状态
      refreshTable: true,
      //展开行id
      expandrowid: [],
      // 查询参数
      queryParams: {
        parentId: null,
        monitorName: null,
        monitorAddr: null,
        monitorType: null,
        monitorStatus: null,
        collectDeviceId: null,
        ancestors: null,
        grade: null,
        buildId: null,
        subentryId: null,
        businessId: null,
        meterTypeId: null,
        meterId: null,
        correctValue: null,
        pt: null,
        ct: null,
        isAmmeter: null,
        isKeyMonitor: null,
        isCircuit: null,
        deptId: null,
        userId: null,
        publicShareType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 选中数组
      ids1: [],
      // 非单个禁用
      single1: true,
      // 非多个禁用
      multiple1: true,
      form1: {},
      // 查询参数
      queryParams1: {
        pageNum: 1,
        pageSize: 10,
        energyType: null,
      },
      open1: false,
      devicetotal: 0,
      title1: "",
      deviceloading: false,
      typeList: [],
      /////////
      // 建筑树列表
      buildOptions: [],
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 分项类型列表
      subentryOptions: [],
      // 业态类型列表
      businessOptions: [],
      // 二级展示节点
      twoKeys: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询计量设备信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.monitorType = 2;
      listShuiMeasurement(this.queryParams).then((response) => {
        this.list = response.data;
        // response.data.forEach(m=>{
        //     if(m.parentId===0){
        //       this.expandrowid.push(m.objid)
        //     }
        //   });
        //   response.data.forEach(m=>{
        //     if(m.parentId===2){
        //       this.expandrowid.push(m.objid)
        //     }
        //   })
        this.ShuiMeasurementList = this.handleTree(
          response.data,
          "objid",
          "parentId"
        );

        console.log("this.expandrowid", this.expandrowid);
        this.loading = false;
      });
    },
    /** 转换计量设备信息数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.objid,
        label: node.monitorName,
        children: node.children,
      };
    },
    /** 查询计量设备信息下拉树结构 */
    getTreeselect() {
      this.queryParams.monitorType = 2;
      listShuiMeasurement(this.queryParams).then((response) => {
        this.ShuiMeasurementOptions = [];
        const data = { objid: 0, monitorName: "顶级节点", children: [] };
        data.children = this.handleTree(response.data, "objid", "parentId");
        this.ShuiMeasurementOptions.push(data);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        objid: null,
        parentId: null,
        monitorId: null,
        monitorName: null,
        monitorAddr: null,
        monitorType: null,
        roomCode: null,
        roomName: null,
        physicalCode: null,
        monitorStatus: null,
        collectDeviceId: null,
        ancestors: null,
        grade: null,
        buildId: null,
        subentryId: null,
        businessId: null,
        meterTypeId: null,
        meterId: null,
        correctValue: null,
        pt: null,
        ct: null,
        isAmmeter: null,
        isKeyMonitor: null,
        isCircuit: null,
        deptId: null,
        userId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        publicShareType: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      this.getTreeselect();
      if (row != null && row.objid) {
        this.form.parentId = row.objid;
      } else {
        this.form.parentId = 0;
      }
      this.getBuildTreeSelect();
      this.getSubentrySelect();
      this.getBusinessSelect();
      this.open = true;
      this.title = "添加计量设备信息";
    },
    /** 展开/折叠操作 */
    toggleExpandAll() {
      this.refreshTable = false;
      this.isExpandAll = !this.isExpandAll;
      this.$nextTick(() => {
        this.refreshTable = true;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getTreeselect();
      if (row != null) {
        this.form.parentId = row.objid;

        const roleMenu = this.getAllTree(row.objid);
        getShuiMeasurement(row.objid).then((response) => {
          this.form = response.data;
          this.open = true;
          this.title = "修改计量设备信息";

          this.$nextTick(() => {
            roleMenu.then((res) => {
              let checkedKeys1 = response.data.buildId.split(",");
              checkedKeys1.forEach((v) => {
                this.$nextTick(() => {
                  this.$refs.build.setChecked(v, true, false);
                });
              });
              let checkedKeys2 = response.data.subentryId.split(",");
              checkedKeys2.forEach((v) => {
                this.$nextTick(() => {
                  this.$refs.subentry.setChecked(v, true, false);
                });
              });
              let checkedKeys3 = response.data.businessId.split(",");
              checkedKeys3.forEach((v) => {
                this.$nextTick(() => {
                  this.$refs.business.setChecked(v, true, false);
                });
              });
            });
          });
        });
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.monitorType = 2;
          this.form.buildId = this.getBuildAllCheckedKeys();
          this.form.subentryId = this.getSubentryAllCheckedKeys();
          this.form.businessId = this.getBusinessAllCheckedKeys();
          if (this.form.objid != null) {
            updateShuiMeasurement(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addShuiMeasurement(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal
        .confirm('是否确认删除计量设备信息编号为"' + row.objid + '"的数据项？')
        .then(function () {
          return delShuiMeasurement(row.objid);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    // 取消按钮-------------------------------------------
    /** 选择采集设备操作 */
    selectDevice() {
      this.reset();
      this.getDeviceList();
      this.open1 = true;
      this.title1 = "选择采集器";
    },
    cancel1() {
      this.open1 = false;
      this.reset1();
    },
    // 表单重置
    reset1() {
      this.form1 = {
        energyType: null,
      };
      this.resetForm("form1");
    },
    /** 搜索按钮操作 */
    handleQuery1() {
      this.queryParams1.pageNum = 1;
      this.getDeviceList();
    },
    /** 重置按钮操作 */
    resetQuery1() {
      this.resetForm("queryForm1");
      this.handleQuery1();
    },
    /** 查询采集设备信息列表 */
    getDeviceList() {
      this.deviceloading = true;
      listInfo(this.queryParams1).then((response) => {
        this.typeList = response.rows;
        this.devicetotal = response.total;
        this.deviceloading = false;
      });
    },
    // 多选框选中数据
    handleSelectionChange1(selection) {
      this.ids1 = selection.map((item) => item.collectDeviceId);
      this.single1 = selection.length !== 1;
      this.multiple1 = !selection.length;
    },
    //
    submitForm1() {
      this.form.collectDeviceId = this.ids1.join();
      this.cancel1();
    },
    ////////////////////////
    /** 查询建筑类型树结构 */
    getBuildTreeSelect() {
      buildTreeSelect().then((response) => {
        this.buildOptions = response.data;
      });
    },
    /** 查询分项类型树结构 */
    getSubentrySelect() {
      subentryTreeSelect().then((response) => {
        this.subentryOptions = response.data;
      });
    },
    /** 查询业态类型树结构 */
    getBusinessSelect() {
      businessTreeSelect().then((response) => {
        this.businessOptions = response.data;
      });
    },
    // 所有建筑节点数据
    getBuildAllCheckedKeys() {
      // 目前被选中的菜单节点
      let checkedKeys = this.$refs.build.getCheckedKeys();
      // 半选中的菜单节点
      let halfCheckedKeys = this.$refs.build.getHalfCheckedKeys();
      checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
      let checkedKeystr = checkedKeys.join();
      return checkedKeystr;
    },
    // 所有分项节点数据
    getSubentryAllCheckedKeys() {
      // 目前被选中的菜单节点
      let checkedKeys = this.$refs.subentry.getCheckedKeys();
      // 半选中的菜单节点
      let halfCheckedKeys = this.$refs.subentry.getHalfCheckedKeys();
      checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
      let checkedKeystr = checkedKeys.join();
      return checkedKeystr;
    },
    // 所有业态节点数据
    getBusinessAllCheckedKeys() {
      // 目前被选中的菜单节点
      let checkedKeys = this.$refs.business.getCheckedKeys();
      // 半选中的菜单节点
      let halfCheckedKeys = this.$refs.business.getHalfCheckedKeys();
      checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
      let checkedKeystr = checkedKeys.join();
      return checkedKeystr;
    },
    /** 查询计量设备信息下拉树结构 */
    getTreeselect() {
      this.queryParams.monitorType = 2;
      listShuiMeasurement(this.queryParams).then((response) => {
        this.ShuiMeasurementOptions = [];
        const data = { objid: 0, monitorName: "顶级节点", children: [] };
        data.children = this.handleTree(response.data, "objid", "parentId");
        this.ShuiMeasurementOptions.push(data);
      });
    },
    /** 根据ID查询菜单树结构 */
    getAllTree(objid) {
      return treeselect(objid).then((response) => {
        this.buildOptions = response.builds;
        this.subentryOptions = response.subentrys;
        this.businessOptions = response.business;
        return response;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('energy/ShuiMeasurement/export', {
        ...this.queryParams
      }, `电计量设备信息_${new Date().getTime()}.xlsx`)
    }
  },
};
</script>
