<template>
  <div>
    <div v-show="$route.name === 'putaway'">
      <head-todo :tabIndex="tabIndex" :urlKey="urlKey" :type="type" @getList="getList"></head-todo>
      <center-list
        :tableData="tableData"
        :pageSize="pageSize"
        :currentPage="currentPage"
        :total="total"
        :tabIndex="tabIndex"
        :urlKey="urlKey"
        @getList="getList"
        @handleClickTabs="handleClickTabs"
        @handleOpenForm="handleOpenForm"
      ></center-list>
    </div>
    <router-view></router-view>
  </div>
</template>
<script>
import HeadTodo from './components/head-todo'
import CenterList from './components/center-list'
import { time } from 'apec-fe-utils'
export default {
  name: 'Putaway',
  components: {
    HeadTodo,
    CenterList,
  },
  data () {
    return {
      query: {
        'queryOrderType': 'ASN',
        'page.currentPage': 1,
        'page.limitCount': 10,
      },
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 0,
      tabIndex: 0,
      urlKey: 'query',
      mode: '',
      type: 'ASN'
    }
  },
  mounted () {
    this.getList('query')
  },
  methods: {
    getList (urlKey, query) {
      const url = this.$API.stockIn.Putaway[urlKey]
      const param = { ...this.query, ...query }
      this.$https.post(url, param).then(res => {
        this.tableData = res.rows
        this.total = res.total
        this.currentPage = res.currentPage
        this.pageSize = res.limit
      })
    },

    handleOpenForm (mode, ...args) {
      this.mode = mode
      this.$router.push({
        name: 'putawayAdd',
        params: {
          mode,
          ...args
        }
      })
    },

    handleClickTabs (tab, event) {
      this.tabIndex = Number(tab.paneName)
      let param = {}
      switch (tab.paneName) {
        case '0':
          param = { 'queryOrderType': 'ASN' }
          this.getList('query', param)
          this.urlKey = 'query'
          this.type = 'ASN'
          break
        case '1':
          param = { 'queryOrderType': 'QC' }
          this.getList('query', param)
          this.urlKey = 'query'
          this.type = 'QC'
          break
        case '2':
          param = { 'queryOrderType': 'SO' }
          this.getList('querySoList', param)
          this.urlKey = 'querySoList'
          this.type = 'SO'
          break
        default:
          break
      }
    }
  },
  // 路由跳回来前判断是否需要刷新列表
  beforeRouteUpdate (to, from, next) {
    if (to.meta.needRefresh) {
      this.getList()
      delete to.meta.needRefresh
    }
    next()
  },
}
</script>
