<template>
  <el-dialog
    v-dialogDrag
    title="查看库存明细"
    :visible.sync="open"
    width="1200px"
    append-to-body
    :before-close="beforeClose"
    @open="dialogOpen"
  >
    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="68px"
    >
      <SearchBar :show-span="18" :collapse-span="6">
        <template #header>
          <el-col :span="6">
            <el-form-item label="产品编码" prop="productCode">
              <el-input v-model="queryParams.productCode" placeholder="请输入物料编码" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="产品名称" prop="productName">
              <el-input v-model="queryParams.productName" placeholder="请输入物料名称" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="仓库" prop="stockCode">
              <!-- <el-input v-model="queryParams.stockCode" placeholder="请输入仓库" /> -->
              <StockSelect
                :ref="`stock1`"
                v-model="queryParams.stockCode"
                filterable
                @change="($event) => { stockChange($event) }"
              />
            </el-form-item>
          </el-col>
        </template>
        <template #body>
          <el-col :span="6">
            <el-form-item label="区域" prop="areaCode">
              <!-- <el-input v-model="queryParams.areaCode" placeholder="请输入区域" /> -->
              <AreaSelect
                :ref="`area1`"
                v-model="queryParams.areaCode"
                filterable
                @change="($event) => { areaChange($event) }"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="货位" prop="locationCode">
              <!-- <el-input v-model="queryParams.locationCode" placeholder="请输入货位" /> -->
              <LocationSelect :ref="`location1`" v-model="queryParams.locationCode" filterable />
            </el-form-item>
          </el-col>
        </template>
        <template #buttons>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </template>
      </SearchBar>
    </el-form>

    <el-table
      v-loading="loading"
      :data="list"
      border
      size="mini"
    >
      <el-table-column
        label="生产订单"
        align="center"
        prop="workOrderNo"
        width="150"
        fixed="left"
      />
      <el-table-column
        label="仓库"
        align="center"
        prop="stockCode"
        width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="区域"
        align="center"
        prop="areaCode"
        width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="货位"
        align="center"
        prop="locationCode"
        width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="产品编码"
        align="center"
        prop="productCode"
        width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="产品名称"
        align="center"
        prop="productName"
        width="150"
        show-overflow-tooltip
      />
      <el-table-column
        label="货位物料剩余总数"
        width="130"
        align="center"
        prop="remainderStorageQty"
      />
      <el-table-column
        label="箱号"
        align="center"
        prop="caseNo"
        width="160"
      />
      <el-table-column label="装箱数量" align="center" prop="inQty" />
      <el-table-column label="检验结果" align="center" prop="testResult">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.WMS_TEST_RESULT" :value="scope.row.testResult" />
        </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 { getProductionPage } from '@/api/wms/inquirePurchase/inventoryInquire'
import StockSelect from '@/views/wms/incoming/wareHousing/components/StockSelect.vue'
import AreaSelect from '@/views/wms/incoming/wareHousing/components/AreaSelect.vue'
import LocationSelect from '@/views/wms/incoming/wareHousing/components/LocationSelect.vue'

export default {
  components: {
    StockSelect,
    AreaSelect,
    LocationSelect
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // WMS 生产发料 主列表
      list: [],
      // 弹出层标题
      title: '',
      showSearch: true,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        productCode: null
      }
    }
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      // 执行查询
      getProductionPage(this.queryParams).then(response => {
        this.list = response.data.list
        this.total = response.data.total
      }).finally(() => {
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    dialogOpen() {
      this.$nextTick(() => {
        this.getList()
      })
    },
    beforeClose(done) {
      this.list = []
      this.total = 0
      done && done()
    },
    stockChange(item) {
      if (item) {
        const { id } = item
        this.$refs[`area1`].options = []
        this.$refs[`area1`].fetchAreaList(id)
      }
    },
    areaChange(item) {
      if (item) {
        const { id } = item
        this.$refs[`location1`].options = []
        this.$refs[`location1`].fetchLocationList(id)
      }
    }
  }
}
</script>

<style>

</style>

