<template>
  <div class="users_list">
    <apass-list
      search-placeholder="请输入关键字"
      :list-total="listTotal"
      @list-action="initDatas"
    >
      <el-breadcrumb separator="/" slot="breadcrumb">
        <el-breadcrumb-item to="/authority">权限管理</el-breadcrumb-item>
        <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      </el-breadcrumb>
      <template slot="header-left">
        <el-button type="primary" @click="$router.push('/authority/users/add')">
          新建用户
        </el-button>
        <el-button @click="$router.push('/authority/users/permission')">
          权限审批
        </el-button>
      </template>
      <div class="apass_table" slot="list">
        <el-table :border="false" :data="listData">
          <el-table-column label="" width="40"></el-table-column>
          <el-table-column label="账号" width="160">
            <template slot-scope="scope">
              <span v-text="scope.row.account"></span>
            </template>
          </el-table-column>
          <el-table-column label="业务系统名称">
            <template slot-scope="scope">
              <span v-text="scope.row.name"></span>
            </template>
          </el-table-column>
          <el-table-column label="用户类型" align="center" width="160">
            <template slot-scope="scope">
              <span v-text="scope.row.role"></span>
            </template>
          </el-table-column>
          <el-table-column label="所属组织">
            <template slot-scope="scope">
              <span v-text="scope.row.organization"></span>
            </template>
          </el-table-column>
          <el-table-column label="账号状态" align="center" width="240">
            <template slot-scope="scope">
              <span v-text="scope.row.state === 0 ? '禁用' : '启用'"></span>
            </template>
          </el-table-column>
          <el-table-column label="上次操作修改时间" align="center" width="200">
            <template slot-scope="scope">
              <span v-text="scope.row.update_time"></span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="300">
            <template slot-scope="scope">
              <div class="row_action">
                <a
                  class="btn"
                  @click="
                    $router.push(`/authority/users/detail/${scope.row.id}`)
                  "
                >
                  详情
                </a>
                <span class="interval_line">|</span>
                <a class="btn" @click="setRole(scope.row)">
                  分配角色
                </a>
                <span class="interval_line">|</span>
                <a
                  class="btn"
                  :class="{ warn: scope.row.state === 1 }"
                  @click="setState(scope.row)"
                >
                  {{ scope.row.state === 0 ? "启用" : "禁用" }}
                </a>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </apass-list>

    <apass-dialog
      ref="dialog"
      width="590px"
      title="分配角色"
      @submit="dialogSubmit"
    >
      <el-table
        slot="content"
        :border="false"
        :data="roleData"
        @selection-change="dialogSelectionChange"
      >
        <el-table-column type="selection" width="60" align="right">
        </el-table-column>
        <el-table-column label="角色">
          <template slot-scope="scope">
            <span v-text="scope.row.name"></span>
          </template>
        </el-table-column>
        <el-table-column label="说明">
          <template slot-scope="scope">
            <span v-text="scope.row.description"></span>
          </template>
        </el-table-column>
      </el-table>
    </apass-dialog>
  </div>
</template>

<script>
import apassList from "@/components/apass-list";
import apassDialog from "@/components/apass-dialog";

export default {
  components: { apassList, apassDialog },
  data: () => ({
    listTotal: 300,
    listData: [
      {
        id: "012344",
        account: "012344",
        name: "贵阳机关事务大数据平台",
        role: "普通用户",
        organization: "贵阳市水利局",
        state: 0,
        update_time: "2020-04-27 13:24:19",
      },
      {
        id: "012345",
        account: "012345",
        name: "贵州省水利厅",
        role: "普通用户",
        organization: "贵阳市水利局",
        state: 1,
        update_time: "2020-04-27 13:24:19",
      },
      {
        id: "012346",
        account: "012346",
        name: "贵州省公安厅",
        role: "普通用户",
        organization: "贵阳市水利局",
        state: 1,
        update_time: "2020-04-27 13:24:19",
      },
      {
        id: "012347",
        account: "012347",
        name: "贵阳机关事务大数据平台",
        role: "普通用户",
        organization: "贵阳市水利局",
        state: 1,
        update_time: "2020-04-27 13:24:19",
      },
      {
        id: "012348",
        account: "012348",
        name: "长兴县应急指挥平台",
        role: "普通用户",
        organization: "贵阳市水利局",
        state: 1,
        update_time: "2020-04-27 13:24:19",
      },
    ],
    roleData: [
      {
        name: "超级管理员",
        description: "拥有所有权限",
      },
      {
        name: "组织管理员",
        description: "拥有对应组织的权限",
      },
      {
        name: "普通用户",
        description: "普通权限用户",
      },
      {
        name: "普通用户-开发者",
        description: "基于普通用户多一些开发的选项",
      },
    ],
    showDialog: false,
  }),
  methods: {
    initDatas(filter) {
      // console.log(filter);

      this.$http
        .get("/apaas/backmgt/user/list", {
          params: {
            keyword: filter.keyword,
            limit: filter.page,
            page: filter.size,
            user_id: "ym",
            user_name: "",
            department_id: "",
            state: 1,
          },
        })
        .then(({ data }) => {
          console.log(data);
          // this.listTotal = data.data.total;
          // this.listData = data.data.data;
        })
        .catch((error) => {
          console.log(error);
        });
    },
    setRole(item) {
      console.log("setRole " + item.name);
      this.$refs.dialog.show();
    },
    setState(item) {
      console.log("setState " + item.name);
    },
    dialogSelectionChange(values) {
      console.log(values);
    },
    dialogSubmit() {
      console.log("dialog submit");
    },
  },
};
</script>

<style scoped>
.users_list {
  height: 100%;
}
</style>
