<template>
  <div class="app-container">
    <el-table
      :data="tableData"
      v-loading="listLoading"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      :tree-props="{child: 'child', haschild: 'child'}">
      <el-table-column
        prop="deptName"
        label="部门名称"
        width="180">
      </el-table-column>
      <el-table-column
        label="负责人"
        prop="leader"
      ></el-table-column>
      <el-table-column
        label="联系电话"
        prop="phone"
      ></el-table-column>
      <el-table-column
        label="排序"
        prop="sortNum"
      >
      </el-table-column>
      <el-table-column align="center" label="状态" class-name="status-col" width="100">
        <template slot-scope="{row}">
          <el-tag v-if="row.status==1" type="danger">
            停用
          </el-tag>
          <el-tag v-else="row.status==0" type="success">
            正常
          </el-tag>
        </template>
      </el-table-column>

<!--      <el-table-column-->
<!--        label="创建时间"-->
<!--      >-->
<!--        <template slot-scope="{row}">-->
<!--          <span v-if="row.createTime != null || row.createTime != '' ">{{row.createTime | getTime}}</span>-->

<!--        </template>-->
<!--      </el-table-column>-->
            <el-table-column label="操作" align="center" fixed="left" class-name="small-padding fixed-width">
              <template slot-scope="{row}">
                <template v-if="webType">
                    <el-button @click="chooseThis(row)" type="primary" size="mini">
                      选择
                    </el-button>
                </template>
                <template v-else>
                  <el-button @click="ERPChoose(row)" type="primary" size="mini">
                    选择
                  </el-button>
                </template>

              </template>
            </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getDeptList, getMenuInfo } from '@/api/system/department.js'
import { getMenu } from '@/utils/getTable.js'
import Cancledialog from '@/components/Dialog/Cancledialog.vue'

export default {
  name:'selectDepart',
  components: {
    Cancledialog,
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        1: 'success',
        0: 'danger'
      }
      return statusMap[status]
    }
  },
  props: {
    isChoose: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      webType: true,
      dialogStatus: '',
      titleDialog: '',
      dialogVisible: false,
      confirmdialog: false,
      listLoading: false,
      tableData: [],
      parentId: 0
    }
  },
  mounted() {
    if (this.$route.query.type === undefined) {
      this.webType = true
    } else {
      this.webType = false
    }
    this.getHomeInfo()
  },
  methods: {
    // 刷新变革
    tableRefresh() {
      // 刷新变革
      this.getHomeInfo()
    },
    getHomeInfo() {
      const _that = this
      _that.listLoading = true
      var data = {}
      if (_that.isChoose || !_that.webType) {
        data = {
          params: {
            status: 0
          }
        }
      }
      getDeptList(data).then(response => {
        console.log(response)
        const data = response.data
        // console.log('getMenuList', data)
        const menuData = getMenu(data)
        // console.log(menuData)
        // console.log(menuData)
        // //  组合表单数据
        _that.tableData = menuData
        // console.log(_that.tableData)
        _that.listLoading = false
      }).catch(err => {
        _that.$message.error(err)
        _that.listLoading = false
      })
    },
    // 弹窗内选择操作
    chooseThis(row) {
      // console.log('点击选择');
      this.$emit('choosePaper', row)
    },
    ERPChoose(row) {
      // this.$message.error(row)
      dyERP.sendJson(JSON.stringify(row))
    }
  }
}
</script>

<style lang="scss" scoped>
  .filter-container {
    margin-bottom: 15px;
  }
</style>
