<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline="true">
        <el-form-item label="异常类型">
          <el-select v-model="search.objTypeName" clearable filterable collapse-tags size="small" style="width:200px;margin-right: 10px;" placeholder="请选择查询内容">
            <el-option v-for="item in objType" :key="item.baseName" :label="item.baseName"
              :value="item.baseName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="物料名称">
          <el-input v-model="search.matName" size="small" placeholder="请输入查询内容" style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="申报日期">
          <el-date-picker
         v-model="search.declareTime"
         type="daterange"
         range-separator="至"
         start-placeholder="开始日期"
         end-placeholder="结束日期"
         size="small"
         format="yyyy 年 MM 月 dd 日"
         value-format="yyyy-MM-dd">
        </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="goon" size="mini" @click="searchData">查询</el-button>
          <el-button icon="el-icon-refresh" type="info" plain size="mini" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <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" @click="checkData">审核</el-button>     
      <el-button icon="el-icon-remove-outline" type="danger" size="mini" @click="recheckData">反审</el-button>
      <!-- <el-button icon="el-icon-circle-plus-outline" type="goon" size="mini" @click="addData">新增</el-button>
      <el-button icon="el-icon-edit" type="goon" size="mini" @click="modifyData">修改</el-button>
      <el-button icon="el-icon-remove-outline" type="danger" size="mini" @click="deleteData">删除</el-button>
      <el-button icon="el-icon-check" type="goon" size="mini" @click="recoverData">启用</el-button>
      <el-button icon="el-icon-check" type="goon" size="mini" @click="submitData">提交</el-button> -->
      </div>
    </div>
    <div class="common-table-div" style="margin-bottom:0;margin-top:0">
       <el-table v-loading="dataLoading" ref="dataTable" border :height="height_top" highlight-current-row @selection-change="handleSelectionChange" :data="table.list" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle" :cell-class-name="tableRowClassName" @current-change="handleCurrentChange" :summary-method="getSummaries" show-summary>
        <el-table-column type="index" label="NO" fixed="left" align="center">
        </el-table-column>
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="objTypeName" label="异常类型" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="matName" label="物料名称" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="lotsNo" label="批次信息" align="center"></el-table-column>
        <!-- <el-table-column sortable width="180px" prop="taskId" label="任务单号" align="center"></el-table-column>
        <el-table-column sortable width="140px" prop="carNo" label="车号"  align="center"></el-table-column> -->
        <el-table-column sortable :show-overflow-tooltip="true" min-width="200px" prop="memo" label="备注"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px"  prop="objFlag1" label="状态" align="center">
          <!-- <template slot-scope="scope">
              <span v-if="scope.row.objFlag == 1">未审核</span>
              <span v-else-if="scope.row.objFlag == 2">已审核</span>
          </template> -->
        </el-table-column>
        <!-- <el-table-column sortable width="90px" label="有效状态" align="center">
          <template slot-scope="scope">
              <span v-if="scope.row.validFlag == 1">有效</span>
              <span v-else-if="scope.row.validFlag == 0">无效</span>
          </template>
        </el-table-column> -->
        <!-- <el-table-column sortable width="" prop="memo" label="备注" align="center"></el-table-column> -->
        <el-table-column sortable :show-overflow-tooltip="true" min-width="95px" prop="declareName" label="申报人" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="declareTime" label="申报时间" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="95px" prop="checkMan" label="审核人" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="checkTime" label="审核时间" align="center"></el-table-column>
      </el-table>
    </div>
    <div class="common-foot-style">
        <el-pagination v-loading="dataLoading" @size-change="pageSizeChange" @current-change="pageCurrentChange"
          :current-page="page.pageNum" :page-sizes="[10, 20, 50, 100, 200]" :page-size="page.pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="page.totalPage" background>
        </el-pagination>
    </div>
    <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-circle-plus-outline" type="goon" size="mini" @click="addData2">新增</el-button>
      <el-button icon="el-icon-edit" type="goon" size="mini" @click="modifyData2">修改</el-button>
      <el-button icon="el-icon-remove-outline" type="danger" size="mini" @click="deleteData2">删除</el-button> -->
      </div>
    </div>
    <div class="common-table-div" style="margin-bottom:0;margin-top:0">
       <el-table v-loading="dataLoading2" ref="dataTable2" border :height="height_bot" highlight-current-row @selection-change="handleSelectionChange2" :data="table.list2" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle" :summary-method="getSummaries2" show-summary>
        <el-table-column type="index" label="NO" fixed="left" align="center">
        </el-table-column>
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="objTypeName" label="异常类型" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="matName" label="物料名称" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="bugTypeName" label="缺陷类型" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="objectNum" label="异常数量" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="unitName" label="异常单位" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="200px" prop="objctDesc" label="异常说明" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="180px" prop="annexName1" label="附件1" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="180px" prop="annexName2" label="附件2" align="center"></el-table-column>
        <!-- <el-table-column width="95px" prop="createMan" label="创建人" align="center"></el-table-column>
        <el-table-column width="160px" prop="createTime" label="创建时间" align="center"></el-table-column>
        <el-table-column width="95px" prop="updateMan" label="修改人" align="center"></el-table-column>
        <el-table-column width="160px" prop="updateTime" label="修改时间" align="center"></el-table-column> -->
      </el-table>
    </div>
    <!-- <div class="common-foot-style">
        <el-pagination v-loading="dataLoading2" @size-change="pageSizeChange2" @current-change="pageCurrentChange2"
          :current-page="page2.pageNum" :page-sizes="[10, 20, 50, 100, 200]" :page-size="page2.pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="page2.totalPage" background>
        </el-pagination>
    </div> -->
  </div>
</template>
<script>
import {
  getCookie
} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  data () {
    return {
      table: {
        list: [],
        list2: [],
        list3: []
      },
      dataLoading: false,
      dataLoading2: false,
      icoreFilterFlag: true,
      page: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 990,
        pageNum: 1,
        totalPage: 0
      },
      showFlag: false,
      Params: {},
      showFlag2: false,
      objId: '',
      Params2: {},
      objType: [],
      multipleSelection3: [],
      // multipleSelection3: {},
      // multipleSelection4: {},
      multipleSelection4: [],
      search: {
        matName: '',
        objTypeName: '',
        declareTime: ''
      },
      height_top:0,
      height_bot:0
    }
  },
  created() {
    this.height_top = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 100;
    this.height_bot = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 100;
  },
 mounted () {
    this.getDataList();
    // this.getDataList2();
    this.addScreen();
    this.addScreen2();
    this.getobjTypeList ()
  },
  methods: {
    getSummaries (param) {
      const { columns, data } = param;
      const sums = [];
       columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
          if (index === 2) {
            sums[index] = this.page.totalPage;
          }
       });
        return sums;
    },
    getSummaries2 (param) {
      const { columns, data } = param;
      const sums = [];
       columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
          if (index === 2) {
            sums[index] = this.page2.totalPage;
          }
       });
        return sums;
    },
    refresh () {
      let _this = this;
      _this.getDataList();
      _this.getDataList2(_this.objId);
    },
    refresh2 () {
      let _this = this;
      _this.getDataList2(_this.objId);
    },
    checkData () {
        let _this = this;
        if (_this.multipleSelection3.length < 1) {
        this.$message.warning('请勾选您要审核的数据！')
        } else {
         for (var j= 0; j < _this.multipleSelection3.length; j++) {
          if (_this.multipleSelection3[j].objFlag === '2') {
          this.$message.warning('请勾选状态为未审核的数据！')  
          return 
          }
        }
        _this.dialogTableVisible = false;
        // _this.multipleSelection = []
        // _this.multipleSelection.push(_this.multipleSelection3)
        for (var i = 0; i < _this.multipleSelection3.length; i++) {
        _this.multipleSelection3[i].checkMan = userName;
        _this.multipleSelection3[i].checkNo = userId
        }
        _this.axios.post('pass/baseManagement/v1/limsobjheats/check', _this.multipleSelection3, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.$message.success('审核成功');
         _this.refresh()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    recheckData () {
       let _this = this;
        if (_this.multipleSelection3.length < 1) {
        this.$message.warning('请勾选您要反审的数据！')
        } else {
         for (var j= 0; j < _this.multipleSelection3.length; j++) {
          if (_this.multipleSelection3[j].objFlag === '1') {
          this.$message.warning('请勾选状态为已审核的数据！')  
          return 
          }
        }
        _this.dialogTableVisible = false;
        // _this.multipleSelection = []
        // _this.multipleSelection.push(_this.multipleSelection3)
        for (var i = 0; i < _this.multipleSelection3.length; i++) {
        _this.multipleSelection3[i].checkMan = userName;
        _this.multipleSelection3[i].checkNo = userId
        }
        _this.axios.post('pass/baseManagement/v1/limsobjheats/uncheck', _this.multipleSelection3, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.$message.success('反审成功');
         _this.refresh()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    searchData () {
        let _this = this;
        _this.dataLoading = true;
        _this.page.pageNum = 1;
        if (_this.search.declareTime[0] === undefined) {
          _this.starTime = '',
          _this.endTime = ''
        } else {
          _this.starTime = _this.search.declareTime[0],
          _this.endTime = _this.search.declareTime[1]
        }
        _this.axios.get('pass/baseManagement/v1/limsobjheats/' + '?pageNum=' + _this.page.pageNum + '&pageSize=' + _this.page.pageSize +
          '&matName=' + _this.search.matName + '&objTypeName=' + _this.search.objTypeName + '&objFlag1=1&objFlag2=2')
        .then(res => {
          _this.dataLoading = false;
          _this.table.list = res.data.list;
          for (let i = 0; i < this.table.list.length; i++) {
           if (this.table.list[i].objFlag === '1') {
            this.table.list[i].objFlag1 = '未审核'
           } else if (this.table.list[i].objFlag === '2') {
           this.table.list[i].objFlag1 = '已审核'
           }
           }
          _this.page.totalPage = res.data.total;
        }).catch(e => {
          _this.dataLoading = false;
        });
      },
    reset () {
      let _this = this;
      _this.search.matName = '';
      _this.search.objTypeName = '';
      _this.search.declareTime = '';
      _this.searchData();
    },
    handleSelectionChange (val) {
      this.multipleSelection3 = val;
      if (val.length > 0) {
        this.objId = val[val.length-1].objId
        this.getDataList2(this.objId);
      }
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.getDataList();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.getDataList();
    },
    handleSelectionChange2 (val) {
      // this.multipleSelection2 = [];
      // this.multipleSelection2.push(val);
      this.multipleSelection4 = val;
    },
    pageSizeChange2 (size) {
      this.page2.pageSize = size;
      this.getDataList2(this.objId);
    },
    pageCurrentChange2 (index) {
      this.page2.pageNum = index;
      this.getDataList2(this.objId);
    },
    handleCurrentChange (val) {
       if (val.objId === null) {
        this.objId = '';
      } else {
        this.objId = val.objId;
      }
      this.getDataList2 (this.objId)
    },
    addScreen () {
      this.$nextTick(() => {
          let ss = document.createElement('div');
          ss.innerHTML = '筛选';
          ss.style = 'text-align: center;'
          this.$refs.dataTable.$el.getElementsByClassName('el-table__fixed')[0].getElementsByTagName('td')[0].appendChild(ss);
       });
    },
    addScreen2 () {
     this.$nextTick(() => {
          let ss = document.createElement('div');
          ss.innerHTML = '筛选';
          ss.style = 'text-align: center;'
          this.$refs.dataTable2.$el.getElementsByClassName('el-table__fixed')[0].getElementsByTagName('td')[0].appendChild(ss);
       });
    },
    getDataList () {
      this.dataLoading = true;
      this.axios.get('pass/baseManagement/v1/limsobjheats/' + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize + '&objFlag1=1&objFlag2=2')
            .then(res => {
              this.dataLoading = false;
              this.table.list = res.data.list;
              // this.table.list = [];
              // for (var i = 0; i < this.table.list3.length; i++) {
              //    if (this.table.list3[i].objFlag ==='1' || this.table.list3[i].objFlag ==='2') {
              //      this.table.list.push(this.table.list3[i])
              //    }
              // }
              for (let i = 0; i < this.table.list.length; i++) {
                if (this.table.list[i].objFlag === '1') {
                 this.table.list[i].objFlag1 = '未审核'
                } else if (this.table.list[i].objFlag === '2') {
                this.table.list[i].objFlag1 = '已审核'
                }
                }
              this.page.totalPage = res.data.total;
            }).catch(e => {
              this.dataLoading = false;
            });
    },
    getDataList2 (objId) {
       this.dataLoading2 = true;
      if (objId === null || objId === '') {
        this.table.list2 = [];
        this.dataLoading2 = false;
        return 0
      } else {
      this.axios.get('pass/baseManagement/v1/limsobjlines/' + '?pageNum=' + this.page2.pageNum + '&pageSize=' + this.page2.pageSize + '&objId=' + objId)
            .then(res => {
              this.dataLoading2 = false;
              this.table.list2 = res.data.list;
              this.page2.totalPage = res.data.total;
            }).catch(e => {
              this.dataLoading2 = false;
            });
      }
    },
   getobjTypeList () {
      this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4826}, {individualType: 'json'}).then(res => {
              this.dataLoading = false;
              this.objType = res.data
            })
   },
   tableRowClassName ({
        row, column, rowIndex, columnIndex
      }) {
        if (columnIndex === 6) {
        if (row.objFlag !== '1') {
          return 'error-green';
        }
        return '';
        }
      },
    // tableRowClassName2 ({
    //     row, column, rowIndex, columnIndex
    //   }) {
    //     if (columnIndex === 7) {
    //     if (row.validFlag !== '1') {
    //       return 'error-row';
    //     }
    //     return '';
    //     }
    //   },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
}
</script>
<style  scoped>
</style>
