<template>
  <div class="page_staffManagement">
    <van-sticky>
      <div class="staffManagementTitle">
        <i class="iconfont icon-zuojiantou jiantou" @click="$router.go(-1)"></i>
        <span class="titleName">{{ name }}用户管理</span>
      </div>
    </van-sticky>
    <div class="staffBox" v-if="admin_user.length > 0">
      <div
        class="staffOne"
        v-for="(item, index) in admin_user"
        :key="index"

        @click="goEditStaff(item.is_sub_admin,item.user_id)"

      >
        <img v-if="item.avatar.length > 0" :src="item.avatar" alt />
        <img
          v-if="item.avatar.length == 0"
          src="../../../../../assets/images/default_avatar.jpg"
          alt
        />
        <p >
          <span>{{ item.user_name }}</span>
          <!-- v-if="isShow(item.is_sub_admin,item.user_id)"  -->
          <i
            class="iconfont icon-bianji bianji"
          ></i>
         
        </p>
      </div>
    </div>
    <div class="noDataBox" v-else>
        <img src="../../../../../assets/images/none.png" alt />
      </div>
    <van-overlay :show="loading" type="spinner" size="30px">
      <div class="wrapper">
        <van-loading size="24px" vertical>正在加载中...</van-loading>
      </div>
    </van-overlay>
  </div>
</template>
<script>
// import "../libs/rem.js";
import { setRem } from "@/libs/functionRem";
import { GetAllStaff } from "@/api/admin_user";
import {Toast} from "vant";

export default {
  data() {
    return {
      loading:false,
      active: 0,
      admin_user: [],
      org_creator: 0,
      name:'',
      isSubSuperAdmin:false,
    };
  },
  methods: {
    isShow:function(is_sub_admin,user_id){
      if (!this.isSubSuperAdmin){
        return true
      }else {
        if (is_sub_admin) {
          if (user_id == this.$store.getters.user.admin.id) {
            return true
          }else{
            return false
          }
        } else {
          if (user_id != this.$store.getters.user.org.creator) {
            return true

          } else {
            return false

          }
        }
      }
    },
    GetAllStaff: function() {
      this.loading = true
      GetAllStaff().then(response => {
        if (response.data.state === 1) {
          this.admin_user = response.data.data.admins;
          this.isSubSuperAdmin = response.data.data.isSubSuperAdmin;

          for (let i = 0; i < this.admin_user.length; i++) {
            // console.log(this.admin_user[i].role_ids.length)
            if (this.admin_user[i].role_ids.length >= 0) {
              let isExist = -1;
              let ids = this.admin_user[i].role_ids.split(",");
              isExist = ids.indexOf(this.$route.query.id.toString());
              if (isExist < 0) {
                this.admin_user.splice(i, 1);
                i = i - 1;
              }
            }
          }
          this.loading = false

        } else {
          this.loading = false

          this.$toast({
            message: response.data.msg
          });
        }
      });
    },
    goEditStaff: function(is_sub_admin, user_id) {
        this.$router.push({ path: "/staff/editstaff?id=" + user_id });
    },
    goAddStaff: function() {
      this.$router.push({ path: "/staff/addstaff" });
    }
  },
  created() {
    this.name = this.$route.query.name
    setRem();
    //获取没被禁用的用户

    this.org_creator  = this.$store.getters.user.org.creator

    this.GetAllStaff();
  }
};
</script>

<style lang="scss" scoped>
.page_staffManagement {
  height: 100%;
  overflow-y: auto;
  background: #fafafa;

  .staffManagementTitle {
    background: #fff;
    padding: 0 1.125rem;
    height: 3.125rem;
    display: flex;
    align-items: center;
  }

  .jiantou {
    font-size: 1.5rem;
    font-weight: 600;
    margin-right: 6rem;
  }

  .titleName {
    font-size: 1.125rem;
    font-weight: 600;
  }

  .iconOne {
    font-size: 1.5rem;
  }

  .staffBox {
    padding-left: 0.875rem;
    background: #fff;

    .staffOne {
      display: flex;
      align-items: center;
      height: 3.75rem;

      img {
        width: 2.5rem;
        height: 2.5rem;
        margin-right: 0.875rem;
        border-radius: 50%;
      }

      p {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-right: 0.875rem;
        flex: 1;
        height: 100%;
        // box-shadow: 0px 1px 0px 0px rgba(0, 0, 0, 0.1);
        border-bottom: 1px solid #e5e5e5;
        font-size: 1rem;
      }

      .bianji {
        font-size: 1.25rem;
        color: #cccccc;
      }
    }
  }
  .noDataBox{
     position: fixed;
     left: 50%;
     top: 50%;
     transform: translate(-50%,-50%);
     img {
       width: 9.375rem;
       height: 9.375rem;
       margin: 0 auto;
       display: block;
    }
  }
  .wrapper {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}
::-webkit-scrollbar {
  width: 0;
}
</style>

<style lang="scss">
.page_staffManagement {
  .van-tabs__line {
    background: #5b98ff;
  }
}

</style>
