<!-- 不合格品台账 -->
<template>
  <div>
    <template v-if="!inboundVisible">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="search()">
        <el-form-item label="物料名称">
          <el-input
            v-model="dataForm.productName"
            placeholder="请输入物料名称"
            clearable
          />
        </el-form-item>
        <el-form-item label="生产批次号">
          <el-input
            v-model="dataForm.batchNumber"
            placeholder="请输入批次号"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button @click="search()">查询</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="disqualificationCode"
          header-align="center"
          align="center"
          min-width="120"
          :show-tooltip-when-overflow="true"
          label="不合格品编码"
        >
        </el-table-column>
        <el-table-column
          prop="invoicesCode"
          header-align="center"
          align="center"
          min-width="120"
          :show-tooltip-when-overflow="true"
          label="审理编码"
        >
        </el-table-column>
        <el-table-column
          prop="orderCode"
          header-align="center"
          align="center"
          min-width="120"
          :show-tooltip-when-overflow="true"
          label="任务单编码"
        >
        </el-table-column>
         <el-table-column
          prop="batchNumber"
          header-align="center"
          align="center"
          min-width="120"
          :show-tooltip-when-overflow="true"
          label="批次号"
        >
        </el-table-column>
        <el-table-column
          prop="productName"
          header-align="center"
          align="center"
          min-width="120"
          :show-tooltip-when-overflow="true"
          label="物料名称"
        >
        </el-table-column>
        <el-table-column
          prop="damageCnt"
          header-align="center"
          align="center"
          min-width="100"
          :show-tooltip-when-overflow="true"
          label="不合格数量"
        >
        </el-table-column>
        <el-table-column
          prop="stateStr"
          header-align="center"
          align="center"
          min-width="120"
          :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('wh:in:inbound')"
              type="text"
              size="small"
              @click="inboundHandle(scope.row)"
              >入库</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>
    </template>
    <stock-order-inbound ref="inbound" v-if="inboundVisible" @onChose="onChose"/>
  </div>
</template>

<script>
import {getUnqList} from '@/api/quality'
import StockOrderInbound from '../warehouse/stock-order-inbound'
export default {
  name: 'quality-unqualified',
  components: {StockOrderInbound},
  data () {
    return {
      inboundVisible: false,
      dataForm: {},
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false
    }
  },
  mounted () {},
  created () {
    this.search()
  },
  methods: {
    onChose () {
      this.inboundVisible = false
    },
    search () {
      this.pageIndex = 1
      this.getDataList()
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    getDataList () {
      this.dataListLoading = true
      let param = {
        current: this.pageIndex,
        size: this.pageSize,
        batchNumber: this.dataForm.batchNumber,
        productName: this.dataForm.productName
      }
      getUnqList(param).then(({ data }) => {
        if (data && data.code === '200') {
          this.dataList = data.data.records
          this.totalPage = Number(data.data.total)
          this.dataList.forEach(item => {
            item.stateStr = item.state === '1' ? '待入库' : item.state === '2' ? '已入库' : ''
          })
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    inboundHandle (item) {
      item.sourceCategory = '4'
      item.cnt = item.damageCnt
      this.inboundVisible = true
      this.$nextTick(() => {
        this.$refs.inbound.init(0, false, item)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
