<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"
      :is-loading="listLoading"
      @clickTopBtn="clickTopBtn"
    />
    <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 { getOperationCodeList, getReceiptNoList, getHWList, getDriverCodeList, getTimeArr } from '@/utils/wmsDic'
const tableProps = [
  {
    prop: 'operationCode',
    label: '作业号'
  },
  {
    prop: 'receiptNo',
    label: '入库单号'
  },
  {
    prop: 'goodsArea',
    label: '货位'
  },
  {
    prop: 'startTime',
    label: '开始时间'
  },
  {
    prop: 'endTime',
    label: '结束时间'
  },
  {
    prop: 'driverCode',
    label: '司机/AGV编号'
  }
]
export default {
  name: 'WarehouseOperation',
  components: { HeadForm, BaseTable, Pagination },
  data() {
    return {
      headFormConfig: [
        {
          type: 'input',
          label: '关键字',
          placeholder: '作业号或入库单号',
          param: 'name',
          width: 250
        },
        {
          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 = {}
        const timeArrList = getTimeArr()
        obj.operationCode = getOperationCodeList()
        obj.receiptNo = getReceiptNoList()
        obj.goodsArea = getHWList()
        obj.startTime = timeArrList[0]
        obj.endTime = timeArrList[1]
        obj.driverCode = getDriverCodeList()
        temp.push(obj)
      }
      this.list = temp
      this.total = num
    },
    btnClick(val) {
      console.log(val)
      this.getList()
    },
    clickTopBtn(val) {
      console.log(val)
      this.$refs.inStoreDocumentsAdd.init()
      this.showTitle = '新增'
    }
  }
}
</script>
