<template>
  <el-dialog class="fittings-modal" title="选择任务飞机" :visible="fittingsVisible" width="1200px" :before-close="closefittingsVisible">
    <div class="fittings-modal-box">
      <div class="fittings-modal-box-left">
        <MenuTree :currentNodeKey="currentNodeKey" :treedata="menuTreeData" @TreeNodeclick="treeNodeClick" v-bind="treeObj"> </MenuTree>
      </div>
      <div class="fittings-modal-box-right">
        <LTable ref="table" :defaultFetch="false" :columns="columns" :dataSource="dialogTableData" :options="options" :fetch="getAircraftsByCode" :pagination="tableRequset"></LTable>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { columns, options, defaultProps } from './index.js'
import { getAircaftTypeAndModelTree, getAircraftsByCode } from '@/api/task/carrierFlightMission'
export default {
  name: 'FittingsModal',
  components: {},
  props: { taskId: {} },
  data() {
    // 这里存放数据
    return {
      currentNodeKey: '',
      currentRow: null,
      menuTreeData: [],
      columns: columns(this),
      options,
      dialogTableData: [],
      defaultProps,
      fittingsVisible: false,
      treeObj: {
        title: '机型',
        activityheight: '500px',
        searchIcon: false,
        configure: defaultProps
      },
      tableRequset: {
        total: 0,
        pageIndex: 1,
        pageSize: 10,
        searchValue: ''
      }
    }
  },
  mounted() {
    this.getAircaftTypeAndModelTree()
  },
  methods: {
    async getAircraftsByCode() {
      let postData = {
        pageIndex: this.tableRequset.pageIndex,
        pageSize: this.tableRequset.pageSize,
        id: this.currentRow.id,
        taskId: this.taskId
      }
      const { code, data } = await getAircraftsByCode(postData)
      if (code == 200) {
        this.dialogTableData = data.list
        this.tableRequset.total = data.totalCount
      }
    },
    async getAircaftTypeAndModelTree() {
      const { code, data } = await getAircaftTypeAndModelTree()
      if (code == 200) {
        this.menuTreeData = data
        this.currentRow = this.menuTreeData[0]
        this.getAircraftsByCode()
      }
    },
    openDittingsModal() {
      this.fittingsVisible = true
    },
    closefittingsVisible() {
      this.fittingsVisible = false
    },
    treeNodeClick(rwo) {
      this.currentRow = rwo
      this.getAircraftsByCode()
    },
    select(row) {
      this.$emit('select', row)
      this.fittingsVisible = false
    }
  }
}
</script>

<style lang="scss">
@import './index.scss';
</style>
