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

      <center-list
        :tableData="tableList"
        :currentPage="currentPage"
        :pageSize="pageSize"
        :total="total"
        @getList="getList"
        @handleSelectChange="cacheSelectedIds"
        @handleOpenEditForm="handleOpenEditForm"
        @handleDateil="handleOpenEditForm">
      </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: 'Quality',
  components: {
    HeadTodo,
    CenterList
  },
  created () {
    this.getList()
  },
  mounted () {

  },
  data () {
    return {
      tableList: [], // 列表数据
      total: 0, // 查询列表数据总条数
      selectedIds: '', // checkbox选中的id字符串序列
      mode: 'create',
      query: {
        // quickCondition: '',
        'page.currentPage': 1,
        'page.limitCount': 10
      },
      currentPage: 1,
      pageSize: 10,
    }
  },
  methods: {

    // 查询列表
    getList (query) {
      const url = this.$API.stockIn.Quality.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
        })
    },

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

    // checkbox勾选id储存
    cacheSelectedIds (ids) {
      this.selectedIds = ids
      console.log('勾选ids：', ids)
    },

  },
  // 路由跳回来前判断是否需要刷新列表
  beforeRouteUpdate (to, from, next) {
    if (to.meta.needRefresh) {
      this.getList()
      delete to.meta.needRefresh
    }
    next()
  },
}
</script>
<style lang="scss">
    .mrg-b{
        margin-bottom: 20px;
    }
    .mrg-l{
        margin-left:10px;
    }
</style>
