<template>
  <div class="app-container">
    <!-- 面包屑 -->
    <el-breadcrumb separator="/" style="margin-bottom: 20px">
      <el-breadcrumb-item
        v-for="(item, index) in routeList"
        :key="item + index"
        :to="{ path: item.path }"
        >{{ item.routeName }}</el-breadcrumb-item
      >
    </el-breadcrumb>
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="水闸名称" prop="wagaName">
        <el-input
          v-model="queryParams.data.wagaName"
          placeholder="请输入水闸名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        >
          <el-button
            type="primary"
            slot="append"
            icon="el-icon-search"
            size="small"
            @click="handleQuery"
          ></el-button>
        </el-input>
      </el-form-item>
      <el-form-item label="行政区划" prop="adcd">
        <el-cascader
          :options="areasOptions"
          v-model="queryParams.data.adcd"
          :props="areasOptionProps"
          placeholder="请选择行政区划"
          clearable
          size="small"
          @change="handleQuery"
        >
        </el-cascader>
      </el-form-item>
      <el-form-item label="水闸类型" prop="wagaType">
        <el-select
          v-model="queryParams.data.wagaType"
          placeholder="请选择水闸类型"
          clearable
          size="small"
          @change="handleQuery"
        >
          <el-option
            v-for="dict in wagaTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <!-- <el-button
          type="cyan"
          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"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['yg:sluiceInfo:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['yg:sluiceInfo:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['yg:sluiceInfo:remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="sluiceInfoList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" fixed />
      <el-table-column
        label="序号"
        type="index"
        width="50"
        align="center"
        fixed
      />

      <el-table-column
        label="水闸名称"
        align="center"
        prop="wagaName"
        min-width="120"
      />
      <el-table-column
        label="行政区划"
        align="center"
        prop="adcd"
        :formatter="formatAdcd"
        min-width="120"
      />
      <el-table-column
        label="水闸编码"
        align="center"
        prop="wagaCode"
        min-width="120"
      />
      <el-table-column
        label="所在位置"
        align="center"
        prop="wagaLoc"
        :formatter="wagaLocFormat"
        min-width="120"
      />
      <el-table-column
        label="标绘水闸"
        align="center"
        prop="plottingSluice"
        min-width="120"
      />
      <el-table-column
        label="验收情况"
        align="center"
        prop="acceptanceStatus"
        :formatter="acceptanceStatusFormat"
        min-width="120"
      />
      <el-table-column
        label="除险加固情况"
        align="center"
        prop="riskEliminationStatus"
        :formatter="riskEliminationStatusFormat"
        min-width="120"
      />
      <el-table-column
        label="是否为枢纽工程"
        align="center"
        prop="isHubProject"
        :formatter="isHubProjectFormat"
        min-width="120"
      />
      <el-table-column
        label="是否为闸站工程"
        align="center"
        prop="isGateStation"
        :formatter="isGateStationFormat"
        min-width="120"
      />
      <el-table-column
        label="是否为套闸工程"
        align="center"
        prop="isSetGateProject"
        :formatter="isSetGateProjectFormat"
        min-width="120"
      />
      <el-table-column
        label="水闸类型"
        align="center"
        prop="wagaType"
        :formatter="wagaTypeFormat"
        min-width="120"
      />
      <!-- <el-table-column
        label="设计过闸流量"
        align="center"
        prop="dslcfl"
        min-width="120"
      />
      <el-table-column
        label="校核过闸流量"
        align="center"
        prop="chlcfl"
        min-width="120"
      />
      <el-table-column
        label="工程规模"
        align="center"
        prop="engScal"
        :formatter="engScalFormat"
        min-width="120"
      />
      <el-table-column
        label="建筑物级别"
        align="center"
        prop="mainBuildGrad"
        :formatter="mainBuildGradFormat"
        min-width="120"
      />
      <el-table-column
        label="设计标准[重现期]"
        align="center"
        prop="dsrcin"
        min-width="120"
      />
      <el-table-column
        label="校核标准[重现期]"
        align="center"
        prop="chrcin"
        min-width="120"
      />
      <el-table-column
        label="历史最大过闸流量(m³/s)"
        align="center"
        prop="historicalMaximumGate"
        min-width="180"
      />
      <el-table-column
        label="历史最大过闸流量日期"
        align="center"
        prop="historicalMaximumDate"
        min-width="150"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.historicalMaximumDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="设计地震烈度"
        align="center"
        prop="designSeismicIntensity"
        min-width="120"
      />
      <el-table-column
        label="闸孔数量"
        align="center"
        prop="gaorNum"
        min-width="120"
      />
      <el-table-column
        label="闸孔总净宽(m)"
        align="center"
        prop="gaorTotNetWid"
        min-width="120"
      />
      <el-table-column
        label="闸门型式"
        align="center"
        prop="gtst"
        :formatter="gtstFormat"
        min-width="120"
      />
      <el-table-column
        label="启闭机数量"
        align="center"
        prop="hoistsNumber"
        min-width="120"
      />
      <el-table-column
        label="观测项目"
        align="center"
        prop="observationProject"
        :formatter="observationProjectFormat"
        min-width="120"
      />
      <el-table-column
        label="闸室结构"
        align="center"
        prop="lockChamberStructure"
        :formatter="lockChamberStructureFormat"
        min-width="120"
      />
      <el-table-column
        label="启闭机形式"
        align="center"
        prop="machineForm"
        :formatter="machineFormFormat"
        min-width="120"
      />
      <el-table-column
        label="消能方式"
        align="center"
        prop="endsst"
        :formatter="endsstFormat"
        min-width="120"
      />
      <el-table-column
        label="自动化控制"
        align="center"
        prop="automationControl"
        min-width="120"
      />

      <el-table-column
        label="关联字段1"
        align="center"
        prop="relation"
        min-width="120"
      />
      <el-table-column
        label="建成时间"
        align="center"
        prop="compDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.compDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="竣工验收时间"
        align="center"
        prop="completionAcceptanceTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.completionAcceptanceTime, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="最近除险加固完工时间"
        align="center"
        prop="recentCompletionTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.recentCompletionTime, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="枢纽建筑物"
        align="center"
        prop="hubBuildings"
        :formatter="hubBuildingsFormat"
        min-width="120"
      />
      <el-table-column
        label="副闸闸孔数量"
        align="center"
        prop="auxiliaryGateHoles"
        min-width="120"
      />
      <el-table-column
        label="副闸闸孔总净宽"
        align="center"
        prop="auxiliaryGateHolesWidth"
        min-width="120"
      /> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
        width="180"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['yg:sluiceInfo:edit']"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['yg:sluiceInfo:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改水闸工程基础信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-row :gutter="15">
        <el-form
          ref="form"
          :model="form"
          :rules="rules"
          label-width="110px"
          label-position="top"
        >
          <el-col :span="8">
            <el-form-item label="水闸名称" prop="wagaName">
              <el-input v-model="form.wagaName" placeholder="请输入水闸名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="行政区划" prop="adcd">
              <el-cascader
                :options="areasOptions"
                v-model="form.adcd"
                :props="areasOptionProps"
                placeholder="请选择行政区划"
                clearable
                size="small"
                style="width: 100%"
                @change="handleChange"
              >
              </el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="水闸编码" prop="wagaCode">
              <el-input v-model="form.wagaCode" placeholder="请输入水闸编码" />
            </el-form-item>
          </el-col>
          <!-- <el-row :gutter="15">
            <el-col :span="24"> -->
          <el-col :span="8">
            <el-form-item label="所在位置（可多选）" prop="wagaLoc">
              <!-- <el-input v-model="form.wagaLoc"  placeholder="请输入所在位置" /> -->
              <el-select
                v-model="form.wagaLoc"
                multiple
                collapse-tags
                placeholder="请选择所在位置"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in wagaLocOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="标绘水闸" prop="plottingSluice">
              <el-input
                v-model="form.plottingSluice"
                placeholder="请输入标绘水闸"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="验收情况">
              <el-radio-group v-model="form.acceptanceStatus">
                <el-radio
                  v-for="dict in acceptanceStatusOptions"
                  :key="dict.dictValue + '验收情况'"
                  :label="dict.dictValue"
                  >{{ dict.dictLabel }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
          <!-- </el-col>
          </el-row> -->
          <el-col :span="8" v-if="form.acceptanceStatus == 0">
            <el-form-item label="建成时间" prop="compDate">
              <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="form.compDate"
                type="month"
                format="yyyy-MM"
                value-format="yyyy-MM-dd"
                placeholder="选择建成时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="form.acceptanceStatus == 1">
            <el-form-item label="竣工验收时间" prop="completionAcceptanceTime">
              <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="form.completionAcceptanceTime"
                type="month"
                format="yyyy-MM"
                value-format="yyyy-MM-dd"
                placeholder="选择竣工验收时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="除险加固情况">
              <el-radio-group v-model="form.riskEliminationStatus">
                <el-radio
                  v-for="dict in riskEliminationStatusOptions"
                  :key="dict.dictValue + '除险加固情况'"
                  :label="dict.dictValue"
                  >{{ dict.dictLabel }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="form.riskEliminationStatus == 1">
            <el-form-item
              label="最近除险加固完工时间"
              prop="recentCompletionTime"
            >
              <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="form.recentCompletionTime"
                type="month"
                format="yyyy-MM"
                value-format="yyyy-MM-dd"
                placeholder="选择最近除险加固完工时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="是否为枢纽工程" prop="isHubProject">
              <el-radio-group v-model="form.isHubProject">
                <el-radio
                  v-for="dict in isHubProjectOptions"
                  :key="dict.dictValue + '枢纽工程'"
                  :label="dict.dictValue"
                  >{{ dict.dictLabel }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="form.isHubProject == 1">
            <el-form-item label="枢纽建筑物（可多选）" prop="hubBuildings">
              <el-select
                v-model="form.hubBuildings"
                multiple
                collapse-tags
                placeholder="请选择枢纽建筑物"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in hubBuildingsOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否为闸站工程" prop="isGateStation">
              <el-radio-group v-model="form.isGateStation">
                <el-radio
                  v-for="dict in isGateStationOptions"
                  :key="dict.dictValue + '闸站工程'"
                  :label="dict.dictValue"
                  >{{ dict.dictLabel }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否为套闸工程" prop="isSetGateProject">
              <el-radio-group v-model="form.isSetGateProject">
                <el-radio
                  v-for="dict in isSetGateProjectOptions"
                  :key="dict.dictValue + '套闸工程'"
                  :label="dict.dictValue"
                  >{{ dict.dictLabel }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="form.isSetGateProject == 1">
            <el-form-item label="副闸闸孔数量（孔）" prop="auxiliaryGateHoles">
              <el-input
                v-model="form.auxiliaryGateHoles"
                placeholder="请输入副闸闸孔数量"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="form.isSetGateProject == 1">
            <el-form-item
              label="副闸闸孔总净宽（m）"
              prop="auxiliaryGateHolesWidth"
            >
              <el-input
                v-model="form.auxiliaryGateHolesWidth"
                placeholder="请输入副闸闸孔总净宽"
              />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="水闸类型（可多选）" prop="wagaType">
              <el-select
                v-model="form.wagaType"
                multiple
                collapse-tags
                placeholder="请选择水闸类型"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in wagaTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设计过闸流量" prop="dslcfl">
              <el-input
                v-model="form.dslcfl"
                placeholder="请输入设计过闸流量"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="校核过闸流量" prop="chlcfl">
              <el-input
                v-model="form.chlcfl"
                placeholder="请输入校核过闸流量"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工程规模" prop="engScal">
              <el-select
                v-model="form.engScal"
                placeholder="请选择工程规模"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in engScalOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="建筑物级别" prop="mainBuildGrad">
              <el-select
                v-model="form.mainBuildGrad"
                placeholder="请选择建筑物级别"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in mainBuildGradOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设计标准[重现期]" prop="dsrcin">
              <el-input
                v-model="form.dsrcin"
                placeholder="请输入设计标准[重现期]"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="校核标准[重现期]" prop="chrcin">
              <el-input
                v-model="form.chrcin"
                placeholder="请输入校核标准[重现期]"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="历史最大过闸流量(m³/s)"
              prop="historicalMaximumGate"
            >
              <el-input
                v-model="form.historicalMaximumGate"
                placeholder="请输入历史最大过闸流量(m³/s)"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="历史最大过闸流量日期"
              prop="historicalMaximumDate"
            >
              <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="form.historicalMaximumDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择历史最大过闸流量日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设计地震烈度" prop="designSeismicIntensity">
              <el-input
                v-model="form.designSeismicIntensity"
                placeholder="请输入设计地震烈度"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="闸孔数量" prop="gaorNum">
              <el-input v-model="form.gaorNum" placeholder="请输入闸孔数量" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="闸孔总净宽(m)" prop="gaorTotNetWid">
              <el-input
                v-model="form.gaorTotNetWid"
                placeholder="请输入闸孔总净宽(m)"
              />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="启闭机数量" prop="hoistsNumber">
              <el-input
                v-model="form.hoistsNumber"
                placeholder="请输入启闭机数量"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="观测项目（可多选）" prop="observationProject">
              <el-select
                v-model="form.observationProject"
                multiple
                collapse-tags
                placeholder="请选择观测项目"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in observationProjectOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="闸室结构（可多选）"
              prop="lockChamberStructure"
            >
              <el-select
                v-model="form.lockChamberStructure"
                multiple
                collapse-tags
                placeholder="请选择闸室结构"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in lockChamberStructureOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="闸门型式（可多选）" prop="gtst">
              <el-checkbox-group v-model="form.gtst">
                <el-checkbox
                  v-for="dict in gtstOptions"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                >
                  {{ dict.dictLabel }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="启闭机形式（可多选）" prop="machineForm">
              <el-checkbox-group v-model="form.machineForm">
                <el-checkbox
                  v-for="dict in machineFormOptions"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                >
                  {{ dict.dictLabel }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="消能方式（可多选）" prop="endsst">
              <el-checkbox-group v-model="form.endsst">
                <el-checkbox
                  v-for="dict in endsstOptions"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                >
                  {{ dict.dictLabel }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="自动化控制（可多选）" prop="automationControl">
              <el-checkbox-group v-model="form.automationControl">
                <el-checkbox
                  v-for="dict in automationControlOptions"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                >
                  {{ dict.dictLabel }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="关联字段1" prop="relation">
              <el-input v-model="form.relation" placeholder="请输入关联字段1" />
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listSluiceInfo,
  getSluiceInfo,
  delSluiceInfo,
  addSluiceInfo,
  updateSluiceInfo,
  exportSluiceInfo,
} from "@/api/yg/sluiceInfo";
import { getAreasData } from "@/api/areas/index";
import { regionData, codeToText, TextToCode } from "element-china-area-data";

export default {
  name: "SluiceInfo",
  data() {
    return {
      areasOptionProps: {
        emitPath: false,
        checkStrictly: true, //选择任意一级
      },
      areasOptions: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 水闸工程基础信息表格数据
      sluiceInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 所在位置字典
      wagaLocOptions: [],
      // 验收情况字典
      acceptanceStatusOptions: [],
      // 除险加固情况字典
      riskEliminationStatusOptions: [],
      // 是否为枢纽工程字典
      isHubProjectOptions: [],
      // 是否为闸站工程字典
      isGateStationOptions: [],
      // 是否为套闸工程字典
      isSetGateProjectOptions: [],
      // 水闸类型字典
      wagaTypeOptions: [],
      // 工程规模字典
      engScalOptions: [],
      // 建筑物级别字典
      mainBuildGradOptions: [],
      // 闸门型式字典
      gtstOptions: [],
      // 观测项目字典
      observationProjectOptions: [],
      // 闸室结构字典
      lockChamberStructureOptions: [],
      // 启闭机形式字典
      machineFormOptions: [],
      // 消能方式字典
      endsstOptions: [],
      // 自动化控制字典
      automationControlOptions: [],
      // 枢纽建筑物字典
      hubBuildingsOptions: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ids: null,
        data: {
          wagaName: null,
          adcd: null,
          wagaCode: null,
          wagaLoc: null,
          plottingSluice: null,
          acceptanceStatus: null,
          riskEliminationStatus: null,
          isHubProject: null,
          isGateStation: null,
          isSetGateProject: null,
          wagaType: null,
          dslcfl: null,
          chlcfl: null,
          engScal: null,
          mainBuildGrad: null,
          dsrcin: null,
          chrcin: null,
          historicalMaximumGate: null,
          historicalMaximumDate: null,
          designSeismicIntensity: null,
          gaorNum: null,
          gaorTotNetWid: null,
          gtst: null,
          hoistsNumber: null,
          observationProject: null,
          lockChamberStructure: null,
          machineForm: null,
          endsst: null,
          automationControl: null,
          createUid: null,
          updateUid: null,
          createTime: null,
          updateTime: null,
          proNo: null,
          proCode: null,
          relation: null,
          compDate: null,
          completionAcceptanceTime: null,
          recentCompletionTime: null,
          hubBuildings: null,
          auxiliaryGateHoles: null,
          auxiliaryGateHolesWidth: null,
          exprDate: null,
        },
        // 排序方式
        params: {
          // 按哪个字段排序
          orderBy: "create_time",
          // desc降序，升序asc
          sortBy: "desc",
        },
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        wagaName: [
          { required: true, message: "请输入水闸名称", trigger: "blur" },
        ],
        wagaCode: [
          { required: true, message: "请输入水闸编码", trigger: "blur" },
        ],
      },
      // 面包屑，路由信息
      routeList: [
        {
          path: "/engineeringCondition/baseInfo",
          routeName: "水闸基本信息列表",
        },
      ],
    };
  },
  created() {
    this.getTreeData();
    this.getList();
    this.getDicts("location").then((response) => {
      this.wagaLocOptions = response.data;
    });
    this.getDicts("completion_acceptance_status").then((response) => {
      this.acceptanceStatusOptions = response.data;
    });
    this.getDicts("reinforcement_situation").then((response) => {
      this.riskEliminationStatusOptions = response.data;
    });
    this.getDicts("whether").then((response) => {
      this.isHubProjectOptions = response.data;
    });
    this.getDicts("whether").then((response) => {
      this.isGateStationOptions = response.data;
    });
    this.getDicts("whether").then((response) => {
      this.isSetGateProjectOptions = response.data;
    });
    this.getDicts("sluice_type").then((response) => {
      this.wagaTypeOptions = response.data;
    });
    this.getDicts("engineering_scale").then((response) => {
      this.engScalOptions = response.data;
    });
    this.getDicts("building_level").then((response) => {
      this.mainBuildGradOptions = response.data;
    });
    this.getDicts("gate_type").then((response) => {
      this.gtstOptions = response.data;
    });
    this.getDicts("observation_project").then((response) => {
      this.observationProjectOptions = response.data;
    });
    this.getDicts("Lock_chamber_structure").then((response) => {
      this.lockChamberStructureOptions = response.data;
    });
    this.getDicts("machine_form").then((response) => {
      this.machineFormOptions = response.data;
    });
    this.getDicts("energy_dissipation_method").then((response) => {
      this.endsstOptions = response.data;
    });
    this.getDicts("automation_control").then((response) => {
      this.automationControlOptions = response.data;
    });
    this.getDicts("Hub_buildings").then((response) => {
      this.hubBuildingsOptions = response.data;
    });
  },
  methods: {
    formatAdcd(row) {
      if (row.adcd) {
        let provinceCode = row.adcd.slice(0, 2);
        let cityCode = row.adcd.slice(2, 4);
        let areaCode = row.adcd.slice(4, 6);
        if (areaCode != "00") {
          return (
            codeToText[provinceCode] +
            "-" +
            codeToText[provinceCode + cityCode] +
            "-" +
            codeToText[provinceCode + cityCode + areaCode]
          );
        } else if (cityCode != "00") {
          return (
            codeToText[provinceCode] + "-" + codeToText[provinceCode + cityCode]
          );
        } else {
          return codeToText[provinceCode];
        }
      }
    },
    // 获取某一项的所有父节点的label值 list为树形结构的数据 id为回显节点的标识
    getParentsByValue(list, value) {
      for (let i in list) {
        if (list[i].value == value) {
          //这里的list[i].value中的value根据你的需求可进行改变
          //查询到就返回该数组对象的value
          return [list[i].value];
        }
        if (list[i].children) {
          let node = this.getParentsByValue(list[i].children, value);
          if (node !== undefined) {
            //查询到把父节把父节点加到数组前面
            node.unshift(list[i].value);
            console.log("node", node);
            return node;
          }
        }
      }
    },

    getTreeData() {
      getAreasData().then((items) => {
        // console.log("getAreasData", items.data);
        let res = [];
        let getChildren = (res, pid) => {
          for (const i of items.data) {
            if (i.parentid === pid) {
              const newItem = {
                label: i.name,
                value: i.id,
              };
              if (i.layer != 3) newItem.children = [];
              res.push(newItem);
              getChildren(newItem.children, newItem.value);
            }
          }
        };
        getChildren(res, items.data[0].parentid);
        console.log(66666666666, res);
        this.areasOptions = res;
        // return res;
      });
    },
    handleChange(value) {
      //value为省市区code数组
      if (value) {
        console.log("value", value);
        var provinceCode = codeToText[value[0]]; //code转为省
        var cityCode = codeToText[value[1]]; //市
        var orgion = codeToText[value[2]]; //区
        console.log(44444444, provinceCode, cityCode, orgion);
        // this.baseMsg.adcd = value[value.length - 1];
        console.log("this.form.adcd", this.form.adcd);
      }
    },
    /** 查询水闸工程基础信息列表 */
    getList() {
      this.loading = true;
      listSluiceInfo(this.queryParams).then((response) => {
        this.sluiceInfoList = response.records;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 所在位置字典翻译
    wagaLocFormat(row, column) {
      let res = "";
      let arr = row.wagaLoc ? JSON.parse(row.wagaLoc) : [];
      arr.forEach((item) => {
        res = res + "+" + this.selectDictLabel(this.wagaLocOptions, item);
      });
      return res.slice(1);
    },
    // 验收情况字典翻译
    acceptanceStatusFormat(row, column) {
      return this.selectDictLabel(
        this.acceptanceStatusOptions,
        row.acceptanceStatus
      );
    },
    // 除险加固情况字典翻译
    riskEliminationStatusFormat(row, column) {
      return this.selectDictLabel(
        this.riskEliminationStatusOptions,
        row.riskEliminationStatus
      );
    },
    // 是否为枢纽工程字典翻译
    isHubProjectFormat(row, column) {
      return this.selectDictLabel(this.isHubProjectOptions, row.isHubProject);
    },
    // 是否为闸站工程字典翻译
    isGateStationFormat(row, column) {
      return this.selectDictLabel(this.isGateStationOptions, row.isGateStation);
    },
    // 是否为套闸工程字典翻译
    isSetGateProjectFormat(row, column) {
      return this.selectDictLabel(
        this.isSetGateProjectOptions,
        row.isSetGateProject
      );
    },
    // 水闸类型字典翻译
    wagaTypeFormat(row, column) {
      return this.selectDictLabel(this.wagaTypeOptions, row.wagaType);
    },
    // 工程规模字典翻译
    engScalFormat(row, column) {
      return this.selectDictLabel(this.engScalOptions, row.engScal);
    },
    // 建筑物级别字典翻译
    mainBuildGradFormat(row, column) {
      return this.selectDictLabel(this.mainBuildGradOptions, row.mainBuildGrad);
    },
    // 闸门型式字典翻译
    gtstFormat(row, column) {
      return this.selectDictLabel(this.gtstOptions, row.gtst);
    },
    // 观测项目字典翻译
    observationProjectFormat(row, column) {
      return this.selectDictLabel(
        this.observationProjectOptions,
        row.observationProject
      );
    },
    // 闸室结构字典翻译
    lockChamberStructureFormat(row, column) {
      return this.selectDictLabel(
        this.lockChamberStructureOptions,
        row.lockChamberStructure
      );
    },
    // 枢纽建筑物字典翻译
    hubBuildingsFormat(row, column) {
      return this.selectDictLabel(this.hubBuildingsOptions, row.hubBuildings);
    },
    // 启闭机形式字典翻译
    machineFormFormat(row, column) {
      return this.selectDictLabel(this.machineFormOptions, row.machineForm);
    },
    // 消能方式字典翻译
    endsstFormat(row, column) {
      return this.selectDictLabel(this.endsstOptions, row.endsst);
    },
    // 自动化控制字典翻译
    automationControlFormat(row, column) {
      return this.selectDictLabels(
        this.automationControlOptions,
        row.automationControl
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        wagaName: null,
        adcd: null,
        wagaCode: null,
        wagaLoc: [],
        plottingSluice: null,
        acceptanceStatus: null,
        riskEliminationStatus: null,
        isHubProject: null,
        isGateStation: null,
        isSetGateProject: null,
        wagaType: [],
        dslcfl: null,
        chlcfl: null,
        engScal: null,
        mainBuildGrad: null,
        dsrcin: null,
        chrcin: null,
        historicalMaximumGate: null,
        historicalMaximumDate: null,
        designSeismicIntensity: null,
        gaorNum: null,
        gaorTotNetWid: null,
        gtst: [],
        hoistsNumber: null,
        observationProject: [],
        lockChamberStructure: [],
        machineForm: [],
        endsst: [],
        automationControl: [],
        createUid: null,
        updateUid: null,
        createTime: null,
        updateTime: null,
        proNo: null,
        proCode: null,
        relation: null,
        compDate: null,
        completionAcceptanceTime: null,
        recentCompletionTime: null,
        hubBuildings: null,
        auxiliaryGateHoles: null,
        auxiliaryGateHolesWidth: null,
      };
      this.resetForm("form");
    },
    // 查询表单重置
    resetQueryForm() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        data: {
          id: null,
          wagaName: null,
          adcd: null,
          wagaCode: null,
          wagaLoc: null,
          plottingSluice: null,
          acceptanceStatus: null,
          riskEliminationStatus: null,
          isHubProject: null,
          isGateStation: null,
          isSetGateProject: null,
          wagaType: null,
          dslcfl: null,
          chlcfl: null,
          engScal: null,
          mainBuildGrad: null,
          dsrcin: null,
          chrcin: null,
          historicalMaximumGate: null,
          historicalMaximumDate: null,
          designSeismicIntensity: null,
          gaorNum: null,
          gaorTotNetWid: null,
          gtst: null,
          hoistsNumber: null,
          observationProject: null,
          lockChamberStructure: null,
          machineForm: null,
          endsst: null,
          automationControl: null,
          createUid: null,
          updateUid: null,
          createTime: null,
          updateTime: null,
          proNo: null,
          proCode: null,
          relation: null,
          compDate: null,
          completionAcceptanceTime: null,
          recentCompletionTime: null,
          hubBuildings: null,
          auxiliaryGateHoles: null,
          auxiliaryGateHolesWidth: null,
          exprDate: null,
        },
        params: {
          // 按哪个字段排序
          orderBy: "create_time",
          // desc降序，升序asc
          sortBy: "desc",
        },
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetQueryForm();
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加水闸工程基础信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      this.routeList.push({
        path: "/sluice/engineeringCondition/sluiceBaseInfo/options",
        routeName: "水闸基本信息",
        isEdit: true,
      });

      // 存储面包屑信息
      this.$store.commit("setRouteList", JSON.stringify(this.routeList));
      // 跳转到选项卡页面
      this.$router.push({
        path:
          "/sluice/engineeringCondition/sluiceBaseInfo/options?baseDataId=" +
          id,
      });
      // getSluiceInfo(id).then((response) => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改水闸工程基础信息";
      // });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          // 下拉框
          this.form.wagaLoc = JSON.stringify(this.form.wagaLoc);
          this.form.wagaType = JSON.stringify(this.form.wagaType);
          this.form.hubBuildings = JSON.stringify(this.form.hubBuildings);

          this.form.observationProject = JSON.stringify(
            this.form.observationProject
          );
          this.form.lockChamberStructure = JSON.stringify(
            this.form.lockChamberStructure
          );
          // 多选框
          this.form.gtst = JSON.stringify(this.form.gtst);
          this.form.machineForm = JSON.stringify(this.form.machineForm);
          this.form.endsst = JSON.stringify(this.form.endsst);
          this.form.automationControl = JSON.stringify(
            this.form.automationControl
          );

          if (this.form.id != null) {
            updateSluiceInfo(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addSluiceInfo(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      if (ids) {
        this.$confirm("是否删除选中的数据？", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(function () {
            return delSluiceInfo(ids);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("删除成功");
          })
          .catch(function () {});
      } else {
        this.$message.warning("请选择要删除的数据！！");
      }
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/css/dialog.scss";
::v-deep {
  .el-dialog {
    margin-top: 2vh !important;
  }
}
</style>
