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

          <center-list
              :tableData="tableList"
              :currentPage="currentPage"
              :pageSize="pageSize"
              :total="total"
              @getList="getList"
              @handleSelectChange="cacheSelectedIds"
              @handelDetailForm="handleOpenForm">
          </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: 'CollectGoods',
  components: {
    HeadTodo,
    CenterList
  },
  data () {
    return {
      // 查询条件
      query: {
        // status: '00,10,20,99',
        // auditStatus: ' 99,90',
        // holdStatus: '00',
        '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.stockIn.collectGoods.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, ...arg) {
      this.mode = mode
      this.$router.push({
        name: 'collectGoodsAdd',
        params: {
          mode,
          ...arg
        }
      })
    },

    // checkbox勾选id储存
    cacheSelectedIds (ids, rows) {
      this.selectedIds = ids
      this.rows = rows
    },

  },
  // 路由跳回来前判断是否需要刷新列表
  beforeRouteUpdate (to, from, next) {
    if (to.meta.needRefresh) {
      this.getList()
      delete to.meta.needRefresh
    }
    next()
  },
}
</script>
