<!--奖励分设置-->
<template>
  <div class="app-container rewardconfig">
    <div class="page-top-title-box">
      <p class="page-top-title-name-p">奖励分设置</p>
      <p class="page-top-title-out-p" v-hasPermiRouter="['exam:rewardConfig:edit']" @click="getList">重置</p>
      <p class="page-top-title-submit-p" v-hasPermiRouter="['exam:rewardConfig:edit']" @click="submitForm">提交</p>
    </div>
    <el-form class="form-content scrollbar-box" ref="form" :model="form" label-width="100px" :rules="rules">
      <el-form-item label="一个月无违规记录奖励分值：" prop="monthNoviolationScore" label-width="240px" style="margin-top:22px;">
        <el-input
          v-model="form.monthNoviolationScore"
          placeholder="请输入一个月无违规记录奖励分值"
          maxLength="5"
          clearable
          style="width:260px;">
          <template slot="append">分</template>
        </el-input>
      </el-form-item>
      <el-form-item label="模拟练习做题奖励分值：" prop="exerciseScore" label-width="240px">
        <el-input
          v-model="form.exerciseScore"
          placeholder="请输入模拟练习做题奖励分值"
          maxLength="5"
          clearable
          style="width:260px;">
          <template slot="append">分</template>
        </el-input>
      </el-form-item>
      <el-form-item label="模拟考试奖励分换算值：" prop="mockExam" label-width="240px">
        <el-input
          v-model="form.mockExam"
          placeholder="请输入模拟考试得分值"
          maxLength="5"
          clearable
          style="width:260px;">
          <template slot="prepend">1奖励分等于</template>
          <template slot="append">分</template>
        </el-input>
      </el-form-item>
      <el-form-item label="学习时长奖励分换算值：" prop="studyLen" label-width="240px">
        <el-input
          v-model="form.studyLen"
          placeholder="请输入学习时长奖励分换算值"
          maxLength="5"
          clearable
          style="width:260px;">
          <template slot="prepend">1奖励分等于</template>
          <template slot="append">分钟</template>
        </el-input>
      </el-form-item>
      <el-form-item label="完成签到考勤获得奖励分值：" prop="signGetScore" label-width="240px">
        <el-input
          v-model="form.signGetScore"
          placeholder="请输入完成签到考勤获得奖励分值"
          maxLength="5"
          clearable
          style="width:260px;">
          <template slot="append">分</template>
        </el-input>
      </el-form-item>
      <el-form-item label="完成离开考勤获得奖励分值：" prop="leaveGetScore" label-width="240px">
        <el-input
          v-model="form.leaveGetScore"
          placeholder="请输入完成离开考勤获得奖励分值"
          maxLength="5"
          clearable
          style="width:260px;">
          <template slot="append">分</template>
        </el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { examRewardConfigList, examRewardConfigEdit } from "@/api/creditViolation/index";
import { creditItemListAllAward,creditItemEditAward } from "@/api/creditViolation/newIndex";

export default {
  name: "Rewardconfig",
  data() {
    return {
      form:{},
      // 表单校验
      rules: {
        monthNoviolationScore: [
          { required: true, message: "请输入一个月无违规记录奖励分值", trigger: "blur" },
          { required: true, message: "请输入一个月无违规记录奖励分值", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
        exerciseScore: [
          { required: true, message: "请输入模拟练习做题奖励分值", trigger: "blur" },
          { required: true, message: "请输入模拟练习做题奖励分值", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
        mockExam: [
          { required: true, message: "请输入模拟考试奖励分换算值", trigger: "blur" },
          { required: true, message: "请输入模拟考试奖励分换算值", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
        studyLen: [
          { required: true, message: "请输入学习时长奖励分换算值", trigger: "blur" },
          { required: true, message: "请输入学习时长奖励分换算值", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
        signGetScore: [
          { required: true, message: "请输入完成签到考勤获得奖励分值", trigger: "blur" },
          { required: true, message: "请输入完成签到考勤获得奖励分值", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
        leaveGetScore: [
          { required: true, message: "请输入完成离开考勤获得奖励分值", trigger: "blur" },
          { required: true, message: "请输入完成离开考勤获得奖励分值", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询数据 */
    getList() {
      let self = this;
      creditItemListAllAward({}).then( response => {
        for(let i=0;i<response.data.length;i++){
          if(response.data[i].configName == '一个月无违规记录奖励分值'){
            self.$set(self.form,'monthNoviolationScore',response.data[i].configValue?response.data[i].configValue:0);
          }else if(response.data[i].configName == '模拟练习做题奖励分值'){
            self.$set(self.form,'exerciseScore',response.data[i].configValue?response.data[i].configValue:0);
          }else if(response.data[i].configName == '模拟考试奖励分换算值'){
            self.$set(self.form,'mockExam',response.data[i].configValue?response.data[i].configValue:0);
          }else if(response.data[i].configName == '学习时长奖励分换算值'){
            self.$set(self.form,'studyLen',response.data[i].configValue?response.data[i].configValue:0);
          }else if(response.data[i].configName == '完成签到考勤获得奖励分值'){
            self.$set(self.form,'signGetScore',response.data[i].configValue?response.data[i].configValue:0);
          }else if(response.data[i].configName == '完成离开考勤获得奖励分值'){
            self.$set(self.form,'leaveGetScore',response.data[i].configValue?response.data[i].configValue:0);
          }
        }
        // this.$set(this,'form',response.data)
      });
    },
    /** 提交按钮 */
    submitForm() {
      let self = this;
      this.$refs["form"].validate(valid => {
        if (valid) {
          let list = [
            {
              sort:'0',
              configName:'一个月无违规记录奖励分值',
              configValue:self.form.monthNoviolationScore,
            },
            {
              sort:'1',
              configName:'模拟练习做题奖励分值',
              configValue:self.form.exerciseScore,
            },
            {
              sort:'2',
              configName:'模拟考试奖励分换算值',
              configValue:self.form.mockExam,
            },
            {
              sort:'3',
              configName:'学习时长奖励分换算值',
              configValue:self.form.studyLen,
            },
            {
              sort:'4',
              configName:'完成签到考勤获得奖励分值',
              configValue:self.form.signGetScore,
            },
            {
              sort:'5',
              configName:'完成离开考勤获得奖励分值',
              configValue:self.form.leaveGetScore,
            },
          ];
          creditItemEditAward(list).then( response => {
            this.getList();
            this.msgSuccess("保存成功")
          });
        }
      });
    },
  }
};
</script>

<style scoped lang="scss">
  .rewardconfig{
    .form-content{
      overflow-y: scroll;
      flex:1;
      .annotation-span{
        margin-left:20px;
        font-size:14px;
        font-weight:500;
        color:#999999;
      }
    }
    .form-bottom-button-box{
      height:80px;
      padding:20px;
      display: flex;
      .null-p-button{
        flex:1;
      }
    }
  }
</style>
