<template>
<div class="count">
  <div v-show="$route.name === 'count'">
    <Query
      class="qc-rules__query"
      :selectedIds="selectedIds"
      @getList="getList"
    ></Query>
    <List
      :currentNo="currentNo"
      :pageSize="pageSize"
      :list="countList"
      :total="total"
      @getList="getList"
      @selectionChange="cacheSelectedIds"
      @toCreator="toCreator"
    ></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: 'Count',
  mixins: [routerMixins],
  components: { Query, List, Creator },
  created () {
  },
  mounted () {
    this.getList()
    // console.log(this)
    // this.$options.activated[0]()
  },

  data () {
    return {
      query: {
        'page.currentPage': 1,
        'page.limitCount': 10,
      }, // 查询条件
      countList: [], // 盘点列表
      total: 0, // 总数据量
      selectedIds: '', // 选中的id字符串序列 (','隔开)

      detailData: {}, // 详情数据
      mode: 'create', // 模式
      currentNo: 1,
      pageSize: 10
    }
  },
  methods: {
    // 获取盘点列表
    getList (query = {}) {
      const url = this.$API.inventory.count.getList
      const param = { ...this.query, ...query }
      param.countNo !== undefined && (param.countNo = `%${param.countNo}%`) // 避免传空值只能查到部分数据
      this.$https.post(url, param)
        .then(data => {
          this.countList = data.rows
          this.total = data.total
          this.currentNo = data.currentPage
          this.pageSize = data.limit
        })
    },
    // 勾选变化, 缓存id
    cacheSelectedIds (ids) {
      this.selectedIds = ids
    },
    // 编辑 或 详情
    toCreator (countNo, mode = 'detail') {
      const url = this.$API.inventory.count.detail
      const param = { countNo }
      this.$https.post(url, param)
        .then(data => {
          this.$router.push({
            name: 'countCreator',
            params: {
              detailData: data.data,
              mode,
            }
          })
        })
    }
  },
}
</script>

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