<template>
  <div>
    <at-table
      @load="loadData"
      :data="data"
      :page-result="pageResult"
      ref="AtTable"
      :dialogTitle="dialogTitle"
      :dialogVisible="dialogVisible"
      :default-sorter="[
        {direction: 'DESC', property: 'bdap.year_'},
        {direction: 'ASC', property: 'bdap.project_code_'},
        {direction: 'DESC', property: 'bdap.TOTAL_INVESTMENT_'},
        {direction: 'ASC', property: 'bdap.project_type_'},
      ]"
      :elAuth="'plan_update'"
      :cellClassNameFn="cellClassNameFn"
      @select-all="handleSelect"
      @select="handleSelect"
      @handleDialogCancel="handleDialogCancel"
      @handleDialogClose="handleDialogClose"
      @handleDialogSubmit="handleDialogSubmit"
      @row-dblclick="handleRowDBClick"
    >
      <template v-slot:searchInput>
        <el-form
          ref="searchForm"
          :model="searchForm"
          label-width="80px"
          class="search-top"
          @submit.native.prevent
        >
          <!-- <project-info-selector
            v-if="isShow"
            v-model="searchForm.projectId"
            @keyup.enter.native="handleSearch"
          ></project-info-selector> -->
          <el-select
            v-model="searchForm.year"
            clearable
            placeholder="请选择年份"
          >
            <el-option
              v-for="item in optionYears"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <dict-select
            v-model="searchForm.projectType"
            dictCode="ndjh-jslx"
            validate="required"
            placeholder="请选择建设类型"
            :clearable="true"
            @keyup.enter.native="handleSearch"
          />
          <dict-select
            v-model="searchForm.projectCode"
            dictCode="xmgl-xmlx"
            validate="required"
            placeholder="请选择项目类型"
            :clearable="true"
            @keyup.enter.native="handleSearch"
          />
          <el-select
            placeholder="请选择项目名称"
            filterable
            clearable
            v-model="searchForm.projectId"
          >
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.projectName"
              :value="item.id"
            >
              <span style="float: left">{{ item.projectName }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px"
                >{{ item.year }}年</span
              >
            </el-option>
          </el-select>

          <el-button
            size="small"
            @click="handleSearch"
            type="primary"
            class="el-icon-search search-btn"
            >查询</el-button
          >
          <el-button
            size="small"
            @click="handleReset"
            type="primary"
            plain
            class="el-icon-refresh"
            >重置</el-button
          >
        </el-form>
      </template>
      <template v-slot:operationBtn>
        <el-button
          size="small"
          type="primary"
          @click="handleAdd"
          icon="el-icon-plus"
          v-methodauth="'plan_add'"
          >添加</el-button
        >
        <ht-delete-button
          :url="deleteUrl"
          :htTable="$refs.AtTable"
          :requestMethod="'POST'"
          v-methodauth="'plan_del'"
          >删除</ht-delete-button
        >
        <import-file
          :importData="importData"
          @load="load"
          v-methodauth="'plan_import'"
        ></import-file>
        <el-button
          size="small"
          type="primary"
          @click="handleExport"
          icon="el-icon-download"
          plain
          style="margin-left: 10px"
          v-methodauth="'plan_export'"
          >导出</el-button
        >
      </template>
      <template>
        <el-table-column type="selection" width="55" align="center">
        </el-table-column>
        <el-table-column type="index" label="序号" width="55" align="center">
        </el-table-column>
        <!-- <el-table-column
          prop="projectInfo.projectCode"
          label="项目代码"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column> -->
        <el-table-column
          prop="projectName"
          label="项目名称"
          align="center"
          width="300"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="projectCode"
          label="项目类型"
          align="center"
          width="170"
          :show-overflow-tooltip="true"
        >
          <template v-slot="{row}">
            <span v-if="row.projectCode !== '----'">
              {{ getDictName('xmgl-xmlx', row.projectCode) }}
            </span>
            <span v-else>----</span>
          </template>
        </el-table-column>
        <ht-table-column
          prop="projectType"
          label="建设类型"
          align="center"
          width="100"
          :show-overflow-tooltip="true"
        >
          <template v-slot="{row}">
            <span v-if="row.projectType !== '----'">
              {{ getDictName('ndjh-jslx', row.projectType) }}
            </span>
            <span v-else>----</span>
          </template>
        </ht-table-column>
        <!-- <el-table-column
          prop="responsibleUnit"
          label="责任单位"
          align="center"
          :show-overflow-tooltip="true"
        > 
        </el-table-column>-->
        <el-table-column
          prop="totalInvestment"
          label="计划总投资(万元)"
          width="150"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="commencementTime"
          label="开工时间"
          align="center"
          width="140"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="completionTime"
          label="完工时间"
          align="center"
          width="140"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="year"
          label="年份"
          align="center"
          width="80"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="totalAnnualInvestment"
          label="计划年度总投资"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="annualTasks"
          label="本年度建设任务"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <!-- <el-table-column
          prop="constructionScaleContent"
          label="建设规模及内容"
          align="center"
          min-width="130"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
         <el-table-column
          prop="constructionAddress"
          label="建设地址"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column> -->
        <!-- <el-table-column
          prop="remarks"
          label="建设规模及内容"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column> -->
      </template>
      <!-- 弹框 -->
      <template v-slot:dialogContent>
        <el-form
          ref="ruleForm"
          data-vv-scope="form"
          status-icon
          :model="form"
          :rules="rules"
          label-width="130px"
          v-if="dialogVisible"
          v-loading.fullscreen="loading"
        >
          <el-row>
            <el-col :span="12">
              <el-form-item label="项目名称" prop="projectName">
                <el-input
                  v-model="form.projectName"
                  placeholder="请选择项目名称"
                  clearable
                ></el-input>
                <!-- <el-input
                  v-model="form.projectName"
                  placeholder="请选择项目名称"
                  @focus="handleFocusProject"
                  :disabled="!isShow"
                  clearable
                >
                  <el-button
                    type="primary"
                    @click="handleFocusProject"
                    slot="append"
                    icon="el-icon-search"
                  ></el-button>
                </el-input> -->
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <!-- <el-form-item label="项目代码" prop="projectInfo.projectCode">
                <el-input
                  v-model="form.projectInfo.projectCode"
                  placeholder="请输入项目代码"
                  :disabled="!isShow"
                  clearable
                ></el-input>
              </el-form-item> -->
              <el-form-item label="项目类型" prop="projectCode">
                <dict-select
                  dictCode="xmgl-xmlx"
                  :hasDefaultOption="true"
                  v-model="form.projectCode"
                  style="width: 100%"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="建设类型" prop="projectType">
                <dict-select
                  dictCode="ndjh-jslx"
                  :hasDefaultOption="true"
                  v-model="form.projectType"
                  style="width: 100%"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="责任单位" prop="responsibleUnit">
                <el-input
                  v-model="form.responsibleUnit"
                  placeholder="请输入责任单位"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="计划总投资" prop="totalInvestment">
                <el-input
                  v-model="form.totalInvestment"
                  placeholder="请输入计划总投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划年度总投资" prop="totalAnnualInvestment">
                <el-input
                  v-model="form.totalAnnualInvestment"
                  placeholder="请输入计划年度总投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="计划1月投资" prop="investment1">
                <el-input
                  v-model="form.investment1"
                  placeholder="请输入计划1月投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划2月投资" prop="investment2">
                <el-input
                  v-model="form.investment2"
                  placeholder="请输入计划2月投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="计划3月投资" prop="investment3">
                <el-input
                  v-model="form.investment3"
                  placeholder="请输入计划3月投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划4月投资" prop="investment4">
                <el-input
                  v-model="form.investment4"
                  placeholder="请输入计划4月投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="计划5月投资" prop="investment5">
                <el-input
                  v-model="form.investment5"
                  placeholder="请输入计划5月投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划6月投资" prop="investment6">
                <el-input
                  v-model="form.investment6"
                  placeholder="请输入计划6月投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="计划7月投资" prop="investment7">
                <el-input
                  v-model="form.investment7"
                  placeholder="请输入计划7月投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划8月投资" prop="investment8">
                <el-input
                  v-model="form.investment8"
                  placeholder="请输入计划8月投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="计划9月投资" prop="investment9">
                <el-input
                  v-model="form.investment9"
                  placeholder="请输入计划9月投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划10月投资" prop="investment10">
                <el-input
                  v-model="form.investment10"
                  placeholder="请输入计划10月投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="计划11月投资" prop="investment11">
                <el-input
                  v-model="form.investment11"
                  placeholder="请输入计划11月投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划12月投资" prop="investment12">
                <el-input
                  v-model="form.investment12"
                  placeholder="请输入计划12月投资"
                  clearable
                  type="number"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="开工时间" prop="commencementTime">
                <el-date-picker
                  v-model="form.commencementTime"
                  type="date"
                  placeholder="请输入开工时间"
                  class="basisType"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="完工时间" prop="completionTime">
                <el-date-picker
                  v-model="form.completionTime"
                  type="date"
                  placeholder="请输入开工时间"
                  class="basisType"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="年份" prop="year">
                <el-select
                  v-model="form.year"
                  clearable
                  placeholder="请选择年份"
                >
                  <el-option
                    v-for="item in optionYears"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <el-form-item label="建设地址" prop="constructionAddress">
                <el-input
                  v-model="form.constructionAddress"
                  placeholder="请输入建设地址"
                  clearable
                >
                </el-input>
              </el-form-item>
           <el-form-item label="建设规模及内容" prop="constructionScaleContent">
            <el-input
              type="textarea"
              v-model="form.constructionScaleContent"
              placeholder="请输入建设规模及内容"
              :rows="3"
            ></el-input>
          </el-form-item> -->
          <el-row>
            <el-form-item
              label="建设规模及内容"
              prop="constructionScaleContent"
            >
              <el-input
                type="textarea"
                v-model="form.constructionScaleContent"
                placeholder="请输入建设规模及内容"
              ></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="本年度建设任务" prop="annualTasks">
                <el-input
                  v-model="form.annualTasks"
                  placeholder="请输入本年度建设任务"
                  clearable
                  type="textarea"
                >
                  <i slot="suffix">万元</i>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-form-item label="备注" prop="remarks">
              <el-input
                type="textarea"
                v-model="form.remarks"
                placeholder="请输入备注"
              ></el-input>
            </el-form-item>
          </el-row>
          <file-table
            @handleFile="accessoryInfo"
            :file="form.accessoryInfo"
            :info="'上传年度计划相关文件'"
          />
        </el-form>
      </template>
      <template v-slot:showTotalData>
        <span class="show-slected">
          已选中<i>{{ selected.numbers }}</i>
          条数据， 计划总投资合计
          <i>{{ moneyFormatter(selected.money1) }} </i>万元, 计划年度总投资合计
          <i>{{ moneyFormatter(selected.money2) }} </i>万元
        </span>
      </template>
      <project-info-dialog
        ref="project"
        :single="true"
        @select="handleSelectProject"
      ></project-info-dialog>
    </at-table>
  </div>
</template>
<script>
import ProjectInfoDialog from '@/components/dialog/ProjectInfoDialog.vue'
import req from '@/request.js'
const BigNumber = require('bignumber.js')
export default {
  name: 'AnnualPlan',
  components: {
    ProjectInfoDialog,
  },
  props: {
    pid: {
      type: String,
      default: '',
    },
    isShow: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      total: {
        projectName: '合计',
        projectCode: '----',
        projectType: '----',
        totalInvestment: 0,
        commencementTime: '----',
        completionTime: '----',
        year: '----',
        totalAnnualInvestment: 0,
        annualTasks: '----',
      },
      selected: {
        numbers: 0,
        money1: '0',
        money2: '0',
      },
      importData: {
        title: '年度计划导入',
        templateName: '年度计划模板.xls',
        downloadUrl: '/../fvue/static/excel/AnnualPlan.xls',
        importUrl:
          window.context.cqxy +
          '/biz/projectApproval/decisionBasis/decisionAnnualPlan/v1/importExcelData',
        showProject: true,
        projectId: '',
      },
      loading: false,
      projectObj: [], //获取的所有项目数组
      searchForm: {
        projectId: '',
        projectCode: '',
        projectType: '',
        year: new Date().getFullYear(),
      }, //顶部搜索参数
      data: [],
      pageResult: {
        page: 1,
        pageSize: 200,
        total: 0,
      },
      form: {},
      dialogVisible: false,
      dialogTitle: '添加',
      optionYears: [],
      options: [],
      //表单验证
      rules: {
        projectName: {
          required: true,
          message: '项目名称不能为空',
          trigger: 'blur',
        },
        // 'projectInfo.projectCode': {
        //   required: true,
        //   message: '项目代码不能为空',
        //   trigger: 'blur',
        // },
        // projectCode: {
        //   required: true,
        //   message: '项目类型不能为空',
        //   trigger: 'blur',
        // },
        // projectType: {
        //   required: true,
        //   message: '建设类型不能为空',
        //   trigger: 'blur',
        // },
        //  responsibleUnit: {
        //   required: true,
        //   message: '责任单位不能为空',
        //   trigger: 'blur',
        // },
        //  totalInvestment: {
        //   required: true,
        //   message: '总投资不能为空',
        //   trigger: 'blur',
        // },
        // commencementTime: {
        //   required: true,
        //   message: '开工时间不能为空',
        //   trigger: 'blur',
        // },
        // completionTime: {
        //   required: true,
        //   message: '完工时间不能为空',
        //   trigger: 'blur',
        // },
      },
    }
  },
  computed: {
    deleteUrl: function () {
      return (
        window.context.cqxy +
        '/biz/projectApproval/decisionBasis/decisionAnnualPlan/v1/delete'
      )
    },
  },
  mounted() {
    this.initProjectAll()
  },
  created() {
    this.getYear()
    this.getProjectData()
  },
  methods: {
    getProjectData() {
      let params = {
        pageBean: {
          page: 1,
          pageSize: -1,
          total: 0,
        },
        sorter: [
          {direction: 'DESC', property: 'bdap.year_'},
          {direction: 'ASC', property: 'bdap.project_code_'},
          {direction: 'DESC', property: 'bdap.TOTAL_INVESTMENT_'},
        ],
      }
      this.$http
        .post(
          '${cqxy}/biz/projectApproval/decisionBasis/decisionAnnualPlan/v1/page',
          params
        )
        .then((resp) => {
          let response = resp.data.value
          this.options = response.rows
        })
    },
    handleReset() {
      this.searchForm.projectId = ''
      this.searchForm.projectCode = ''
      this.searchForm.projectType = ''
      this.searchForm.year = ''
      this.$refs['searchForm'].resetFields()
      this.pageResult = {
        page: 1,
        pageSize: 20,
        total: 0,
      }
      this.$nextTick(() => {
        this.$refs.AtTable.load()
      })
    },
    handleSelectProject(data) {
      this.form.projectInfo = data
      this.form.projectName = data.projectName
      this.form.projectCode = data.projectType
      this.form.projectId = data.id
      this.form.commencementTime = data.commencementTime
      this.form.completionTime = data.completionTime
      this.form.responsibleUnit = data.responsibleUnit
      this.form.constructionAddress = data.projectAddress
      this.form.constructionScaleContent = data.projectContent
      this.form.totalInvestment = data.projectMoney
      this.form.remarks = data.remarks
      // this.importData.projectId=data.id
      this.$refs.ruleForm.clearValidate()
    },
    //打开选择项目弹框
    handleFocusProject() {
      this.$refs.project.open()
    },
    //导入后重新加载数据
    load() {
      this.$refs.AtTable.load()
    },
    //导出
    handleExport() {
      let query = []
      let search = {
        'bdap.id_': this.searchForm.projectId,
        'bdap.project_code_': this.searchForm.projectCode,
        'bdap.project_type_': this.searchForm.projectType,
        'bdap.year_': this.searchForm.year,
      }
      if (!this.isShow) {
        search['bdap.id_'] = this.pid
      }
      for (let i in search) {
        if (search[i]) {
          query.push({
            group: 'advance',
            operation: 'LIKE',
            property: i,
            relation: 'AND',
            value: search[i],
          })
        }
      }
      let param = {
        pageBean: {
          page: 1,
          pageSize: -1,
          showTotal: true,
        },

        querys: query,
        sorter: [],
      }
      req
        .downloadPostCopy(
          '${cqxy}/biz/projectApproval/decisionBasis/decisionAnnualPlan/v1/exportDataToExcel',
          param
        )
        .then((res) => {
          if (res.status == 200) {
            this.$message.success('导出成功')
          } else {
            this.$message.error('导出失败')
          }
        })
    },
    //获取附件信息
    accessoryInfo(info) {
      this.form.accessoryInfo = info
    },
    initProjectAll() {
      //初始获取所有项目数据
      if (this.isShow) {
        this.$http.post('${cqxy}/biz/projectManagement/pm/v1/All').then(
          (res) => {
            this.projectObj = res.data.value
          },
          (error) => {
            reject(error)
          }
        )
      } else {
        let params = {
          pageBean: {
            page: 1,
            pageSize: 500,
            total: 0,
          },
          querys: [
            {
              group: 'main',
              operation: 'EQUAL',
              property: 'id',
              relation: 'AND',
              value: this.pid,
            },
          ],
        }
        this.$http
          .post('${cqxy}/biz/projectManagement/pm/v1/page', params)
          .then((res) => {
            if (res.data.state) {
              let resp = res.data.value
              this.projectObj = resp.rows
            }
          })
      }
    },
    //查询
    handleSearch() {
      this.$refs.AtTable.load()
    },
    afterSaveData() {
      setTimeout(() => {
        this.dialogVisible = false
        this.$refs.AtTable.load()
      }, 500)
    },
    handleAdd() {
      this.dialogTitle = '添加'
      this.dialogVisible = true
      this.form = {
        projectName: '',
        projectCode: 1,
        projectId: '',
        commencementTime: '',
        completionTime: '',
        responsibleUnit: '',
        constructionAddress: '',
        constructionScaleContent: '',
        totalInvestment: '',
        remarks: '',
        year: new Date().getFullYear(),
        projectType: 1,
        projectInfo: {
          projectName: '',
          projectCode: '',
        },
        accessoryInfo: [],
      }
      // if (this.isShow) {
      //   let selectedProject = this.projectObj.find(item => {
      //     if (item.currentProject && item.currentProject == 1) {
      //       return item.currentProject == 1
      //     }
      //   })
      //   this.form.projectInfo = selectedProject
      //   this.form.projectId = selectedProject.id
      //   this.form.projectCode = selectedProject.projectType
      //   this.form.projectName = selectedProject.projectName
      //   this.form.responsibleUnit = selectedProject.responsibleUnit
      //   this.form.commencementTime = selectedProject.commencementTime
      //   this.form.completionTime = selectedProject.completionTime
      //   this.form.responsibleUnit = selectedProject.responsibleUnit
      //   this.form.constructionAddress = selectedProject.projectAddress
      //   this.form.constructionScaleContent = selectedProject.projectContent
      //   this.form.totalInvestment = selectedProject.projectMoney
      //   this.form.remarks = selectedProject.remarks
      // } else {
      //   //根据项目id查询
      //   this.form.projectInfo = this.projectObj[0]
      //   this.form.projectId = this.projectObj[0].id
      //   this.form.projectCode = this.projectObj[0].projectType
      //   this.form.projectName = this.projectObj[0].projectName
      //   this.form.responsibleUnit = this.projectObj[0].responsibleUnit
      //   this.form.commencementTime = this.projectObj[0].commencementTime
      //   this.form.completionTime = this.projectObj[0].completionTime
      //   this.form.responsibleUnit = this.projectObj[0].responsibleUnit
      //   this.form.constructionAddress = this.projectObj[0].projectAddress
      //   this.form.constructionScaleContent = this.projectObj[0].projectContent
      //   this.form.totalInvestment = this.projectObj[0].projectMoney
      //   this.form.remarks = this.projectObj[0].remarks
      // }
    },
    handleRowDBClick(data) {
      // if (this.getMethodauth('plan_update')) {
      this.dialogTitle = '修改'
      this.$http
        .post(
          '${cqxy}/biz/projectApproval/decisionBasis/decisionAnnualPlan/v1/detail/' +
            data.id
        )
        .then((res) => {
          this.dialogVisible = true
          let response = res.data.value
          this.form = response
        })
      // }
    },
    handleSelect(selection) {
      selection.forEach((item, index) => {
        if (item.projectName === '合计') {
          selection.splice(index, 1)
        }
      })
      this.selected.numbers = selection.length
      let total1 = this.calculationTotalNumber(selection, 'totalInvestment')
      let total2 = this.calculationTotalNumber(
        selection,
        'totalAnnualInvestment'
      )
      this.selected.money1 = total1
      this.selected.money2 = total2
    },
    //取消
    handleDialogCancel() {
      this.dialogVisible = false
    },
    //关闭窗口
    handleDialogClose(val) {
      this.dialogVisible = false
    },
    //提交保存
    handleDialogSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.form.accessoryInfo && this.form.accessoryInfo.length > 0) {
            this.loading = true
            this.form.accessoryInfo.forEach((item) => {
              if (item.id) {
                delete item.id
              }
            })
          }
          this.$http
            .post(
              '${cqxy}/biz/projectApproval/decisionBasis/decisionAnnualPlan/v1/save',
              this.form
            )
            .then((res) => {
              if (res.status == 200) {
                setTimeout(() => {
                  this.$message.success(res.data.message)
                  this.afterSaveData()
                }, 500)
              } else {
                this.$message.error(res.data.message)
              }
              this.loading = false
            })
        }
        // else if (this.form.accessoryInfo.length === 0) {
        //   this.$message.error('至少上传一个附件')
        // }
        else {
          this.$message({
            message: '*号必填项,不能为空!',
            type: 'warning',
          })
          return false
        }
      })
    },
    loadData(param, cb) {
      let query = []
      let search = {
        'bdap.id_': this.searchForm.projectId,
        'bdap.project_code_': this.searchForm.projectCode,
        'bdap.project_type_': this.searchForm.projectType,
        'bdap.year_': this.searchForm.year,
      }
      if (!this.isShow) {
        search['bdap.id_'] = this.pid
        this.importData.projectId = this.pid
      }
      for (let i in search) {
        if (search[i]) {
          query.push({
            group: 'main',
            operation: 'LIKE',
            property: i,
            relation: 'AND',
            value: search[i],
          })
        }
      }

      if (param.querys && param.querys.length) {
        param.querys.push(...query)
      } else {
        param.querys = query
      }

      this.$http
        .post(
          '${cqxy}/biz/projectApproval/decisionBasis/decisionAnnualPlan/v1/page',
          param
        )
        .then(
          (resp) => {
            let response = resp.data.value
            this.selected = {
              numbers: 0,
              money1: '0',
              money2: '0'
            }
            let data = response.rows
            this.total.totalInvestment = this.calculationTotal(
              data,
              'totalInvestment'
            )
            this.total.totalAnnualInvestment = this.calculationTotal(
              data,
              'totalAnnualInvestment'
            )
            if (data.length !== 0) {
              data.push(this.total)
            }
            this.data = data
            this.pageResult = {
              page: response.page,
              pageSize: response.pageSize,
              total: response.total,
            }
          },
          (error) => {
            reject(error)
          }
        )
        .finally(() => {
          if (cb) {
            cb()
          }
        })
    },
    getYear() {
      const myDate = new Date()
      const startYear = myDate.getFullYear() - 5 //起始年份
      const endYear = myDate.getFullYear() + 1 //结束年份
      for (let i = endYear; i >= startYear; i--) {
        this.optionYears.push({
          label: i,
          value: i,
        })
      }
    },
    //返回一个boolean类型，是否显示列表按钮
    getMethodauth(elAuth) {
      let allMethod = window.sessionStorage.allMethod
      let methodAuth = window.sessionStorage.methodAuth
      let allMethodArray = allMethod && allMethod.split(',')
      let methodAuthArray = methodAuth && methodAuth.split(',')
      // 无权限则隐藏按钮
      if (
        methodAuthArray &&
        methodAuthArray.includes(elAuth) &&
        allMethodArray &&
        allMethodArray.includes(elAuth)
      ) {
        return true
      } else {
        return false
      }
    },
    // 计算列表合同金额合计金额
    calculationTotal(data, key) {
      let total = new BigNumber(0)
      if (key && data && data.length !== 0) {
        data.forEach((item) => {
          if (item[key]) {
            total = total.plus(item[key])
          } else {
            total = total.plus(0)
          }
        })
      }
      return this.moneyFormatter(total)
    },
    calculationTotalNumber(data, key) {
      let total = new BigNumber(0)
      if (key && data && data.length !== 0) {
        data.forEach((item) => {
          if (item[key]) {
            total = total.plus(item[key])
          } else {
            total = total.plus(0)
          }
        })
      }
      return total
    },
    cellClassNameFn(row) {
      // 列表项目名称为【合计】隐藏复选框
      if (row.row.projectName === '合计') {
        return 'table-column-hidden'
      }
    },
  },
}
</script>
<style lang="scss" scoped>
@import '@/assets/css/common.scss';

/deep/ .el-input__suffix > .el-input__icon {
  display: none;
}
.show-slected {
  font-size: 18px;
  i {
    font-style: normal;
    font-weight: 700;
    margin: 0 5px;
    color: #f40;
  }
}
/deep/ .table-column-hidden .el-checkbox__input {
  display: none;
}
/deep/ .table-column-hidden .cell > div {
  display: none;
}
</style>
