<template>
  <el-dialog
    v-dialogDrag
    title="退料入库明细"
    :visible.sync="open"
    width="1200px"
    append-to-body
    @open="dialogOpen"
    @close="dialogClose"
  >

    <!-- 操作工具栏 -->

    <!-- 列表 -->
    <el-table
      v-loading="loading"
      :data="list"
      border
      size="mini"
    >
      <el-table-column
        label="物料批次"
        align="center"
        width="150"
        prop="materialBatch"
      />
      <el-table-column
        label="入库仓库"
        align="center"
        prop="erpStockId"
        width="130"
        show-overflow-tooltip
      />
      <el-table-column label="入库区域" align="center" prop="wmsStoreAreaId" />
      <el-table-column label="入库货位" align="center" prop="wmsStoreId" />
      <el-table-column
        label="物料名称"
        align="center"
        width="120"
        prop="materialName"
      />
      <el-table-column
        label="退料单号"
        align="center"
        prop="rejectNo"
        width="120"
      />
      <el-table-column label="供应商" align="center" prop="supplierCode" />
      <el-table-column
        label="物料编码"
        align="center"
        prop="materialNo"
        width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="领料单号"
        align="center"
        prop="receiveOrderNo"
        width="120"
      />
      <el-table-column
        label="发料单号"
        align="center"
        prop="sendOrderNo"
        width="150"
      />
      <el-table-column label="发料数量" align="center" prop="sendQty" />
      <el-table-column label="退料数量" align="center" prop="rejectOrderNo" />
      <el-table-column label="入库数量" align="center" prop="inQty" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </el-dialog>
</template>

<script>
import { getIncomingRejectDetailStockedPage, exportIncomingProduceDetailExcel } from '@/api/wms/incoming/reject'
export default {
  name: 'IncomingProduceDetail',
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入库业务 生产入库明细列表
      list: [],
      // 弹出层标题
      title: '',
      id: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        rejectNo: null,
        supplierCode: null,
        materialNo: null,
        receiveOrderNo: null,
        sendOrderNo: null,
        sendQty: null,
        rejectOrderNo: null,
        erpStockId: null,
        wmsStoreAreaId: null,
        wmsStoreId: null,
        inQty: null,
        createTime: []
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        masterId: [{ required: true, message: '主表ID不能为空', trigger: 'blur' }],
        productCode: [{ required: true, message: '产品编码不能为空', trigger: 'blur' }],
        workOrderNo: [{ required: true, message: '生产订单编号不能为空', trigger: 'blur' }]
      }
    }
  },
  created() {
    // this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      // 执行查询
      getIncomingRejectDetailStockedPage(this.queryParams).then(response => {
        this.list = response.data.list
        this.total = response.data.total
      }).finally(() => {
        this.loading = false
      })
    },
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        masterId: undefined,
        warehousingOrderNo: undefined,
        productCode: undefined,
        planAmount: undefined,
        workOrderNo: undefined,
        caseNo: undefined,
        inQty: undefined,
        stockCode: undefined,
        areaCode: undefined,
        locationCode: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      const params = { ...this.queryParams }
      params.pageNo = undefined
      params.pageSize = undefined
      this.$modal.confirm('是否确认导出所有入库业务 生产入库明细数据项?').then(() => {
        this.exportLoading = true
        return exportIncomingProduceDetailExcel(params)
      }).then(response => {
        this.$download.excel(response, '入库业务 生产入库明细.xls')
        this.exportLoading = false
      }).catch(() => {})
    },
    dialogOpen() {
      this.getList()
    },
    dialogClose() {
      this.getList()
    }
  }
}
</script>

