<template>
  <div class="permission_list">
    <apass-list
      @list-action="listAction"
      :list-total="listTotal"
      :hide-header="true"
    >
      <el-breadcrumb separator="/" slot="breadcrumb">
        <el-breadcrumb-item to="/authority">权限管理</el-breadcrumb-item>
        <el-breadcrumb-item to="/authority/users">用户管理</el-breadcrumb-item>
        <el-breadcrumb-item>权限审批</el-breadcrumb-item>
      </el-breadcrumb>
      <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.user_id"></span>
            </template>
          </el-table-column>
          <el-table-column label="业务系统名称">
            <template slot-scope="scope">
              <span v-text="scope.row.user_name"></span>
            </template>
          </el-table-column>
          <el-table-column label="用户类型" align="center" width="240">
            <template slot-scope="scope">
              <span
                v-text="
                  ['-', '超级管理员', '组织管理员', '普通用户', '开发者'][
                    scope.row.is_admin || 0
                  ]
                "
              ></span>
            </template>
          </el-table-column>
          <el-table-column label="用户所属组织">
            <template slot-scope="scope">
              <span v-text="scope.row.department"></span>
            </template>
          </el-table-column>
          <el-table-column label="用户状态" align="center" width="160">
            <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_date"></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="permissionAction(scope.row)">
                  通过
                </a>
                <span class="interval_line">|</span>
                <a class="btn warn" @click="permissionAction(scope.row, false)">
                  拒绝
                </a>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </apass-list>
  </div>
</template>

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

export default {
  components: { apassList, apassDialog },
  data: () => ({
    listTotal: 0,
    listData: [],
  }),
  methods: {
    listAction(filters) {
      this.$http
        .get("/apaas/backmgt/user/userApply/list", {
          params: {
            page: filters.page,
            limit: filters.size,
          },
        })
        .then(({ data }) => {
          this.listTotal = data.total;
          this.listData = data.data;
        })
        .catch((error) => {
          console.log(error);
        });
    },
    permissionAction(item, passFlag = true) {
      this.$http
        .put(
          "/apaas/backmgt/user/userApply",
          {},
          {
            params: {
              result: passFlag ? 1 : 0,
              user_id: item.user_id,
              id: item.id,
            },
          }
        )
        .then(({ data }) => {
          this.$message({
            message: `操作成功.`,
            type: "success",
          });
        })
        .catch((error) => {
          this.$message({
            message: `操作失败.`,
            type: "warning",
          });
        });
    },
  },
};
</script>

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