<template>
<div class="inside-business">
  <div v-show="$route.name === 'insideBusiness'">
    <Query
      class="inside-business__query"
      :selectedIds="selectedIds"
      @getList="getList"
    ></Query>
    <List
      :currentNo="currentNo"
      :pageSize="pageSize"
      :list="insideBusinessList"
      :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: 'InsideBusiness',
  mixins: [ routerMixins ],
  components: { Query, List },
  created () {
  },
  mounted () {
    this.getList()
  },

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

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