<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-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'

export default {
  name: "AuthDataSource",
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "dept",
      // 分页信息
      total: 0,
      pageNum: 1,
      pageSize: 1,
      // 基本信息
      baseInfo: {
        name: "测试1",
        systemName: "云计算系统",
        databaseName: "yunjisuan",
      },
      // 部门列表
      deptList: [],
      // 用户列表
      userList: []
    };
  },
  created() {
    this.loading = true;
    setTimeout(() => this.loading = false, 200)
    this.init()
  },
  methods: {
    parseTime,
    init(){
      let response = {
        "code": 200,
        "msg": "操作成功",
        "data": [
          {
            "createBy": 1,
            "createTime": "2023-09-29 11:47:27",
            "updateBy": null,
            "updateTime": null,
            "deptId": 100,
            "parentId": 0,
            "ancestors": "0",
            "deptName": "muyu牧鱼科技",
            "orderNum": 0,
            "leader": "muyu牧鱼",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
          },
          {
            "createBy": 1,
            "createTime": "2023-09-29 11:47:27",
            "updateBy": null,
            "updateTime": null,
            "deptId": 101,
            "parentId": 100,
            "ancestors": "0,100",
            "deptName": "深圳总公司",
            "orderNum": 1,
            "leader": "muyu牧鱼",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
          },
          {
            "createBy": 1,
            "createTime": "2023-09-29 11:47:27",
            "updateBy": null,
            "updateTime": null,
            "deptId": 102,
            "parentId": 100,
            "ancestors": "0,100",
            "deptName": "长沙分公司",
            "orderNum": 2,
            "leader": "muyu牧鱼",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
          },
          {
            "createBy": 1,
            "createTime": "2023-09-29 11:47:27",
            "updateBy": null,
            "updateTime": null,
            "deptId": 103,
            "parentId": 101,
            "ancestors": "0,100,101",
            "deptName": "研发部门",
            "orderNum": 1,
            "leader": "muyu牧鱼",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
          },
          {
            "createBy": 1,
            "createTime": "2023-09-29 11:47:27",
            "updateBy": null,
            "updateTime": null,
            "deptId": 104,
            "parentId": 101,
            "ancestors": "0,100,101",
            "deptName": "市场部门",
            "isAuth": true,
            "orderNum": 2,
            "leader": "muyu牧鱼",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
          },
          {
            "createBy": 1,
            "createTime": "2023-09-29 11:47:27",
            "updateBy": null,
            "updateTime": null,
            "deptId": 105,
            "parentId": 101,
            "ancestors": "0,100,101",
            "deptName": "测试部门",
            "orderNum": 3,
            "leader": "muyu牧鱼",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
          },
          {
            "createBy": 1,
            "createTime": "2023-09-29 11:47:27",
            "updateBy": null,
            "updateTime": null,
            "deptId": 106,
            "parentId": 101,
            "ancestors": "0,100,101",
            "deptName": "财务部门",
            "orderNum": 4,
            "leader": "muyu牧鱼",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
          },
          {
            "createBy": 1,
            "createTime": "2023-09-29 11:47:27",
            "updateBy": null,
            "updateTime": null,
            "deptId": 107,
            "parentId": 101,
            "ancestors": "0,100,101",
            "deptName": "运维部门",
            "orderNum": 5,
            "leader": "muyu牧鱼",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
          },
          {
            "createBy": 1,
            "createTime": "2023-09-29 11:47:27",
            "updateBy": null,
            "updateTime": null,
            "deptId": 108,
            "parentId": 102,
            "ancestors": "0,100,102",
            "deptName": "市场部门",
            "orderNum": 1,
            "leader": "muyu牧鱼",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
          },
          {
            "createBy": 1,
            "createTime": "2023-09-29 11:47:27",
            "updateBy": null,
            "updateTime": null,
            "deptId": 109,
            "parentId": 102,
            "ancestors": "0,100,102",
            "deptName": "财务部门",
            "orderNum": 2,
            "leader": "muyu牧鱼",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
          }
        ]
      }
      this.deptList = this.handleTree(response.data, "deptId");
      this.userList = [
        {
          "createBy": "admin",
          "createTime": "2023-04-23 16:11:38",
          "updateBy": null,
          "updateTime": null,
          "remark": "管理员",
          "userId": 1,
          "deptId": 103,
          "userName": "admin",
          "nickName": "智能车联",
          "email": "ry@163.com",
          "phonenumber": "15888888888",
          "isAuth": true,
          "dept": {
            "deptName": "研发部门"
          }
        },
        {
          "createBy": "admin",
          "createTime": "2023-04-23 16:11:38",
          "updateBy": null,
          "updateTime": null,
          "remark": "测试员",
          "userId": 2,
          "deptId": 105,
          "userName": "ry",
          "nickName": "智能车联",
          "email": "ry@qq.com",
          "phonenumber": "15666666666",
          "dept": {
            "deptName": "测试部门"
          }
        }
      ]
    }
  },
};
</script>
