campus.vue 13.3 KB
<!-- 校招绩效配置 -->
<template>
  <div class="content">
    <el-form :model="infoData" :rules="rules" ref="configForm">
      <el-form-item label="" prop="campusList" label-width="0">
        <div class="config-table">
          <template>
            <el-table :data="infoData.campusList" :header-cell-style="rowClass">
              <el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
              <el-table-column prop="jobType" label="职级" min-width="145">
                <template slot-scope="scope">
                  <el-form-item :prop="`campusList[${scope.$index}].jobType`" :rules="rules.jobType" label-width="0">
                    <el-select clearable filterable v-model="scope.row['jobType']" @change="handleSelect" style="width: 130px" placeholder="请选择">
                      <el-option v-for="item in baseData.jobTypeList" :key="item.confId" :label="item.confValue" :value="item.confId">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="penertrationRate" label="渗透率要求" min-width="215">
                <template slot-scope="scope">
                  <el-form-item :prop="`campusList[${scope.$index}].startValue`" :rules="rules.startValue">
                    <el-input class="rate_input" @input="handleInput($event, 'startValue', scope)" v-model="scope.row['startValue']" placeholder="请输入">
                      <span slot="suffix" class="suffix_text">%</span>
                    </el-input>
                  </el-form-item> -
                  <el-form-item :prop="`campusList[${scope.$index}].endValue`" :rules="rules.endValue">
                    <el-input class="rate_input" @input="handleInput($event, 'endValue', scope)" v-model="scope.row['endValue']" placeholder="请输入">
                      <span slot="suffix" class="suffix_text">%</span>
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="calculateValue" label="提成系数" min-width="175">
                <template slot="header">
                  <div class="custom-header">
                    <span>提成系数</span>
                    <span class="label_tip">(业绩提成点数)</span>
                  </div>
                </template>
                <template slot-scope="scope">
                  <el-form-item :prop="`campusList[${scope.$index}].calculateValue`" :rules="rules.calculateValue">
                    <el-input class="rate_input" @input="handleInput($event, 'calculateValue', scope)" v-model="scope.row['calculateValue']" placeholder="请输入">
                      <span slot="suffix" class="suffix_text">%</span>
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="percentage" label="提成分配机制" min-width="580">
                <template slot="header">
                  <div class="custom-header">
                    <span>提成分配机制</span>
                    <span class="label_tip">(个人+导师+区域督导+奖励池=100%员工业绩提成金额)</span>
                  </div>
                </template>
                <template slot-scope="scope">
                  个人
                  <el-form-item :prop="`campusList[${scope.$index}].grCommissionRatio`" :rules="rules.grCommissionRatio">
                    <el-input class="rate_input" @input="handleInput($event, 'grCommissionRatio', scope)" v-model="scope.row['grCommissionRatio']" placeholder="请输入">
                      <span slot="suffix" class="suffix_text">%</span>
                    </el-input> + 
                  </el-form-item>
                  导师
                  <el-form-item :prop="`campusList[${scope.$index}].dsCommissionRatio`" :rules="rules.dsCommissionRatio">
                    <el-input class="rate_input" @input="handleInput($event, 'dsCommissionRatio', scope)" v-model="scope.row['dsCommissionRatio']" placeholder="请输入">
                      <span slot="suffix" class="suffix_text">%</span>
                    </el-input> + 
                  </el-form-item>
                  督导
                  <el-form-item :prop="`campusList[${scope.$index}].ddCommissionRatio`" :rules="rules.ddCommissionRatio">
                    <el-input class="rate_input" @input="handleInput($event, 'ddCommissionRatio', scope)" v-model="scope.row['ddCommissionRatio']" placeholder="请输入">
                      <span slot="suffix" class="suffix_text">%</span>
                    </el-input> + 
                  </el-form-item>
                  奖励池
                  <el-form-item :prop="`campusList[${scope.$index}].jlcCommissionRatio`" :rules="rules.jlcCommissionRatio">
                    <el-input class="rate_input" @input="handleInput($event, 'jlcCommissionRatio', scope)" v-model="scope.row['jlcCommissionRatio']" placeholder="请输入">
                      <span slot="suffix" class="suffix_text">%</span>
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="" label="操作" width="60">
                <template slot-scope="scope">
                  <el-button type="text" @click="del(scope.$index)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </template>
          <div class="add_btn">
            <el-button size="small" icon="el-icon-plus" @click="addRow">新增一行</el-button>
          </div>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { deepClone } from '@/common/util'
import { staffLevelList } from '@/common/constants.js'
import { limitPrice } from '@/common/format'
import BigNumber from 'bignumber.js'
export default {
  name: 'CampusConfig',
  data() {
    var endValidator = (rule, value, callback) => {
      const index = rule.fullField.match(/\d+/)[0]
      const start = this.infoData.campusList[index].startValue
      const end = this.infoData.campusList[index].endValue
      if ((value - 0) < (start - 0) || (end && (value - 0) > (end - 0))) {
        callback(new Error('区间有误'))
      } else {
        callback();
      }
    }
    return {
      rules: {
        campusList: [
          {required: true, message: '请配置绩效方案', trigger: 'change' },
        ],
        jobType: [
          { required: true, message: '请选择职级', trigger: 'change' }
        ],
        startValue: [
          { required: true, message: '请输入比例', trigger: 'blur' },
          { validator: endValidator, trigger: 'blur' }
        ],
        endValue: [
          { required: true, message: '请输入比例', trigger: 'blur' },
          { validator: endValidator, trigger: 'blur' }
        ],
        calculateValue: [
          { required: true, message: '请输入比例', trigger: 'blur' }
        ],
        grCommissionRatio: [
          { required: true, message: '请输入比例', trigger: 'blur' }
        ],
        dsCommissionRatio: [
          { required: true, message: '请输入比例', trigger: 'blur' }
        ],
        ddCommissionRatio: [
          { required: true, message: '请输入比例', trigger: 'blur' }
        ],
        jlcCommissionRatio: [
          { required: true, message: '请输入比例', trigger: 'blur' }
        ]
      },
      baseData: {
        jobTypeList: deepClone(staffLevelList.slice(0, staffLevelList.length - 3)) // 剔除区域督导选项
      },
      infoData: {}
    }
  },

  props: {
    configInfo: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },

  computed: {},

  mounted() {
    this.infoData = deepClone(this.configInfo)
  },

  methods: {
    rowClass({ row, rowIndex }) {
      return 'background:#F2F4F7;color:#333333;font-size:14px;font-weight:600;'
    },
    addRow() {
      let obj = {
        jobType: '',
        startValue: '',
        endValue: '',
        calculateValue: '',
        grCommissionRatio: '',
        dsCommissionRatio: '',
        ddCommissionRatio: '',
        jlcCommissionRatio: ''
      }
      this.infoData.campusList.push(obj)
      this.$nextTick(() => {
        this.$refs['configForm'].clearValidate()
      })
    },
    del(index) {
      this.$confirm('确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.infoData.campusList.splice(index, 1)
        this.$nextTick(() => {
          this.$refs['configForm'].clearValidate()
        })
      }).catch(() => {
      })
    },
    handleInput(e, key, scope) {
      e = e.replace(/[^\d.]/g, '')
      let index = scope.$index
      let oldValue = `${this.infoData.campusList[index]['old' + key]}`
      this.$set(this.infoData.campusList[index], key, limitPrice(e, oldValue, 3, key == 'startValue' || key == 'endValue' ? 0 : 2, 0, 100))
      this.$set(this.infoData.campusList[index], 'old' + key, this.infoData.campusList[index][key])
    },
    // 选择职级后将列表顺序排序
    handleSelect() {
      this.infoData.campusList?.sort((a, b) => a.jobType - b.jobType)
    },
    // 获取配置数据
    getFormData() {
      return new Promise((resolve, reject) => {
        resolve(this.infoData)
      })
    },
    validateCustomForm() {
      return new Promise((resolve, reject) => {
        this.$refs['configForm'].validate((valid) => {
          if (valid) {
            if (!this.validateCoverage()) {
              resolve('error')
              return
            }
            resolve(this.infoData)
          } else {
            resolve('error')
          }
        })
      })
    },
    // 校验渗透率区间是否覆盖完整和提成分配机制总合是否为100%
    validateCoverage() {
      const jobTypes = {}
      const arr = this.infoData.campusList
      // 将campusList按jobType分组
      for (const item of arr) {
        if (!jobTypes[item.jobType]) {
          jobTypes[item.jobType] = []
        }
        jobTypes[item.jobType].push(item)
      }
      // 遍历每个jobType
      for (const jobType in jobTypes) {
        const jobTypeText = this.baseData.jobTypeList.find(item => item.confId == jobType).confValue
        const intervals = jobTypes[jobType]
        // 按startValue排序
        intervals.sort((a, b) => a.startValue - b.startValue)
        let values = []
        intervals.forEach(item => {
          values.push(item.startValue)
          values.push(item.endValue)
        })
        // 检查渗透率区间是否覆盖完整的0-100%
        values.sort((a, b) => a - b)
        if (values[0] != 0 || values[values.length - 1] != 100) {
          this.$message.warning(`绩效配置单个职级渗透率要求需满足100%的比例范围`)
          return false
        }
        // 检查渗透率区间是否连续且无重叠
        for (let i = 1; i < intervals.length; i++) {
          const startValue = new BigNumber(intervals[i].startValue || 0)
          const endValue = new BigNumber(intervals[i - 1]?.endValue || 0)
          if (startValue.minus(endValue).toNumber() > 1) {
            this.$message.warning(`职级 ${jobTypeText} 渗透率区间不连续`)
            return false
          }
          if (startValue.toNumber() <= endValue.toNumber()) {
            this.$message.warning(`职级 ${jobTypeText} 渗透率区间存在重叠`)
            return false
          }
        }
        // 检查提成分配机制的总和是否等于100%
        for (const item of intervals) {
          const grCommissionRatio = new BigNumber(item.grCommissionRatio)
          const dsCommissionRatio = new BigNumber(item.dsCommissionRatio)
          const ddCommissionRatio = new BigNumber(item.ddCommissionRatio)
          const jlcCommissionRatio = new BigNumber(item.jlcCommissionRatio)
          const total = grCommissionRatio.plus(dsCommissionRatio).plus(ddCommissionRatio).plus(jlcCommissionRatio).toNumber()
          if (total != 100) {
            const penertrationRate = `${item.startValue}-${item.endValue}`
            this.$message.warning(`职级 ${jobTypeText} 渗透率区间 ${penertrationRate} 的提成分配机制的总和必须等于100%`)
            return false
          }
        }
      }
      return true
    }
  }
}
</script>

<style lang="scss" scoped>
.content {
  padding-top: 10px;
  .config-table{
    .custom-header {
      .label_tip {
        font-size: 12px;
        font-weight: normal;
        color: #333333;
      }
    }
    .rate_input {
      display: inline-block;
      width: 90px;
      .suffix_text {
        display: flex;
        align-items: center;
        height: 100%;
      }
    }
    .add_btn{
      margin-top: 10px;
    }
  }
  ::v-deep.config-table {
    .el-table .cell {
      padding: 0 10px;
    }
    .el-table__body-wrapper {
      .el-table__row td:nth-child(1) {
        border-left: 1px solid #ebeef5;
      }

      .el-table__row td:nth-last-child(1) {
        border-right: 1px solid #ebeef5;
      }
      .el-table__row .cell {
        padding: 16px 10px;
      }
    }

    .select {
      .el-tag {
        width: auto;
      }
    }
    .el-form-item{
      display: inline-block;
      margin-bottom: 0;
    }
  }
}
</style>