<!--
 * @Descripttion: 
 * @version: 
 * @Author: ysh
 * @Date: 2022-09-08 17:16:12
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2025-01-10 15:13:48
-->
<template>
  <div>
    <!-- 搜索栏 -->
    <el-row>
      <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="90px">
        <el-form-item label="项目编号" prop="projectNumber">
          <el-input v-model="queryParams.projectNumber" placeholder="请输入项目编号" clearable @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item label="成果名称" prop="achiName">
          <el-input v-model="queryParams.achiName" placeholder="请输入成果名称" clearable @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item label="数据年份" prop="dataYear">
          <el-input v-model="queryParams.dataYear" placeholder="请输入数据年份" clearable @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item label="成果类型" prop="resultType">
          <el-input v-model="queryParams.resultType" placeholder="请输入成果类型" clearable @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <!-- 操作栏 -->
    <el-row style="margin-bottom: 10px;">
      <el-button type="primary" size="small" icon="el-icon-plus" @click="handleAddAchievement"
        v-hasPermi="['file:achievement:add']">新增成果</el-button>
      <el-button type="success" size="small" icon="el-icon-download" @click="handleExprot"
        v-hasPermi="['file:achievement:export']">导出</el-button>
      <el-button type="warning" size="small" icon="el-icon-upload" @click="uploadAchievement"
        v-hasPermi="['file:achievement:add']">上传成果表</el-button>
      <el-button type="danger" size="small" icon="el-icon-delete" :disabled="multiple" @click="handleDeleteMany"
        v-hasPermi="['file:achievement:remove']">批量删除
      </el-button>
    </el-row>
    <!-- 表格 -->
    <el-row>
      <el-table :data="achiTableData" style="width: 100%" stripe v-loading="loading" :row-key="getRowKeys"
        @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="50px" :reserve-selection="true" />
        <el-table-column type="index" label="序号" width="50px" align="center" />
        <el-table-column prop="projectNumber" label="项目编号" align="center" />
        <el-table-column prop="achiName" label="成果名称" width="200px" align="center" />
        <el-table-column prop="dataYear" label="数据年份" align="center">
          <!-- <template #default="scope">
              {{ parseInt(scope.row.dataYear)}}
            </template> -->
        </el-table-column>
        <el-table-column prop="resultType" label="成果类型" align="center">
          <template slot-scope="scope">
            {{ selectDictLabel(dict.type.cmc_achi_type, scope.row.resultType) }}
          </template>
        </el-table-column>
        <el-table-column prop="scaleGrade" label="比例尺或等级" align="center">
          <template slot-scope="scope">
            {{ selectDictLabel(dict.type.cmc_scale_grade, scope.row.scaleGrade) }}
          </template>
        </el-table-column>
        <el-table-column prop="fileType" label="文件类型" align="center" />
        <el-table-column prop="workLoad" label="工作量" align="center" />
        <el-table-column prop="unit" label="单位" align="center" />
        <el-table-column prop="dataSource" label="数据来源" align="center" />
        <el-table-column prop="dataType" label="数据类型" align="center" />
        <el-table-column prop="storageAddress" label="存储地址" align="center" />
        <!-- <el-table-column prop="kmlUrl" label="KML地址" align="center" /> -->
        <el-table-column label="有无KML" align="center" :formatter="formatterKmlurl"></el-table-column>
        <el-table-column prop="remark" label="备注" align="center" />
        <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-tooltip content="修改" placement="top">
              <el-button type="text" icon="el-icon-edit-outline" @click="handleUpdate(scope.row)"
                v-hasPermi="['file:achievement:edit']">
              </el-button>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                v-hasPermi="['file:achievement:remove']">
              </el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getAchiList" />
    </el-row>
    <!-- 新增成果表 -->
    <el-dialog :title="addTitle" :visible.sync="addOpen" width="50%">
      <!-- <el-form :model="form" ref="achiRef" label-width="110px" :rules="rules">
        <el-row :gutter="10">
          <el-col :span="15">
            <el-form-item label="项目编号" prop="projectNumber">
              <el-input v-model="form.projectNumber" disabled placeholder="请输入项目编号" />
            </el-form-item>
            <el-form-item label="项目名称" prop="projectName">
              <el-input v-model="form.projectName" disabled placeholder="请输入项目名称" />
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-button type="primary" size="mini" @click="openProject = true">选择项目</el-button>
          </el-col>
          <el-col :span="6">
            <el-form-item label="数据年份" prop="dataYear">
              <el-input v-model="form.dataYear" placeholder="请输入数据年份" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="成果名称" prop="achiName">
              <el-input v-model="form.achiName" placeholder="请输入成果名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="成果类型" prop="resultType">
              <el-row :gutter="20">
                <el-col :span="22">
                  <el-select v-model="form.resultType" placeholder="请选择成果类型" :style="{ width: '100%' }" clearable
                    multiple>
                    <el-option v-for="dict in dict.type.cmc_achi_type" :key="dict.value" :label="dict.label"
                      :value="dict.value">
                    </el-option>
                  </el-select>
                </el-col>
              </el-row>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="比例尺或等级" prop="scaleGrade">
              <el-select v-model="form.scaleGrade" placeholder="请选择比例尺或等级" :style="{ width: '100%' }" clearable>
                <el-option v-for="dict in dict.type.cmc_scale_grade" :key="dict.value" :label="dict.label"
                  :value="dict.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="文件类型" prop="fileType">
              <el-input v-model="form.fileType" placeholder="请输入文件类型" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="工作量" prop="workLoad">
              <el-input v-model="form.workLoad" placeholder="请输入工作量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位" prop="unit">
              <el-input v-model="form.unit" placeholder="请输入单位" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="数据来源" prop="dataSource">
              <el-input v-model="form.dataSource" placeholder="请输入数据来源" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="数据类型" prop="dataType">
              <el-select v-model="form.dataType" placeholder="请选择数据类型">
                <el-option label="原始数据" value="原始数据" />
                <el-option label="成果数据" value="成果数据" />
                <el-option label="过程数据" value="过程数据" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="存储地址" prop="storageAddress">
              <el-select v-model="form.storageAddress" placeholder="请选择" filterable allow-create clearable>
                <el-option v-for="item, index in storageList" :key="index" :label="item.storageAddress"
                  :value="item.storageAddress" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="KML地址" prop="kmlUrl">
              <div style="display: flex;">
                <div>
                  <el-input v-model="kmlFileName" placeholder="请选择Kml文件" disabled />
                </div>
                <div>
                  <el-upload ref="uploadAchiKml" class="upload-demo" action="" :auto-upload="false"
                    :on-success="successUploadAchiKml" accept=".kml" :on-change="changeUploadKml"
                    :show-file-list="false">
                    <el-button type="primary" icon="el-icon-plus"></el-button>
                  </el-upload>
                </div>
              </div>

            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="生产日期" prop="productionTime">
              <el-date-picker v-model="form.productionTime" type="month" placeholder="选择日期" format="YYYY年MM月"
                value-format="YYYY年MM月" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="提交时间" prop="submitDate">
              <el-date-picker v-model="form.submitDate" type="date" placeholder="选择日期" format="YYYY年MM月DD日"
                value-format="YYYY年MM月DD日" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" type="textarea" :max="250" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template> -->
      <add-achi :project="form" @getList="getAchiList" @cancel="addOpen = false"></add-achi>
    </el-dialog>
    <!-- 修改成果 -->
    <el-dialog :title="addTitle" :visible.sync="modifyOpen" width="50%">
      <!-- <el-form :model="modifyForm" ref="achiModifyRef" label-width="110px" :rules="modifyRules">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="项目编号">
              <el-input :disabled="true" v-model="modifyForm.projectNumber" placeholder="请输入项目编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="成果名称" prop="achiName">
              <el-input v-model="modifyForm.achiName" placeholder="请输入成果名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="数据年份" prop="dataYear">
              <el-input v-model="modifyForm.dataYear" placeholder="请输入数据年份" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="成果类型" prop="resultType">
              <el-row :gutter="20">
                <el-col :span="22">
                  <el-select v-model="modifyForm.resultType" placeholder="请选择成果类型" :style="{ width: '100%' }" clearable
                    multiple>
                    <el-option v-for="dict in dict.type.cmc_achi_type" :key="dict.value" :label="dict.label"
                      :value="dict.value">
                    </el-option>
                  </el-select>
                </el-col>
                <el-col :span="2">
                  <el-button icon="el-icon-plus" @click="handleResult">
                  </el-button>
                </el-col>
              </el-row>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="比例尺或等级" prop="scaleGrade">
              <el-select v-model="modifyForm.scaleGrade" placeholder="请选择比例尺或等级" :style="{ width: '100%' }" clearable>
                <el-option v-for="dict in dict.type.cmc_scale_grade" :key="dict.value" :label="dict.label"
                  :value="dict.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="文件类型" prop="fileType">
              <el-input v-model="modifyForm.fileType" placeholder="请输入文件类型" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="工作量" prop="workLoad">
              <el-input v-model="modifyForm.workLoad" placeholder="请输入工作量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位" prop="unit">
              <el-input v-model="modifyForm.unit" placeholder="请输入单位" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="数据来源" prop="dataSource">
              <el-input v-model="modifyForm.dataSource" placeholder="请输入数据来源" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="数据类型" prop="dataType">
              <el-select v-model="modifyForm.dataType" placeholder="请选择数据类型">
                <el-option label="原始数据" value="原始数据" />
                <el-option label="成果数据" value="成果数据" />
                <el-option label="过程数据" value="过程数据" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="存储地址" prop="storageAddress">
              <el-select v-model="modifyForm.storageAddress" placeholder="请选择" filterable allow-create clearable>
                <el-option v-for="item, index in storageList" :key="index" :label="item.storageAddress"
                  :value="item.storageAddress" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="KML地址" prop="kmlUrl">
              <div style="display: flex;">
                <div>
                  <el-input v-model="kmlFileName" placeholder="请选择Kml文件" disabled />
                </div>
                <div>
                  <el-upload ref="uploadAchiKml" class="upload-demo" action="" :auto-upload="false"
                    :on-success="successUploadAchiKml" accept=".kml" :on-change="changeUploadKml"
                    :show-file-list="false">
                    <el-button type="primary" icon="el-icon-plus"></el-button>
                  </el-upload>
                </div>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="提交时间" prop="submitDate">
              <el-date-picker v-model="modifyForm.submitDate" type="date" placeholder="选择日期" format="YYYY-MM-DD"
                value-format="YYYY-MM-DD" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="modifyForm.remark" placeholder="请输入备注" type="textarea" :max="250" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitModifyForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template> -->
      <modify-achi :modifyForm="modifyForm" @getList="getAchiList"  @cancel="modifyOpen = false"></modify-achi>
    </el-dialog>
    <!-- 用户上传excel -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px">
      <el-upload ref="uploadRef" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url"
        :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-change="handleFileUploadChange"
        :on-success="handleFileSuccess" :auto-upload="false" drag v-loading="uploadLoading"
        element-loading-text="正在上传，请稍等">
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <template #tip>
          <div class="el-upload__tip text-center">
            <span>仅允许导入xls、xlsx格式文件。</span>
            <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
              @click="importTemplate">下载模板</el-link>
          </div>
        </template>
      </el-upload>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitUpload">确 定</el-button>
          <el-button @click="upload.open = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog title="选择项目" :visible.sync="openProject" width="70%" append-to-body>
      <project-choose @chooseProject="confirmProject"></project-choose>
    </el-dialog>
  </div>
</template>

<script>
import { listAchievement, uploadAchievementSheet, addAchievement, updateAchievement, delAchievement } from "@/api/file/achievement";
import { getProject, downloadTemplate } from "@/api/file/project";
import { saveAs } from 'file-saver'
import { getToken } from "@/utils/auth";
import { listStorage } from "@/api/file/storage";
import { cloneDeep } from "lodash";
import { listType } from '@/api/system/dict/type'
import projectChoose from '@/views/flowable/form/components/chooseProject.vue';
import AddAchi from '../components/addAchi.vue';
import ModifyAchi from '../components/modifyAchi.vue';
export default {
  name: "Achievement",
  dicts: ['cmc_achi_type', 'cmc_scale_grade'],
  components: {
    projectChoose,
    AddAchi,
    ModifyAchi,
  },
  data() {
    return {
      achiTableData: [],
      loading: true,
      total: 0,
      multiple: true,
      ids: [],
      openProject: false,
      chooseProject: {},
      addOpen: false,
      modifyOpen: false,
      addTitle: '成果增加',
      storageList: [],
      projectList: [],
      kmlFileName: '',
      uploadLoading: false,
      fileList: [],
      form: {},
      modifyForm: {},
      uploadFormData: undefined,
      submitFormData: undefined,
      kmlfile: undefined,
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部'Content-Type': 'multipart/form-data', 
        headers: { 'Authorization': "Bearer " + getToken() },
        data: undefined,
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/file/achievement/uploadSheet"
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: undefined,
        projectId: undefined,
        projectNumber: undefined,
        achiName: undefined,
        dataYear: undefined,
        scaleGrade: undefined,
        resultType: undefined,
        fileType: undefined,
        kmlUrl: undefined,
        kmlLng: undefined,
        kmlLat: undefined,
        workLoad: undefined,
        unit: undefined,
        dataSource: undefined,
        dataType: undefined,
        storageId: undefined,
        remark: undefined,
      },
      rules: {
        projectNumber: [{ required: true, message: "项目编号不能为空", trigger: "blur" }],
        achiName: [{ required: true, message: "成果名称不能为空", trigger: "blur" }],
        dataYear: [{ required: true, message: "数据年份不能为空", trigger: "blur" }],
        resultType: [{ required: true, message: "数据类型不能为空", trigger: "blur" }],
        scaleGrade: [{ required: true, message: "比例尺或等级不能为空", trigger: "blur" }],
      },
      modifyRules: {
        projectId: [{ required: true, message: "项目编号不能为空", trigger: "change" }],
        achiName: [{ required: true, message: "成果名称不能为空", trigger: "blur" }],
        dataYear: [{ required: true, message: "数据年份不能为空", trigger: "blur" }],
        resultType: [{ required: true, message: "数据类型不能为空", trigger: "change" }],
        scaleGrade: [{ required: true, message: "比例尺或等级不能为空", trigger: "change" }],
      }
    }
  },

  created() {
    this.getAchiList();
    this.getStorageList();
  },
  /* ------------------------------------------------------------------------------------------------------------ */
  methods: {
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getAchiList();
    },
    getAchiList() {
      this.loading = true;
      if (this.$store.getters.roles.includes('projectLeader') && !this.$store.getters.roles.includes('leader')) {
        this.queryParams.projectLeader = this.$store.getters.userId
      }
      listAchievement(this.queryParams).then(res => {
        this.achiTableData = res.rows;
        this.total = res.total;
        this.loading = false;
      })
    },
    /** 多选框选中数据 */
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.multiple = !selection.length;
    },
    /* 新增成果 */
    handleAddAchievement() {
      this.reset();
      this.addOpen = true;
      this.kmlFileName = '';
      this.addTitle = "成果增加";
    },
    /* 修改成果按钮 */
    handleUpdate(row) {
      this.modifyForm = cloneDeep(row);
      this.modifyForm.projectNumber = this.modifyForm.projectNumber + '-' + this.modifyForm.projectName
      // this.kmlFileName = "";
      // this.kmlFileName = row.kmlUrl;
      // if (typeof (this.modifyForm.resultType) == "string") {
      //   if (this.modifyForm.resultType.indexOf(',') != -1) {
      //     this.modifyForm.resultType = this.modifyForm.resultType.split(',');
      //   } else {
      //     this.modifyForm.resultType = this.modifyForm.resultType.split();
      //   }
      // }
      // if (typeof (this.modifyForm.scaleGrade) == "string") {
      //   if (this.modifyForm.scaleGrade.indexOf(',') != -1) {
      //     this.modifyForm.scaleGrade = this.modifyForm.scaleGrade.split(',');
      //   } else {
      //     this.modifyForm.scaleGrade = this.modifyForm.scaleGrade.split();
      //   }
      // }
      // let dates =  this.modifyForm.submitDate.slice(0,10)
      // this.modifyForm.submitDate = dates;

      this.addTitle = "成果修改"
      this.modifyOpen = true;
    },
    /* 删除按钮 */
    handleDelete(row) {
      const achiIds = row.id;
      const achiName = row.achiName
      this.$modal.confirm('是否确认成果名为"' + achiName + '"的数据项？').then(function () {
        return delAchievement(achiIds);
      }).then(() => {
        this.getAchiList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /* 批量删除操作 */
    handleDeleteMany() {
      this.$modal.confirm('是否确认删除？').then(function () {
        return delAchievement(this.ids);
      }).then(() => {
        this.getAchiList();
        this.ids = [];
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /* 导出 */
    handleExprot() {
      // 为true时为导出所有表
      if (this.multiple) {
        this.download("/file/achievement/export", { ...this.queryParams }, `成果表_所有数据.xlsx`);
      } else {
        this.download("/file/achievement/exportBatch/" + this.ids, { ...this.queryParams }, `成果表_${this.ids.length}条.xlsx`);
      }
    },
    /* 增加确定按钮 */
    submitForm() {
      this.submitFormData = new FormData();
      this.submitFormData.append('uploadKmlFile', this.kmlfile);
      this.$refs["achiRef"].validate(valid => {
        if (valid) {
          for (let i in this.form) {
            this.submitFormData.append(i, this.form[i] == null ? "" : this.form[i]);
          }
          addAchievement(this.submitFormData).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.addOpen = false;
            this.getAchiList();
          });
        } else {
          this.$modal.msgError("请完善必填项");
        }
      })
    },

    /* 修改确定按钮 */
    submitModifyForm() {
      this.submitFormData = new FormData();
      this.submitFormData.append('uploadKmlFile', this.kmlfile);
      this.$refs["achiModifyRef"].validate(valid => {
        delete this.modifyForm.params;
        for (let i in this.modifyForm) {
          this.submitFormData.append(i, this.modifyForm[i] == null ? "" : this.modifyForm[i]);
        }
        this.modifyForm.resultType = this.modifyForm.resultType.toString();
        this.modifyForm.scaleGrade = this.modifyForm.scaleGrade.toString();
        updateAchievement(this.submitFormData).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.modifyOpen = false;
          this.getAchiList();
        });
      })

    },
    /* 取消按钮 */
    cancel() {
      this.addOpen = false;
      this.modifyOpen = false;
    },
    /* 重置新增和修改表单 */
    reset() {
      this.form = {
        id: undefined,
        projectId: undefined,
        projectNumber: undefined,
        achiName: undefined,
        dataYear: undefined,
        scaleGrade: [],
        resultType: [],
        fileType: undefined,
        kmlUrl: undefined,
        kmlLng: undefined,
        kmlLat: undefined,
        workLoad: undefined,
        unit: undefined,
        dataSource: undefined,
        dataType: undefined,
        storageId: undefined,
        remark: undefined,
      }
      this.modifyForm = {
        id: undefined,
        projectId: undefined,
        projectNumber: undefined,
        achiName: undefined,
        dataYear: undefined,
        scaleGrade: [],
        resultType: [],
        fileType: undefined,
        kmlUrl: undefined,
        kmlLng: undefined,
        kmlLat: undefined,
        workLoad: undefined,
        unit: undefined,
        dataSource: undefined,
        dataType: undefined,
        storageId: undefined,
        remark: undefined,
      }
      this.resetForm("achiRef");
    },
    // 上传成果excel
    uploadAchievement() {
      this.upload.title = "上传成果表";
      this.upload.open = true;
    },
    /**Excel文件上传中处理 */
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
      this.uploadLoading = true;
    },
    /* Excel文件改变时 */
    handleFileUploadChange(file, fileList) {
      if (fileList.length > 1) {
        fileList.splice(0, 1);
      }
      this.uploadFormData = new FormData();
      this.uploadFormData.append("file", file);
      this.upload.data = this.uploadFormData;
    },
    /* kml文件改变时 */
    changeUploadKml(file, fileList) {
      if (fileList.length > 1) {
        fileList.splice(0, 1);
      }
      this.kmlFileName = file.name;
      this.kmlfile = file.raw;
    },
    /* 下载模板 */
    importTemplate() {
      // const path = "http://127.0.0.1:8083/profile/template/cg-template.xlsx"
      const path = "http://oa.sccehui.com:6104/prod-api/profile/template/cg-template.xlsx"
      downloadTemplate(path).then(res => {
        const blob = new Blob([res])
        saveAs(blob, '成果表模版.xlsx');
      });
      // this.download("file/achievement/importTemplate", {
      // }, `成果表模板.xlsx`);
    },
    /** Excel文件上传成功处理 */
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.uploadLoading = false;
      this.fileList = [];
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.$refs["uploadRef"].clearFiles();
      this.getAchiList();
    },
    /* Excel上传提交按钮 */
    submitUpload() {
      this.$refs['uploadRef'].submit();
    },
    /* kml文件上传成功处理 */
    successUploadAchiKml(response, file, fileList) {
      this.$refs["uploadAchiKml"].clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
    },
    /* 获取存储地址列表 */
    getStorageList() {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 999999;
      listStorage(this.queryParams).then(response => {
        this.storageList = response.rows;
        this.queryParams.pageSize = 10;
      })
    },

    formatterKmlurl(row, cloumn) {
      if (row.kmlUrl == "" || row.kmlUrl == null) {
        return "无";
      } else {
        return "有";
      }
    },
    // 操作成果类型字典
    handleResult() {
      listType().then(res => {
        if (res.code == 200) {
          let datas = res.rows;
          for (let d of datas) {
            if (d.dictType == "cmc_achi_type") {
              this.$router.push({ path: "/system/dict-data/index/" + d.dictId });
              return
            }
          }
        }
      })

    },
    // 获取表格的row-key,
    getRowKeys(row) {
      return row.id;
    },
    confirmProject(val) {
      if (val.length > 1) {
        this.$message.error('请选择一个项目');
        return
      } else if (val.length == 1) {
        this.chooseProject = val[0]
        // this.chooseProject.projectNumber = this.chooseProject.projectNumber + '-' + this.chooseProject.projectName;
        this.$set(this.form, 'projectNumber', this.chooseProject.projectNumber)
        this.$set(this.form, 'projectName', this.chooseProject.projectName)
        this.form.projectId = val[0].projectId
        this.$refs.achiRef.validateField('projectNumber')
        this.form.dataYear = val[0].projectNumber.substring(0, 4)
      }
      this.openProject = false
    },
  }
}
</script>

<style lang="scss" scoped>
@import "@/assets/styles/element-reset.scss";
</style>