perConfigForm.vue 13.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
<template>
  <div class="performance-box">
    <div class="explain-box">
      <span>设置员工在单店的工资提成</span>
      <span class="explain" @click="handleExplain('performanceConfig')">示例说明</span>
    </div>
    <glsx-combi-form class="edit-form-container"
                     ref="editFormRef1"
                     label-width="154px"
                     default-width="432px"
                     :is-block="true"
                     form-ref="editChildRef"
                     :form-obj="configInfo"
                     :form-data="performanceFormData"
                     :form-rules="formRules">
      <!-- 基本工资/元 -->
      <div slot="basicWage">
        <el-input type="text" :disabled="isDisabled" class="input-w-432" v-model="configInfo.basicWage"
                  @blur="handleCalcuPrice('configInfo', 'basicWage')" placeholder="请输入"></el-input>
      </div>
      <!-- 保底工资/元 -->
      <div slot="minimumWage">
        <el-input type="text" :disabled="isDisabled" class="input-w-432" v-model="configInfo.minimumWage"
                  @blur="handleCalcuPrice('configInfo', 'minimumWage')" placeholder="请输入"></el-input>
      </div>
      <div :slot="item" :key="index" v-for="(item, index) in addHtmls">
        <div>
          <!--均客单奖励 高客单奖励 高产值奖励 成交率奖励-->
          <template v-if="item == 'outputBonus' || item == 'upgradeRateBonus' || item == 'averagePriceBonus'">
            <d2-table ref="orderRef" class="award-wrap" :table-data="configInfo[item + 'List']"
                      :table-params="tableDataItem(item)" :has-page="false">
              <template slot="startValue" slot-scope="scope">
                <span v-if="scope.scope.isStartEdit">{{ scope.scope.startValue }}</span>
                <el-form-item v-else style="margin-bottom: 0px;margin-right: 0;">
                  <el-input class="input-w-136" v-model="scope.scope.startValue" placeholder="请输入" disabled></el-input>
                </el-form-item>
              </template>
              <template slot="endValue" slot-scope="scope">
                <span v-if="scope.scope.isEndEdit">--</span>
                <el-form-item v-else style="margin-bottom: 0px;margin-right: 0;" :prop="item + 'List.' + scope.index + '.endValue'"
                              :rules="checkEndValue(scope.scope)">
                  <el-input class="input-w-136" :disabled="isDisabled" v-model="scope.scope.endValue" placeholder="请输入"
                            @blur="handleCalculate(item, 'endValue', scope.index)"></el-input>
                </el-form-item>
              </template>
              <template slot="calculateValue" slot-scope="scope">
                <el-form-item style="margin-bottom: 0px;margin-right: 0;" :prop="item + 'List.' + scope.index + '.calculateValue'"
                              :rules="formRules.calculateValue">
                  <el-input class="input-w-136" :disabled="isDisabled" v-model="scope.scope.calculateValue" :placeholder="item == 'outputBonus' ?'请输入' : '0.00-10.00'"
                            @blur="handleCalculate(item, 'calculateValue', scope.index)"></el-input>
                </el-form-item>
              </template>
              <div class="table-btns" slot="auth-button" slot-scope="scope">
                <el-button @click="handleDelete(item, scope.index)" :disabled="isDisabled" type="text" size="small">删除</el-button>
              </div>
            </d2-table>
            <div class="add-txt">
              <el-button icon="el-icon-plus" :disabled="isDisabled" @click="addLine(item)">新增一行</el-button>
            </div>
          </template>
        </div>
      </div>
    </glsx-combi-form>
    <explain-dialog :is-explain="isExplain" :diff-explain="diffExplain" @handleClose="handleDialogClose"></explain-dialog>
  </div>
</template>
<script>
import BigNumber from 'bignumber.js'
import explainDialog from './explainDialog.vue'
import { deepClone } from '@/common/util'
export default {
  name: 'PerConfigForm',
  components: {
    explainDialog
  },
  props: {
    perConfigInfo: Object, // 配置信息
    pageDisabled: Boolean // 是否可编辑
  },
  data() {
    var checkPrice = (rule, value, callback) => {
      if (value && isNaN(+value)) {
        callback(new Error('请输入数字值'))
      } else {
        if (+value < 0 || +value > 999999.98) {
          callback(new Error('仅支持输入0~999999.98'))
        } else {
          callback()
        }
      }
    }
    return {
      formRules: {
        basicWage: [
          { required: true, message: '请输入基本工资/元', trigger: 'blur' },
          { validator: checkPrice, trigger: 'blur' }
        ],
        minimumWage: [
          { required: false, message: '请输入保底工资/元', trigger: 'blur' },
          { validator: checkPrice, trigger: 'blur' }
        ],
        calculateValue: [
          { required: true, message: '请输入', trigger: 'blur' },
          { validator: checkPrice, trigger: 'blur' }
        ]
      },
      performanceFormData: [{
        label: '基本工资',
        name: 'basicWage',
        addHtml: 'basicWage',
        type: 'input',
        isHide: false
      }, {
        label: '保底工资',
        name: 'minimumWage',
        isHide: false,
        addHtml: 'minimumWage'
      }, {
        label: '高产值奖励',
        name: 'outputBonus',
        addHtml: 'outputBonus',
        isHide: false
      }, {
        label: '成交率奖励',
        name: 'upgradeRateBonus',
        addHtml: 'upgradeRateBonus',
        isHide: false
      }, {
        label: '均客单奖励',
        name: 'averagePriceBonus',
        addHtml: 'averagePriceBonus',
        isHide: false
      }],
      isExplain: false,
      diffExplain: '',
      addHtmls: ['outputBonus', 'upgradeRateBonus', 'averagePriceBonus'],
      averagePriceBonusTable: { // 均客单奖励Table
        tableOption: {
          width: '80px'
        },
        tableColumns: []
      },
      outputBonusTable: { // 高产值奖励Table
        tableOption: {
          width: '80px'
        },
        tableColumns: []
      },
      upgradeRateBonusTable: { // 成交奖励Table
        tableOption: {
          width: '80px'
        },
        tableColumns: []
      },
      configInfo: {}
    }
  },
  watch: {
    configInfo: {
      handler() {
        this.initCommission()
      },
      deep: true
    }
  },
  computed: {
    isDisabled: {
      get() {
        return this.pageDisabled
      },
      set() { }
    }
  },
  created() {
    this.configInfo = deepClone(this.perConfigInfo)
  },
  methods: {
    // 还原提成配置
    resetCommission() {
      this.isDisabled = true
      this.configInfo = deepClone(this.perConfigInfo)
    },
    // 初始化提成配置
    initCommission() {
      const arr = deepClone(this.addHtmls)
      arr?.forEach(val => {
        if (!this.configInfo[val + 'List']?.length) {
          this.addLine(val, 1)
        }
        setTimeout(() => {
          this.initTableColumns(val)
        })
      })
    },
    // switch开关
    changeFormAttr(formName, attrName, labelList, attrValue) {
      labelList.forEach(item => {
        const idx = this[formName].findIndex(k => k.name == item)
        this[formName][idx][attrName] = attrValue
      })
    },
    tableDataItem(v) {
      return this[v + 'Table']
    },
    // 示例说明
    handleExplain(item) {
      this.diffExplain = item
      this.isExplain = true
    },
    // 关闭示例弹窗
    handleDialogClose() {
      this.isExplain = false
    },
    // 初始化奖励Table
    initTableColumns(value) {
      const tableColumns = [
        {
          label: `区间开始值`,
          prop: 'startValue',
          addHtml: 'startValue',
          minWidth: 200
        },
        {
          label: '区间结束值',
          prop: 'endValue',
          addHtml: 'endValue',
          minWidth: 200
        },
        {
          label: '提成比例/%',
          prop: 'calculateValue',
          addHtml: 'calculateValue',
          minWidth: 200
        }
      ]
      const params = this[[value] + 'Table']
      if (!params) return
      const unit = value !== 'upgradeRateBonus' ? '/元' : '/%'
      const calculateText = value == 'outputBonus' ? '提成比例/%' : '提成系数'
      tableColumns.forEach((item, index) => {
        if (index < 2) {
          item.label = item.label + unit
        } else {
          item.label = calculateText
        }
      })
      params.tableColumns = tableColumns
    },
    // 新增一行
    addLine(item, line = 2) {
      !this.configInfo[item + 'List'] ? (this.configInfo[item + 'List'] = []) : ''
      const formData = this.configInfo[item + 'List']
      formData.push({
        startValue: line == 2 ? '' : 0,
        endValue: item == 'upgradeRateBonus' ? 100 : 999999.99, // 成交率奖励区间值为百分比
        calculateValue: '',
        isStartEdit: line == 1,
        isEndEdit: true
      })
      if (line == 2) {
        // 上一行区间结束值/元 设为可编辑
        formData[formData.length - 2].isEndEdit = false
        if (formData[formData.length - 2].endValue && formData[formData.length - 2].endValue < (item == 'upgradeRateBonus' ? 100 : 999999.99)) {
          formData[formData.length - 1].startValue = new BigNumber(formData[formData.length - 2].endValue).plus(0.01).toNumber()
        } else {
          formData[formData.length - 2].endValue = ''
        }
      }
      this.$forceUpdate()
    },
    // 删除
    handleDelete(item, index) {
      const data = this.configInfo
      if (data[item + 'List']?.length > 1) {
        data[item + 'List']?.splice(index, 1)
      }
    },
    handleCalcuPrice(formName, data) {
      const max = 999999.98
      this[formName][data] = this[formName][data] != '' && this[formName][data] >= 0 ? (this[formName][data] > max ? max : new BigNumber(this[formName][data]).dp(2).toNumber()) : ''
    },
    // 区间值/提成比例/提成系数 失去焦点
    handleCalculate(item, key, index) {
      const formData = this.configInfo[item + 'List']
      let max = 0
      switch (item) {
        case 'outputBonus':
          max = key == 'calculateValue' ? 100 : 999999.97
          break
        case 'upgradeRateBonus':
          max = key == 'calculateValue' ? 10 : 99.99
          break
        case 'averagePriceBonus':
          max = key == 'calculateValue' ? 10 : 999999.97
          break
      }
      formData[index][key] = formData[index][key] > max ? max : formData[index][key]
      formData[index][key] = formData[index][key] ? new BigNumber(formData[index][key]).dp(2).toNumber() : ''
      // 下一行区间开始值自动在上一行的区间结束值的基础上+0.01
      if (formData[index + 1] && key == 'endValue' && formData[index][key]) formData[index + 1].startValue = new BigNumber(formData[index][key]).plus(0.01).toNumber()
      // 提成比例/系数 可输入0
      if (!formData[index][key] && key != 'calculateValue') formData[index][key] = ''
    },
    // 自定义校验区间结束值
    checkEndValue(row) {
      return [{
        required: true,
        validator: (rule, value, callback) => {
          if (!value) {
            callback(new Error("请输入"))
          } else if (+value <= row.startValue) {
            callback(new Error('结束值需大于开始值'))
          } else if (+value <= 0) {
            callback(new Error('不能小于等于0'))
          } else {
            callback()
          }
        },
        trigger: 'blur'
      }]
    },
    // 保存校验
    submitValide() {
      return new Promise((resolve, reject) => {
        this.$refs.editFormRef1?.$refs.editChildRef?.validate(async (valid) => {
          if (valid) {
            resolve(this.configInfo)
          } else {
            resolve('error')
          }
        })
      })
    }
  }
}
</script>
<style scoped lang="scss">
.performance-box{
  background: #FAFAFA;
  border-radius: 4px;
  margin-bottom: 20px;
  padding: 10px 20px;
  .explain-box{
    font-weight: 600;
    color: #333333;
    margin: 0 -20px 0 -20px;
    padding-left: 20px;
    border-bottom: 1px solid #E8E8EA;
  }
  .explain{
      margin-left: 9px;
      color: #2a58ad;
      cursor: pointer;
    }
  .edit-form-container{
    padding: 20px 0;
    .input-w-432{
      width: 432px
    }
    .award-wrap{
      width: 750px;
      ::v-deep td{
        height: 64px;
      }
      ::v-deep .el-form-item__error {
        padding-top: 2px;
        z-index: 9999999;
        position: static;
        text-align: left;
      }
      .input-w-136{
        width: 136px;
      }

    }
  }
}
.switchStyle ::v-deep .el-switch__label {
  position: absolute;
  display: none;
  color: #fff;
  font-size: 12px !important;
  line-height: 20px;
}

.el-switch__core {
  background-color: rgba(166, 166, 166, 1);
}

// form-label 必填标识样式
::v-deep #outputBonus, ::v-deep #upgradeRateBonus, ::v-deep #averagePriceBonus{
  .el-form-item__label:before {
    content: '*';
    color: #F56C6C;
    margin-right: 4px;
  }
}

.switchStyle{
  ::v-deep .el-switch__label {
    position: absolute;
    display: none;
    color: #fff;
  }
  /*打开时文字位置设置*/
  ::v-deep .el-switch__label--right {
    z-index: 1;
    right: 20px;

  }
  /*关闭时文字位置设置*/
  ::v-deep .el-switch__label--left {
    z-index: 1;
    left: 20px;
  }
  ::v-deep .el-switch__label--left.is-active {
    display: block;
    span{
      font-size: 12px;
      color: #999999;
    }
  }
  ::v-deep .el-switch__label--right.is-active {
    display: block;
    span{
      font-size: 12px;
      color: #FFFFFF;
    }
  }
}
</style>