<template>
  <div>
    <head-todo
      :selectedIds="selectedIds"
      @getList="getList"
      @handleOpenForm="handleOpenAddForm"
    >
    </head-todo>

    <center-list
      :tableData="tableList"
      :total="total"
      @handleSelectChange="cacheSelectedIds"
      @getList="getList"
      @handleOpenForm="handleOpenEditForm"
      @handleOpenDetail="handleOpenDetail"
    >
    </center-list>

    <add-form
      :addFormVisible="addFormVisible"
      :rowData="rowData"
      :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: 'DockBasicdataList',
  components: {
    HeadTodo,
    CenterList,
    AddForm
  },
  data () {
    return {
      tableList: [],
      total: 0,
      query: {
        'page.currentPage': 1,
        'page.limitCount': 10,
      },
      selectedIds: [],
      addFormVisible: false,
      rowData: {},
      mode: 'create',
      currentPage: 1,
      pageSize: 10
    }
  },
  created () {
    this.getList()
  },
  mounted () {

  },
  methods: {
    getList (query) {
      const url = this.$API.platform.DockBasicdataList.getList
      const param = { ...this.query, ...query }
      this.$https.post(url, param).then(res => {
        this.tableList = res.rows
        this.tableList.map(item => {
          if (item.vehicleType !== null) {
            const arr1 = item.vehicleType.split(',')
            item.vehicleText = arr1.map(ele => this.$utils.keyMatcher(ele, this.$keys.platform.vehicleType).name).join(',')
          }
        })
        this.total = res.total
        this.currentPage = res.currentPage
        this.pageSize = res.limit
      })
    },

    // 新增
    handleOpenAddForm (mode) {
      // this.rowData = {}
      this.mode = mode
      this.addFormVisible = true
    },

    // 编辑
    handleOpenEditForm (mode, rowData) {
      this.mode = mode
      this.rowData = rowData
      this.addFormVisible = true
    },

    // 详情
    handleOpenDetail (mode, data) {
      this.rowData = data
      this.mode = mode
      this.addFormVisible = true
    },

    // 关闭新增弹窗
    handleFormClose () {
      this.addFormVisible = !this.addFormVisible
    },

    // checkbox勾选储存id
    cacheSelectedIds (ids) {
      this.selectedIds = ids
    }
  }
}
</script>
