<template>
  <!-- 工程管理页面 -->
  <div class="app-container">
    <!-- 表格 -->
    <TableModel
      :formLabel="formLabelTower"
      :columnsList="columnsListTower"
      :request-api="queryProjListApi"
      ref="tableRef"
      @transIdList="getIdList"
    >
      <template slot="btn" slot-scope="{ queryParams }">
        <el-button type="primary" @click="handleAddTower()" icon="el-icon-plus" size="mini"
        >新增杆塔</el-button
        >
        <el-button
          @click="handleExportData(
                    exportList,
                    'base/tbProject/export',
                    '工程清单',
                    queryParams
                  )"
          icon="el-icon-upload2"
          size="mini"
        >导出数据</el-button
        >
        <el-button
          icon="el-icon-download"
          size="mini"
        >数据模板下载</el-button
        >
        <el-button
          icon="el-icon-download"
          size="mini"
        >导入数据</el-button
        >
      </template>
      <template slot="handle" slot-scope="{ data }">
        <el-button
          type="primary"
          size="mini"
          @click="handleEditTower(data)"
        >编辑</el-button
        >
        <el-button
          type="danger"
          size="mini"
          @click="handleDeleteData(data.id, deleteProjApi)"
        >删除</el-button
        >
      </template>
    </TableModel>

    <DialogModel
      :dialogConfig="dialogConfigTowerAdd"
      @closeDialogOuter="closeDialogTowerAddOuter"
    >
      <template slot="outerContent">
        <!-- 新增以及修改数据的表单组件 -->
        <TableTowerAdd
          :send-add-data="sendAddData"
          @closeAdd="closeAdd"
        >
        </TableTowerAdd>
      </template>
    </DialogModel>

  </div>
</template>

<script>
import {
  queryProjListApi
} from '@/api/base/proj'
import { formLabelTower, columnsListTower, dialogConfigTowerAdd } from '../config-tower'
import { commonMixin } from '../../mixins/common'
import TableTowerAdd from './table-tower-add.vue'
export default {
  name: 'tower',
  props: {
    sendData: {
      type: Object,
      default: () => null,
    },
  },
  methods: {
    queryProjListApi,
    handleAddTower() {
      this.dialogConfigTowerAdd.outerVisible = true
    },
    handleEditTower(data) {
      this.sendAddData = data
      this.dialogConfigTowerAdd.outerVisible = true
    },
    closeAdd() {
      this.dialogConfigTowerAdd.outerVisible = false
    },
    closeDialogTowerAddOuter() {
      this.dialogConfigTowerAdd.outerVisible = false
    },
    getIdList(idList) {
      this.exportList = []
      idList.forEach(item => {
        this.exportList.push(item.id)
      })
    },
  },
  mixins: [commonMixin],
  components: {
    TableTowerAdd
  },
  created() {

  },
  mounted() {
    console.log(this.sendData, '-----------')
  },
  data() {
    return {
      // 搜索区表单配置项
      formLabelTower,
      // 表格导出id列表
      exportList: [],
      // 列表区配置项
      columnsListTower,
      // 弹框区配置项
      dialogConfigTowerAdd,
      // 新建时弹框标题
      addDialogTitle: '新建项目部',
      // 修改时弹框标题
      editDialogTitle: '修改项目部',
      sendAddData: undefined
    }
  },
}
</script>
