<template>
<div class="qcItems">
  <div v-show="$route.name === 'qcItems'">
    <Query
      class="qc-items__query"
      :selection="selection"
      @getList="getList"
    ></Query>
    <List
      :list="qcItemsList"
      :currentNo="currentNo"
      :pageSize="pageSize"
      :total="total"
      @getList="getList"
      @selectionChange="cacheSelectedIds"
    ></List>
  </div>
  <router-view></router-view>
</div>
</template>

<script>
import Query from './components/Query'
import List from './components/List'
import Creator from './components/Creator'
import routerMixins from './routerMixins'

export default {
  name: 'QCItems',
  mixins: [routerMixins],
  components: { Query, List, Creator },
  created () {
  },
  mounted () {
    this.getList()
  },

  data () {
    return {
      query: {
        'page.currentPage': 1,
        'page.limitCount': 20,
      }, // 查询条件
      qcItemsList: [], // 质检项列表
      total: 0, // 总数据量
      selection: [], // 选中的id字符串序列 (','隔开)

      detailData: {}, // 详情数据
      mode: 'create', // 新增框模式
      currentNo: 1,
      pageSize: 10
    }
  },
  methods: {
    // 获取质检项列表
    getList (query = {}) {
      const url = this.$API.warehouseBasic.qcItems.getList
      const param = { ...this.query, ...query }
      // param.itemGroupCode !== undefined && (param.itemGroupCode = `%${param.itemGroupCode}%`) // 避免传空值只能查到部分数据
      this.$https.post(url, param)
        .then(data => {
          this.qcItemsList = data.rows
          this.total = data.total
          this.currentNo = data.currentPage
          this.pageSize = data.limit
        })
    },
    // 勾选变化, 缓存id
    cacheSelectedIds (ids) {
      this.selection = ids
    },
  },
}
</script>

<style lang="scss" scoped>
.qc-items__query {
  margin-bottom: 20px;
}
</style>
