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

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

  data () {
    return {
      query: {
        'page.currentPage': 1,
        'page.limitCount': 10,
      }, // 查询条件
      mvOrderList: [], // 移动单列表
      total: 0, // 总数据量
      selectedIds: '', // 选中的id字符串序列 (','隔开)
      currentNo: 1,
      pageSize: 10
    }
  },
  methods: {
    // 获取移动单列表
    getList (query = {}) {
      const url = this.$API.inventory.mvOrder.getList
      const param = { ...this.query, ...query }
      param.mvNo !== undefined && (param.mvNo = `%${param.mvNo}%`) // 避免传空值只能查到部分数据
      // param.quickCondition !== undefined && (param.quickCondition = `%${param.quickCondition}%`) // 避免传空值只能查到部分数据
      this.$https.post(url, param)
        .then(data => {
          this.mvOrderList = data.rows
          this.total = data.total
          this.currentNo = data.currentPage
          this.pageSize = data.limit
        })
    },
    // 勾选变化, 缓存id
    cacheSelectedIds (ids) {
      this.selectedIds = ids
      console.log('mvOrder cache ids =', ids)
    },
    // 编辑 或 详情
    toCreator (mvNo, mode = 'detail') {
      const url = this.$API.inventory.mvOrder.detail
      const param = { mvNo }
      this.$https.post(url, param)
        .then(data => {
          this.$router.push({
            name: 'mvOrderCreator',
            params: {
              detailData: data.data,
              mode,
            }
          })
        })
    }
  },
}
</script>

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