<!--个人积分记录-->
<template>
  <div class="record_my">
    <div class="title-form-box">
      <div>
        <p :class="queryParams.pointsType == 1?'title-form-colorA':'title-form-colorB'" @click="pointsTypeClick(1)">奖励分明细</p>
        <p :class="queryParams.pointsType == 2?'title-form-colorA':'title-form-colorB'" @click="pointsTypeClick(2)">信用分明细</p>
      </div>
    </div>
    <div class="bottom-el-table">
      <div class="user-info-box">
        <img class="user-img" :src="userData.avatar" v-if="userItem.avatar">
        <img class="user-img" src="@/assets/ZDimages/basicsModules/tx_cion.png" v-else>
        <div class="user-info-min">
          <div class="user-info-min-top">
            <p>{{userData.userName}}</p>
            <p :class="userData.userStatus == 0?'color-p-a':(userData.userStatus == 1?'color-p-b':(userData.userStatus == 2?'color-p-c':''))">{{userData.userStatus == 0?'正常':(userData.userStatus == 1?'负面清单':(userData.userStatus == 2?'黑名单':''))}}</p>
          </div>
          <div class="user-info-min-bottom" v-if="queryParams.pointsType == 1">
            <div>
              <p>获得总奖励分：</p>
              <p class="num-color-one">{{userData.awadTotalScore}}</p>
            </div>
            <div>
              <p>已扣减奖励分：</p>
              <p class="num-color-two">{{userData.awadRedeemedScore}}</p>
            </div>
          </div>
          <div class="user-info-min-bottom" v-if="queryParams.pointsType == 2">
            <div>
              <p>总信用分：</p>
              <p class="num-color-one">{{userData.creditTotalScore}}</p>
            </div>
            <div>
              <p>已扣减信用分：</p>
              <p class="num-color-two">{{userData.creditRedeemedScore}}</p>
            </div>
          </div>
        </div>
        <div class="user-info-num">
          <div class="user-info-num-min">
            <p class="user-info-num-p user-info-num-color-b">{{userData.creditRemainingScore}}</p>
            <div>
              <img src="@/assets/ZDimages/creditViolation/icon_27.png">
              <p>信用分</p>
            </div>
          </div>
          <p class="user-info-num-null"></p>
          <div class="user-info-num-min">
            <p class="user-info-num-p user-info-num-color-a">{{userData.awadRemainingScore}}</p>
            <div>
              <img src="@/assets/ZDimages/creditViolation/icon_28.png">
              <p>奖励分</p>
            </div>
          </div>
        </div>
      </div>
      <div class="instruction-box" v-if="queryParams.pointsType == 1">
        <p class="instruction-name-p">奖励分规则</p>
        <div class="instruction-text-box-one">
          <p>获得：</p>
          <p>出入实验室完成签到、签退考勤，参加模拟考试，模拟练习，通过安全教育学习以及规定时间内无违规均可获得奖励。</p>
        </div>
        <div class="instruction-text-box-two">
          <p>兑换：</p>
          <p>奖励分可以在兑换机扫码兑换丰富礼品，累加到一定分值，还可以优先享受实验室资源。</p>
        </div>
      </div>
      <div class="instruction-box" v-if="queryParams.pointsType == 2">
        <p class="instruction-name-p">信用分规则</p>
        <div class="instruction-text-box-one">
          <p>获得：</p>
          <p>满足信用合格分值获取条件，获得信用合格分；完成违规处理恢复信用分。</p>
        </div>
        <div class="instruction-text-box-two">
          <p>扣分：</p>
          <p>违规扣分，黑名单将无法进入实验室。</p>
        </div>
      </div>
      <div class="page-form-title-box" style="padding:0 20px 0 0;height:60px;">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="时间段" prop="dateRange" label-width="65px">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="状态" prop="bonusType" label-width="50px">
            <el-select v-model="queryParams.bonusType" clearable placeholder="请选择状态">
              <el-option
                v-for="dict in bonusTypeOptions"
                :key="dict.id"
                :label="dict.name"
                :value="dict.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
        </el-form>
      </div>
      <div class="page-content-box" style="padding:20px 0 0;">
        <el-table class="table-box" v-loading="loading" border :data="recordList" v-if="queryParams.pointsType == 1">
          <!--<el-table-column label="姓名" align="left" prop="userName" />-->
          <el-table-column label="奖励分变动信息" align="left" prop="changeInfo" show-overflow-tooltip/>
          <el-table-column label="时间" align="left" prop="createTime" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="积分变动" align="left" prop="scoreChange" show-overflow-tooltip>
            <template slot-scope="scope">
              <span :class="scope.row.scoreChange>0?'table-colorA':(scope.row.scoreChange<0?'table-colorB':'')">{{scope.row.scoreChange>0?'+'+scope.row.scoreChange:scope.row.scoreChange}}</span>
            </template>
          </el-table-column>
          <el-table-column label="奖励分余额" align="left"  prop="scoreLeft" show-overflow-tooltip/>
        </el-table>
        <el-table class="table-box" v-loading="loading" border :data="recordList" v-if="queryParams.pointsType == 2">
          <!--<el-table-column label="姓名" align="left" prop="userName" />-->
          <el-table-column label="信用分变动信息" align="left" prop="changeInfo" show-overflow-tooltip/>
          <el-table-column label="时间" align="left" prop="createTime" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="积分变动" align="left" prop="scoreChange" show-overflow-tooltip>
            <template slot-scope="scope">
              <span :class="scope.row.scoreChange>0?'table-colorA':(scope.row.scoreChange<0?'table-colorB':'')">{{scope.row.scoreChange>0?'+'+scope.row.scoreChange:scope.row.scoreChange}}</span>
            </template>
          </el-table-column>
          <el-table-column label="信用分余额" align="left"  prop="scoreLeft" show-overflow-tooltip/>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          layout="total, prev, pager, next, sizes, jumper"
          :page.sync="queryParams.page"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>

<script>
  import { examPointsRecordGetMyPointsLogInfo,examPointsRecordGetMyPointsLoglist } from "@/api/creditViolation/index";
  import { creditMainSelectDetailStatistics,creditMainGetUserReward,creditMainGetUserCre } from "@/api/creditViolation/newIndex";

export default {
  name: "Record",
  data() {
    return {
      userItem:JSON.parse(localStorage.getItem('user')),
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户积分记录表格数据
      recordList: [],
      // 查询参数
      queryParams: {
        pointsType:1,
        page: 1,
        pageSize:20,
        bonusType:null
      },
      // 日期范围
      dateRange: [],
      //状态
      bonusTypeOptions:[
        {id:"1",name:"获得"},
        {id:"2",name:"扣减"},
      ],
      //用户信息
      userData:{},
    };
  },
  created() {
    this.getList();
    this.examPointsRecordGetMyPointsLogInfo();
  },
  methods: {
    //信用分/奖励分-查询
    examPointsRecordGetMyPointsLogInfo(){
      creditMainSelectDetailStatistics({pointsType:this.queryParams.pointsType}).then( response => {
        this.userData =  response.data;
      });
    },
    //搜索状态切换
    pointsTypeClick(type){
      if(this.queryParams.pointsType != type){
        this.queryParams.pointsType = type;
        this.queryParams.page = 1;
        this.resetForm("queryForm");
        this.dateRange=[];
        this.examPointsRecordGetMyPointsLogInfo();
        this.getList();
      }
    },
    /** 查询用户积分记录列表 */
    getList() {
      this.loading = true;
      let obj = {
        page:this.queryParams.page,
        pageSize:this.queryParams.pageSize,
        bonusType:this.queryParams.bonusType,
      }
      if(this.dateRange&&this.dateRange.length>0) {
        obj.startTime=this.dateRange[0]+'T00:00:00'
        obj.endTime=this.dateRange[1]+'T23:59:59'
      } else {
        obj.startTime=null;
        obj.endTime=null
      }
      if(this.queryParams.pointsType == 1){
        creditMainGetUserReward(obj).then( response => {
          this.$set(this,'recordList',response.data.records);
          this.$set(this,'total',response.data.total);
          this.loading = false;
        });
      }else if(this.queryParams.pointsType == 2){
        creditMainGetUserCre(obj).then( response => {
          this.$set(this,'recordList',response.data.records);
          this.$set(this,'total',response.data.total);
          this.loading = false;
        });
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange=[];
      this.handleQuery();
    },
  }
};
</script>
<style scoped lang="scss">
  .record_my {
    flex:1;
    display: flex!important;
    flex-direction: column;
    overflow: hidden;

    .title-form-box{
      margin-top:10px;
      height:50px;
      div{
        display: flex;
        margin-left:40px;
        p{
          width:150px;
          text-align: center;
          font-size:16px;
          line-height:50px;
          cursor:pointer;
          margin:0 13px 0 0;
          border-top-left-radius: 10px;
          border-top-right-radius: 10px;
        }
        .title-form-colorA{
          background: #0045af;
          color:#fff;
        }
        .title-form-colorB{
          background: #e0e0e0;
          color:#999;
        }
      }
    }
    .bottom-el-table{
      flex: 1;
      display: flex!important;
      flex-direction: column;
      box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
      padding:0 20px 20px!important;
      margin:0 20px 20px;
      overflow: hidden;
      border-radius:10px;
      .user-info-box{
        display: flex;
        overflow: hidden;
        margin-right:20px;
        .user-img{
          width:120px;
          height:120px;
          margin:22px 21px 21px 26px;
          border-radius:50%;
        }
        .user-info-min{
          flex:1;
          .user-info-min-top{
            display: flex;
            p{
              line-height:30px;
              margin:41px 27px 16px 0;
            }
            p:nth-child(1){
              font-size:18px;
            }
            p:nth-child(2){
              font-size:14px;
              padding:0 10px;
              border-radius:4px;
            }
            .color-p-a{
              background: #0183FA;
              color:#fff;
            }
            .color-p-b{
              background: #999;
              color:#fff;
            }
            .color-p-c{
              background: #F59A23;
              color:#fff;
            }
          }
          .user-info-min-bottom{
            display: flex;
            div{
              display: flex;
              margin-right:70px;
              p{
                font-size:16px;
                color:#999999;
              }
              .num-color-one{
                color:#0b8d0e;
              }
              .num-color-two{
                color:#ff7070;
              }
            }
          }
        }
        .user-info-num{
          display: flex;
          .user-info-num-min{
            width:120px;
            .user-info-num-p{
              line-height:77px;
              font-size:22px;
              margin:16px 0 0 0;
              text-align: right;
            }
            .user-info-num-color-a{
              color:#ff9300;
            }
            .user-info-num-color-b{
              color:#0183fa;
            }
            div{
              display: flex;
              img{
                margin-left:31px;
                width:24px;
                height:24px;
              }
              p{
                line-height:27px;
                font-size:16px;
                margin:0;
                flex: 1;
                text-align: right;
              }
            }
          }
          .user-info-num-null{
            width:2px;
            height:32px;
            margin:68px 0 0 31px;
            background: #e0e0e0;
          }
        }
      }
      .instruction-box{
        background: #d1e9fe;
        border-radius:10px;
        overflow: hidden;
        margin-bottom:20px;
        .instruction-name-p{
          color:#333;
          margin:11px 22px 0;
          line-height:34px;
          font-size:16px;
        }
        .instruction-text-box-one{
          display: flex;
          p{
            line-height:34px;
            font-size:16px;
            margin:0;
          }
          p:nth-child(1){
            color:#0b8d0e;
            margin-left:33px;
          }
          p:nth-child(2){
            color:#666;
            margin-right:33px;
          }
        }
        .instruction-text-box-two{
          display: flex;
          p{
            line-height:34px;
            font-size:16px;
            margin:0;
          }
          p:nth-child(1){
            color:#ff9300;
            margin-left:33px;
          }
          p:nth-child(2){
            color:#666;
            margin-right:33px;
            margin-bottom:11px;
          }
        }
      }
    }
    .button-box{
      width:120px;
      display: flex;
    }
    .table-colorA{
      color:#70B603;
    }
    .table-colorB{
      color:#EC808D;
    }
  }
</style>

