<!--个人积分记录-->
<template>
  <div class="record_my">
    <div class="title-form-box">
      <div>
        <p :class="queryParams.pointsType == 2?'title-form-colorA':'title-form-colorB'" @click="pointsTypeClick(2)">奖励分明细</p>
        <p :class="queryParams.pointsType == 1?'title-form-colorA':'title-form-colorB'" @click="pointsTypeClick(1)">信用分明细</p>
      </div>
    </div>
    <div class="bottom-el-table">
      <div class="user-info-box">
        <img class="user-img" :src="userData.avatar" v-if="userData.avatar">
        <img class="user-img" src="@/assets/ZDimages/tx_cion.png" v-else>
        <div class="user-info-min">
          <div class="user-info-min-top">
            <p>{{userData.nickName}}</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 == 2">
            <div>
              <p>获得总奖励分：</p>
              <p class="num-color-one">{{userData.obtainPoints}}</p>
            </div>
            <div>
              <p>已扣减奖励分：</p>
              <p class="num-color-two">{{userData.exchangePoints}}</p>
            </div>
          </div>
          <div class="user-info-min-bottom" v-if="queryParams.pointsType == 1">
            <div>
              <p>总信用分：</p>
              <p class="num-color-one">{{userData.obtainPoints}}</p>
            </div>
            <div>
              <p>已扣减信用分：</p>
              <p class="num-color-two">{{userData.exchangePoints}}</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.creditScore}}</p>
            <div>
              <img src="@/assets/ZDimages/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.bonusPoints}}</p>
            <div>
              <img src="@/assets/ZDimages/icon_28.png">
              <p>奖励分</p>
            </div>
          </div>
        </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="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>
      <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>
        <el-form-item>
          <p class="inquire-button-one" @click="handleQuery">查询</p>
          <p class="reset-button-one" @click="resetQuery">重置</p>
        </el-form-item>
      </el-form>
      <el-table 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="messageContent"/>
        <el-table-column label="时间" align="left" prop="createTime" />
        <el-table-column label="积分变动" align="left" prop="points">
          <template slot-scope="scope">
            <span :class="scope.row.points>0?'table-colorA':(scope.row.points<0?'table-colorB':'')">{{scope.row.points>0?'+'+scope.row.points:scope.row.points}}</span>
          </template>
        </el-table-column>
        <el-table-column label="奖励分余额" align="left"  prop="surplusPoints"/>
      </el-table>
      <el-table 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="messageContent"/>
        <el-table-column label="时间" align="left" prop="createTime" />
        <el-table-column label="积分变动" align="left" prop="points">
          <template slot-scope="scope">
            <span :class="scope.row.points>0?'table-colorA':(scope.row.points<0?'table-colorB':'')">{{scope.row.points>0?'+'+scope.row.points:scope.row.points}}</span>
          </template>
        </el-table-column>
        <el-table-column label="信用分余额" align="left"  prop="surplusPoints"/>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        layout="total, prev, pager, next, sizes, jumper"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { listRecord, getRecord, delRecord,myListRecord, addRecord, updateRecord, getMyPointsLoglist ,getMyPointsLogInfo } from "@/api/exam/record";

export default {
  name: "Record",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户积分记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pointsType:2,
        pageNum: 1,
        pageSize: 10,
        bonusType:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 日期范围
      dateRange: [],
      //状态
      bonusTypeOptions:[
        {id:"1",name:"获得"},
        {id:"2",name:"扣减"},
      ],
      //用户信息
      userData:{},
    };
  },
  created() {
    this.getList();
    this.getMyPointsLogInfo();
    this.getDicts("points_mode").then(response => {
      this.pointsMode = response.data;
    });
  },
  methods: {
    getMyPointsLogInfo(){
      getMyPointsLogInfo({pointsType:this.queryParams.pointsType}).then( response => {
        this.userData =  response.data;
      });
    },
    //搜索状态切换
    pointsTypeClick(type){
      if(this.queryParams.pointsType != type){
        this.queryParams.pointsType = type;
        this.queryParams.pageNum = 1;
        this.resetForm("queryForm");
        this.dateRange=[];
        this.getMyPointsLogInfo();
        this.getList();
      }
    },
    /** 查询用户积分记录列表 */
    getList() {
      this.loading = true;
      if(this.dateRange&&this.dateRange.length>0)
      {
        this.queryParams.beginTime=this.dateRange[0]
        this.queryParams.endTime=this.dateRange[1]
      }
      else
      {
        this.queryParams.beginTime=null;
        this.queryParams.endTime=null
      }
      getMyPointsLoglist(this.queryParams).then( response => {
        this.recordList =  response.rows;
        this.total =  response.total;
        this.loading = false;
      });
    },
     // 行为字典翻译
    modeFormat(row, column) {
      return this.selectDictLabel(this.pointsMode, row.mode);
    },
    pointsFormat(row,a)
    {
      return row.recordType.code===1?`+ ${row.points}`:`- ${row.points}`
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        points: null,
        joinUserId: null,
        mode: null,
        deptName: null,
        deptId: null,
        createTime: null,
        userId: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange=[];
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户积分记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecord(id).then( response => {
        this.form =  response.data;
        this.open = true;
        this.title = "修改用户积分记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRecord(this.form).then( response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecord(this.form).then( response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('确认删除用户积分记录吗?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delRecord(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('exam/record/export', {
        ...this.queryParams
      }, `exam_record.xlsx`)
    }
  }
};
</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>

