<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline='true'>
        <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="searchData">查询</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'>
        <div class="common-title-div">
          <div class="common-title-name">
            <img style="width: 25px; height: 25px" src='../../../..//assets/img/imgScreen/logo.png' />
            内审信息
          </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="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-col>
      <el-col :span='14'>
        <div class="common-title-div">
          <div class="common-title-name">
            <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="submitLoading" style="border:3px;"
              @click="submit">提交</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: '',
        entrTime: []
      },
      baseData: {
        isoTypeCode: '485304',
        isoTypeName: '内审',
        isoNo: '',
        isoName: '',
        isoDesc: '',
        memo: ''
      },
      TooData: {
        isoTypeCode: '485304',
        isoTypeName: '内审',
        isoNo: '',
        isoName: '',
        isoDesc: '',
        memo: '',
        filePath: '',
      },
      srcUrl: '',
      confirmLoading: false,
      TooconfirmLoading: false,
      isoTypeCodeType: [],
      loading: false,
      savetDataLoading: false,
      submitLoading: false,
      auitdLoading: false,
      tableLoading: false,
      tableLoading2: false,
      auditDataLoading: false,
      deleteDataLoading: false,
      tableData: [],
      tableData2: [],
      table1RowChange1: [],//表格2选中的数据
      tableRowChange1: [],//表格2选中的数据
      tableClick: {},//表格1点击的数据
      testPostNameType: [],//岗位信息
      mainHeight: 0,
      theight: 0,
      multipleSelection: [],
      multipleSelection1: [],
      icoreFilterFlag: true,
      pageIndex: 1,
      pageSize: 50,
      total_main: 0,
      recordShowFlag: false,//审核页面显示:
      ToorecordShowFlag: false,
      optNoParameter: '', //登录人岗位
      typeToop: 0,
    }
  },
  created() {
    this.mainHeight = window.innerHeight - 120
    this.theight = window.innerHeight - 120
    this.searchForm.entrTime = [this.getYNM(new Date()) + ' 00:00:00', this.getYNM(new Date()) + ' 23:59:59']
    //体系名称列表
    this.axios.post("pass/baseManagement/v1/limsisotmps/queryListByIsoTypeCode", { isoTypeCode: 485304 }, { individualType: 'json' }).then(res => {
      this.isoTypeCodeType = res.data;
    });
    this.gettestPostNameTypeList();
    this.getCompany();
  },
  mounted() {
    this.searchData();
  },
  methods: {
    // 关闭弹窗
    closeDialog() {
      this.baseData = {
        isoTypeCode: '485304',
        isoTypeName: '内审',
        isoNo: '',
        isoName: '',
        isoDesc: '',
        memo: ''
      }
    },
    ToocloseDialog() {
      this.TooData = {
        isoTypeCode: '485304',
        isoTypeName: '内审',
        isoNo: '',
        isoName: '',
        isoDesc: '',
        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: '485304',
        isoTypeName: '内审',
        isoNo: '',
        isoName: '',
        isoDesc: '',
        memo: ''
      }
      this.recordShowFlag = false;
    },
    Toocancel() {
      this.TooData = {
        isoTypeCode: '485304',
        isoTypeName: '内审',
        isoNo: '',
        isoName: '',
        isoDesc: '',
        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.tableClick == {} || this.tableClick == null) {
        this.$message.error("请点击一条内审信息！");
        return;
      }
      this.deleteDataLoading = true;
      this.axios.post("pass/baseManagement/v1/limsisodatas/deleteData", this.tableClick, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.axios.get('pass/baseManagement/v1/file/delFile/' + this.tableClick.filePath, { individualType: 'json' })
          this.$message.success("删除成功");
          this.searchData();
        } else {
          this.$message.error(res.message)
        }
        this.deleteDataLoading = false;
      }).catch(err => {
        this.deleteDataLoading = 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("不支持这个类型的文件展示！")
      }
    },
    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 : ''
          this.searchData();
        } else {
          this.$message.error(e.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    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,
        isoName: this.searchForm.matName,
        sdId: this.$route.query.Name,
        isoTypeCode: '485304'
      }
      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)
      })
    },
    searchFollowDate(row) {
      this.tableClick = 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.searchData()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    table2SelectionChange(val) {
      this.multipleSelection1 = val;
    },
    handleSizeChangeMain(pageSize) {
      this.pageIndex = 1;
      this.pageSize = pageSize;
      this.searchData();
    },
    handleCurrentChangeMain(pageIndex) {
      this.pageIndex = pageIndex;
      this.searchData();
    },
    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>
