<template>
  <div>
    <div class="rule-row">
      <div class="rule-title">
        <div class="title">规则说明：</div>
      </div>
      <div class="rule-content">
        <div class="content">派遣员得分 = 按时派遣分数 + 准确派遣分 + 按时处理审核分+按时调整分</div>
        <div class="content">按时派遣分数 = 按时派遣数/派遣数 * 100 * 按时派遣因子</div>
        <div class="content">准确派遣分 = 准确派遣数/派遣数 * 100 * 准确派遣因子</div>
        <div class="content">按时处理审核分 = 按时处理审核数/处理审核数 * 100 * 按时处理审核因子</div>
        <div class="content">按时调整分 = 按时调整数/调整数 * 100 * 按时调整因子</div>
      </div>
    </div>
    <div class="rule-row">
      <div class="rule-title">
        <div class="title">考核因子：</div>
      </div>
      <div class="rule-content">
        <el-row>
          <span class="sub-title">按时派遣因子</span>
          <el-input v-model="accessRule.disOntime" size="small" class="sub-input">
            <template slot="append">%</template>
          </el-input>
          <el-button type="text" class="submit-button" @click="updateAccessFactor()">修改</el-button>
        </el-row>
        <el-row>
          <span class="sub-title">准确派遣因子</span>
          <el-input v-model="accessRule.disExact" size="small" class="sub-input">
            <template slot="append">%</template>
          </el-input>
          <el-button type="text" class="submit-button" @click="updateAccessFactor()">修改</el-button>
        </el-row>
        <el-row>
          <span class="sub-title">按时处理审核因子</span>
          <el-input v-model="accessRule.processAuditOntime" size="small" class="sub-input">
            <template slot="append">%</template>
          </el-input>
          <el-button type="text" class="submit-button" @click="updateAccessFactor()">修改</el-button>
        </el-row>
        <el-row>
          <span class="sub-title">按时调整因子</span>
          <el-input v-model="accessRule.adjustOntime" size="small" class="sub-input">
            <template slot="append">%</template>
          </el-input>
          <el-button type="text" class="submit-button" @click="updateAccessFactor()">修改</el-button>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
import { getAssessFactor, updateAssessFactor } from '@/api/assess/assessRule'
import { validateIntPlus } from '@/utils/validate'
export default {
  name: 'AssessRuleDispatcher',
  data() {
    return {
      role: '',
      accessRule: {
        id: '', // id
        shouldReport: '', // 监督员，要求上报数
        checkFactor: '', // 监督员，核查因子
        verify: '', // 监督员，核实因子
        registerOntimeReceiver: '', // 受理员，按时立案因子
        disVerifyOntime: '', // 受理员，按时发送核实因子
        disCheckOntime: '', // 受理员 按时发送核查因子
        registerOntimeDispatcher: '', // 值班长，按时立案因子
        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.disOntime, 0, 100)) {
        this.$message.error('按时派遣因子的允许填写范围为0到100')
        return false
      }
      if (!validateIntPlus('' + this.accessRule.disExact, 0, 100)) {
        this.$message.error('准确派遣因子的允许填写范围为0到100')
        return false
      }
      if (!validateIntPlus('' + this.accessRule.processAuditOntime, 0, 100)) {
        this.$message.error('按时处理审核因子的允许填写范围为0到100')
        return false
      }
      if (!validateIntPlus('' + this.accessRule.adjustOntime, 0, 100)) {
        this.$message.error('按时调整因子的允许填写范围为0到100')
        return false
      }
      return true
    }
  }
}
</script>

<style lang="scss" scoped>
.title {
  font-size: 16px;
  padding-top: 10px;
  font-weight: bolder;
}
.sub-title{
  padding: 10px;
  font-size: 16px;
  font-weight: bolder;
  width: 150px;
  display: inline-block;
}
.content{
  font-size: 16px;
  padding: 10px;
}
.submit-button{
  margin-left: 10px;
}
.sub-input{
  width: 120px;
}
.rule-row {
  display: flex;
}
.rule-title {
  width: 20%;
  text-align: end;
}
.rule-content {
  width: 80%;
}
 /deep/ input.el-input__inner {
  color: red;
  font-size: 16px;
}
</style>
