<template>
  <div>
    <div v-show="$route.name === 'dockDispatchList'">
      <head-todo :tabIndex="tabIndex" :urlKey="urlKey" @getList="getList" @getTableList="getTableList"></head-todo>
      <center-list
        :tableData="tableData"
        :pageSize="pageSize"
        :currentPage="currentPage"
        :total="total"
        :tabIndex="tabIndex"
        :urlKey="urlKey"
        :markDockData="markDockData"
        @getList="getList"
        @handleClickTabs="handleClickTabs"
        @handleOpenDetail="handleOpenDetail"
      ></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: 'DockDispatchList',
  components: {
    HeadTodo,
    CenterList
  },
  data () {
    return {
      query: {
        'page.currentPage': 1,
        'page.limitCount': 10,
      },
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 0,
      tabIndex: 0,
      urlKey: 'getAsnList',
      date: time.formatDate(new Date()),
      markDockData: []
    }
  },
  mounted () {
    this.getList('getAsnList')
  },
  methods: {
    getTableList (val) {
      this.tableData = val
    },
    getData (url, param) {
      return this.$https.post(url, param)
    },
    getList (urlKey, query) {
      const url = this.$API.platform.DockDispatchList[urlKey]
      const dockUrl = this.$API.platform.DockDispatchList.queryDock
      const param = { ...this.query, ...query }
      if (urlKey === 'getdockList') {
        const params = { ...param, ...{ currentDate: this.date, type: 'look' } }
        this.$https.all([this.getData(url, params), this.getData(dockUrl, params)]).then(res => {
          this.tableData = res[0].rows
          this.markDockData = res[1].rows
          this.total = res.total
          this.currentPage = res.currentPage
          this.pageSize = res.limit
        })
        return
      }
      this.$https.post(url, param).then(res => {
        this.tableData = res.rows || []
        this.total = res.total
        this.currentPage = res.currentPage
      })
    },

    // 编辑
    handleOpenDetail (...args) {
      this.$router.push({
        name: 'dockDispatchListAdd',
        params: { ...args }
      })
    },

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