<template>
  <!-- 工程管理页面 -->
  <div class="app-container">
    <!-- 表格 -->
    <TableModel
      :formLabel="formLabel"
      :columnsList="columnsList"
      :request-api="queryProjDeptListApi"
      ref="tableRef"
      @transIdList="getIdList"
    >
      <template slot="btn" slot-scope="{ queryParams }">
        <el-button type="primary" @click="handleAddData()" icon="el-icon-plus" size="mini"
        >新建项目部</el-button
        >
        <el-button
          @click="handleExportData(
                    exportList,
                    'base/tbProDepart/export',
                    '项目部清单',
                    queryParams
                  )"
          icon="el-icon-upload2"
          size="mini"
        >导出数据</el-button
        >
      </template>
      <template slot="handle" slot-scope="{ data }">
        <el-button
          type="primary"
          size="mini"
          @click="handleEditData(data)"
        >编辑</el-button
        >
        <el-button
          type="danger"
          size="mini"
          @click="handleDeleteData(data.id, deleteProjDeptApi)"
        >删除</el-button
        >
      </template>
      <template slot="headUserPhone" slot-scope="{ data }">
        {{ phoneCrypto(data.headUserPhone) || '-' }}
      </template>
    </TableModel>

    <!-- 新增以及修改时的弹框 -->
    <DialogModel
      :dialogConfig="dialogConfig"
      @closeDialogOuter="closeDialogOuter"
    >
      <template slot="outerContent">
        <!-- 新增以及修改数据的表单组件 -->
        <FormProject
          :editParams="editParams"
          @closeDialog="closeDialog"
        />
      </template>
    </DialogModel>
  </div>
</template>

<script>
import { formLabel, columnsList, dialogConfig, queryProvinces } from './config'
import { commonMixin } from '../mixins/common'
import {
  queryProjDeptListApi,
  deleteProjDeptApi
} from '@/api/base/projDept'
import FormProject from './components/form-project'
export default {
  name: 'ProjectDepart',
  methods: {
    queryProjDeptListApi,
    deleteProjDeptApi,
    getIdList(idList) {
      this.exportList = []
      idList.forEach(item => {
        this.exportList.push(item.id)
      })
    }
  },
  mixins: [commonMixin],
  components: {
    FormProject
  },
  created() {
    queryProvinces()
  },
  data() {
    return {
      // 搜索区表单配置项
      formLabel,
      // 表格导出id列表
      exportList: [],
      // 列表区配置项
      columnsList,
      // 弹框区配置项
      dialogConfig,
      // 新建时弹框标题
      addDialogTitle: '新建项目部',
      // 修改时弹框标题
      editDialogTitle: '修改项目部',
    }
  },
}
</script>
