<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="projectName">
        <el-input
          v-model="queryParams.data.projectName"
          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>
        <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="['build:info: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="['build:info: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="['build:info:remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="infoList"
      @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="projectName"
        min-width="120"
      />
      <!-- <el-table-column label="项目法人" align="center" prop="unitLeader" min-width="120" /> -->
      <!-- <el-table-column
        label="项目法人"
        align="center"
        prop="projectLegalPerson"
        min-width="120"
      /> -->
      <el-table-column
        label="项目法人单位"
        align="center"
        prop="projectLegalUnit"
        min-width="120"
      />
      <el-table-column
        label="单位负责人电话"
        align="center"
        prop="projectLegalPhone"
        min-width="120"
      />
      <el-table-column
        label="工程等别"
        align="center"
        prop="engineeringGrade"
        :formatter="engineeringGradeFormat"
        min-width="120"
      />
      <el-table-column
        label="工程用途"
        align="center"
        prop="engineeringPurposes"
        :formatter="engineeringPurposesFormat"
        min-width="120"
      />
      <el-table-column
        label="工程用途"
        align="center"
        prop="workCategory"
        :formatter="workCategoryFormat"
        min-width="120"
      />
      <el-table-column
        label="项目建设地址"
        align="center"
        prop="constructionAddress"
        min-width="120"
      />
      <el-table-column
        label="建设模式"
        align="center"
        prop="constructionMode"
        :formatter="constructionModeFormat"
        min-width="120"
      />
      <el-table-column
        label="建设性质"
        align="center"
        prop="constructionNature"
        :formatter="constructionNatureFormat"
        min-width="120"
      />
      <el-table-column
        label="建设内容"
        align="center"
        prop="constructionContent"
        min-width="120"
      />
      <el-table-column
        label="行政区划"
        align="center"
        prop="adcd"
        min-width="120"
      />
      <el-table-column
        label="所属流域"
        align="center"
        prop="basin"
        min-width="120"
      />
      <el-table-column
        label="项目类型"
        align="center"
        prop="projectType"
        :formatter="projectTypeFormat"
        min-width="120"
      />
      <!-- <el-table-column label="资金来源" align="center" prop="fundingSource"
        min-width="120"/> -->
      <el-table-column
        label="是否172项重大水利工程"
        align="center"
        prop="isMajorProject"
        :formatter="isBelongPlanningFormat"
        min-width="120"
      />
      <el-table-column
        label="项目投资主体"
        align="center"
        prop="investmentSubject"
        min-width="120"
      />
      <el-table-column
        label="建设阶段"
        align="center"
        prop="constructionPhase"
        min-width="120"
      />
      <el-table-column
        label="资金下达文号"
        align="center"
        prop="fundingNumber"
        min-width="120"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        min-width="180"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="viewInfo(scope.row)"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['build:info:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['build:info: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
    >
      <el-row :gutter="15">
        <el-form
          ref="form"
          :model="form"
          :rules="rules"
          label-width="180px"
          label-position="top"
        >
          <el-col :span="24">
            <el-form-item label="项目名称" prop="projectName">
              <!-- <el-input
                v-model="form.projectName"
                placeholder="请输入项目名称"
              /> -->
              <el-select
                v-model="form.projectName"
                placeholder="请输入项目名称"
                filterable
                clearable
                size="small"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in projectNameOptions"
                  :key="dict.projectName + dict.id"
                  :label="dict.projectName + '[' + dict.projectCode + ']'"
                  :value="dict.projectName + '[' + dict.projectCode + ']'"
                  @click.native="getId(dict)"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="项目法人单位" prop="projectLegalUnit">
              <el-input
                v-model="form.projectLegalUnit"
                placeholder="请输入项目法人单位"
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="项目法人" prop="unitLeader">
              <el-input
                v-model="form.unitLeader"
                placeholder="请输入项目法人"
              />
            </el-form-item>
          </el-col> -->
          <!-- <el-col :span="12">
            <el-form-item label="项目法人" prop="projectLegalPerson">
              <el-input
                v-model="form.projectLegalPerson"
                placeholder="请输入项目法人"
              />
            </el-form-item>
          </el-col> -->
          <el-col :span="24">
            <el-form-item label="单位负责人电话" prop="projectLegalPhone">
              <el-input
                v-model="form.projectLegalPhone"
                placeholder="请输入单位负责人电话"
              />
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="项目类型" prop="projectType">
              <div style="margin-bottom: 10px">
                <el-radio v-model="radio" label="zd" @input="changeisMajor()"
                  >重大项目</el-radio
                >
                <el-radio v-model="radio" label="ms" @input="changeisMajor()"
                  >面上项目</el-radio
                >
              </div>
              <div>
                <el-radio
                  v-model="form.projectType"
                  v-for="dict in radio == 'zd'
                    ? zd_projectTypeOptions
                    : ms_projectTypeOptions"
                  :label="dict.dictValue"
                  :key="dict.dictLabel + dict.id"
                >
                  {{ dict.dictLabel }}
                </el-radio>
              </div>
              <!-- <el-select
                v-model="form.projectType"
                placeholder="请选择项目类型"
                style="width: 100%"
              >
                <div style="margin-bottom: 10px">
                  <el-radio v-model="radio" label="zd">重大项目</el-radio>
                  <el-radio v-model="radio" label="ms">面上项目</el-radio>
                </div>
                重大项目选项
                <template v-if="radio == 'zd'">
                  <el-option
                    v-for="dict in zd_projectTypeOptions"
                    :key="dict.dictLabel + dict.id"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  />
                </template>
                面上项目选项
                <template v-if="radio == 'ms'">
                  <el-option
                    v-for="dict in ms_projectTypeOptions"
                    :key="dict.dictLabel + dict.id"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  />
                </template>
              </el-select> -->
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="工程等别" prop="engineeringGrade">
              <!-- <el-input
                v-model="form.engineeringGrade"
                placeholder="请输入工程等别"
              /> -->
              <el-select
                v-model="form.engineeringGrade"
                placeholder="请输入工程等别"
                filterable
                clearable
                size="small"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in engineeringGradeOptions"
                  :key="dict.dictLabel + dict.id"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工程用途" prop="engineeringPurposes">
              <!-- <el-input
                v-model="form.engineeringPurposes"
                placeholder="请输入工程用途"
              /> -->
              <el-select
                v-model="form.engineeringPurposes"
                placeholder="请输入工程用途"
                filterable
                clearable
                size="small"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in engineeringPurposesOptions"
                  :key="dict.dictLabel + dict.id"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工程类别" prop="workCategory">
              <!-- <el-input
                v-model="form.workCategory"
                placeholder="请输入工程类别"
              /> -->
              <el-select
                v-model="form.workCategory"
                placeholder="请输入工程用途"
                filterable
                clearable
                size="small"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in workCategoryOptions"
                  :key="dict.dictLabel + dict.id"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目建设地址" prop="constructionAddress">
              <el-input
                v-model="form.constructionAddress"
                placeholder="请输入项目建设地址"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="建设模式" prop="constructionMode">
              <!-- <el-input
                v-model="form.constructionMode"
                placeholder="请输入建设模式"
              /> -->
              <el-select
                v-model="form.constructionMode"
                placeholder="请输入建设模式"
                filterable
                clearable
                size="small"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in constructionModeOptions"
                  :key="dict.dictLabel + dict.id"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="建设性质" prop="constructionNature">
              <!-- <el-input
                v-model="form.constructionNature"
                placeholder="请输入建设性质"
              /> -->
              <el-select
                v-model="form.constructionNature"
                placeholder="请输入建设模式"
                filterable
                clearable
                size="small"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in constructionNatureOptions"
                  :key="dict.dictLabel + dict.id"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="建设内容" prop="constructionContent">
              <el-input
                v-model="form.constructionContent"
                placeholder="请输入建设内容"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="行政区划" prop="adcd">
              <!-- <el-input v-model="form.adcd" placeholder="请输入行政区划" /> -->
              <el-cascader
                :options="areasOptions"
                v-model="adcdArr"
                :props="areasOptionProps"
                placeholder="请选择行政区划"
                clearable
                size="small"
                style="width: 100%"
                @change="handleChange"
              >
              </el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属流域" prop="basin">
              <el-input v-model="form.basin" placeholder="请输入所属流域" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资金下达文号" prop="fundingNumber">
              <el-input
                v-model="form.fundingNumber"
                placeholder="请输入资金下达文号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="中央资金" prop="centralArrangedFunds">
              <el-input
                v-model="form.centralArrangedFunds"
                placeholder="请输入中央资金"
              >
                <template slot="append">万元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="中央资金比例" prop="centralArrangedFundsRate">
              <el-input
                v-model="form.centralArrangedFundsRate"
                placeholder="请输入中央资金比例"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="省级资金" prop="provincialFunding">
              <el-input
                v-model="form.provincialFunding"
                placeholder="请输入省级资金"
              >
                <template slot="append">万元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="省级资金比例" prop="provincialFundingRate">
              <el-input
                v-model="form.provincialFundingRate"
                placeholder="请输入省级资金比例"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地市资金" prop="cityLevelFunds">
              <el-input
                v-model="form.cityLevelFunds"
                placeholder="请输入地市资金"
              >
                <template slot="append">万元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地市资金比例" prop="cityLevelFundsRate">
              <el-input
                v-model="form.cityLevelFundsRate"
                placeholder="请输入地市资金比例"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区县资金" prop="countyLevelFunds">
              <el-input
                v-model="form.countyLevelFunds"
                placeholder="请输入区县资金"
              >
                <template slot="append">万元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区县资金比例" prop="cityLevelFundsRate">
              <el-input
                v-model="form.countyLevelFundsRate"
                placeholder="请输入区县资金比例"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="乡镇及群众自筹和其他投资"
              prop="townshipInvestments"
            >
              <el-input
                v-model="form.townshipInvestments"
                placeholder="请输入乡镇及群众自筹和其他投资"
              >
                <template slot="append">万元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="乡镇及群众自筹和其他投资比例"
              prop="townshipInvestmentsRate"
            >
              <el-input
                v-model="form.townshipInvestmentsRate"
                placeholder="请输入乡镇及群众自筹和其他投资比例"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否172项重大水利工程" prop="isMajorProject">
              <!-- <el-input
                v-model="form.isMajorProject"
                placeholder="请输入是否172项重大水利工程"
              /> -->
              <el-select
                v-model="form.isMajorProject"
                placeholder="是否172项重大水利工程"
                clearable
                size="small"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in isMajorProjectOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="建设阶段" prop="constructionPhase">
              <el-input
                v-model="form.constructionPhase"
                placeholder="请输入建设阶段"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="项目投资主体" prop="investmentSubject">
              <el-input
                v-model="form.investmentSubject"
                placeholder="请输入项目投资主体"
              />
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <!-- <div slot="footer" class="dialog-footer"> -->
      <div class="dialog-footer" style="left: 20px; bottom: 5px">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--查看 -->
    <el-dialog
      :title="viewTitle"
      :visible.sync="viewOpen"
      width="1200px"
      append-to-body
      @close="closeView"
    >
      <!-- 查看在建项目基本信息 -->
      <div class="infoTitle">在建项目基本信息</div>
      <div class="draLine"></div>
      <div class="content">
        <el-descriptions
          class="margin-top"
          :column="2"
          border
          :labelStyle="{
            'text-align': 'left',
            width: '180px',
            height: '50px',
          }"
          :contentStyle="{}"
        >
          <el-descriptions-item span="2">
            <template slot="label"> 项目名称 </template>
            <!-- {{ this.viewTitle }} -->
            {{ this.proMsg.projectName + "[" + this.proMsg.proCode + "]" }}
          </el-descriptions-item>
          <!-- <el-descriptions-item>
            <template slot="label"> 项目法人 </template>
            {{ this.proMsg.projectLegalPerson }}
          </el-descriptions-item> -->
          <el-descriptions-item>
            <template slot="label"> 项目编号 </template>
            {{ this.proMsg.proCode }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 单位负责人电话 </template>
            {{ this.proMsg.projectLegalPhone }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 工程等别 </template>
            {{ engineeringGradeFormat(this.proMsg) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 工程用途 </template>
            {{ engineeringPurposesFormat(this.proMsg) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 工程类别 </template>
            {{ workCategoryFormat(this.proMsg) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 项目建设地址 </template>
            {{ this.proMsg.constructionAddress }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 建设模式 </template>
            {{ constructionModeFormat(this.proMsg) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 建设性质 </template>
            {{ constructionNatureFormat(this.proMsg) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 建设内容 </template>
            {{ this.proMsg.constructionContent }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 行政区划 </template>
            {{ this.proMsg.adcd }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 所属流域 </template>
            {{ this.proMsg.basin }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 开工日期 </template>
            {{ this.proMsg.commencementDate || "-" }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 计划竣工日期 </template>
            {{ this.proMsg.plannedCompletionDate || "-" }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 项目类型 </template>
            {{ projectTypeFormat(this.proMsg) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 总投资金额（万元） </template>
            {{ this.proMsg.total }}
          </el-descriptions-item>

          <el-descriptions-item>
            <template slot="label"> 中央资金（万元） </template>
            {{ this.proMsg.centralArrangedFunds }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 中央资金比例 </template>
            {{ this.proMsg.centralArrangedFundsRate }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 省级资金（万元） </template>
            {{ this.proMsg.provincialFunding }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 省级资金比例 </template>
            {{ this.proMsg.provincialFundingRate }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 地市资金（万元） </template>
            {{ this.proMsg.cityLevelFunds }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 地市资金比例 </template>
            {{ this.proMsg.cityLevelFundsRate }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 区县资金（万元） </template>
            {{ this.proMsg.countyLevelFunds }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 区县资金比例 </template>
            {{ this.proMsg.cityLevelFundsRate }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 乡镇及群众自筹和其他投资（万元） </template>
            {{ this.proMsg.countyLevelFunds }}
          </el-descriptions-item>

          <el-descriptions-item>
            <template slot="label"> 乡镇及群众自筹和其他投资比例 </template>
            {{ this.proMsg.cityLevelFundsRate }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 是否172项重大水利工程 </template>
            {{ this.proMsg.isMajorProject }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 项目投资主体 </template>
            {{ this.proMsg.investmentSubject }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 建设阶段 </template>
            {{ this.proMsg.constructionPhase }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 资金下达文号 </template>
            {{ this.proMsg.fundingNumber }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listInfo,
  getInfo,
  delInfo,
  addInfo,
  updateInfo,
  exportInfo,
} from "@/api/build/projectInfo";
import {
  listProposal,
  getProposal,
  delProposal,
  addProposal,
  updateProposal,
  exportProposal,
  getProjectCode,
} from "@/api/earlyStage/proposal";
import { getAreasData } from "@/api/areas/index";
import { regionData, codeToText, TextToCode } from "element-china-area-data";
export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目基本信息管理表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      viewTitle: "",
      // 是否显示弹出层
      open: false,
      viewOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ids: null,
        data: {
          isMajor: null,
          projectName: null,
          unitLeader: null,
          projectLegalPerson: null,
          projectLegalUnit: null,
          projectLegalPhone: null,
          engineeringGrade: null,
          engineeringPurposes: null,
          workCategory: null,
          constructionAddress: null,
          constructionMode: null,
          constructionNature: null,
          constructionContent: null,
          adcd: null,
          basin: null,
          projectType: null,
          // fundingSource: null,

          centralArrangedFunds: null,
          centralArrangedFundsRate: null,
          provincialFunding: null,
          provincialFundingRate: null,
          cityLevelFunds: null,
          cityLevelFundsRate: null,
          countyLevelFunds: null,
          countyLevelFundsRate: null,
          townshipInvestments: null,
          townshipInvestmentsRate: null,

          isMajorProject: null,
          investmentSubject: null,
          constructionPhase: null,
          fundingNumber: null,
          proCode: null,
          proNo: null,
          createUid: null,
          createTime: null,
          updateUid: null,
          updateTime: null,
          owerDept: null,
        },
        // 排序方式
        params: {
          // 按哪个字段排序
          orderBy: "create_time",
          // desc降序，升序asc
          sort: "desc",
        },
      },
      // 表单参数
      form: {},
      adcdArr: [],
      copyForm: {},
      // 表单校验
      rules: {
        projectLegalPhone: [
          {
            required: true,
            type: "string",
            pattern:
              /^(13[0-9]|14[01456879]|15[0-3,5-9]|16[2567]|17[0-8]|18[0-9]|19[0-3,5-9])\d{8}$/,
            message: "请输入正确的手机号",
            trigger: "blur",
          },
        ],
        centralArrangedFunds: [
          {
            // required: true,
            message: "请输入中央资金",
            trigger: "blur",
          },
          {
            pattern:
              /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: "请输入数字,可保留两位小数",
            trigger: "blur",
          },
        ],
        provincialFunding: [
          {
            // required: true,
            message: "请输入省级资金",
            trigger: "blur",
          },
          {
            pattern:
              /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: "请输入数字,可保留两位小数",
            trigger: "blur",
          },
        ],
        cityLevelFunds: [
          {
            // required: true,
            message: "请输入地市资金",
            trigger: "blur",
          },
          {
            pattern:
              /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: "请输入数字,可保留两位小数",
            trigger: "blur",
          },
        ],
        countyLevelFunds: [
          {
            // required: true,
            message: "请输入区县资金",
            trigger: "blur",
          },
          {
            pattern:
              /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: "请输入数字,可保留两位小数",
            trigger: "blur",
          },
        ],
        townshipInvestments: [
          {
            // required: true,
            message: "请输入乡镇及群众自筹和其他投资",
            trigger: "blur",
          },
          {
            pattern:
              /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: "请输入数字,可保留两位小数",
            trigger: "blur",
          },
        ],
      },
      //项目名称
      projectNameOptions: [],
      proNo: "",
      proCode: "",
      adcd: "",
      // 是否是是否172项重大水利工程
      isMajorProjectOptions: [],
      radio: "zd",
      // 重大项目字典
      zd_projectTypeOptions: [],
      // 面上项目字典
      ms_projectTypeOptions: [],
      // 工程等别字典
      engineeringGradeOptions: [],
      // 工程用途字典
      engineeringPurposesOptions: [],
      // 工程类别字典
      workCategoryOptions: [],
      // 建设模式字典
      constructionModeOptions: [],
      // 建设性质字典
      constructionNatureOptions: [],
      proMsg: {},
      // 面包屑，路由信息
      routeList: [
        {
          path: "/building/projectInfo",
          routeName: "项目基本信息管理",
        },
      ],
      areasOptions: [],
      areasOptionProps: {
        // emitPath: false,
        checkStrictly: true, //选择任意一级
      },
    };
  },
  created() {
    this.getList();
    this.getDicts("whether").then((response) => {
      this.isMajorProjectOptions = response.data;
    });
    this.getDicts("major_project").then((response) => {
      // console.log("4444444444444444", response.data);
      this.zd_projectTypeOptions = response.data;
    });
    this.getDicts("general_project").then((response) => {
      // console.log("5555555555555", response.data);
      this.ms_projectTypeOptions = response.data;
    });
    this.getDicts("engineering_grade").then((response) => {
      this.engineeringGradeOptions = response.data;
    });
    this.getDicts("project_purposes").then((response) => {
      this.engineeringPurposesOptions = response.data;
    });
    this.getDicts("project_category").then((response) => {
      this.workCategoryOptions = response.data;
    });
    this.getDicts("Construction_mode").then((response) => {
      this.constructionModeOptions = response.data;
    });
    this.getDicts("CONSTRUCTION_NATURE").then((response) => {
      this.constructionNatureOptions = response.data;
    });
    this.getTreeData();
  },
  methods: {
    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) {
        this.form.adcd = JSON.stringify(value);
        console.log("value", value, this.form.adcd);
        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.baseMsg.adcd", this.baseMsg.adcd);
        // this.form.province = provinceCode;
        // this.form.city = cityCode;
        // this.form.area = orgion;
        // this.selectedOptions = provinceCode + cityCode + orgion;
      }
    },
    // 保留项目类型
    changeisMajor() {
      if (this.radio == this.copyForm.isMajor) {
        this.form.projectType = this.copyForm.projectType;
      } else {
        this.form.projectType = "";
      }
    },
    // 工程等别字典翻译
    engineeringGradeFormat(row, column) {
      return this.selectDictLabel(
        this.engineeringGradeOptions,
        row.engineeringGrade
      );
    },
    // 工程用途字典翻译
    engineeringPurposesFormat(row, column) {
      return this.selectDictLabel(
        this.engineeringPurposesOptions,
        row.engineeringPurposes
      );
    },
    // 工程类别字典翻译
    workCategoryFormat(row, column) {
      return this.selectDictLabel(this.workCategoryOptions, row.workCategory);
    },
    // 建设模式字典
    constructionModeFormat(row, column) {
      return this.selectDictLabel(
        this.constructionModeOptions,
        row.constructionMode
      );
    },

    // 建设性质字典
    constructionNatureFormat(row, column) {
      return this.selectDictLabel(
        this.constructionNatureOptions,
        row.constructionNature
      );
    },

    // 项目类型字典翻译
    projectTypeFormat(row, column) {
      if (row.isMajor == "zd") {
        return this.selectDictLabel(
          this.zd_projectTypeOptions,
          row.projectType
        );
      } else if (row.isMajor == "ms") {
        return this.selectDictLabel(
          this.ms_projectTypeOptions,
          row.projectType
        );
      }
    },
    // 是否是是否172项重大水利工程
    isBelongPlanningFormat(row, column) {
      return this.selectDictLabel(
        this.isMajorProjectOptions,
        row.isMajorProject
      );
    },
    projectNameFormat(row) {
      if (row.projectName)
        return row.projectName.slice(0, row.projectName.indexOf("["));
    },
    getId(res) {
      // console.log(res)
      getProposal(res.id).then((response) => {
        // console.log(response.data)
        this.proNo = response.data.proNo;
        this.proCode = response.data.projectCode;
        this.adcd = response.data.adcd;
      });
    },
    /** 查询项目基本信息管理列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then((response) => {
        this.infoList = response.records;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        isMajor: null,
        projectName: null,
        unitLeader: null,
        projectLegalPerson: null,
        projectLegalUnit: null,
        projectLegalPhone: null,
        engineeringGrade: null,
        engineeringPurposes: null,
        workCategory: null,
        constructionAddress: null,
        constructionMode: null,
        constructionNature: null,
        constructionContent: null,
        adcd: null,
        basin: null,
        projectType: null,
        // fundingSource: null,

        centralArrangedFunds: null,
        centralArrangedFundsRate: null,
        provincialFunding: null,
        provincialFundingRate: null,
        cityLevelFunds: null,
        cityLevelFundsRate: null,
        countyLevelFunds: null,
        countyLevelFundsRate: null,
        townshipInvestments: null,
        townshipInvestmentsRate: null,

        isMajorProject: null,
        investmentSubject: null,
        constructionPhase: null,
        fundingNumber: null,
        proCode: null,
        proNo: null,
        createUid: null,
        createTime: null,
        updateUid: null,
        updateTime: null,
        owerDept: null,
      };
      this.resetForm("form");
    },
    // 查询表单重置
    resetQueryForm() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        data: {
          id: null,
          isMajor: null,
          projectName: null,
          unitLeader: null,
          projectLegalPerson: null,
          projectLegalUnit: null,
          projectLegalPhone: null,
          engineeringGrade: null,
          engineeringPurposes: null,
          workCategory: null,
          constructionAddress: null,
          constructionMode: null,
          constructionNature: null,
          constructionContent: null,
          adcd: null,
          basin: null,
          projectType: null,
          // fundingSource: null,

          centralArrangedFunds: null,
          centralArrangedFundsRate: null,
          provincialFunding: null,
          provincialFundingRate: null,
          cityLevelFunds: null,
          cityLevelFundsRate: null,
          countyLevelFunds: null,
          countyLevelFundsRate: null,
          townshipInvestments: null,
          townshipInvestmentsRate: null,

          isMajorProject: null,
          investmentSubject: null,
          constructionPhase: null,
          fundingNumber: null,
          proCode: null,
          proNo: null,
          createUid: null,
          createTime: null,
          updateUid: null,
          updateTime: null,
          owerDept: null,
        },
      };
      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;
    },

    // 查看信息
    viewInfo(row) {
      this.viewTitle = row.projectName.slice(0, row.projectName.indexOf("["));
      this.proMsg = row;
      console.log("proMsg", row);
      this.viewOpen = true;
    },

    // 关闭弹窗
    closeView() {
      this.proMsg = {};
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      listProposal(this.queryParams).then((response) => {
        this.projectNameOptions = response.records;
      });
      this.radio = "zd";
      this.open = true;
      this.title = "添加项目基本信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // const id = row.id || this.ids;
      this.routeList[0].routeName = row.projectName;
      this.routeList.push({
        path: "/building/projectInfo/projectProcess",
        routeName: row.proCode,
        isEdit: true,
      });

      // 存储面包屑信息
      this.$store.commit("setRouteList", JSON.stringify(this.routeList));
      // 存储专题项目基础信息
      // this.$store.commit("setBaseFormData", JSON.stringify(response.data));
      // 跳转到选项卡页面
      this.$router.push({
        // path: "/project/special/options",
        path: "/building/projectInfo/projectProcess?baseDataId=" + row.id,
      });
      // this.reset();
      // const id = row.id || this.ids;
      // getInfo(id).then((response) => {
      //   this.form = response.data;
      //   if (this.form)
      //     listProposal(this.queryParams).then((response) => {
      //       this.projectNameOptions = response.records;
      //     });
      //   // 重大项目与面上项目 区分
      //   this.radio = this.form.isMajor;
      //   this.form.projectName =
      //     this.form.projectName + "[" + this.form.proCode + "]";
      //   this.copyForm = { ...this.form };
      //   this.open = true;
      //   this.title = "修改项目基本信息管理";
      // });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.isMajor = this.radio;
          if (this.proNo) {
            this.form.proNo = this.proNo;
          }
          if (this.proCode) {
            this.form.proCode = this.proCode;
          }
          if (this.adcd) {
            this.form.adcd = this.adcd;
          }
          if (
            this.form.projectName &&
            this.form.projectName.indexOf("[") != -1
          ) {
            this.form.projectName = this.form.projectName.slice(
              0,
              this.form.projectName.indexOf("[")
            );
          }
          console.log(this.form);
          // console.log("this.form.isMajor", this.form.isMajor);
          if (this.form.id != null) {
            updateInfo(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addInfo(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 delInfo(ids);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("删除成功");
          })
          .catch(function () {});
      } else {
        this.$message.warning("请选择要删除的数据！！");
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      let message = "是否确认导出所有的数据项?";
      if (this.ids) {
        message = "是否确认导出选中的数据项?";
        queryParams.ids = this.ids;
      }
      this.$confirm(message, "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportInfo(queryParams);
        })
        .then((response) => {
          this.downloadFile(response, true, response.msg);
          // this.download(response.msg);
        })
        .catch(function () {});
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/css/dialog.scss";

::v-deep {
  .el-dialog {
    margin-top: 2vh !important;
  }

  .el-dialog__body {
    transform: scale(1);
  }
}

.dialog-footer {
  // position: sticky;
}
</style>
