<template>
<div class="movement">
  <div v-show="$route.name === 'movement'">
    <Query
      class="movement__query"
      :selectedIds="selectedIds"
      @getList="getList"
    ></Query>
    <List
      :currentNo="currentNo"
      :pageSize="pageSize"
      :list="movementList"
      :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 routerMixins from '../routerMixins'

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

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

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