<template>
    <div>
        <head-todo
        :rows="rows"
        :selectIds="selectIds"
        @getList="getList"
        @handleOpenForm="handleOpenForm">
        </head-todo>

        <center-list
            :tableData="tableList"
            :currentPage="currentPage"
            :pageSize="pageSize"
            :total="total"
            @handleSelectChange="cacheSelectedIds"
            @getList="getList"
            @handleOpenForm="handleOpenForm">
        </center-list>
        <add-form
         :addFormVisible="addFormVisible"
         :rowData="rowData"
         :rows="rows"
         :mode="mode"
          @handleFormClose="handleFormClose"
          @saveOK="getList">
        </add-form>
    </div>
</template>
<script>
import HeadTodo from './components/head-todo'
import CenterList from './components/center-list'
import AddForm from './components/add-form'
export default {
  name: 'LibraryPlace',
  components: {
    HeadTodo,
    CenterList,
    AddForm
  },
  data () {
    return {
      tableList: [],
      total: 0,
      query: {
        'page.currentPage': 1,
        'page.limitCount': 10,
      },
      addFormVisible: false,
      rows: [],
      rowData: {},
      mode: 'create',
      selectIds: [],
      currentPage: 1,
      pageSize: 10
    }
  },
  created () {
    this.getList()
  },
  methods: {
    getList (query) {
      const url = this.$API.warehouseBasic.libraryPlace.getList
      const param = { ...this.query, ...query }
      this.$https.post(url, param).then(res => {
        this.tableList = res.rows
        this.total = res.total
        this.currentPage = res.currentPage
        this.pageSize = res.limit
      })
    },

    // 共用表单
    handleOpenForm (mode, ...args) {
      this.mode = mode
      if (mode !== 'create' && mode !== 'batch') {
        this.$nextTick(() => {
          this.rowData = args[0]
        })
      }
      this.addFormVisible = true
    },

    // 关闭新增弹窗
    handleFormClose () {
      this.addFormVisible = !this.addFormVisible
    },
    // checkbox勾选储存每一行数据对象
    cacheSelectedIds (row, ids) {
      this.rows = row
      this.selectIds = ids
    }
  }
}
</script>
