<template>
<div class="adjustment">
  <div v-show="$route.name === 'adjustment'">
    <Query
      class="adjustment__query"
      :selectedIds="selectedIds"
      @getList="getList"
    ></Query>
    <List
      :currentNo="currentNo"
      :pageSize="pageSize"
      :list="adjustmentList"
      :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: 'Adjustment',
  mixins: [ routerMixins ],
  components: { Query, List, Creator },
  created () {
  },
  mounted () {
    this.getList()
  },

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

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

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