<!--
 * @Author: zwq
 * @Date: 2020-12-29 15:41:11
 * @LastEditors: zwq
 * @LastEditTime: 2022-01-12 16:27:58
 * @Description:
-->
<template>
  <div class="app-container">
    <el-form
      ref="formData"
      :model="formData"
      :inline="true"
      size="medium"
      label-width="100px"
    >
      <el-form-item :label="$t('module.basicData.Warehouse.TaskType')" prop="taskType">
        <el-select v-model="formData.taskType" filterable :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.Warehouse.TaskType')])" clearable>
          <el-option
            v-for="item in taskTypeList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('module.basicData.Warehouse.TaskStatus')" prop="status">
        <el-select v-model="formData.status" filterable :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.Warehouse.TaskStatus')])" clearable>
          <el-option
            v-for="item in equipmentList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('module.basicData.Warehouse.VehicleName')" prop="equipmentId">
        <el-select v-model="formData.equipmentId" filterable :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.Warehouse.VehicleName')])" clearable>
          <el-option
            v-for="item in equipmentList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('module.basicData.Warehouse.TimeSlot')" prop="time">
        <el-date-picker
          v-model="formData.timeSlot"
          type="daterange"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          :start-placeholder="$t('module.orderManage.order.StartTime')"
          :end-placeholder="$t('module.orderManage.order.StartTime')"
          :range-separator="$t('module.orderManage.order.To')"
          clearable
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getList()"> {{ 'btn.search' | i18nFilter }} </el-button>
      </el-form-item>
    </el-form>
    <base-table
      :page="formData.current"
      :limit="formData.size"
      :table-config="tableProps"
      :table-data="list"
      :is-loading="listLoading"
    />
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="formData.current"
      :limit.sync="formData.size"
      @pagination="getList()"
    />
  </div>
</template>

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

const tableProps = [
  {
    prop: 'taskCode',
    label: i18n.t('module.basicData.Warehouse.Code'),
    align: 'center'
  },
  {
    prop: 'createTime',
    label: i18n.t('module.basicData.Warehouse.ExecutionTime'),
    align: 'center'
  },
  {
    prop: 'status',
    label: i18n.t('module.basicData.Warehouse.TaskStatus'),
    align: 'center'
  },
  // {
  //   prop: 'taskType',
  //   label: i18n.t('module.basicData.Warehouse.TaskType'),
  //   align: 'center'
  // },
  {
    prop: 'name',
    label: i18n.t('module.basicData.Warehouse.VehicleName'),
    align: 'center'
  },
  // {
  //   prop: 'substrateNo',
  //   label: i18n.t('module.basicData.Warehouse.BoxStatus'),
  //   align: 'center'
  // },
  {
    prop: 'wcode',
    label: i18n.t('module.basicData.Warehouse.BoxNumber'),
    align: 'center'
  },
  {
    prop: 'wcurrProcessCode',
    label: i18n.t('module.basicData.Warehouse.PreviousOperation'),
    align: 'center'
  },
  {
    prop: 'wnextProcessCode',
    label: i18n.t('module.basicData.Warehouse.NextOperation'),
    align: 'center'
  },
  {
    prop: 'updateTime',
    label: i18n.t('module.basicData.Warehouse.CompletionTime'),
    align: 'center'
  },
  {
    prop: 'currLocation',
    label: i18n.t('module.basicData.Warehouse.StartLocation'),
    align: 'center'
  },
  {
    prop: 'targetLocation',
    label: i18n.t('module.basicData.Warehouse.TargetLocation'),
    align: 'center'
  }
]

export default {
  name: 'ScrapInfo',
  components: { Pagination, BaseTable },
  data() {
    return {
      trueWidth: 200,
      tableProps,
      list: [],
      total: 0,
      listLoading: false,
      formData: {
        taskType: '',
        status: '',
        equipmentId: '',
        timeSlot: [],
        endTime: '',
        startTime: '',
        current: 1,
        size: 10
      },
      taskTypeList: [{
        'label': '出库',
        'value': 0
      }, {
        'label': '入库',
        'value': 1
      }, {
        'label': '流转',
        'value': 2
      }],
      equipmentList: []
    }
  },
  created() {
    this.init()
    this.getList()
  },
  methods: {
    init() {
      const listQuery = {
        current: 1,
        size: 500
      }
      this.equipmentList.splice(0, this.equipmentList.length)
      equipmentInfoList(listQuery).then(response => {
        if (response.data.records) {
          this.equipmentList = response.data.records
        }
      })
    },
    getList() {
      if (this.formData.timeSlot) {
        this.formData.startTime = this.formData.timeSlot[0]
        this.formData.endTime = this.formData.timeSlot[1]
      } else {
        this.formData.startTime = ''
        this.formData.endTime = ''
      }
      this.listLoading = true
      HistoricalTaskList(this.formData).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>
