<template>
  <div class="app-container">
    <head-form :form-config="headFormConfig" @headBtnClick="btnClick" />
    <base-table
      :page="listQuery.current"
      :limit="listQuery.size"
      :height="tableH"
      :table-config="tableProps"
      :table-data="list"
    />
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.current"
      :limit.sync="listQuery.size"
      @pagination="getList()"
    />
  </div>
</template>
<script>
import HeadForm from '@/components/basicData/HeadForm'
import BaseTable from '@/components/BaseTable'
import Pagination from '@/components/Pagination'
import { tableHeight } from '@/utils/index'
import { getProductSpecList, getMaterialCodeList, getTrayList, getHWList, getBatchList, getGoodsList } from '@/utils/wmsDic'
import moment from 'moment'
const tableProps = [
  {
    prop: 'productName',
    label: '品名'
  },
  {
    prop: 'spec',
    label: '规格'
  },
  {
    prop: 'status',
    label: '库存状态'
  },
  {
    prop: 'materialCode',
    label: '物料编码'
  },
  {
    prop: 'storeArea',
    label: '库区'
  },
  {
    prop: 'goodsArea',
    label: '货位'
  },
  {
    prop: 'trayID',
    label: '托盘号'
  },
  {
    prop: 'productionTime',
    label: '生产日期'
  },
  {
    prop: 'validityTime',
    label: '有效期'
  },
  {
    prop: 'batch',
    label: '批次号',
    minWidth: 200
  },
  {
    prop: 'num',
    label: '库存数量'
  }
]
export default {
  name: 'InventoryQuery',
  components: { HeadForm, BaseTable, Pagination },
  data() {
    return {
      headFormConfig: [
        {
          type: 'input',
          label: '关键字',
          placeholder: '请输入库区,货位,物料编码,托盘条码',
          param: 'name',
          width: 300
        },
        {
          type: 'datePicker',
          label: '时间范围',
          dateType: 'daterange',
          format: 'yyyy-MM-dd',
          valueFormat: 'yyyy-MM-dd',
          rangeSeparator: '-',
          startPlaceholder: '开始时间',
          endPlaceholder: '结束时间',
          param: 'searchTime'
        },
        {
          type: 'button',
          btnName: 'btn.search',
          name: 'search',
          color: 'primary'
        }
      ],
      listQuery: {
        current: 1,
        size: 20
      },
      tableH: tableHeight(275),
      tableProps,
      list: [],
      listLoading: false,
      total: 0,
      showTitle: ''
    }
  },
  mounted() {
    window.addEventListener('resize', () => {
      this.tableH = tableHeight(275)
    })
    this.getList()
  },
  methods: {
    getList() {
      const temp = []
      const num = 20
      for (let i = 0; i < num; i++) {
        const obj = {}
        obj.productName = getGoodsList()
        const sj = Math.floor(Math.random() * 720 + 10)
        obj.spec = getProductSpecList()
        obj.status = parseInt(Math.random() * 2) ? '已分配' : '未分配'
        obj.materialCode = getMaterialCodeList()
        obj.goodsArea = getHWList()
        obj.storeArea = obj.goodsArea[2] + '区'
        obj.trayID = getTrayList()
        obj.productionTime = moment().subtract(sj, 'days').subtract(sj, 'hour').subtract(sj, 'minutes').subtract(sj, 'seconds').format('YYYY-MM-DD hh:mm:ss')
        obj.validityTime = parseInt(sj / 5) + '个月'
        obj.batch = getBatchList()
        obj.num = Math.floor(Math.random() * 2000)
        temp.push(obj)
      }
      this.list = temp
      this.total = num
    },
    btnClick(val) {
      console.log(val)
      this.getList()
    }
  }
}
</script>
