<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline='true'>
        <el-form-item label="体系名称">
          <el-input v-model="searchForm.matName" @keyup.enter.native="searchAllData()" size="small"
            placeholder="请输入体系名称" style="width:150px"></el-input>
        </el-form-item>
        <el-form-item label="体系说明">
          <el-input v-model="searchForm.isoDesc" @keyup.enter.native="searchAllData()" size="small"
            placeholder="请输入体系说明" style="width:150px"></el-input>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-date-picker v-model="searchForm.entrTime" type="daterange" range-separator="至" start-placeholder="开始日期"
            end-placeholder="结束日期" size="small" style="width:400px" format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss" :default-time="['00:00:00', '23:59:59']">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="goon" size="mini" v-loading="tableLoading"
            @click="searchAllData">查询</el-button>
          <el-button icon="el-icon-refresh" type="info" plain size="mini" @click="resetData">重置</el-button>
          <el-button icon="el-icon-back" type="goon" size="mini" @click="toBack">返回消息通知</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-row>
      <el-col :span='10'>
        <el-tabs type="border-card" v-model="activeName" class="testManagement_left">
          <el-tab-pane label="待审核" name="first">
            <div class="common-title-div">
              <div class="common-title-name" style="margin-right: 10px">
                <img style="width: 25px; height: 25px" src='../../../..//assets/img/imgScreen/logo.png' />
                <span v-if="cIsoTypeCode == '485304'">待内审信息</span>
                <span v-else-if="cIsoTypeCode == '485305'">待管理评审</span>
                <span v-else-if="cIsoTypeCode == '485306'">待计划管理</span>
                <span v-else-if="cIsoTypeCode == '485303'">待供应商管理</span>
                <span v-else-if="cIsoTypeCode == '485308'">待质检计划管理</span>
                <span v-else>待表格信息</span>
              </div>
              <div>
                <el-button icon="el-icon-circle-plus-outline" type="goon" size="mini" @click="addData">新增信息</el-button>
                <el-button icon="el-icon-circle-plus-outline" type="goon" size="mini"
                  @click="TooaddData">新增文件</el-button>
                <el-button icon="el-icon-remove-outline" type="danger" size="mini" v-loading="disableDataLoading"
                  @click="disableData">停用</el-button>
              </div>
            </div>
            <div class="common-table-div" style="margin-bottom:0;margin-top:0">
              <el-table v-loading="tableLoading" ref="dataTable" border :height="mainHeight" highlight-current-row
                @selection-change="handleSelectionChange" :data="tableData" :icore-filter-flag="icoreFilterFlag"
                :header-cell-style="tableHeaderCellStyle" @current-change="table1RowChange"
                @row-click="searchFollowDate" :cell-class-name="tableRowClassName" :summary-method="getSummaries2"
                show-summary>
                <el-table-column type="index" label="NO" align="center"></el-table-column>
                <!-- <el-table-column type="selection" width="50" align="center"></el-table-column> -->
                <el-table-column show-overflow-tooltip sortable width="60" align="center" prop="stateFlagName"
                  label="状态"></el-table-column>
                <el-table-column show-overflow-tooltip sortable width="100" align="center" prop="isoName"
                  label="体系名称"></el-table-column>
                <el-table-column show-overflow-tooltip sortable width="100" align="center" prop="isoDesc"
                  label="体系说明"></el-table-column>
                <el-table-column show-overflow-tooltip sortable width="100" align="center" prop="isoTypeName"
                  label="类型"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="filePath" label="下载/预览"
                  align="center">
                  <template slot-scope="scope">
                    <el-tooltip content="下载" placement="bottom" effect="light">
                      <el-button :disabled="!scope.row.filePath" type="goon" size="mini" icon="el-icon-download" circle
                        @click="
                          imgPreView(
                            scope.row,
                            scope.row.filePath
                          )
                          ">
                      </el-button>
                    </el-tooltip>
                    <el-tooltip content="预览" placement="bottom" effect="light">
                      <el-button :disabled="!scope.row.filePath" type="warning" size="mini" icon="el-icon-view" circle
                        @click="
                          imgPreViewY(
                            scope.row,
                            scope.row.filePath
                          )
                          ">
                      </el-button>
                    </el-tooltip>
                  </template>
                </el-table-column>
                <el-table-column show-overflow-tooltip sortable width="100" align="center" prop="createMan"
                  label="创建人"></el-table-column>
                <el-table-column show-overflow-tooltip sortable width="120" align="center" prop="createTime"
                  label="创建时间"></el-table-column>
              </el-table>
            </div>
            <div class="common-foot-style">
              <el-pagination @size-change="handleSizeChangeMain" @current-change="handleCurrentChangeMain"
                :current-page="pageIndex" :page-sizes="[10, 20, 30, 50, 100, 200]" :page-size="pageSize" size="mini"
                layout="total, sizes, prev, pager, next, jumper" :total="total_main" background></el-pagination>
            </div>
          </el-tab-pane>
          <el-tab-pane label="已审核完成" name="wancheng">
            <div class="common-title-div">
              <div class="common-title-name" style="margin-right: 10px">
                <img style="width: 25px; height: 25px" src='../../../..//assets/img/imgScreen/logo.png' />
                <span v-if="cIsoTypeCode == '485304'">已内审信息</span>
                <span v-else-if="cIsoTypeCode == '485305'">已管理评审</span>
                <span v-else-if="cIsoTypeCode == '485306'">已计划管理</span>
                <span v-else-if="cIsoTypeCode == '485303'">已供应商管理</span>
                <span v-else-if="cIsoTypeCode == '485308'">已质检计划管理</span>
                <span v-else>已表格信息</span>
              </div>
              <div>
                <el-button icon="el-icon-remove-outline" type="danger" size="mini" v-loading="disableDataLoading"
                  @click="disableData1">停用</el-button>
              </div>
            </div>
            <div class="common-table-div" style="margin-bottom:0;margin-top:0">
              <el-table v-loading="tableLoading" ref="dataTable" border :height="mainHeight" highlight-current-row
                @selection-change="handleSelectionChange3" :data="tableData3" :icore-filter-flag="icoreFilterFlag"
                :header-cell-style="tableHeaderCellStyle" @current-change="table1RowChange"
                @row-click="searchFollowDate3" :cell-class-name="tableRowClassName" :summary-method="getSummaries2"
                show-summary>
                <el-table-column type="index" label="NO" align="center"></el-table-column>
                <!-- <el-table-column type="selection" width="50" align="center"></el-table-column> -->
                <el-table-column show-overflow-tooltip sortable width="60" align="center" prop="stateFlagName"
                  label="状态"></el-table-column>
                <el-table-column show-overflow-tooltip sortable width="100" align="center" prop="isoName"
                  label="体系名称"></el-table-column>
                <el-table-column show-overflow-tooltip sortable width="100" align="center" prop="isoDesc"
                  label="体系说明"></el-table-column>
                <el-table-column show-overflow-tooltip sortable width="100" align="center" prop="isoTypeName"
                  label="类型"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="filePath" label="下载/预览"
                  align="center">
                  <template slot-scope="scope">
                    <el-tooltip content="下载" placement="bottom" effect="light">
                      <el-button :disabled="!scope.row.filePath" type="goon" size="mini" icon="el-icon-download" circle
                        @click="
                          imgPreView(
                            scope.row,
                            scope.row.filePath
                          )
                          ">
                      </el-button>
                    </el-tooltip>
                    <el-tooltip content="预览" placement="bottom" effect="light">
                      <el-button :disabled="!scope.row.filePath" type="warning" size="mini" icon="el-icon-view" circle
                        @click="
                          imgPreViewY(
                            scope.row,
                            scope.row.filePath
                          )
                          ">
                      </el-button>
                    </el-tooltip>
                  </template>
                </el-table-column>
                <el-table-column show-overflow-tooltip sortable width="100" align="center" prop="createMan"
                  label="创建人"></el-table-column>
                <el-table-column show-overflow-tooltip sortable width="120" align="center" prop="createTime"
                  label="创建时间"></el-table-column>
              </el-table>
            </div>
            <div class="common-foot-style">
              <el-pagination @size-change="handleSizeChangeMain3" @current-change="handleCurrentChangeMain3"
                :current-page="page3.pageIndex" :page-sizes="[10, 20, 30, 50, 100, 200]" :page-size="page3.pageSize"
                size="mini" layout="total, sizes, prev, pager, next, jumper" :total="page3.total_main"
                background></el-pagination>
            </div>
          </el-tab-pane>
          <el-tab-pane label="已停用" name="tiyong">
            <div class="common-title-div">
              <div class="common-title-name" style="margin-right: 10px">
                <img style="width: 25px; height: 25px" src='../../../..//assets/img/imgScreen/logo.png' />
                <span v-if="cIsoTypeCode == '485304'">已停用信息</span>
                <span v-else-if="cIsoTypeCode == '485305'">已停用评审</span>
                <span v-else-if="cIsoTypeCode == '485306'">已停用计划</span>
                <span v-else-if="cIsoTypeCode == '485303'">已停用供应商</span>
                <span v-else-if="cIsoTypeCode == '485308'">已停用计划管理</span>
                <span v-else>表格信息</span>
              </div>
              <div>
                <el-button icon="el-icon-check" type="goon" size="mini" v-loading="enableDataLoading"
                  style="border:3px;" @click="enableData">启用</el-button>
                <el-button icon="el-icon-remove-outline" type="danger" size="mini" v-loading="deleteDataLoading"
                  @click="deleteData">删除</el-button>
              </div>
            </div>
            <div class="common-table-div" style="margin-bottom:0;margin-top:0">
              <el-table v-loading="tableLoading" ref="dataTable" border :height="mainHeight" highlight-current-row
                @selection-change="handleSelectionChange4" :data="tableData4" :icore-filter-flag="icoreFilterFlag"
                :header-cell-style="tableHeaderCellStyle" @current-change="table1RowChange"
                @row-click="searchFollowDate4" :cell-class-name="tableRowClassName" :summary-method="getSummaries2"
                show-summary>
                <el-table-column type="index" label="NO" align="center"></el-table-column>
                <!-- <el-table-column type="selection" width="50" align="center"></el-table-column> -->
                <el-table-column show-overflow-tooltip sortable width="60" align="center" prop="stateFlagName"
                  label="状态"></el-table-column>
                <el-table-column show-overflow-tooltip sortable width="100" align="center" prop="isoName"
                  label="体系名称"></el-table-column>
                <el-table-column show-overflow-tooltip sortable width="100" align="center" prop="isoDesc"
                  label="体系说明"></el-table-column>
                <el-table-column show-overflow-tooltip sortable width="100" align="center" prop="isoTypeName"
                  label="类型"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="filePath" label="下载/预览"
                  align="center">
                  <template slot-scope="scope">
                    <el-tooltip content="下载" placement="bottom" effect="light">
                      <el-button :disabled="!scope.row.filePath" type="goon" size="mini" icon="el-icon-download" circle
                        @click="
                          imgPreView(
                            scope.row,
                            scope.row.filePath
                          )
                          ">
                      </el-button>
                    </el-tooltip>
                    <el-tooltip content="预览" placement="bottom" effect="light">
                      <el-button :disabled="!scope.row.filePath" type="warning" size="mini" icon="el-icon-view" circle
                        @click="
                          imgPreViewY(
                            scope.row,
                            scope.row.filePath
                          )
                          ">
                      </el-button>
                    </el-tooltip>
                  </template>
                </el-table-column>
                <el-table-column show-overflow-tooltip sortable width="100" align="center" prop="createMan"
                  label="创建人"></el-table-column>
                <el-table-column show-overflow-tooltip sortable width="120" align="center" prop="createTime"
                  label="创建时间"></el-table-column>
              </el-table>
            </div>
            <div class="common-foot-style">
              <el-pagination @size-change="handleSizeChangeMain4" @current-change="handleCurrentChangeMain4"
                :current-page="page4.pageIndex" :page-sizes="[10, 20, 30, 50, 100, 200]" :page-size="page4.pageSize"
                size="mini" layout="total, sizes, prev, pager, next, jumper" :total="page4.total_main"
                background></el-pagination>
            </div>
          </el-tab-pane>
        </el-tabs>
      </el-col>
      <el-col :span='14'>
        <div class="common-title-div">
          <div class="common-title-name" style="margin-right: 10px">
            <img style="width: 25px; height: 25px" src='../../../..//assets/img/imgScreen/logo.png' />
            表格内容
          </div>
          <div>
            <el-button icon="el-icon-check" type="goon" size="mini" v-loading="savetDataLoading" style="border:3px;"
              @click="savetData">保存</el-button>
            <el-button icon="el-icon-search" type="goon" size="mini" v-loading="loading"
              @click="previewData">预览</el-button>
            <el-button icon="el-icon-check" type="goon" size="mini" v-loading="submitLoading" style="border:3px;"
              @click="submit">提交</el-button>
            <el-button icon="el-icon-remove-outline" type="danger" size="mini" v-loading="ofSubmitLoading"
              @click="ofSubmit">取消提交</el-button>
          </div>
        </div>
        <div class="common-table-div" style="margin-bottom:0;margin-top:0">
          <el-table v-loading="tableLoading2" ref="dataTable2" border :height="theight" highlight-current-row
            :data="tableData2" @selection-change="table2SelectionChange" :icore-filter-flag="icoreFilterFlag"
            :header-cell-style="tableHeaderCellStyle" @current-change="tableRowChange"
            :cell-class-name="tableRowClassName1" :summary-method="getSummaries2" show-summary>
            <el-table-column type="index" label="NO" align="center"></el-table-column>
            <el-table-column type="selection" width="45" align="center"></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="isoItemName" label="执行项目"
              min-width="100"></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="itemSit" label="项目填入位置"
              min-width="80"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="120" prop="valueSit" label="项目填入值"
              align="center">
              <template slot-scope="scope">
                <el-input v-model="scope.row.valueSit" :disabled="scope.row.itemSit == null || scope.row.stateFlag == 1"
                  :id="scope.column.id + '--' + scope.$index" @keydown.native="keyDown($event, scope.row, scope.$index)"
                  size="small" style="width: 100%">
                </el-input>
              </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="optName" label="执行岗位"
              min-width="100"></el-table-column>
            <!-- <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="createTime" label="执行时间" min-width="100"></el-table-column> -->
            <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="doOrder" label="执行顺序"
              min-width="100"></el-table-column>
            <!-- <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="memo3" label="意见" min-width="100"></el-table-column> -->
          </el-table>
        </div>
      </el-col>
    </el-row>
    <el-dialog @close="closeDialog" :visible.sync="recordShowFlag" width="50%" :close-on-click-modal="false">
      <el-form ref="baseData" label-width="80px" :model="baseData">
        <el-row>
          <el-col>
            <el-form-item prop="isoTypeName" label="体系类型">
              <el-input v-model="baseData.isoTypeName" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item prop="isoName" label="体系名称">
              <el-select v-model="baseData.isoNo" clearable filterable style="width: 100%" collapse-tags size="small">
                <el-option v-for="(item, index) in isoTypeCodeType" :key="index" :label="item.isoName"
                  :value="item.isoNo">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item prop="isoName" label="体系说明">
              <el-input v-model="baseData.isoDesc" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item prop="entrTypeCode" label="备注">
              <el-input v-model="baseData.memo" size="small"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="goon" size="mini" icon="el-icon-check" v-loading="confirmLoading"
          @click="addDateList">确定</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="cancel">取消</el-button>
      </span>
    </el-dialog>
    <el-dialog @close="ToocloseDialog" :visible.sync="ToorecordShowFlag" width="50%" :close-on-click-modal="false">
      <el-form ref="TooData" label-width="80px" :model="TooData" :rules="formRules">
        <el-row>
          <el-col>
            <el-form-item prop="isoTypeName" label="体系类型">
              <el-input v-model="TooData.isoTypeName" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item prop="isoName" label="体系名称">
              <el-select v-model="TooData.isoNo" clearable filterable style="width: 100%" collapse-tags size="small">
                <el-option v-for="(item, index) in isoTypeCodeType" :key="index" :label="item.isoName"
                  :value="item.isoNo">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item prop="isoName" label="体系说明">
              <el-input v-model="TooData.isoDesc" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item prop="entrTypeCode" label="备注">
              <el-input v-model="TooData.memo" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="文件上传" prop="filePath">
              <el-input v-model="TooData.filePath" size="small" readonly disabled
                style="width: 392px; display: inline-block"></el-input>
              <el-upload class="upload" action="" v-if="TooData.filePath - 0 === 0"
                style="width: 40px; display: inline-block" :multiple="false" :show-file-list="false" accept=""
                :http-request="httpRequest">
                <el-button type="goon" size="mini" icon="el-icon-upload2"></el-button>
              </el-upload>
              <el-button v-else type="primary" size="mini" class="el-icon-circle-close" @click="dropFile"></el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="goon" size="mini" icon="el-icon-check" v-loading="TooconfirmLoading"
          @click="TooaddDateList">确定</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="Toocancel">取消</el-button>
      </span>
    </el-dialog>
    <div>
      <div ref="file"></div>
    </div>
  </div>
</template>
<script>
import { getCookie, formatDate } from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
let docx = require("docx-preview");
import pdf from 'vue-pdf'
export default {
  data() {
    return {
      formRules: {
        filePath: [{ required: true, message: '该项不能为空', trigger: 'input' }]
      },
      searchForm: {
        matName: '',
        isoDesc: '',
        entrTime: []
      },
      baseData: {
        isoTypeCode: this.cIsoTypeCode,
        isoTypeName: this.cIsoTypeName,
        isoNo: '',
        isoName: '',
        isoDesc: new Date().getFullYear(),
        memo: ''
      },
      TooData: {
        isoTypeCode: this.cIsoTypeCode,
        isoTypeName: this.cIsoTypeName,
        isoNo: '',
        isoName: '',
        isoDesc: new Date().getFullYear(),
        memo: '',
        filePath: '',
      },
      cIsoTypeCode: '',
      cIsoTypeName: '',
      srcUrl: '',
      activeName: 'first',
      confirmLoading: false,
      TooconfirmLoading: false,
      isoTypeCodeType: [],
      cIsoTypeCodeType: [],
      loading: false,
      savetDataLoading: false,
      submitLoading: false,
      auitdLoading: false,
      tableLoading: false,
      tableLoading2: false,
      auditDataLoading: false,
      deleteDataLoading: false,
      ofSubmitLoading: false,
      enableDataLoading: false,
      disableDataLoading: false,
      tableData: [],
      tableData3: [],
      tableData4: [],
      tableData2: [],
      table1RowChange1: [],//表格2选中的数据
      tableRowChange1: [],//表格2选中的数据
      tableClick: {},//表格1点击的数据
      tableClick3: {},
      tableClick4: {},
      testPostNameType: [],//岗位信息
      mainHeight: 0,
      theight: 0,
      multipleSelection: [],
      multipleSelection3: [],
      multipleSelection4: [],
      multipleSelection1: [],
      icoreFilterFlag: true,
      page3: {
        pageIndex: 1,
        pageSize: 50,
        total_main: 0
      },
      page4: {
        pageIndex: 1,
        pageSize: 50,
        total_main: 0
      },
      pageIndex: 1,
      pageSize: 50,
      total_main: 0,
      recordShowFlag: false,//审核页面显示:
      ToorecordShowFlag: false,
      optNoParameter: '', //登录人岗位
      typeToop: 0,
    }
  },
  async created() {
    this.mainHeight = window.innerHeight - 120
    this.theight = window.innerHeight - 120
    let aaa = new Date()
    let bbb = new Date().getTime() - 60000 * 60 * 24 * 365;
    aaa.setTime(bbb);
    this.searchForm.entrTime = [this.getYNM(aaa) + ' 00:00:00', this.getYNM(new Date()) + ' 23:59:59']

    const cfs = await this.axios.get("pass/baseManagement/v1/limsbaseinfos/like/?pageNum=1&pageSize=50&baseCode=4853", { individualType: "json" });
    if (cfs.data && cfs.data.list.length > 0) {
      this.cIsoTypeCodeType = cfs.data.list;
    }
    this.cIsoTypeCode = this.$route.query.isoTypeCode
    this.axios.post("pass/baseManagement/v1/limsisotmps/queryListByIsoTypeCode", { isoTypeCode: this.cIsoTypeCode }, { individualType: 'json' }).then(res => {
      this.isoTypeCodeType = res.data;
    });
    this.gettestPostNameTypeList();
    this.getCompany();
    this.cIsoTypeName = this.getCode(this.cIsoTypeCode, this.cIsoTypeCodeType, 'baseCode', 'baseName')
    this.baseData.isoTypeCode = this.cIsoTypeCode;
    this.baseData.isoTypeName = this.cIsoTypeName;
    this.TooData.isoTypeCode = this.cIsoTypeCode;
    this.TooData.isoTypeName = this.cIsoTypeName;
    this.searchAllData();
  },
  async mounted() {
  },
  methods: {
    // 关闭弹窗
    closeDialog() {
      this.baseData = {
        isoTypeCode: this.cIsoTypeCode,
        isoTypeName: this.cIsoTypeName,
        isoNo: '',
        isoName: '',
        isoDesc: new Date().getFullYear(),
        memo: ''
      }
    },
    ToocloseDialog() {
      this.TooData = {
        isoTypeCode: this.cIsoTypeCode,
        isoTypeName: this.cIsoTypeName,
        isoNo: '',
        isoName: '',
        isoDesc: new Date().getFullYear(),
        memo: '',
        filePath: ''
      }
    },
    toBack() {
      this.$router.push({ path: '/messagePushConfiguration' })
    },
    gettestPostNameTypeList() {
      let obj = {
        'object': { validFlag: 1 },
        'pageIndex': 1,
        'pageSize': 99999
      }
      this.axios.post('pass/baseManagement/v1/limsbaseposts/queryLimsBasePostPage/', obj, { individualType: 'json' }).then(res => {
        this.testPostNameType = res.data.list;
      })
    },
    getYNM(date) {
      let year = date.getFullYear().toString();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      month = month < 10 ? "0" + month : month;
      day = day < 10 ? "0" + day : day;
      return `${year}-${month}-${day}`;
    },
    getCode(code, arr, codeKey, nameKey) {
      if (!code) {
        return '';
      }
      let targetRow = arr.find(item => {
        return item[codeKey] === code;
      });
      // console.log(targetRow, 'targetRow');
      return targetRow ? targetRow[nameKey] : '';
    },
    addData() {
      this.recordShowFlag = true;
    },
    TooaddData() {
      this.ToorecordShowFlag = true;
    },
    cancel() {
      this.baseData = {
        isoTypeCode: this.cIsoTypeCode,
        isoTypeName: this.cIsoTypeName,
        isoNo: '',
        isoName: '',
        isoDesc: new Date().getFullYear(),
        memo: ''
      }
      this.recordShowFlag = false;
    },
    Toocancel() {
      this.TooData = {
        isoTypeCode: this.cIsoTypeCode,
        isoTypeName: this.cIsoTypeName,
        isoNo: '',
        isoName: '',
        isoDesc: new Date().getFullYear(),
        memo: '',
        filePath: '',
      }
      this.ToorecordShowFlag = false;
    },
    // 文件上传
    async httpRequest(e) {
      let _this = this;
      if (!e.file) {
        // 没有文件
        return false
      }
      let file = new FormData()
      file.append('file', e.file)
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }
      this.axios.post('pass/baseManagement/v1/file/upload', file, config).then(res => {
        if (res.code === '0' || res.code === '200') {
          this.$message.success('上传成功')
          this.TooData.filePath = res.data[0].fileName
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        return this.$message.error(e.message)
      })
    },
    // 删除已有文件
    async dropFile() {
      let result = await this.MessageBox.confirm('确认删除该文件重新上传吗？').catch(() => 'cancel')
      if (result == 'cancel') return
      try {
        const data = await this.axios.get('pass/baseManagement/v1/file/delFile/' + this.TooData.filePath, { individualType: 'json' })
        if (data === '1') {
          this.TooData.filePath = ''
          this.$message.success('文件删除成功')
        } else {
          this.$message.error(data.message)
        }
      } catch (e) {
        this.$message.error('文件删除失败，请重试')
      }
    },
    deleteData() {
      if (this.tableClick4 == {} || this.tableClick4 == null) {
        this.$message.error("请点击一条表格信息！");
        return;
      }
      this.deleteDataLoading = true;
      this.axios.post("pass/baseManagement/v1/limsisodatas/deleteData", this.tableClick4, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.axios.get('pass/baseManagement/v1/file/delFile/' + this.tableClick4.filePath, { individualType: 'json' })
          this.$message.success("删除成功");
          this.searchData4();
        } else {
          this.$message.error(res.message)
        }
        this.deleteDataLoading = false;
      }).catch(err => {
        this.deleteDataLoading = false;
        this.$message.error(err.message)
      })
    },
    //停用
    disableData() {
      if (this.tableClick == {} || this.tableClick == null) {
        this.$message.error("请点击一条表格信息！");
        return;
      }
      this.disableDataLoading = true;
      let str = {
        id: this.tableClick.sdId,
        validFlag: '0'
      }
      this.axios.post("pass/baseManagement/v1/limsisodatas/updateValidFlag", str, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success("停用成功");
          this.searchAllData();
        } else {
          this.$message.error(res.message)
        }
        this.disableDataLoading = false;
      }).catch(err => {
        this.disableDataLoading = false;
        this.$message.error(err.message)
      })
    },
    disableData1() {
      if (this.tableClick3 == {} || this.tableClick3 == null) {
        this.$message.error("请点击一条表格信息！");
        return;
      }
      this.disableDataLoading = true;
      let str = {
        id: this.tableClick3.sdId,
        validFlag: '0'
      }
      this.axios.post("pass/baseManagement/v1/limsisodatas/updateValidFlag", str, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success("停用成功");
          this.searchAllData();
        } else {
          this.$message.error(res.message)
        }
        this.disableDataLoading = false;
      }).catch(err => {
        this.disableDataLoading = false;
        this.$message.error(err.message)
      })
    },
    //启用
    enableData() {
      if (this.tableClick4 == {} || this.tableClick4 == null) {
        this.$message.error("请点击一条表格信息！");
        return;
      }
      this.enableDataLoading = true;
      let str = {
        id: this.tableClick4.sdId,
        validFlag: '1'
      }
      this.axios.post("pass/baseManagement/v1/limsisodatas/updateValidFlag", str, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success("停用成功");
          this.searchAllData();
        } else {
          this.$message.error(res.message)
        }
        this.enableDataLoading = false;
      }).catch(err => {
        this.enableDataLoading = false;
        this.$message.error(err.message)
      })
    },
    addDateList() {
      if (this.baseData.isoNo == "") {
        this.$message.error("请选择体系名称！");
        return;
      }
      this.confirmLoading = true;
      this.baseData.isoName = this.getCode(this.baseData.isoNo, this.isoTypeCodeType, "isoNo", "isoName")
      this.axios.post("pass/baseManagement/v1/limsisodatas/saveLimsIsoDataByAudit", this.baseData, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success("添加成功");
          this.searchData();
        } else {
          this.$message.error(res.message)
        }
        this.confirmLoading = false;
      }).catch(err => {
        this.confirmLoading = false;
        this.$message.error(err.message)
      })
      this.recordShowFlag = false;
    },
    TooaddDateList() {
      if (this.TooData.isoNo == "") {
        this.$message.error("请选择体系名称！");
        return;
      }
      if (this.TooData.filePath == "") {
        this.$message.error("请上传文件！");
        return;
      }
      this.TooconfirmLoading = true;
      this.TooData.isoName = this.getCode(this.TooData.isoNo, this.isoTypeCodeType, "isoNo", "isoName")
      this.axios.post("pass/baseManagement/v1/limsisodatas/saveLimsIsoDataByAuditToo", this.TooData, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success("添加成功");
          this.searchData();
        } else {
          this.$message.error(res.message)
        }
        this.TooconfirmLoading = false;
      }).catch(err => {
        this.TooconfirmLoading = false;
        this.$message.error(err.message)
      })
      this.ToorecordShowFlag = false;
    },
    auitd() {
      if (this.multipleSelection.length < 1) {
        this.$message.error("请选择要审核的内容！")
        return
      }
      for (let i = 0; i < this.multipleSelection.length; i++) {
        if (this.multipleSelection[i].stateFlag == '1') {
          this.$message.error("请选择编辑状态的数据！")
          return
        }
      }
      this.auitdLoading = true;
      this.axios.post("pass/baseManagement/v1/limsisodatas/auitdList", this.multipleSelection, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success("审核成功！");
        } else {
          this.$message.error(res.message)
        }
        this.auitdLoading = false;
      }).catch(err => {
        this.auitdLoading = false;
        this.$message.error(err.message)
      })
    },
    previewData() {
      if (this.tableData2.length < 1) {
        this.$message.error("表格内容中没有数据！")
        return
      }
      let str = this.tableData2[0].sdId
      this.loading = true;
      this.axios.get('pass/baseManagement/v1/limsisodatads/previewData/' + str, { responseType: 'blob' }, { headers: { 'content-type': 'application/x-www-form-urlencoded' } }).then(res => {
        docx.renderAsync(res, this.$refs.file)
        this.loading = false;
      }).catch(e => {
        this.loading = false;
        return this.$message.error(e.message)
      })
    },
    imgPreView(row, fileName) {
      this.axios.get('pass/baseManagement/v1/file/download/' + fileName, { responseType: 'blob' }, { headers: { 'content-type': 'application/x-www-form-urlencoded' } }).then(res => {
        let blob = new Blob([res]);
        let elink = document.createElement('a');
        elink.download = fileName;
        elink.style.display = 'none';
        elink.target = "_blank";
        elink.href = URL.createObjectURL(blob);
        document.body.appendChild(elink);
        elink.click();
        URL.revokeObjectURL(elink.href); // 释放URL对象
        document.body.removeChild(elink);
      }).catch(e => {
        return this.$message.error(e.message)
      })
    },
    imgPreViewY(row, fileName) {
      let aaa = fileName.substr(fileName.indexOf(".") + 1);
      if (aaa == "docx") {
        this.axios.get('pass/baseManagement/v1/file/download/' + fileName, { responseType: 'blob' }, { headers: { 'content-type': 'application/x-www-form-urlencoded' } }).then(res => {
          docx.renderAsync(res, this.$refs.file)
        }).catch(e => {
          return this.$message.error(e.message)
        })
      } else if (aaa == "pdf") {
        this.axios.get('pass/baseManagement/v1/file/download/' + fileName, { responseType: 'blob' }, { headers: { 'content-type': 'application/x-www-form-urlencoded' } }).then(res => {
          const binaryData = [];
          binaryData.push(res);
          this.srcUrl = window.URL.createObjectURL(new Blob(binaryData, { type: 'application/pdf' }))
          window.open(this.srcUrl);
        }).catch(e => {
          return this.$message.error(e.message)
        })
      } else {
        docx.renderAsync(new Blob(), this.$refs.file)
        return this.$message.error("不支持这个类型的文件展示！")
      }
    },
    ofSubmit() {
      if (this.multipleSelection1.length < 1) {
        this.$message.error("请选择要取消提交的表格数据！")
        return
      }
      let bg = false;
      let bg1 = false;
      this.multipleSelection1.forEach(s => {
        if (s.stateFlag == 0) {
          bg = true;
        }
        if (s.optNo != this.optNoParameter) {
          bg1 = true;
        }
      })
      if (bg) {
        this.$message.error("未提交的数据不能取消提交！")
        return
      }
      // if(bg1){
      //     this.$message.error("您不是这个岗位的，不可取消提交！")
      //     return
      // }
      this.ofSubmitLoading = true;
      this.axios.post("pass/baseManagement/v1/limsisodatads/ofSubmitLimsIsoDataD", this.multipleSelection1, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success("取消提交成功！");
          this.searchFollow(this.tableClick);
        } else {
          this.$message.error(res.data)
        }
        this.ofSubmitLoading = false;
      }).catch(err => {
        this.ofSubmitLoading = false;
        this.$message.error(err.data)
      })
    },
    submit() {
      if (this.multipleSelection1.length < 1) {
        this.$message.error("请选择要提交的表格数据！")
        return
      }
      let bg = false;
      let bg1 = false;
      this.multipleSelection1.forEach(s => {
        if (s.stateFlag == 1) {
          bg = true;
        }
        if (s.optNo != this.optNoParameter) {
          bg1 = true;
        }
      })
      if (bg) {
        this.$message.error("已提交的数据不能在次提交！")
        return
      }
      if (bg1) {
        this.$message.error("您不是这个岗位的，不可提交数据！")
        return
      }
      this.submitLoading = true;
      this.axios.post("pass/baseManagement/v1/limsisodatads/submitLimsIsoDataD", this.multipleSelection1, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success("提交成功！");
          this.searchFollow(this.tableClick);
        } else {
          this.$message.error(res.data)
        }
        this.submitLoading = false;
      }).catch(err => {
        this.submitLoading = false;
        this.$message.error(err.data)
      })
    },
    savetData() {
      if (this.tableData2.length < 1) {
        this.$message.error("表格内容中没有数据！")
        return
      }
      this.savetDataLoading = true;
      this.axios.post("pass/baseManagement/v1/limsisodatads/updateDataList", this.tableData2, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success("保存成功！");
          this.searchFollow(this.tableClick);
        } else {
          this.$message.error(res.message)
        }
        this.savetDataLoading = false;
      }).catch(err => {
        this.savetDataLoading = false;
        this.$message.error(err.message)
      })
    },
    //获取个人所属哪个岗位
    getCompany() {
      this.axios.get('pass/baseManagement/v1/limslrcemps/' + userId).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.optNoParameter = res.data ? res.data.postNo : ''
        } else {
          this.$message.error(e.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    searchAllData() {
      this.searchData();
      this.searchData3();
      this.searchData4();
    },
    searchData() {
      let startTime = ''
      let endTime = ''
      if (!this.searchForm.entrTime) {
        startTime = ''
        endTime = ''
      } else {
        startTime = this.searchForm.entrTime[0]
        endTime = this.searchForm.entrTime[1]
      }
      let obj = {
        pageNum: this.pageIndex,
        pageSize: this.pageSize,
        startTime: startTime,
        endTime: endTime,
        stateFlag: '0',
        validFlag: '1',
        isoDesc: this.searchForm.isoDesc,
        isoName: this.searchForm.matName,
        isoTypeCode: this.cIsoTypeCode
      }
      this.tableLoading = true;
      this.axios.post("pass/baseManagement/v1/limsisodatas/queryLimsIsoDataAuitd", obj, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData = res.data.list
          this.total_main = res.data.total
          this.tableData.forEach(item => {
            item.stateFlagName = item.stateFlag === '0' ? '编辑' : item.stateFlag === '1' ? '提交' : ''
          })
          if (this.tableData.length > 0) {
            this.$refs.dataTable.setCurrentRow(this.tableData[0]);
            this.searchFollow(this.tableData[0])
          }
          this.tableLoading = false;
        } else {
          this.$message.error(res.message)
          this.tableLoading = false;
        }
      }).catch(err => {
        this.tableLoading = false;
        this.$message.error(err.message)
      })
    },
    searchData3() {
      let startTime = ''
      let endTime = ''
      if (!this.searchForm.entrTime) {
        startTime = ''
        endTime = ''
      } else {
        startTime = this.searchForm.entrTime[0]
        endTime = this.searchForm.entrTime[1]
      }
      let obj = {
        pageNum: this.page3.pageIndex,
        pageSize: this.page3.pageSize,
        startTime: startTime,
        endTime: endTime,
        stateFlag: '1',
        validFlag: '1',
        isoDesc: this.searchForm.isoDesc,
        isoName: this.searchForm.matName,
        isoTypeCode: this.cIsoTypeCode
      }
      this.tableLoading = true;
      this.axios.post("pass/baseManagement/v1/limsisodatas/queryLimsIsoDataAuitd", obj, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData3 = res.data.list
          this.page3.total_main = res.data.total
          this.tableData3.forEach(item => {
            item.stateFlagName = item.stateFlag === '0' ? '编辑' : item.stateFlag === '1' ? '提交' : ''
          })
          this.tableLoading = false;
        } else {
          this.$message.error(res.message)
          this.tableLoading = false;
        }
      }).catch(err => {
        this.tableLoading = false;
        this.$message.error(err.message)
      })
    },
    searchData4() {
      let startTime = ''
      let endTime = ''
      if (!this.searchForm.entrTime) {
        startTime = ''
        endTime = ''
      } else {
        startTime = this.searchForm.entrTime[0]
        endTime = this.searchForm.entrTime[1]
      }
      let obj = {
        pageNum: this.page4.pageIndex,
        pageSize: this.page4.pageSize,
        startTime: startTime,
        endTime: endTime,
        validFlag: '0',
        isoDesc: this.searchForm.isoDesc,
        isoName: this.searchForm.matName,
        isoTypeCode: this.cIsoTypeCode
      }
      this.tableLoading = true;
      this.axios.post("pass/baseManagement/v1/limsisodatas/queryLimsIsoDataAuitd", obj, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData4 = res.data.list
          this.page4.total_main = res.data.total
          this.tableData4.forEach(item => {
            item.stateFlagName = item.stateFlag === '0' ? '编辑' : item.stateFlag === '1' ? '提交' : ''
          })
          this.tableLoading = false;
        } else {
          this.$message.error(res.message)
          this.tableLoading = false;
        }
      }).catch(err => {
        this.tableLoading = false;
        this.$message.error(err.message)
      })
    },
    searchFollowDate(row) {
      this.tableClick = row;
      this.searchFollow(row);
    },
    searchFollowDate3(row) {
      this.tableClick3 = row;
      this.searchFollow(row);
    },
    searchFollowDate4(row) {
      this.tableClick4 = row;
      this.searchFollow(row);
    },
    searchFollow(row) {
      this.tableLoading2 = true;
      this.axios.post("pass/baseManagement/v1/limsisodatads/queryLimsIsoDataDsByIsoNo", row, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData2 = res.data;
          this.tableData2.forEach(item => {
            item.optName = this.getCode(item.optNo, this.testPostNameType, 'postNo', 'postName')
          })
          this.tableLoading2 = false;
        } else {
          this.$message.error(res.message)
          this.tableLoading2 = false;
        }
      }).catch(err => {
        this.tableLoading2 = false;
        this.$message.error(err.message)
      })
    },
    tableRowChange(row) {
      this.tableRowChange1 = row;
    },
    table1RowChange(row) {
      this.table1RowChange1 = row;
    },
    resetData() {
      this.searchForm.matName = ''
      this.searchForm.entrTime = [this.getYNM(new Date()) + ' 00:00:00', this.getYNM(new Date()) + ' 23:59:59']
      this.searchAllData()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSelectionChange3(val) {
      this.multipleSelection3 = val;
    },
    handleSelectionChange4(val) {
      this.multipleSelection4 = val;
    },
    table2SelectionChange(val) {
      this.multipleSelection1 = val;
    },
    handleSizeChangeMain(pageSize) {
      this.pageIndex = 1;
      this.pageSize = pageSize;
      this.searchData();
    },
    handleCurrentChangeMain(pageIndex) {
      this.pageIndex = pageIndex;
      this.searchData();
    },
    handleSizeChangeMain3(pageSize) {
      this.page3.pageIndex = 1;
      this.page3.pageSize = pageSize;
      this.searchData3();
    },
    handleCurrentChangeMain3(pageIndex) {
      this.page3.pageIndex = pageIndex;
      this.searchData3();
    },
    handleSizeChangeMain4(pageSize) {
      this.page4.pageIndex = 1;
      this.page4.pageSize = pageSize;
      this.searchData4();
    },
    handleCurrentChangeMain4(pageIndex) {
      this.page4.pageIndex = pageIndex;
      this.searchData4();
    },
    keyDown(event, row, rindex) {
      let tdTarget = event.target;
      let pid = tdTarget.id;
      if (!pid) {
        return true;
      }
      let ids = pid.split("--");
      if (ids.length != 2) {
        return true;
      }
      let columnId = ids[0];
      let index = ids[1];
      let that = this;
      while (tdTarget.tagName !== 'TD') {
        tdTarget = tdTarget.parentElement;
      }
      // 如果按下键盘下键或者回车键
      if (event.keyCode === 40 || event.keyCode === 13) {
        let ind = Number(rindex) + 1;
        let id = '#' + columnId + '--' + ind;
        let input = $(id);
        if (input) {
          this.$refs.dataTable2.setCurrentRow(this.tableData2[ind]);
          input.focus();
          input.blur();
          input.select(); // 选中内容
          event.stopPropagation();
          event.stopImmediatePropagation();
          event.preventDefault();
          return false;
        }
      } else if (event.keyCode === 38) { // 键盘上键
        let ind = Number(index) - 1;
        let id = '#' + columnId + '--' + ind;
        let input = $(id);
        if (input) {
          this.$refs.dataTable2.setCurrentRow(this.tableData2[ind]);
          input.focus();
          input.select(); // 选中内容
          event.stopPropagation();
          event.stopImmediatePropagation();
          event.preventDefault();
          return false;
        }
      }
    },
    getSummaries2(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
        }
        if (index === 1) {
          sums[index] = data.length;
        } else if (column.property === "quantity") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].quantity ? data[i].quantity : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        } else if (column.property === "factweight") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].factweight ? data[i].factweight : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        }
      });
      return sums;
    },
    tableHeaderCellStyle() {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    },
    //停用变色
    tableRowClassName({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 1) {
        if (row.stateFlag == '1') {
          return 'error-green';
        }
      }
    },
    //停用变色
    tableRowClassName1({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 1) {
        if (row.stateFlag == '1') {
          return 'error-green';
        }
        if (row.stateFlag == '2') {
          return 'error-row';
        }
      }
    },
  }
}
</script>
