<!-- 入库检验 -->
<template>
  <div class="check">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="queryPage()">
      <el-form-item label="零件（物品）名称">
        <el-input v-model="dataForm.materialName" placeholder="零件（物品）名称" clearable/>
      </el-form-item>
      <el-form-item>
        <el-button @click="queryPage()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        label="序号"
        type="index"
        width="50"
        align="center">
      </el-table-column>
      <el-table-column
        prop="inspectionCode"
        header-align="center"
        align="center"
        min-width="220"
        label="检验单编码">
      </el-table-column>
      <el-table-column
        prop="materialName"
        header-align="center"
        align="center"
        width="120"
        :show-tooltip-when-overflow="true"
        label="名称">
      </el-table-column>
      <el-table-column
        prop="materialTypeId"
        header-align="center"
        align="center"
        label="类别">
      </el-table-column>
      <el-table-column
        prop="specifications"
        header-align="center"
        align="center"
        width="120"
        :show-tooltip-when-overflow="true"
        label="规格">
      </el-table-column>
      <el-table-column
        prop="batchNumber"
        header-align="center"
        align="center"
        label="批次号">
      </el-table-column>
      <el-table-column
        prop="cnt"
        header-align="center"
        align="center"
        label="实际数量">
      </el-table-column>
      <el-table-column
        prop="qualifiedCnt"
        header-align="center"
        align="center"
        label="合格数量">
      </el-table-column>
      <el-table-column
        prop="unitName"
        header-align="center"
        align="center"
        label="单位">
      </el-table-column>
      <el-table-column
        prop="conclusion"
        header-align="center"
        align="center"
        label="检验结论">
      </el-table-column>
      <el-table-column
        prop="-"
        header-align="center"
        align="center"
        label="检验员">
      </el-table-column>
      <el-table-column
        prop="applicant"
        header-align="center"
        align="center"
        label="申请人">
      </el-table-column>
      <el-table-column
        prop="notes"
        header-align="center"
        align="center"
        width="160"
        :show-tooltip-when-overflow="true"
        label="备注">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button v-if="isAuth('quality:inspection:info')" type="text" size="small" @click="addOrUpdateHandle(scope.row.inspectionId, true)">查看</el-button>
          <el-button v-if="isAuth('quality:inspection:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.inspectionId, false)">处理</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './ibc-add-or-update'
  import { getInBoundCheckList } from '@/api/check'
  export default {
    name: 'in-bound-check',
    components: {AddOrUpdate},
    data () {
      return {
        addOrUpdateVisible: false,
        dataForm: {},
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: []
      }
    },
    created () {
      this.getDataList()
    },
    methods: {
      // 查询
      queryPage () {
        this.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        let params = {
          'current': this.pageIndex,
          'size': this.pageSize,
          'materialName': this.dataForm.materialName ? this.dataForm.materialName : null
        }
        getInBoundCheckList(params).then(({data}) => {
          if (data && data.code === '200') {
            this.dataList = data.data.records
            this.totalPage = Number(data.data.total)
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id, disable) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id, disable)
        })
      }
    }
  }
</script>

<style scoped>

</style>

