<template>
<div class="block-log">
  <div v-show="$route.name === 'blockLog'">
    <Query
      class="block-log__query"
      :selectedIds="selectedIds"
      @getList="getList"
    ></Query>
    <List
      :currentNo="currentNo"
      :pageSize="pageSize"
      :list="blockList"
      :total="total"
      @selectionChange="cacheSelectedIds"
      @getList="getList"
    ></List>
  </div>
  <router-view></router-view>
</div>
</template>

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

export default {
  name: 'BlockLog',
  components: { Query, List },
  created () {
  },
  mounted () {
    this.getList()
  },

  data () {
    return {
      query: {
        'page.currentPage': 1,
        'page.limitCount': 10,
      }, // 查询条件
      blockList: [], // 盘点列表
      total: 0, // 总数据量
      selectedIds: '', // 选中的id字符串序列 (','隔开)
      currentNo: 1,
      pageSize: 10
    }
  },
  methods: {
    // 获取盘点列表
    getList (query = {}) {
      const url = this.$API.inventoryQuery.blockLog.getList
      const param = { ...this.query, ...query }
      param.quickCondition !== undefined && (param.quickCondition = `%${param.quickCondition}%`) // 避免传空值只能查到部分数据
      this.$https.post(url, param)
        .then(data => {
          this.blockList = data.rows
          this.total = data.total
          this.currentNo = data.currentPage
          this.pageSize = data.limit
        })
    },
    // 勾选变化, 缓存id
    cacheSelectedIds (ids) {
      this.selectedIds = ids
      console.log('blockLog cache ids =', ids)
    }
  },
}
</script>

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