<!-- 活动解析 -->
<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" :offset="1"><div class="main-header-item" >
            <div class="block" >
              <el-date-picker
                v-model="selMonth"
                type="month"
                placeholder="选择月"
                value-format="yyyy-MM"
                @change="GetTeacherSalaryList()">
              </el-date-picker>
            </div>
          </div>
          </el-col>
          <el-col :span="6"  :offset="3">
            <!-- <div  @click="handApor()" :class="{superactive:Activeindex == false,ApporStyles:true}" >手动批改</div>
            <div  @click="AutoApor()"  :class="{superactive:Activeindex == true,ApporStyles:true}" >自动批改</div> -->
          </el-col>
          <el-col :span="4" :offset="16">
            <div class="main-header-item">
              <i class="el-icon-printer"></i>
              <span @click="excel()">导出表格</span>
            </div>
          </el-col>
        </el-row>
        <el-table
          :data="getTeacherSalaryList.list"
          :header-cell-class-name="tableheaderClassName"
          :header-cell-style="{
          'background-color': '#F6F7FB',
          'color': '#393939',
          'font-size': '16px'
           }"
          size="medium"
          border
          stripe
        >
          <el-table-column
            label="注册老师"
            header-align="center"
          >
            <template slot-scope="scope">
              <div class="scope-list">
                <img :src='BASE_URL+scope.row.imgUrl' alt="" class="table-img" v-if="scope.row.imgUrl">
                <img src="../../assets/img/user.jpg" alt="" v-if="!scope.row.imgUrl" class="table-img">
                <span class="scope-name">{{scope.row.name}}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="lowGradeCount"
            label="1～2年级0.2元/张"
            header-align="center"
          >
          </el-table-column>
          <el-table-column
            prop="middleGradeCount"
            label="3～4年级0.3元/张"
            header-align="center"
          ></el-table-column>
          <el-table-column
            prop="highGradeCount"
            label="5～6年级0.4元/张"
            header-align="center">
          </el-table-column>
          <el-table-column
            prop="total"
            label="总计"
            header-align="center"
            width="400"
          >
          </el-table-column>
        </el-table>
        <!-- 分页显示 -->
        <div class="page-block" v-if="parseInt(getTeacherSalaryList.pages) > 10">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="pageChange"
            :page-sizes="[10]"
            layout="total,prev, pager, next"
            :total= parseInt(getTeacherSalaryList.pages)
          ></el-pagination>
        </div>
      </el-col>

    </el-row>


    <!--弹框-->
    <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>是否导出表格？</div>
        </div>
        <div class="model-btn">
          <div class="model-btn-items main-gay">是</div>
          <div class="model-btn-items model-grdeen">否</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import { mapGetters, mapActions } from "vuex";
  import { IMG_BASE_URL } from '@/ImgConfig'
  export default {
    components: { },
    name: "actvResolveLabel",
    props: {},
    data() {
      return {
        Activeindex:false,
          BASE_URL:IMG_BASE_URL,
        selMonth:'',
        hiddenModel:false,
        isPigai:false,
        ItemList: [
          {
            text:'数据监控'
          },
          {
            text:'当天'
          },
          {
            text:'当月'
          },
        ],
        filters: {
          actvNm: "",
          actvCrtUserId: "",
          actvType: "",
          actvSmallType: "",
          // 排序
          MaxtimeValue:'',
          oneMonth:'',
          pageNo: 1,
          pageSize: 10,
          count: 0,
          orderField: "",
          orderAD: ""
        }
      };
    },
    watch: {},
    computed: {
      ...mapGetters(["getUser","getTeacherSalaryList"])
    },
    methods: {
      ...mapActions(["setUser"]),
      // 表格头部样式
      tableheaderClassName({ row, rowIndex }) {
        return "table-head-th";
      },
      //表格导出
      excel(){
        try {
          //var curTbl = document.getElementById(tableId);
          //var lenRow = curTbl.rows.length;
          var curTbl = $('.el-table')[0];
          var lenRow = curTbl.rows.length;
          //创建AX对象excel
          var oXL = new ActiveXObject("Excel.Application");
          //获取workbook对象
          var oWB = oXL.Workbooks.Add();
          var oSheet = oWB.ActiveSheet;

          //取得表格行数
          for (var i = 0; i < lenRow; i++) {
            var lenCol = curTbl.rows(i).cells.length;
            //取得每行的列数
            for (var j = 0; j < lenCol; j++)
            {
              oSheet.Cells(i + 1, j + 1).value = curTbl.rows(i).cells(j).innerText;

            }
          }
          oXL.Visible = true; //设置excel可见属性
          //oXL.UserControl = true;
          //oXL=null
        } catch (e) {
          if ((!+'\v1')) { //ie浏览器
            alert("无法启动Excel，请确保电脑中已经安装了Excel!")
          } else {
            let arr = this.getTeacherSalaryList.list;
            let str = '注册老师,1～2年级0.2元/张,3～4年级0.3元/张,5～6年级0.4元/张,总计/元';
            for (let i = 0; i < arr.length; i++) {
              str += "\n" + arr[i].name + ',' + arr[i].lowGradeCount + ',' + arr[i].middleGradeCount + ',' + arr[i].highGradeCount + ',' + arr[i].total
            }
            var uri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(str);
            var downloadLink = document.createElement("a");
            downloadLink.href = uri;
            downloadLink.download = "export.csv";

            document.body.appendChild(downloadLink);
            downloadLink.click();
            document.body.removeChild(downloadLink);
          }
        }
      },
      // 手动批改
      handApor(){
        this.Activeindex = false;
      },
         // 自动批改
      AutoApor(){
         this.Activeindex = true;
      },
      //弹框
      isShow(str){
        let _this = this;
        console.log(str)
        if (str == 1){
          _this.hiddenModel = true;
          _this.isPigai = false;
        } else if (str == 2){
          _this.isPigai = true;
          _this.hiddenModel = false;
        }

      },
      //关闭弹框
      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 GetTeacherSalaryList() {
        this.$store.dispatch("GetTeacherSalaryList", {
          pageNo: this.filters.pageNo,
          pageSize: this.filters.pageSize,
          oneMonth:this.selMonth,
          maxCreateTime: this.formatDate()
        });
      },
      // 分页
      pageChange(val) {
        this.filters.pageNo = val;
        this.GetTeacherSalaryList();
      },
      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.GetTeacherSalaryList();
      },
      // 排序
      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;
      },

    },
    mounted() {
      sessionStorage.setItem('tabIndex',2);
      console.log(sessionStorage.getItem('tabIndex'))
     this.GetTeacherSalaryList()
    }
  };
</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;
  }
.el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color:#52cc60!important;
    color: #fff;
}
  .main-items{
    color: #393939;
    text-align: center;
    line-height: 80px;
  }
  .main-header-item{
    cursor: pointer;
    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:10px;
    text-align: center;
  }
  .scope-name{
    margin-left: 13px;
  }

  .model-text{
    background:rgba(255,255,255,1);
    border-radius:10px;
  }

  .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;
  }
  .el-table .table-head-th{
    background-color:#F6F7FB;
    font-size: 16px !important;
    color: #393939;

  }
  .page-block{
    text-align: center !important;
    margin-top: 15px;
  }
  .scope-list{
    margin-left: 18px;
    text-align: left;
  }
  .ApporStyles{
    display:inline-block;
    width: 100px;
    height: 30px;
    line-height:30px;
    background-color: #fff;
    border-radius:15px;
    font-size: 14px;
    color:#7C819D;
    cursor: pointer;
  }
  .superactive{
    background-color: #52CC60;
    color:#fff;
  }
</style>
