<!--
 * @Author: zwq
 * @Date: 2020-12-29 15:41:11
 * @LastEditors: zwq
 * @LastEditTime: 2022-01-18 14:30:25
 * @Description:
-->
<template>
  <div class="app-container">
    <el-form ref="listQuery" :model="listQuery" :inline="true" label-width="120px" @keyup.enter.native="getList()">
      <el-form-item :label="$t('module.basicData.Warehouse.StorageBoxNumber')" prop="code">
        <el-select
          v-model="listQuery.code"
          :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.Warehouse.StorageBoxNumber')])"
          clearable
          filterable
          :style="{width: '100%'}"
        >
          <el-option
            v-for="(item, index) in storageBoxList"
            :key="index"
            :label="item.code"
            :value="item.code"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getList()">{{ 'btn.search' | i18nFilter }}</el-button>
      </el-form-item>
      <base-table
        :page="listQuery.current"
        :limit="listQuery.size"
        :table-config="tableProps"
        :table-data="list"
        :is-loading="listLoading"
      />
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.current"
        :limit.sync="listQuery.size"
        @pagination="getList()"
      />
    </el-form></div>
</template>

<script>
import { StorageBoxInfoList, StorageBoxRackCode } from '@/api/basicData/Warehouse/StorageBoxInfo'
import BaseTable from '@/components/BaseTable'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import warehouse from '@/filters/basicData/warehouse'
import i18n from '@/lang'
/**
 * 表格表头配置项 TypeScript接口注释
 * tableConfig<ConfigItem> = []
 *
 * Interface ConfigItem = {
 *  prop: string,
 *  label: string,
 *  width: string,
 *  align: string,
 *  subcomponent: function,
 *  filter: function
 * }
 *
 *
 */

const tableProps = [
  {
    prop: 'storageCode',
    label: i18n.t('module.basicData.Warehouse.StorageBoxNumber'),
    align: 'center'
  },
  {
    prop: 'status',
    label: i18n.t('module.basicData.Warehouse.BoxStatus'),
    filter: warehouse('enableState'),
    align: 'center'
  },
  {
    prop: 'currLocation',
    label: i18n.t('module.basicData.Warehouse.CurrentLocation'),
    align: 'center'
  },
  {
    prop: 'isEmpty',
    label: i18n.t('module.basicData.Warehouse.IsEmpty'),
    filter: warehouse('yesOrNo'),
    align: 'center'
  }
]

export default {
  name: 'StorageBoxInfo',
  components: { Pagination, BaseTable },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      keyName: i18n.t('module.basicData.Warehouse.StorageBoxNumber'),
      placeholderName: this.$t('module.basicData.Warehouse.StorageBoxNumber'),
      trueWidth: 200,
      tableProps,
      list: [],
      storageBoxList: [],
      total: 0,
      listLoading: true,
      listQuery: {
        current: 1,
        size: 10,
        code: ''
      }
    }
  },
  created() {
    this.getList()
    const listQuery1 = {
      current: 1,
      size: 100
    }
    StorageBoxRackCode(listQuery1).then(res => {
      this.storageBoxList = res.data.records
    })
  },
  methods: {
    getList() {
      this.listLoading = true
      StorageBoxInfoList(this.listQuery).then(response => {
        if (response.data.records) {
          this.list = response.data.records
        } else {
          this.list.splice(0, this.list.length)
        }
        this.total = response.data.total
        this.listLoading = false
      })
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
