<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="dikeName">
        <el-input
          v-model="queryParams.data.dikeName"
          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="dikeType">
        <el-select
          v-model="queryParams.data.dikeType"
          placeholder="请选择堤防类型"
          clearable
          size="small"
          @change="handleQuery"
        >
          <el-option
            v-for="dict in embankmentTypeOptions"
            :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:dikeInfo: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:dikeInfo: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:dikeInfo:remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="dikeInfoList"
      @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="dikeName"
        min-width="120"
      />
      <!-- <el-table-column
        label="行政区划"
        align="center"
        prop="adcd"
        :formatter="formatAdcd"
        min-width="120"
      /> -->

      <el-table-column
        label="堤防编码"
        align="center"
        prop="dikeCode"
        min-width="120"
      />
      <el-table-column
        label="标绘堤防"
        align="center"
        prop="plotEmbankments"
        min-width="120"
      />
      <el-table-column
        label="起点行政区划"
        align="center"
        prop="adcdStart"
        min-width="120"
      >
        <template slot-scope="scope">
          <span>{{ formatAdcd(scope.row.adcdStart) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="终点行政区划"
        align="center"
        prop="adcdEnd"
        min-width="120"
      >
        <template slot-scope="scope">
          <span>{{ formatAdcd(scope.row.adcdEnd) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="起点桩号"
        align="center"
        prop="dikeStartNum"
        min-width="120"
      />
      <el-table-column
        label="终点桩号"
        align="center"
        prop="dikeEndNum"
        min-width="120"
      />
      <el-table-column
        label="堤防类型"
        align="center"
        prop="dikeType"
        :formatter="embankmentTypeFormat"
        min-width="120"
      />
      <!-- <el-table-column
        label="所在河流"
        align="center"
        prop="riverLocation"
        min-width="120"
      />
      <el-table-column
        label="河流岸别"
        align="center"
        prop="riversideClassification"
        :formatter="riversideClassificationFormat"
        min-width="120"
      />
      <el-table-column
        label="所在湖泊名称"
        align="center"
        prop="lakeName"
        min-width="120"
      />
      <el-table-column
        label="所在海岸名称"
        align="center"
        prop="coastlineName"
        min-width="120"
      />
      <el-table-column
        label="是否为蓄滞洪区堤防"
        align="center"
        prop="isFloodStorageDetention"
        :formatter="isFloodStorageDetentionFormat"
        min-width="150"
      />
      <el-table-column
        label="所在蓄滞洪区名称"
        align="center"
        prop="storageDetentionAreaName"
        min-width="130"
      />
      <el-table-column
        label="堤防蓄滞洪区段起点桩号"
        align="center"
        prop="areaStartingStationNumber"
        min-width="170"
      />
      <el-table-column
        label="堤防蓄滞洪区段终点桩号"
        align="center"
        prop="areaEndStationNumber"
        min-width="170"
      />
      <el-table-column
        label="堤防蓄滞洪区段总长度(m)"
        align="center"
        prop="totalLengthFloodStorage"
        min-width="180"
      />
      <el-table-column
        label="蓄滞洪区特殊情况说明"
        align="center"
        prop="floodStorageDetentionAreasExplanation"
        min-width="150"
      />
      <el-table-column
        label="堤防跨界情况"
        align="center"
        prop="crossBorderSituation"
        :formatter="crossBorderSituationFormat"
        min-width="120"
      />
      <el-table-column
        label="堤防型式"
        align="center"
        prop="dikePatt"
        :formatter="embankmentTyperFormat"
        min-width="120"
      />
      <el-table-column
        label="建成时间"
        align="center"
        prop="compDate"
        min-width="120"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.compDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="最近达标加固完工状态"
        align="center"
        prop="recentComplianceReinforcementStatus"
        :formatter="recentComplianceReinforcementStatusFormat"
        min-width="150"
      />
      <el-table-column
        label="最近达标加固完成时间"
        align="center"
        prop="recentComplianceReinforcementTime"
        min-width="150"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(
              scope.row.recentComplianceReinforcementTime,
              "{y}-{m}-{d}"
            )
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="工程任务"
        align="center"
        prop="engTask"
        :formatter="engineeringTasksFormat"
        min-width="120"
      />
      <el-table-column
        label="堤防级别"
        align="center"
        prop="dikeGrad"
        :formatter="embankmentLevelFormat"
        min-width="120"
      />
      <el-table-column
        label="设计防洪（潮）标准[重现期]"
        align="center"
        prop="designFloodControl"
        min-width="120"
      />
      <el-table-column
        label="堤防长度(m)"
        align="center"
        prop="dikeLen"
        min-width="120"
      />
      <el-table-column
        label="规划防洪（潮）标准[重现期]"
        align="center"
        prop="planningFloodControl"
        min-width="120"
      />
      <el-table-column
        label="达到规划标准的堤防长度(m)"
        align="center"
        prop="embankmentLengthPlanningStandards"
        min-width="190"
      />
      <el-table-column
        label="保护人口(单位：万人)"
        align="center"
        prop="populationProtection"
        min-width="120"
      />
      <el-table-column
        label="保护农田(单位：万亩)"
        align="center"
        prop="protectingFarmland"
        min-width="120"
      />
      <el-table-column
        label="重要基础设施"
        align="center"
        prop="criticalInfrastructure"
        min-width="120"
      /> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="180"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['yg:dikeInfo:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['yg:dikeInfo: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="80px"
          label-position="top"
        >
          <el-col :span="8">
            <el-form-item label="堤防名称" prop="dikeName">
              <el-input v-model="form.dikeName" 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="dikeCode">
              <el-input v-model="form.dikeCode" placeholder="请输入堤防编码" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="标绘堤防" prop="plotEmbankments">
              <!-- <el-input
                v-model="form.plotEmbankments"
                placeholder="请输入标绘堤防"
              /> -->
              <el-button type="primary" style="width: 100px">标绘</el-button>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="起点行政区划" prop="adcdStart">
              <!-- <el-input
                v-model="form.adcdStart"
                placeholder="请输入起点行政区划"
              /> -->
              <el-cascader
                :options="areasOptions"
                v-model="form.adcdStart"
                :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="adcdEnd">
              <!-- <el-input
                v-model="form.adcdEnd"
                placeholder="请输入终点行政区划"
              /> -->
              <el-cascader
                :options="areasOptions"
                v-model="form.adcdEnd"
                :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="dikeStartNum">
              <el-input
                v-model="form.dikeStartNum"
                placeholder="请输入起点桩号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="终点桩号" prop="dikeEndNum">
              <el-input
                v-model="form.dikeEndNum"
                placeholder="请输入终点桩号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="堤防类型" prop="dikeType">
              <el-radio-group v-model="form.dikeType">
                <el-radio
                  v-for="dict in embankmentTypeOptions"
                  :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.dikeType == 0">
            <el-form-item label="所在河流" prop="riverLocation">
              <!-- <el-input
                v-model="form.riverLocation"
                placeholder="请输入所在河流"
              /> -->
              <el-select
                v-model="form.riverLocation"
                placeholder="请选择所在河流"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in 0"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="form.dikeType == 0">
            <el-form-item label="河流岸别">
              <el-radio-group v-model="form.riversideClassification">
                <el-radio
                  v-for="dict in riversideClassificationOptions"
                  :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.dikeType == 1">
            <el-form-item label="所在湖泊名称" prop="lakeName">
              <el-input
                v-model="form.lakeName"
                placeholder="请输入所在湖泊名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="form.dikeType == 2">
            <el-form-item label="所在海岸名称" prop="coastlineName">
              <el-input
                v-model="form.coastlineName"
                placeholder="请输入所在海岸名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="form.dikeType != 2">
            <el-form-item label="是否为蓄滞洪区堤防">
              <el-radio-group v-model="form.isFloodStorageDetention">
                <el-radio
                  v-for="dict in isFloodStorageDetentionOptions"
                  :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.dikeType != 2 && form.isFloodStorageDetention == 1"
          >
            <el-form-item
              label="所在蓄滞洪区名称"
              prop="storageDetentionAreaName"
            >
              <el-input
                v-model="form.storageDetentionAreaName"
                placeholder="请输入所在蓄滞洪区名称"
              />
            </el-form-item>
          </el-col>
          <el-col
            :span="8"
            v-if="form.dikeType != 2 && form.isFloodStorageDetention == 1"
          >
            <el-form-item
              label="堤防蓄滞洪区段起点桩号"
              prop="areaStartingStationNumber"
            >
              <el-input
                v-model="form.areaStartingStationNumber"
                placeholder="请输入堤防蓄滞洪区段起点桩号"
              />
            </el-form-item>
          </el-col>
          <el-col
            :span="8"
            v-if="form.dikeType != 2 && form.isFloodStorageDetention == 1"
          >
            <el-form-item
              label="堤防蓄滞洪区段终点桩号"
              prop="areaEndStationNumber"
            >
              <el-input
                v-model="form.areaEndStationNumber"
                placeholder="请输入堤防蓄滞洪区段终点桩号"
              />
            </el-form-item>
          </el-col>
          <el-col
            :span="8"
            v-if="form.dikeType != 2 && form.isFloodStorageDetention == 1"
          >
            <el-form-item
              label="堤防蓄滞洪区段总长度(m)"
              prop="totalLengthFloodStorage"
            >
              <el-input
                v-model="form.totalLengthFloodStorage"
                placeholder="请输入堤防蓄滞洪区段总长度(m)"
              />
            </el-form-item>
          </el-col>
          <el-col
            :span="8"
            v-if="form.dikeType != 2 && form.isFloodStorageDetention == 1"
          >
            <el-form-item
              label="蓄滞洪区特殊情况说明"
              prop="floodStorageDetentionAreasExplanation"
            >
              <el-input
                v-model="form.floodStorageDetentionAreasExplanation"
                placeholder="请输入蓄滞洪区特殊情况说明"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="堤防跨界情况">
              <el-radio-group v-model="form.crossBorderSituation">
                <el-radio
                  v-for="dict in crossBorderSituationOptions"
                  :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="dikePatt">
              <el-select
                v-model="form.dikePatt"
                multiple
                collapse-tags
                placeholder="请选择堤防型式"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in embankmentTyperOptions"
                  :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="compDate">
              <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="form.compDate"
                type="date"
                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.recentComplianceReinforcementStatus"
              >
                <el-radio
                  v-for="dict in recentComplianceReinforcementStatusOptions"
                  :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.recentComplianceReinforcementStatus == 1"
          >
            <el-form-item
              label="最近达标加固完成时间"
              prop="recentComplianceReinforcementTime"
            >
              <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="form.recentComplianceReinforcementTime"
                type="date"
                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.engTask">
                <el-radio
                  v-for="dict in engineeringTasksOptions"
                  :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="dikeGrad">
              <el-select
                v-model="form.dikeGrad"
                placeholder="请选择堤防级别"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in embankmentLevelOptions"
                  :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="designFloodControl"
            >
              <el-input
                v-model="form.designFloodControl"
                placeholder="请输入设计防洪（潮）标准[重现期]"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="堤防长度(m)" prop="dikeLen">
              <el-input
                v-model="form.dikeLen"
                placeholder="请输入堤防长度(m)"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="规划防洪（潮）标准[重现期]"
              prop="planningFloodControl"
            >
              <el-input
                v-model="form.planningFloodControl"
                placeholder="请输入规划防洪（潮）标准[重现期]"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="达到规划标准的堤防长度(m)"
              prop="embankmentLengthPlanningStandards"
            >
              <el-input
                v-model="form.embankmentLengthPlanningStandards"
                placeholder="请输入达到规划标准的堤防长度(m)"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="保护人口(单位：万人)"
              prop="populationProtection"
            >
              <el-input
                v-model="form.populationProtection"
                placeholder="请输入保护人口(单位：万人)"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="保护农田(单位：万亩)"
              prop="protectingFarmland"
            >
              <el-input
                v-model="form.protectingFarmland"
                placeholder="请输入保护农田(单位：万亩)"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="重要基础设施" prop="criticalInfrastructure">
              <el-input
                v-model="form.criticalInfrastructure"
                placeholder="请输入重要基础设施"
              />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="关联字段1" prop="relations">
              <el-input
                v-model="form.relations"
                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 {
  listDikeInfo,
  getDikeInfo,
  delDikeInfo,
  addDikeInfo,
  updateDikeInfo,
  exportDikeInfo,
} from "@/api/yg/dikeInfo";
import { getAreasData } from "@/api/areas/index";
import { regionData, codeToText, TextToCode } from "element-china-area-data";

export default {
  name: "DikeInfo",
  data() {
    return {
      areasOptionProps: {
        emitPath: false,
        checkStrictly: true, //选择任意一级
      },
      areasOptions: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 堤防基本信息表格数据
      dikeInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 堤防类型字典
      embankmentTypeOptions: [],
      // 河流岸别字典
      riversideClassificationOptions: [],
      // 是否为蓄滞洪区堤防字典
      isFloodStorageDetentionOptions: [],
      // 堤防跨界情况字典
      crossBorderSituationOptions: [],
      // 堤防型式字典
      embankmentTyperOptions: [],
      // 最近达标加固完工状态字典
      recentComplianceReinforcementStatusOptions: [],
      // 工程任务字典
      engineeringTasksOptions: [],
      // 堤防级别字典
      embankmentLevelOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ids: null,
        data: {
          dikeName: null,
          dikeEndNum: null,
          dikeType: null,
        },
        // 排序方式
        params: {
          // 按哪个字段排序
          orderBy: "create_time",
          // desc降序，升序asc
          sortBy: "desc",
        },
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        dikeName: [
          { required: true, message: "堤防名称不能为空", trigger: "blur" },
        ],
        dikeCode: [
          { required: true, message: "请输入堤防编码", trigger: "blur" },
        ],
      },
      // 面包屑，路由信息
      routeList: [
        {
          path: "/engineeringCondition/baseInfo",
          routeName: "堤防基本信息列表",
        },
      ],
    };
  },
  created() {
    this.getTreeData();
    this.getList();
    this.getDicts("embankment_type").then((response) => {
      this.embankmentTypeOptions = response.data;
    });
    this.getDicts("riverside_classification").then((response) => {
      this.riversideClassificationOptions = response.data;
    });
    this.getDicts("whether").then((response) => {
      this.isFloodStorageDetentionOptions = response.data;
    });
    this.getDicts("cross_border_situation").then((response) => {
      this.crossBorderSituationOptions = response.data;
    });
    this.getDicts("embankment_form").then((response) => {
      this.embankmentTyperOptions = response.data;
    });
    this.getDicts("reach_the_standard").then((response) => {
      this.recentComplianceReinforcementStatusOptions = response.data;
    });
    this.getDicts("project_task").then((response) => {
      this.engineeringTasksOptions = response.data;
    });
    this.getDicts("embankment_level").then((response) => {
      this.embankmentLevelOptions = response.data;
    });
  },
  methods: {
    formatAdcd(adcd) {
      if (adcd) {
        let provinceCode = adcd.slice(0, 2);
        let cityCode = adcd.slice(2, 4);
        let areaCode = 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];
        }
      }
    },

    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;
      listDikeInfo(this.queryParams).then((response) => {
        this.dikeInfoList = response.records;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 堤防类型字典翻译
    embankmentTypeFormat(row, column) {
      return this.selectDictLabel(this.embankmentTypeOptions, row.dikeType);
    },
    // 河流岸别字典翻译
    riversideClassificationFormat(row, column) {
      return this.selectDictLabel(
        this.riversideClassificationOptions,
        row.riversideClassification
      );
    },
    // 是否为蓄滞洪区堤防字典翻译
    isFloodStorageDetentionFormat(row, column) {
      return this.selectDictLabel(
        this.isFloodStorageDetentionOptions,
        row.isFloodStorageDetention
      );
    },
    // 堤防跨界情况字典翻译
    crossBorderSituationFormat(row, column) {
      return this.selectDictLabel(
        this.crossBorderSituationOptions,
        row.crossBorderSituation
      );
    },
    // 堤防型式字典翻译
    embankmentTyperFormat(row, column) {
      return this.selectDictLabel(this.embankmentTyperOptions, row.dikePatt);
    },
    // 最近达标加固完工状态字典翻译
    recentComplianceReinforcementStatusFormat(row, column) {
      return this.selectDictLabel(
        this.recentComplianceReinforcementStatusOptions,
        row.recentComplianceReinforcementStatus
      );
    },
    // 工程任务字典翻译
    engineeringTasksFormat(row, column) {
      return this.selectDictLabel(this.engineeringTasksOptions, row.engTask);
    },
    // 堤防级别字典翻译
    embankmentLevelFormat(row, column) {
      return this.selectDictLabel(this.embankmentLevelOptions, row.dikeGrad);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dikeName: null,
        adcdStart: "440000",
        dikeCode: null,
        plotEmbankments: null,
        adcdEnd: "440000",
        dikeStartNum: null,
        dikeEndNum: null,
        dikeType: null,
        riverLocation: null,
        riversideClassification: null,
        lakeName: null,
        coastlineName: null,
        isFloodStorageDetention: null,
        storageDetentionAreaName: null,
        areaStartingStationNumber: null,
        areaEndStationNumber: null,
        totalLengthFloodStorage: null,
        floodStorageDetentionAreasExplanation: null,
        crossBorderSituation: null,
        dikePatt: [],
        compDate: null,
        recentComplianceReinforcementStatus: null,
        recentComplianceReinforcementTime: null,
        engTask: null,
        dikeGrad: null,
        designFloodControl: null,
        dikeLen: null,
        planningFloodControl: null,
        embankmentLengthPlanningStandards: null,
        populationProtection: null,
        protectingFarmland: null,
        criticalInfrastructure: null,
        createUid: null,
        updateUid: null,
        createTime: null,
        updateTime: null,
        proCode: null,
        proNo: null,
        owerDept: null,
        remarks: null,
        relations: null,
      };
      this.resetForm("form");
    },
    // 查询表单重置
    resetQueryForm() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        data: {
          id: null,
          dikeName: null,
          adcdStart: null,
          dikeCode: null,
          plotEmbankments: null,
          adcdEnd: null,
          dikeStartNum: null,
          dikeEndNum: null,
          dikeType: null,
          riverLocation: null,
          riversideClassification: null,
          lakeName: null,
          coastlineName: null,
          isFloodStorageDetention: null,
          storageDetentionAreaName: null,
          areaStartingStationNumber: null,
          areaEndStationNumber: null,
          totalLengthFloodStorage: null,
          floodStorageDetentionAreasExplanation: null,
          crossBorderSituation: null,
          dikePatt: null,
          compDate: null,
          recentComplianceReinforcementStatus: null,
          recentComplianceReinforcementTime: null,
          engTask: null,
          dikeGrad: null,
          designFloodControl: null,
          dikeLen: null,
          planningFloodControl: null,
          embankmentLengthPlanningStandards: null,
          populationProtection: null,
          protectingFarmland: null,
          criticalInfrastructure: null,
          createUid: null,
          updateUid: null,
          createTime: null,
          updateTime: null,
          proCode: null,
          proNo: null,
          owerDept: null,
          remarks: null,
          relations: 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: "/dyke/engineeringCondition/dykeBaseInfo/options",
        routeName: "堤防基本信息",
        isEdit: true,
      });

      // 存储面包屑信息
      this.$store.commit("setRouteList", JSON.stringify(this.routeList));
      // 跳转到选项卡页面
      this.$router.push({
        path:
          "/dyke/engineeringCondition/dykeBaseInfo/options?baseDataId=" + id,
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          // 下拉框多选
          this.form.dikePatt = JSON.stringify(this.form.dikePatt);

          if (this.form.id != null) {
            updateDikeInfo(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addDikeInfo(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 delDikeInfo(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>
