<template>
  <div class="app-container">
    <h4 class="form-header h4">基本信息</h4>
    <el-form ref="form" :model="baseInfo" label-width="120px">
      <el-row>
        <el-col :offset="2" :span="8">
          <el-form-item label="数据接入名称" prop="nickName">
            <el-input v-model="baseInfo.name" disabled/>
          </el-form-item>
        </el-col>
        <el-col :offset="2" :span="8">
          <el-form-item label="系统名称" prop="userName">
            <el-input v-model="baseInfo.systemName" disabled/>
          </el-form-item>
        </el-col>
        <el-col :offset="2" :span="8">
          <el-form-item label="数据库名称" prop="nickName">
            <el-input v-model="baseInfo.databaseName" disabled/>
          </el-form-item>
        </el-col>
        <el-col :offset="2" :span="8">
          <el-form-item label="表名称" prop="nickName">
            <el-input v-model="baseInfo.tableName" disabled/>
          </el-form-item>
        </el-col>
        <el-col :offset="2" :span="8">
          <el-form-item label="表中文名" prop="nickName">
            <el-input v-model="baseInfo.tableAsName" disabled/>
          </el-form-item>
        </el-col>
        <el-col :offset="2" :span="8">
          <el-form-item label="数据量" prop="nickName">
            <el-input v-model="baseInfo.total" disabled/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-tabs type="border-card" v-model="activeName">
      <el-tab-pane label="部门授权" name="dept">
        <el-table
          ref="deptTable"
          v-loading="loading"
          :data="deptList"
          :default-expand-all="true"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          row-key="deptId"
        >
          <el-table-column label="部门名称" prop="deptName" ></el-table-column>
          <el-table-column label="部门负责人" prop="leader" ></el-table-column>
          <el-table-column label="邮箱" prop="email" ></el-table-column>
          <el-table-column align="center" label="创建时间" prop="createTime" >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作" prop="createTime" >
            <template slot-scope="scope">
              <el-switch
                style="display: block"
                v-model="scope.row.isAuth"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-text="已授权"
                inactive-text="未授权">
              </el-switch>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total> 0" :limit.sync="pageSize" :page.sync="pageNum" :total="total"/>
      </el-tab-pane>
      <el-tab-pane label="用户授权" name="user">
        <el-table ref="table" v-loading="loading" :data="userList">
          <el-table-column align="center" label="用户名称" prop="userName"/>
          <el-table-column align="center" label="用户昵称" prop="nickName"/>
          <el-table-column align="center" label="用户部门" prop="dept.deptName"/>
          <el-table-column align="center" label="用户邮箱" prop="email"/>
          <el-table-column align="center" label="用户手机号" prop="phonenumber"/>
          <el-table-column align="center" label="创建时间" prop="createTime" />
          <el-table-column align="center" label="操作" prop="createTime" >
            <template slot-scope="scope">
              <el-switch
                style="display: block"
                v-model="scope.row.isAuth"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-text="已授权"
                inactive-text="未授权">
              </el-switch>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total> 0" :limit.sync="pageSize" :page.sync="pageNum" :total="total"/>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>

import { parseTime } from '@/utils/muyu';
import {listDept} from "@/api/system/dept";
import {listRole} from "@/api/system/role";
import {listDatasource} from "@/api/etl/datasource";
import {listUser} from "@/api/system/user";

export default {
  name: "AuthTable",
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "dept",
      // 分页信息
      total: 0,
      pageNum: 1,
      pageSize: 1,
      // 基本信息
      baseInfo: {
        name: "1",
        systemName: "111",
        databaseName: "ry_cloud",
        tableName: "sys_user",
        tableAsName: "用户表",
        total: "3条",
      },
      // 部门列表
      deptList: [],
      // 用户列表
      userList: [],
      arr:[],
      source:{}
    };
  },
  created() {
    this.loading = true;
    setTimeout(() => this.loading = false, 200)
    this.init()
    this.getListDept()
    this.getListRole()
    this.getSource()
  },
  methods: {
    getSource(){
      listDatasource(this.source).then(res=>{
        console.log(res)
        this.arr=res.data.rows
      })
    },
    getListDept(){
      listDept().then(res=>{
        this.deptList=res.data
        console.log(res)
      })
    },
    getListRole(){
      listUser().then(res=>{
        console.log(res)
        this.userList=res.data.rows
      })
    },
    parseTime,
    init(){

    }
  },
};
</script>
