<template>
    <div>
      <div v-show="$route.name === 'picking'">
        <div>
          <head-todo
            :selectedIds="selectedIds"
            :rows="rows"
            @getList="getList">
        </head-todo>
          <center-list
              :tableData="tableList"
              :currentPage="currentPage"
              :pageSize="pageSize"
              :total="total"
              @getList="getList"
              @handleSelectChange="cacheSelectedIds"
              @handleOpenDetail="handleOpenForm">
          </center-list>
        </div>

      </div>
        <router-view></router-view>
    </div>
</template>
<script>
import HeadTodo from './components/head-todo'
import CenterList from './components/center-list'
export default {
  name: 'Picking',
  components: {
    HeadTodo,
    CenterList,
  },
  data () {
    return {
      query: {
        'page.currentPage': 1,
        'page.limitCount': 10
      },
      tableList: [], // 查询列表
      total: 0, // 查询总条数
      selectedIds: '', // checkbox勾选id
      mode: 'create',
      rows: [],
      currentPage: 1,
      pageSize: 10
    }
  },
  created () {
    this.getList()
  },
  mounted () {
  },
  methods: {
    // 查询列表
    getList (query) {
      const url = this.$API.stockOut.picking.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, data) {
      this.mode = mode
      this.$router.push({
        name: 'pickingDetail',
        params: {
          mode,
          data,
        }
      })
    },

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