<!-- 活动解析 -->
<template>
  <div>
    <!-- table 表格 -->
    <el-row :gutter="20" class="main-items" >

      <!--数据监控-->
      <el-col :span="20" class="main" :offset="2">
        <el-row :gutter="20" class="main-header">
          <el-col :span="3"><div class="main-header-item" >注册老师数：{{getManagerList.registerTeacherCount}}人</div></el-col>
          <el-col :span="3"><div class="main-header-item">活跃老师数：{{getManagerList.activeTeacherCount}}人</div></el-col>
          <el-col :span="4"><div class="main-header-item">注册用户数：{{getManagerList.registerUserCount}}人</div></el-col>
          <el-col :span="4"><div class="main-header-item">活跃用户数：{{getManagerList.activeUserCount}}人</div></el-col>
        </el-row>
        <el-table
          :data="getManagerList.list"
          highlight-current-row
          size="medium"
          border
          stripe
        >
          <el-table-column
            label="小组管理员"
            header-align="center"
          >
            <template  slot-scope="scope">
              <img :src="BASE_URL +scope.row.imgUrl" alt="" class="table-img">
              <span class="scope-name">{{scope.row.name}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="groupCount"
            label="小组人数"
            header-align="center"
          >
          </el-table-column>
          <el-table-column
            prop="attendanceRate"
            label="老师出勤率"
            header-align="center"
          ></el-table-column>
          <el-table-column
            prop="homeworkCount"
            label="作业批改总份数"
            header-align="center">
          </el-table-column>
          <el-table-column
            prop="homeworkPicCount"
            label="作业批改总张数"
            header-align="center"
          >
          </el-table-column>
          <el-table-column
            prop="avgTime"
            label="批改平均用时"
            header-align="center"></el-table-column>
          <el-table-column
            prop="avgMark"
            label="家长平均评分"
            header-align="center"></el-table-column>
          <el-table-column
            prop="status"
            label="是否在线"
            header-align="center"></el-table-column>
          <el-table-column prop="status" label="" header-align="center" width="250">
            <template slot-scope="scope">
              <el-button type="success" plain >小组详情</el-button>
              <el-button type="success" @click="isShow(1,scope.row.managerId)">管理员详情</el-button>
            </template>
          </el-table-column>

        </el-table>
        <!-- 分页显示 -->
        <div class="page-block">
          <el-pagination
            background
            class="all_pagination"
            @size-change="handleSizeChange"
            @current-change="pageChange"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            >
          </el-pagination>
        </div>
      </el-col>

    </el-row>

    <!--可分配老师-->
    <div class='showModel' @click="allShowModel(1)" v-if="hiddenModel"></div>
    <div class='model' v-if="hiddenModel">
      <div class='model-text'>
        <div class="model-manager">
          <div>校区管理员</div>
          <div><img src="../../assets/img/del@2x.png" alt="" @click="allShowModel(1)"></div>
        </div>
        <div class="model-items">
          <div class="model-items-first">
            <div>
              <img :src="BASE_URL+getManagerDetail.imgUrl" alt="" class="model-items-first-img">
              <div class="model-items-first-left">
                <div>{{getManagerDetail.name}}（{{getManagerDetail.status}}）</div>
                <div class="model-items-first-left-down">{{getManagerDetail.school}}</div>
              </div>
            </div>
            <div>
              <el-button type="danger" plain round @click="isShow(2,getManagerDetail.name)"><i class="el-icon-bottom"></i><span>降级</span></el-button>
            </div>
          </div>
          <div class="model-items-other model-active">批改科目 : {{getManagerDetail.subject}}</div>
          <div class="model-items-other">批改年级 : <span v-for="(v, k) of arrGrade" :key=k class="scope-name">{{v}}</span></div>
          <div class="model-items-other model-active">可批改时间：<el-button type="info" round v-for="(v, k) of arrPeriod" :key=k>{{v}}</el-button></div>
          <div class="model-items-other">手机号 : {{getManagerDetail.phone}}</div>
          <div class="model-items-other model-active-last">上次登录时间 : {{getManagerDetail.lastOnlineTime}}</div>
        </div>

      </div>
    </div>
    <!--所有未批改作业-->
    <div class='showModel' @click="allShowModel(2)" v-if="isPigai"></div>
    <div class='model' v-if="isPigai">
      <div class='model-text'>
        <div class="model-text-items">
          <div><img src="../../assets/img/del@2x.png" alt="" @click="allShowModel(2)" class="model-text-items-close"></div>
          <div>是否要将{{superName}}老师降级为普通批改老师？</div>
        </div>
        <div class="model-btn">
          <div class="model-btn-items main-gay" @click="Downgrade()">是</div>
          <div class="model-btn-items model-grdeen" @click="allShowModel(2)">否</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import { mapGetters, mapActions } from "vuex";
  export default {
    components: { },
    name: "actvResolveLabel",
    props: {},
    data() {
      return {
        BASE_URL:'https://xt.sharingschool.com/upload/',
        hiddenModel:false,
        isPigai:false,
        managerId:'',
        superName:'',
        count:0,
        arrPeriod:[],
        arrGrade:[],
        ItemList: [
          {
            text:'数据监控'
          },
          {
            text:'当天'
          },
          {
            text:'当月'
          },
        ],

        filters: {
          actvNm: "",
          actvCrtUserId: "",
          actvType: "",
          actvSmallType: "",
          // 排序
          MaxtimeValue:"",
          pageNo: 1,
          pageSize: 10,
          count: 0,
          orderField: "",
          orderAD: ""
        }
      };
    },
    watch: {},
    computed: {
      ...mapGetters(["getUser","getManagerList","getManagerDetail"])
    },
    methods: {
      ...mapActions(["setUser"]),

      isShow(str,res){
        let _this = this;
        console.log(str,res)
        if (str == 1){
          _this.hiddenModel = true;
          _this.isPigai = false;
          _this.managerId = res;
          _this.GetManagerDetail(res)
        } else if (str == 2){
          _this.isPigai = true;
          _this.hiddenModel = false;
          _this.superName = res
        }

      },
      //关闭弹框
      allShowModel(str) {
        let _this = this;
        if (str == 1){
          _this.hiddenModel = false;
        } else if (str == 2){
          _this.isPigai = false;
        }
      },
      //时间封装
      formatDate: function () {
        let date = new Date();
        let y = date.getFullYear();
        let MM = date.getMonth() + 1;
        MM = MM < 10 ? ('0' + MM) : MM;
        let d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        let h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        let m = date.getMinutes();
        m = m < 10 ? ('0' + m) : m;
        let s = date.getSeconds();
        s = s < 10 ? ('0' + s) : s;
        return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
      },
      // 获取超级管理员数据
      async SuperManagerList() {
        this.$store.dispatch("SuperManagerList", {
          maxCreateTime: this.formatDate(),
          pageNo: this.filters.pageNo,
          pageSize: this.filters.pageSize
        });
      },
      // 查看校区管理员详情
      async GetManagerDetail(str) {
        this.$store.dispatch("GetManagerDetail", {
          managerId: str
        });
        var arr = this.getManagerDetail.grade.split(',');
        this.arrPeriod = this.getManagerDetail.period.split(';');
        var arrList = [];
        for (var i in arr) {
          if (arr[i] == '一年级' || arr[i] == '二年级') {
            arrList.push('1-2年级')
          } else if (arr[i] == '三年级' || arr[i] == "四年级") {
            arrList.push('3-4年级')
          } else if (arr[i] == '五年级' || arr[i] == "六年级") {
            arrList.push('5-6年级')
          }
        }
        this.arrGrade = this.uniq(arrList);
      },
      //校区管理员降级
      async Downgrade() {
        this.$store.dispatch("Downgrade", {
          managerId: this.managerId
        });
        this.allShowModel(2)
      },
      // 分页
      pageChange(val) {
        this.filters.pageNo = val;
        this.SuperManagerList();
      },
      changeDateSlot(dateSlot) {
        if (dateSlot) {
          this.filters.startDate = dateSlot[0];
          this.filters.endDate = dateSlot[1];
        } else {
          this.filters.startDate = null;
          this.filters.endDate = null;
        }
      },
      actvTypeChange(typeList) {
        switch (typeList.length) {
          case 1:
            this.filters.actvType = typeList[0];
            this.filters.actvSmallType = null;
            break;
          case 2:
            this.filters.actvType = null;
            this.filters.actvSmallType = typeList[1];
            break;
          default:
            this.filters.actvType = null;
            this.filters.actvSmallType = null;
            break;
        }
      },
      handleSizeChange(val) {
        this.filters.pageSize = val;
        this.SuperManagerList();
      },
      // 排序
      sortChange(sort) {
        this.filters.orderField = sort.prop;
        this.filters.orderAD = sort.order != null ? sort.order : "";
        this.itemListReshow();
      },
      clearSearch() {
        this.filters.actvNm = null;
        this.filters.actvCrtUserId = null;
        this.filters.actvType = null;
        this.filters.actvSmallType = null;
        this.filtersActvType = [];
        this.createDateSlot = null;
      },
      // 数组去重
      uniq(array){
        var temp = []; //一个新的临时数组
        for (var i = 0; i < array.length; i++){
          if (temp.indexOf(array[i]) == -1) {
            temp.push(array[i]);
          }
        }
        return temp;
      }
    },
    mounted() {
      this.SuperManagerList()
      this.count = this.getManagerList.pages;

    }
  };
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

  .main{
    background-color: #fff;
    margin-top: 16px;
    padding: 0 !important;
    border: 1px solid #E1E1E1;
    min-height: 980px;
  }

  el-table{
    color: #999999;
    font-size: 18px;
  }
  .main-items{
    color: #393939;
    text-align: center;
    line-height: 80px;
  }
  .main-header-item{
    font-size: 16px;
    color: #7E7E7E;
  }

  .input-with-select .el-input-group__prepend {
    background-color: #fff;
  }

  .table-img{
    width:36px;
    height:36px;
    border-radius:6px;
  }
  .showModel{
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background: #000000;
    opacity: 0.2;
    overflow: hidden;
    z-index: 1000;
    color: #fff;

  }
  .model{
    z-index: 1001;
    width:40%;
    height:auto;
    position: fixed;
    top: 30%;
    left: 30%;
    margin:auto;
    background: #fff;
    border-radius:30px;
    text-align: center;
  }

  .model-items-first{
    padding: 0 34px;
    display: flex;
    justify-content: space-between;
  }
  .model-items-first-img{
    width: 68px;
    height: 68px;
    border-radius: 8px;
    position: relative;
    bottom: 20px;
  }
  .model-items-first-left{
    display: inline-block;
    color: #393939;
    font-size: 24px;
    margin-left: 14px;
    text-align: left;
  }
  .model-items-first-left-down{
    color: #7E7E7E;
    font-size: 18px;
  }
  .model-text{
    background:rgba(255,255,255,1);
    border-radius:10px;
  }
  .model-items-other{
    height: 60px;
    line-height: 60px;
    color: #393939;
    font-size: 20px;
    text-align: left;
    padding: 0 34px;

  }
  .model-active{
    background-color: #F6F7FB;
  }
  .model-active-last{
    border-radius:0 0 30px 30px;
    background-color: #F6F7FB;
  }

  .model-manager{
    display: flex;
    justify-content: space-between;
    margin: 30px;
    color: #393939;
    font-size: 24px;
  }
  .model-btn{
    display: flex;
    justify-content: space-around;
    margin-bottom: 44px;
  }
  .model-btn-items{
    width:154px;
    height:50px;
    line-height: 50px;
    text-align: center;
    font-size: 18px;
    border-radius:4px;
  }
  .main-gay{
    background:rgba(246,247,251,1);
    color: #7E7E7E;
  }
  .model-grdeen{
    background-color: #52CC60;
    color: #fff;
  }
  .model-text-items-close{
    position: absolute;
    top: 10px;
    right: 15px;
  }
  .model-text-items{
    position: relative;
    color: #000000;
    font-size: 24px;
    text-align: center;
    padding: 40px 0 50px 0;
  }
  .scope-name{
    margin-left: 13px;
  }
</style>
