<template>
  <div class="table-container">
    <el-row class="second-title">规则说明</el-row>
    <div>
      <el-row class="content">监督员得分 = 上报分数 - 未按时核查分 - 未按时核实分</el-row>
      <el-row class="content">上报分数 = 有效上报数量/要求上报数量 * 100</el-row>
      <el-row class="content">未按时核查分 = 超时核查数/安排核查数 * 100 * 核查因子</el-row>
      <el-row class="content">按时核实分 = 超时核实数/安排核实数 * 100 * 核实因子</el-row>
    </div>
    <el-row style="padding:20px"/>
    <el-row class="second-title">考核因子</el-row>
    <div>
      <el-row>
        <el-col :span="8" class="cell">要求上报数量</el-col>
        <el-col :span="8" class="cell">核查因子</el-col>
        <el-col :span="8" class="cell">核实因子</el-col>
      </el-row>
      <el-row>
        <el-col :span="8" class="cell">
          <el-input v-model="accessRule.shouldReport" size="small" style="width:25%"/>
          <el-button type="text" class="submit-button" @click="updateAccessFactor()">修改</el-button>
        </el-col>
        <el-col :span="8" class="cell">
          <el-input v-model="accessRule.checkFactor" size="small" style="width:25%"/> %
          <el-button type="text" class="submit-button" @click="updateAccessFactor()">修改</el-button>
        </el-col>
        <el-col :span="8" class="cell">
          <el-input v-model="accessRule.verify" size="small" style="width:25%"/> %
          <el-button type="text" class="submit-button" @click="updateAccessFactor()">修改</el-button>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { getAssessFactor, updateAssessFactor } from '@/api/assess/assessRule'
import { validateIntPlus } from '@/utils/validate'
export default {
  name: 'AssessRuleSupervisor',
  data() {
    return {
      role: '',
      accessRule: {
        id: '', // id
        shouldReport: '', // 监督员，要求上报数
        checkFactor: '', // 监督员，核查因子
        verify: '', // 监督员，核实因子
        registerOntimeReceiver: '', // 受理员，按时立案因子
        disVerifyOntime: '', // 受理员，按时发送核实因子
        disCheckOntime: '', // 受理员 按时发送核查因子
        registerOntimeMonitor: '', // 值班长，按时立案因子
        closeOntime: '', // 值班长，按时结案因子
        teamMark: '', // 值班长，团队分因子
        disOntime: '', // 派遣员，按时派遣因子
        disExact: '', // 派遣员，准确派遣因子
        processAuditOntime: '', // 派遣员，按时处理审核因子
        adjustOntime: '' // 派遣员，按时调整因子
      }
    }
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    // 获取考核规则
    fetchData() {
      getAssessFactor().then(response => {
        this.accessRule = response.data
      })
    },
    // 更新考核规则
    updateAccessFactor() {
      if (this.validateData()) {
        updateAssessFactor(this.accessRule).then(response => {
          if (response.code === 200) {
            this.$message.success('修改成功')
          }
        })
      }
    },
    validateData() {
      if (!validateIntPlus('' + this.accessRule.shouldReport, 0, 10000)) {
        this.$message.error('应上报数的允许填写范围为0到10000')
        return false
      }
      if (!validateIntPlus('' + this.accessRule.checkFactor, 0, 100)) {
        this.$message.error('核查因子的允许填写范围为0到100')
        return false
      }
      if (!validateIntPlus('' + this.accessRule.verify, 0, 100)) {
        this.$message.error('核实因子的允许填写范围为0到100')
        return false
      }
      return true
    }
  }

}
</script>

<style lang="scss" scoped>
.second-title{
  border: 1px solid #eee;
  background-color: #eee;
  border-top: 0;
  font-size: 1.5em;
  padding: 10px;
  text-align: center;
}
.content{
  border: 1px solid #eee;
  border-top: 0;
  font-size: 1.2em;
  padding: 5px;
  text-align: center;
}
.cell{
  border: 1px solid #eee;
  font-size: 1.2em;
  border-top: 0;
  padding: 5px;
  text-align: center;
  position: relative;
}
.submit-button{
  margin-left: 10px;
}
 /deep/ input.el-input__inner {
  color: red;
  font-size: 1.2em;
}
</style>
