<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item :label="$t('年份')" prop="year">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.year"
                        type="year"
                        value-format="yyyy"
                        :placeholder="$t('请选择')+$t('年份')">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="$t('负责人')" prop="responsible">
        <el-select v-model="queryParams.responsible" filterable :placeholder="$t('请选择')+$t('负责人')">
          <el-option
            v-for="dict in responsibleOptions2"
            :key="dict.staffid"
            :label="dict.name"
            :value="dict.staffid">
            <span style="float: left">{{ dict.name }}</span>
            <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.staffid }}</span>
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</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"
          :disabled="single"
          v-hasPermi="['plant:targetmeasures:add']"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['plant:targetmeasures:export']"
        >{{ $t('导出目标跟踪表') }}</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="targetlistList" :span-method="mergeMethod" @selection-change="handleSelectionChange" :cell-class-name="tableCellClassName" :height="clientHeight" border>
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column :label="$t('年份')" align="center" prop="year" width="50" />
      <el-table-column :label="$t('序号')" align="center" prop="item" width="50" />
      <el-table-column :label="$t('内容')" align="center" prop="description" width="270"/>
      <el-table-column :label="$t('目标')" align="center" prop="targets" />
      <el-table-column :label="$t('方案/行动计划/措施')" align="center" prop="measures" width="600" />
      <el-table-column :label="$t('负责人')" align="center" prop="responsible" width="200"/>
      <el-table-column :label="$t('计划完成日期')" align="center" prop="expectedDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expectedDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" fixed="right" width="110" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['plant:targetlist:edit']"
            v-if="scope.row.measures!=null"
          >{{ $t('修改') }}</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['plant:targetlist:remove']"
            v-if="scope.row.measures!=null"
          >{{ $t('删除') }}</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="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item :label="$t('年份')" prop="year">
          <el-input v-model="form.year" disabled />
        </el-form-item>
        <el-form-item :label="$t('序号')" prop="item">
          <el-input v-model="form.item" disabled />
        </el-form-item>
        <el-form-item :label="$t('内容')" prop="description">
          <el-input v-model="form.description" disabled />
        </el-form-item>
        <el-form-item :label="$t('目标')" prop="targets">
          <el-input v-model="form.targets" disabled />
        </el-form-item>
        <el-form-item :label="$t('方案/行动计划/措施')" prop="measures" label-width="150px">
          <el-input v-model="form.measures" :placeholder="$t('请输入') + $t('方案/行动计划/措施')" />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('负责人')" prop="responsible">
              <el-select v-model="responsibles" filterable multiple :placeholder="$t('请选择') + $t('负责人')">
                <el-option
                  v-for="dict in responsibleOptions"
                  :key="dict.staffid"
                  :label="dict.name"
                  :value="dict.staffid">
                  <span style="float: left">{{ dict.name }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.staffid }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('计划完成日期')" prop="expectedDate" label-width="110px">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.expectedDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              :placeholder="$t('请选择') + $t('计划完成日期')">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('备注')" prop="remarks">
              <el-input v-model="form.remarks" :placeholder="$t('请输入') + $t('第四季度')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('归属部门')" prop="deptId" label-width="110px">
              <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" :placeholder="$t('请选择') + $t('归属部门')" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">{{ $t('确 定') }}</el-button>
        <el-button @click="cancel">{{ $t('取 消') }}</el-button>
      </div>
    </el-dialog>

    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          {{ $t('将文件拖到此处，或') }}
          <em>{{ $t('点击上传') }}</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport" />{{ $t('是否更新已经存在的用户数据') }}
          <el-link type="info" style="font-size:12px" @click="importTemplate">{{ $t('下载模板') }}</el-link>
        </div>
        <div class="el-upload__tip" style="color:#ff0000" slot="tip">{{ $t('提示：仅允许导入“xls”或“xlsx”格式文件！') }}</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">{{ $t('确 定') }}</el-button>
        <el-button @click="upload.open = false">{{ $t('取 消') }}</el-button>
      </div>
    </el-dialog>

    <!-- 下载对话框 -->
    <el-dialog v-dialogDrag :title="download.title" :visible.sync="download.open" width="400px" append-to-body>
      <el-form :model="queryParams" ref="queryForm" label-width="68px">
        <el-form-item :label="$t('年份')" prop="year">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="queryParams.year"
                          type="year"
                          value-format="yyyy"
                          :placeholder="$t('请选择') + $t('年份')">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="cyan" icon="el-icon-download" size="mini" @click="downloadOperate">{{ $t('下载') }}</el-button>
        </el-form-item>
      </el-form>
      <form ref="downloadForm" :action="downloadAction" target="FORMSUBMIT">
        <input name="year" v-model="downloadForm.year"  hidden  />
      </form>
    </el-dialog>

    <!-- 报告附件对话框 -->
    <el-dialog v-dialogDrag :title="doc.title" :visible.sync="doc.open" width="1000px" append-to-body >
      <el-upload
                 ref="doc"
                 :limit="50"
                 :headers="doc.headers"
                 :action="doc.url + '?pType=' + doc.pType + '&pId=' + doc.pId"
                 :disabled="doc.isUploading"
                 :on-progress="handleFileDocProgress"
                 :on-success="handleFileDocSuccess"
                 :auto-upload="true"
                 drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          {{ $t('将文件拖到此处，或') }}
          <em>{{ $t('点击上传') }}</em>
        </div>
      </el-upload>
      <el-table :data="doc.commonfileList" border>
        <el-table-column :label="$t('文件名')" align="center" prop="fileName" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <a  class="link-type"  @click="handleDownload(scope.row)">
              <span>{{ scope.row.fileName }}</span>
            </a>
          </template>
        </el-table-column>
        <el-table-column :label="$t('大小(Kb)')" align="center" prop="fileSize" :show-overflow-tooltip="true" width="80" />
        <el-table-column :label="$t('上传人')" align="center" prop="creator" :show-overflow-tooltip="true" width="120"/>
        <el-table-column :label="$t('培训日期')" align="center" prop="pDate"  width="150">
          <template slot-scope="scope">
            <el-date-picker
              v-if="scope.row.isEdit"
              v-model="scope.row.pDate"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('日期')">
            </el-date-picker>
            <span v-else>{{ parseTime(scope.row.pDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('操作')" align="center" width="220" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.fileName.endsWith('pdf')"
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleSee(scope.row)"
            >{{ $t('预览') }}</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-download"
              @click="handleDownload(scope.row)"
            >{{ $t('下载') }}</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDeleteDoc(scope.row)"
              v-hasPermi="['training:trainingrecords:file']"
            >{{ $t('删除') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog v-dialogDrag :title="pdf.title" :visible.sync="pdf.open" width="1300px" append-to-body>
        <div style="margin-top: -60px;float: right;margin-right: 40px;">
          <el-button size="mini" type="text" @click="openPdf">{{$t('新页面打开PDF')}}</el-button></div>
        <div style="margin-top: -30px">
          <iframe :src="pdf.pdfUrl" frameborder="0" width="100%" height="700px"></iframe>
        </div>
      </el-dialog>

      <div slot="footer" class="dialog-footer">
        <!--        <el-button type="primary" @click="submitFileForm">{{ $t('确 定') }}</el-button>-->
        <el-button @click="doc.open = false">{{ $t('返 回') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { getTargetmeasures, delTargetmeasures, addTargetmeasures, updateTargetmeasures, exportTargetmeasures, importTemplate} from "@/api/plant/targetmeasures";
  import { listMeasures, getTargetlist } from "@/api/plant/targetlist";
  import {listAllStaffmgr, listStaffmgr} from "@/api/plant/staffmgr";
  import { treeselect } from "@/api/system/dept";
  import { getToken } from "@/utils/auth";
  import {allFileList, delCommonfile } from "@/api/common/commonfile";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";


  export default {
    name: "Targetmeasures",
    components: { Treeselect },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: false,
        // 总条数
        total: 0,
        //负责人多选
        responsibles: [],
        // 目标措施表格数据
        targetmeasuresList: [],
        // 目标录入表格数据
        targetlistList: [],
        //行动项表格数据
        targetactionList: [],
        // 人员字典
        responsibleOptions: [],
        responsibleOptions2: [],
        principalOptions: [],
        // 弹出层标题
        title: "",
        // 部门树选项
        deptOptions: undefined,
        clientHeight:300,
        // 是否显示弹出层
        open: false,
        // 用户导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/plant/targetmeasures/importData"
        },
        // 报告附件参数
        doc: {
          file: "",
          // 是否显示弹出层（报告附件）
          open: false,
          // 弹出层标题（报告附件）
          title: this.$t('附件'),
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 报告附件上传位置编号
          ids: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/common/commonfile/uploadFile",
          commonfileList: null,
          queryParams: {
            pId: null,
            pType: ''
          },
          pType: '',
          pId: null,
          form: {}
        },
        pdf : {
          title: '',
          pdfUrl: '',
          numPages: null,
          open: false,
          pageNum: 1,
          pageTotalNum: 1,
          loadedRatio: 0,
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20
        },
        //人员表查询参数
        staffmgrQueryParams: {
          actualposts: "12,14,16,18,20,24,26"
        },
        staffmgrPrincipal: {
          actualposts: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          measures: [
            { required: true, message: this.$t('方案/行动计划/措施') + this.$t('不能为空'), trigger: "blur" }
          ],
          expectedDate: [
            { required: true, message: this.$t('计划完成日期') + this.$t('不能为空'), trigger: "blur" }
          ],
          deptId: [
            { required: true, message: this.$t('部门编号') +this.$t('不能为空'), trigger: "blur" }
          ]
        },
        //下载按钮参数
        download: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
        },
        //下载参数
        downloadForm: {
          year: '',
        },
        downloadAction: process.env.VUE_APP_BASE_API +'/plant/targetmeasures/exportPDF',
      };
    },
    watch: {
      // 根据名称筛选部门树
      deptName(val) {
        this.$refs.tree.filter(val);
      }
    },
    created() {
      //设置表格高度对应屏幕高度
      this.$nextTick(() => {
        this.clientHeight = document.body.clientHeight -250
      })
      this.getResponsible();
      this.getResponsible2();
      this.getPrincipal();
      this.getTreeselect();
    },
    methods: {
      /** 查询目标措施列表 */
      getList() {
        let _this = this
        this.loading = true;
        listMeasures(this.queryParams).then(response => {
          response.rows.forEach(function (value,key,arr) {
            var responsiblesName = null;
            if (value.responsible != null) {
              let responsibles = value.responsible.split(",");
              responsibles.forEach(function (id, index) {
                _this.responsibleOptions2.forEach(function (item) {
                  if (item.staffid === id) {
                    if (index === 0) {
                      responsiblesName = item.name
                    }else {
                      responsiblesName = responsiblesName + "," + item.name
                    }
                  }
                });
              });
            }
            response.rows[key].responsible = responsiblesName;
          });
          this.targetlistList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      getResponsible() {
        listStaffmgr(this.staffmgrQueryParams).then(response => {
          this.responsibleOptions = response.rows;
          this.getList();
        });
      },
      getResponsible2() {
        listAllStaffmgr(this.staffmgrQueryParams).then(response => {
          this.responsibleOptions2 = response.rows;
          this.getList();
        });
      },
      getPrincipal() {
        listStaffmgr(this.staffmgrPrincipal).then(response => {
          this.principalOptions = response.rows;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          targetlistId: null,
          item: null,
          description: null,
          targets: null,
          year: null,
          measures: null,
          responsible: null,
          expectedDate: null,
          firstquarter: null,
          halfyear: null,
          threequarter: null,
          annual: null,
          firstquarterStatus: null,
          halfyearStatus: null,
          threequarterStatus: null,
          annualStatus: null,
          firstChecker: null,
          secondChecker: null,
          threeChecker: null,
          annualChecker: null,
          delFlag: null,
          createrCode: null,
          createdate: null,
          updaterCode: null,
          updatedate: null,
          deptId: null,
          remarks: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd(row) {
        this.reset();
        const id = row.id || this.ids
        getTargetlist(id).then(response => {
          this.form.year = response.data.year;
          this.form.item = response.data.item;
          this.form.description = response.data.description;
          this.form.targets = response.data.targets;
          this.form.targetlistId = response.data.id;
          this.responsibles = [];
          this.open = true;
          this.title = this.$t('添加')+this.$t('目标措施');
        });
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        const measuresId = row.measuresId;
        getTargetmeasures(measuresId).then(response => {
          this.form = response.data;
          if (this.form.responsible != null) {
            this.responsibles = this.form.responsible.split(',');
          }else {
            this.responsibles = [];
          }
          getTargetlist(id).then(response => {
            this.form.year = response.data.year;
            this.form.item = response.data.item;
            this.form.description = response.data.description;
            this.form.targets = response.data.targets;
            this.open = true;
            this.title = this.$t('修改')+this.$t('目标措施');
          });
        });
      },
      /** 提交按钮 */
      submitForm() {
        var responsibleId = null;
        this.responsibles.forEach(function (value,key,arr) {
          if (key != 0) {
            responsibleId = responsibleId + "," + value;
          }else if (key == 0) {
            responsibleId = value;
          }
        })
        this.form.responsible = responsibleId;
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateTargetmeasures(this.form).then(response => {
                this.msgSuccess(this.$t('修改成功'));
                this.open = false;
                this.getList();
              });
            } else {
              addTargetmeasures(this.form).then(response => {
                this.msgSuccess(this.$t('新增成功'));
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.measuresId
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: "warning"
        }).then(function() {
          return delTargetmeasures(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess(this.$t('删除成功'));
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download.open = true;
        this.download.title = this.$t('导出目标跟踪表');
      },
      /** 下载按钮操作 */
      downloadOperate() {
        if (this.queryParams.year == null) {
          this.msgError(this.$t('请选择')+this.$t('年份'));
        }else {
          this.downloadForm.year = this.queryParams.year;
          this.$nextTick(() => {
            this.$refs['downloadForm'].submit()
            this.resetForm("queryForm");
          })
        }
      },
      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = this.$t('用户导入');
        this.upload.open = true;
      },
      /** 下载模板操作 */
      importTemplate() {
        importTemplate().then(response => {
          this.download(response.msg);
        });
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.$alert(response.msg, this.$t('导入结果'), { dangerouslyUseHTMLString: true });
        this.getList();
      },
      // 提交上传文件
      submitFileForm() {
        this.$refs.upload.submit();
      },
      //合并单元格
      mergeMethod({ row, column, rowIndex, columnIndex }) {
        if (columnIndex === 0) {
          const _row = this.setTable(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 1) {
          const _row = this.setTable(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 2) {
          const _row = this.setTable(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 3 ) {
          const _row = this.setTable(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 4 ) {
          const _row = this.setTable(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 5 ) {
          const _row = this.setTableTwo(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 6 ) {
          const _row = this.setTableTwo(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 7 ) {
          const _row = this.setTableTwo(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 8 ) {
          const _row = this.setTableTwo(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 9 ) {
          const _row = this.setTableTwo(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 10 ) {
          const _row = this.setTableTwo(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 11 ) {
          const _row = this.setTableTwo(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 12 ) {
          const _row = this.setTableTwo(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 13 ) {
          const _row = this.setTableTwo(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 14 ) {
          const _row = this.setTableTwo(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 15 ) {
          const _row = this.setTableTwo(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 20 ) {
          const _row = this.setTableTwo(this.targetlistList).merge[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
      },
      setTable(tableData) {
        let spanArr = [],
          concat = 0;
        tableData.forEach((item, index) => {
          if (index === 0) {
            spanArr.push(1);
          } else {
            if (item.item === tableData[index - 1].item) {
              //第一列需合并相同内容的判断条件
              spanArr[concat] += 1;
              spanArr.push(0);
            } else {
              spanArr.push(1);
              concat = index;
            }
          }
        });
        return {
          merge: spanArr
        };
      },
      setTableTwo(tableData) {
        let spanArr = [],
          concat = 0;
        tableData.forEach((item, index) => {
          if (index === 0) {
            spanArr.push(1);
          } else {
            if (item.measures === tableData[index - 1].measures) {
              //第一列需合并相同内容的判断条件
              spanArr[concat] += 1;
              spanArr.push(0);
            } else {
              spanArr.push(1);
              concat = index;
            }
          }
        });
        return {
          merge: spanArr
        };
      },
      /** 报告附件按钮操作 */
      handleDoc(row , fileType) {
        this.doc.pType = fileType
        this.doc.queryParams.pType = fileType
        this.doc.id = row.id;
        var titleType = '';
        if (fileType === 'targetMeasures-first') {
          titleType = this.$t('第一季度')+' '+this.$t('附件')
        }else if (fileType === 'targetMeasures-second') {
          titleType = this.$t('第二季度')+' '+this.$t('附件')
        }else if (fileType === 'targetMeasures-third') {
          titleType = this.$t('第三季度')+' '+this.$t('附件')
        }else {
          titleType = this.$t('第四季度')+' '+this.$t('附件')
        }
        this.doc.title = titleType;
        this.doc.open = true;
        this.doc.queryParams.pId = row.id
        this.doc.pId = row.id
        this.getFileList()
        this.$nextTick(() => {
          this.$refs.doc.clearFiles()
        })
      },
      getFileList (){
        allFileList(this.doc.queryParams).then(response => {
          response.forEach(element => {
            element["isEdit"] = false
          });
          response.forEach(element => {
            element["isAdd"] = false
          });
          this.doc.commonfileList = response;
        });
      },
      //附件上传中处理
      handleFileDocProgress(event, file, fileList) {
        this.doc.file = file;
        this.doc.isUploading = true;
      },
      //附件上传成功处理
      handleFileDocSuccess(response, file, fileList) {
        this.doc.isUploading = false;
        this.$alert(response.msg, this.$t('导入结果'), { dangerouslyUseHTMLString: true });
        this.getFileList()
      },
      // 文件下载处理
      handleDownload(row) {
        var name = row.fileName;
        var url = row.fileUrl;
        var suffix = url.substring(url.lastIndexOf("."), url.length);
        const a = document.createElement('a')
        a.setAttribute('download', name)
        a.setAttribute('target', '_blank')
        a.setAttribute('href', process.env.VUE_APP_BASE_API + url)
        a.click()
      },
      /** 删除按钮操作 */
      handleDeleteDoc(row) {
        const ids = row.id || this.ids;
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: "warning"
        }).then(function() {
          return delCommonfile(ids);
        }).then(() => {
          this.getFileList()
          this.msgSuccess(this.$t('删除成功'));
        })
      },
      //pdf预览
      openPdf(){
        window.open(this.pdf.pdfUrl);//path是文件的全路径地址
      },
      handleSee (row){
        this.pdf.open =true
        this.pdf.title = row.fileName
        this.pdf.pdfUrl = process.env.VUE_APP_BASE_API +'/pdf/web/viewer.html?file=' + process.env.VUE_APP_BASE_API + row.fileUrl
      },
    }
  };
</script>

<style scoped>
  /deep/.el-input.is-disabled .el-input__inner{
    background-color: #F5F7FA;
    border-color: #ecedf0;
    color: #636363;
    cursor: not-allowed;
  }
</style>
