<template>
    <div>
      <div v-show="$route.name === 'wmKitOrderList'">
        <head-todo
        :selectedIds="selectedIds"
        @getList="getList"
        @handleOpenAddForm="handleOpenForm">
        </head-todo>

        <center-list
            :tableData="tableList"
            :currentPage="currentPage"
            :pageSize="pageSize"
            :total="total"
            @handleSelectChange="cacheSelectedIds"
            @getList="getList"
            @handleOpenEditForm="handleOpenEditForm"
            @handleOpenDetail="handleOpenDetailForm">
        </center-list>
      </div>
      <router-view></router-view>
    </div>
</template>
<script>
import HeadTodo from './components/head-todo'
import CenterList from './components/center-list'
export default {
  name: 'WmKitOrderList',
  components: {
    HeadTodo,
    CenterList
  },
  data () {
    return {
      tableList: [],
      total: 0,
      query: {
        'page.currentPage': 1,
        'page.limitCount': 10,
      },
      mode: 'create',
      selectedIds: [],
      currentPage: 1,
      pageSize: 10
    }
  },
  created () {
    this.getList()
  },
  mounted () {

  },
  methods: {
    getList (query) {
      const url = this.$API.maintain.WmKitOrderList.getList
      const param = { ...this.query, ...query }
      this.$https.post(url, param).then(res => {
        this.tableList = res.rows
        this.total = res.total
        this.currentPage = res.currentPage
        this.pageSize = res.limit
      })
    },

    //  新增
    handleOpenForm (mode) {
      this.mode = mode
      this.$router.push({
        name: 'wmKitOrderListAdd',
        params: {
          mode
        }
      })
    },

    // 编辑
    handleOpenEditForm (mode, ...args) {
      this.mode = mode
      this.$router.push({
        name: 'wmKitOrderListAdd',
        params: {
          mode,
          ...args
        }
      })
    },

    // 详情
    handleOpenDetailForm (mode, ...args) {
      this.mode = mode
      this.$router.push({
        name: 'wmKitOrderListAdd',
        params: {
          mode,
          ...args
        }
      })
    },

    // checkbox勾选储存id
    cacheSelectedIds (ids) {
      this.selectedIds = ids
    }
  },
  // 路由跳回来前判断是否需要刷新列表
  beforeRouteUpdate (to, from, next) {
    if (to.meta.needRefresh) {
      this.getList()
      delete to.meta.needRefresh
    }
    next()
  },
}
</script>
