performanceScheme.bak.vue 45 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 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
<!-- 绩效方案 -->
<template>
  <d2-container v-loading="$store.state.d2admin.loading.value" class="performanceScheme">
    <el-form ref="form"
             class="form"
             label-width="280px"
             :model="formData"
             :rules="rules">
      <div class="warp_box">
        <div class="title space-b">
          <div class="title-wrap">
            <div class="line"></div>
            <span>渠道配置</span>
          </div>
          <div class="merchant-text">当前配置门店:{{ `${routerQuery.merchantName}${routerQuery.merchantId}` }}</div>
        </div>
        <div class="warp_content">
          <el-form-item label="适用招聘类型:" prop="hireType">
            <el-radio-group v-model="tempHireType" @change="changePerformance($event, 'hireType', 'tempHireType')">
              <!-- <el-radio-button size="small" :label="1">校招管培生</el-radio-button> -->
              <el-radio-button :label="2" size="small">社会招聘</el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="所属业务:" prop="sceneType">
            <el-radio-group v-model="tempSceneType"
                            aria-hidden="false"
                            @change="changePerformance($event, 'sceneType', 'tempSceneType')">
              <el-radio :label="1">轻改</el-radio>
              <el-radio :label="0">会员权益/升级</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="方案类型:" prop="configType">
            <el-radio-group v-if="formData.hireType == 2 && formData.sceneType == 0"
                            v-model="tempConfigType"
                            aria-hidden="false"
                            @change="changePerformance($event, 'configType', 'tempConfigType')">
              <el-radio :label="1">按月度产值要求拿提成</el-radio>
              <el-radio :label="3">权益延保按渗透率拿提成</el-radio>
              <el-radio :label="4">5月赛力斯新绩效方案</el-radio>
            </el-radio-group>
            <el-radio-group v-if="formData.hireType == 2 && formData.sceneType == 1"
                            v-model="tempConfigType"
                            aria-hidden="false">
              <el-radio :label="1">按月度产值要求拿提成</el-radio>
            </el-radio-group>
            <el-radio-group v-if="formData.hireType == 1"
                            v-model="tempConfigType"
                            aria-hidden="false">
              <el-radio :label="2">按渗透率拿提成</el-radio>
            </el-radio-group>
          </el-form-item>
        </div>
      </div>
      <div v-if="formData.hireType && isShow" class="warp_box">
        <div class="title">
          <div class="line"></div>
          <span>绩效配置</span>
          <el-button plain
                     size="small"
                     style="margin-left: 20px;"
                     type="primary"
                     @click="clearConfig">清空配置并提交</el-button>
        </div>
        <el-form-item class="schemeName"
                      label="当前方案名称:"
                      label-width="120px"
                      prop="schemeName">
          <el-input v-model="formData.schemeName"
                    maxlength="20"
                    placeholder="请输入方案名称"
                    style="width: 432px;"></el-input>
        </el-form-item>
        <div class="warp_content">
          <!-- 校招 -->
          <template v-if="formData.configType == 2">
            <campus ref="configForm" :config-info="formData.configInfo"></campus>
          </template>
          <!-- 社招轻改 -->
          <template v-if="formData.configType == 1 && formData.hireType == 2">
            <social :ref="`perConfigForm_`"
                    :goods-type-list="goodsTypeList"
                    :per-config-info="socialConfigInfo"></social>
          </template>
          <!-- 社招会员权益按渗透率 -->
          <template v-if="formData.configType == 3">
            <el-tabs v-model="carTypeDefaultActiveName">
              <el-tab-pane v-for="subItem in carTypeData"
                           :key="subItem.carType"
                           :name="subItem.carType">
                <span slot="label"><i v-if="subItem.validateErrFlag" class="el-icon-warning car-error-txt"></i>{{ subItem.carTypeName }}</span>
                <warranty-penetration :ref="`warrantyForm_${subItem.carType}`"
                                      :goods-type-list="goodsTypeList"
                                      :performance-info="subItem.performanceInfo"
                                      @resetRadio="resetRadio"></warranty-penetration>
              </el-tab-pane>
            </el-tabs>
          </template>
          <!-- 社招会员权益 5月赛力斯新绩效方案 -->
          <template v-if="formData.configType == 4">
            <el-tabs v-model="seresCarTypeActiveName">
              <el-tab-pane v-for="subItem in seresCarTypeData"
                           :key="subItem.carType"
                           :name="subItem.carType">
                <span slot="label"><i v-if="subItem.validateErrFlag" class="el-icon-warning car-error-txt"></i>{{ subItem.carTypeName }}</span>
                <seres :ref="`seresForm_${subItem.carType}`"
                       :goods-type-list="goodsTypeList"
                       :performance-info="subItem.configInfo"
                       :show-other-config-flag="seresCarTypeActiveName == '1'"
                       @resetRadio="resetRadio"></seres>
              </el-tab-pane>
            </el-tabs>
          </template>
        </div>
      </div>
    </el-form>
    <div class="footer_box">
      <el-button
        :disabled="$store.state.d2admin.loading.value"
        type="primary"
        @click="handleConfirm">提交</el-button>
      <el-button class="cancel-btn"
                 @click="handleClose">取消</el-button>
    </div>
  </d2-container>
</template>
<script>
import campus from './components/campus.vue'
import social from './components/social.vue'
import warrantyPenetration from './components/warrantyPenetration.vue'
import { configPerformancePlanApi, getPerformancePlanDetailApi, getStoreLastDetailApi, deleteStoreSalaryApi } from '@api/resident'
import { deepClone } from '@/common/util'
import { getAllCategory } from '@api/product'
import { baseConfig } from '@/main'
import seres from './components/seres.vue'
export default {
  name: 'PerformanceScheme',
  components: {
    campus,
    social,
    warrantyPenetration,
    seres
  },
  data() {
    return {
      addOrEdit: '',
      formData: {},
      copyFormData: {
        hireType: '',
        sceneType: '',
        configType: '',
        schemeName: '',
        configInfo: {
          campusList: []
        }
      },
      tempHireType: '',
      tempSceneType: '',
      tempConfigType: '',
      rules: {
        hireType: [
          { required: true, message: '请选择适用招聘类型', trigger: 'change' }
        ],
        sceneType: [
          { required: true, message: '请选择所属业务', trigger: 'blur' }
        ],
        configType: [
          { required: true, message: '请选择方案类型', trigger: 'blur' }
        ]
      },
      socialConfigInfo: {},
      carTypeData: [],
      configItems: ['outputBonus', 'upgradeRateBonus'],
      defaultActiveName: '2', // 默认选中初级驻店
      carDefaultActive: 'all',
      routerQuery: {},
      carTypeDefaultActiveName: '',
      goodsTypeList: [],
      selfBuildGoodsType: baseConfig.selfBuildGoodsType || '', // 服务商自建类目值
      seresCarTypeData: [{
        carType: '1',
        carTypeName: '单问界',
        configInfo: {
          seresList: [],
          otherOptionsList: []
        }
      }, {
        carType: '3',
        carTypeName: '鸿蒙',
        configInfo: {
          seresList: [],
          otherOptionsList: []
        }
      }],
      seresCarTypeActiveName: '1'
    }
  },
  beforeRouteEnter(to, from, next) {
    if (to.query.addOrEdit == 'edit') {
      to.meta.title = '编辑绩效方案'
    } else {
      to.meta.title = '新增绩效方案'
    }
    next()
  },
  mounted() {
    const params = this.$route.query?.params && JSON.parse(this.$route.query?.params)
    this.addOrEdit = this.$route.query?.addOrEdit
    this.routerQuery = params
    // 获取车型
    this.getCarType()
  },
  methods: {
    getCarType() {
      const performanceInfo = {
        campusList: [],
        customerList: [],
        fixedList: []
      }
      let brandIds = this.routerQuery?.brandIds || []
      brandIds = brandIds?.filter(v => v != this.baseConfig.brandId) // 去除鸿蒙智行主品牌
      const hasMultipleBrands = brandIds.length > 1
      const hasSpecificBrand = brandIds.includes(this.baseConfig.childrenBrandId) // 是否包含问界子品牌
      this.copyCarTypeData = hasMultipleBrands
        ? [
          ...(hasSpecificBrand
            ? [
              { carType: '1', carTypeName: '单问界', performanceInfo }
            ]
            : []),
          { carType: '2', carTypeName: '其他车系', performanceInfo }
        ]
        : (brandIds.length === 1
          ? (hasSpecificBrand
            ? [{ carType: '1', carTypeName: '单问界', performanceInfo }]
            : [{ carType: '2', carTypeName: '其他车系', performanceInfo }])
          : [])
      // this.copyCarTypeData = [{
      //   carType: '1',
      //   carTypeName: '单问界',
      //   performanceInfo
      // }, {
      //   carType: '2',
      //   carTypeName: '其他车系',
      //   performanceInfo
      // }]
      this.carTypeDefaultActiveName = this.copyCarTypeData[0]?.carType
      // 获取三级类目数据
      getAllCategory({ categoryTypeList: this.selfBuildGoodsType, pageSize: 9999, currentPage: 1 }).then(res => {
        this.goodsTypeList = res?.list || []
        // 获取最新配置的绩效数据
        this.getLastConfig()
      })
    },
    getLastConfig() {
      this.carTypeData = deepClone(this.copyCarTypeData)
      getStoreLastDetailApi({ merchantId: this.routerQuery.merchantId }).then(res => {
        const params = {
          merchantId: this.routerQuery.merchantId,
          hireType: !this.routerQuery.hireType ? 2 : this.routerQuery.hireType, // 若该门店无配置任何内容,默认选中社会招聘
          sceneType: !this.routerQuery.sceneType ? 0 : this.routerQuery.sceneType, // 若无配置内容,默认选中会员权益
          configType: 3 // 若无配置默认选中按延保渗透率
        }
        if (!res?.length) this.getDetail(params)
        const obj = this.splitArrayByProperty(res, 'configType') // 根据绩效方案类型分组
        let data = {}
        const priorityKeys = ['3', '4', '1', '2'] // 定义优先级顺序 3延保渗透率 4:5月赛力斯新绩效方案 1社招轻改 2校招渗透率
        for (const key of priorityKeys) {
          if (obj[key]?.length) {
            // 如果度大于1,取会员权益场景作为默认选中
            data = obj[key].length > 1
              ? obj[key].find(item => item.sceneType === 0) || obj[key][0]
              : obj[key][0]
            break
          }
        }
        this.socialConfigInfo = {}
        this.setDetailInfo(data)
      })
    },
    splitArrayByProperty(arr, property) {
      return arr.reduce((acc, obj) => {
        const key = obj[property]
        if (!acc[key]) {
          acc[key] = []
        }
        acc[key].push(obj)
        return acc
      }, {})
    },
    // 个人均产值根据区间值相同合并数据
    mergeArrayObjects(arr) {
      const merged = []
      arr.forEach(item => {
        const { startValue, endValue, calculateValue, oldstartValue, oldendValue, oldcalculateValue, ...rest } = item
        const { goodsType, secondaryGoodsType, thirdLevelGoodsType } = rest || {}
        rest.productType = [goodsType, secondaryGoodsType, thirdLevelGoodsType].filter(item => item != -1 && Boolean(item))
        rest.productTypeFocus = false
        const found = merged.find(m => m.startValue === startValue && m.endValue === endValue)
        if (found) {
          // 直接将其他属性对象推入others数组
          found.others.push(rest)
          found.productConfig.push({ calculateValue: calculateValue, oldcalculateValue: oldcalculateValue })
        } else {
          // 创建新对象并初始化
          merged.push({
            startValue,
            endValue,
            oldstartValue,
            oldendValue,
            productConfig: [{ calculateValue: calculateValue, oldcalculateValue: oldcalculateValue }],
            others: [rest] // 初始化为包含当前对象的其他属性的数组
          })
        }
      })
      return merged
    },
    setDetailInfo(res, params) {
      ['hireType', 'sceneType', 'configType'].forEach(key => this.updateData(key, res, params))
      this.formData = res || deepClone(this.copyFormData)
      if (res?.configType == 2) { // 校招
        res?.configItemList?.forEach(val => {
          val.oldstartValue = val.startValue
          val.oldendValue = val.endValue
          val.oldcalculateValue = val.calculateValue
          val.oldgrCommissionRatio = val.grCommissionRatio
          val.olddsCommissionRatio = val.dsCommissionRatio
          val.oldddCommissionRatio = val.ddCommissionRatio
          val.oldjlcCommissionRatio = val.jlcCommissionRatio
        })
        this.formData.configInfo = {
          campusList: res?.configItemList || []
        }
      } else if (res?.configType == 1) { // 社招轻改
        const configInfo = this.socialConfigInfo
        res?.configItemList?.forEach(item => {
          item.oldstartValue = item.startValue
          item.oldendValue = item.endValue
          item.oldcalculateValue = item.calculateValue
          for (const item of this.configItems) {
            if (!configInfo?.[item + 'List']) configInfo[item + 'List'] = []
          }
          if (item.jobType == 2 || item.jobType == 11) {
            const performanceTypeMap = {
              2: 'outputBonusList',
              4: 'upgradeRateBonusList'
            }
            const targetList = performanceTypeMap[`${item.performanceType}`]
            if (targetList) {
              if (item.performanceType == 2) {
                configInfo[targetList].push({ ...item, productConfig: [] })
              } else configInfo[targetList].push(item)
            }
          }
        })
        // 处理个人均产值数据
        this.socialConfigInfo.outputBonusList = this.mergeArrayObjects(configInfo.outputBonusList)
        this.socialConfigInfo.productConfigList = (configInfo.outputBonusList[0]?.others) || []
      } else if (res?.configType == 3) { // 社招渗透率
        res?.configItemList?.forEach(item => {
          item.oldstartValue = item.startValue
          item.oldendValue = item.endValue
          item.oldoutputCommissionRatio = item.outputCommissionRatio
          item.oldcalculateValue = item.calculateValue
          item.oldconditionStartValue = item.conditionStartValue
          item.oldconditionEndValue = item.conditionEndValue
          if (item.conditionGoodsType || item.conditionSecondaryGoodsType || item.conditionThirdLevelGoodsType) item.conditionFlag = true
          item.selectProductType = this.pushBasedOnPriority(item.goodsType, item.secondaryGoodsType, item.thirdLevelGoodsType)
          const { goodsType, secondaryGoodsType, thirdLevelGoodsType } = item || {}
          const { conditionGoodsType, conditionSecondaryGoodsType, conditionThirdLevelGoodsType } = item || {}
          item.productType = [goodsType, secondaryGoodsType, thirdLevelGoodsType].filter(item => item != -1 && Boolean(item))
          item.conditionProductType = [conditionGoodsType, conditionSecondaryGoodsType, conditionThirdLevelGoodsType].filter(item => item != -1 && Boolean(item))
          this.carTypeData?.forEach(val => {
            if (item.configCarType == val.carType) {
              if (item.jobType == 2 || item.jobType == 11) {
                if (item.performanceType == 5) {
                  val.performanceInfo?.customerList?.push(item)
                } else if (item.performanceType == 6) {
                  val.performanceInfo?.fixedList?.push(item)
                } else {
                  val.performanceInfo?.campusList?.push(item)
                }
              }
            }
          })
        })
      } else {
        res?.configItemList?.forEach(item => {
          item.oldstartValue = item.startValue
          item.oldendValue = item.endValue
          item.oldcalculateValue = item.calculateValue
          item.oldconditionStartValue = item.conditionStartValue
          item.oldconditionEndValue = item.conditionEndValue
          item.oldoutputCommissionRatio = item.outputCommissionRatio
          item.oldconditionCalculateValue = item.conditionCalculateValue
          // 判断是否存在条件
          if (item.conditionGoodsType || item.conditionSecondaryGoodsType || item.conditionThirdLevelGoodsType || item.conditionProductDefineId ||
            (item.outputCommissionRatio && item.conditionCalculateValue)) item.conditionFlag = true
          // 按类目配置
          if (item.goodsType) {
            item.selectProductType = this.pushBasedOnPriority(item.goodsType, item.secondaryGoodsType, item.thirdLevelGoodsType)
            const { goodsType, secondaryGoodsType, thirdLevelGoodsType } = item || {}
            const { conditionGoodsType, conditionSecondaryGoodsType, conditionThirdLevelGoodsType } = item || {}
            item.productType = [goodsType, secondaryGoodsType, thirdLevelGoodsType].filter(item => item != -1 && Boolean(item))
            item.conditionProductType = [conditionGoodsType, conditionSecondaryGoodsType, conditionThirdLevelGoodsType].filter(item => item != -1 && Boolean(item))
          }
          // 按圈定产品配置
          if (item.productDefineId) {
            item.productDefineId = item.productDefineId
            item.conditionProductDefineId = item.conditionProductDefineId
          }
          item.type = item?.productDefineId ? 1 : '', // 按圈定产品或按类目
          item.termType = item?.conditionCalculateValue ? '' : 1, // 条件是按比例加固定金额还是按区间
          this.seresCarTypeData?.forEach(val => {
            if (item.configCarType == val.carType) {
              if (item.jobType == 2 || item.jobType == 11) {
                if (item.performanceType == 1) {
                  val.configInfo?.seresList?.push(item)
                } else if (item.performanceType == 7) {
                  val.configInfo?.otherOptionsList?.push(item)
                }
              }
            }
          })
        })
      }
      if (res?.schemeName) {
        this.$set(this.formData, 'schemeName', res.schemeName)
      } else {
        this.$set(this.formData, 'schemeName', this.formData.configType == 1 ? '按月度产值要求拿提成' : this.formData.configType == 2 ? '按渗透率拿提成' : this.formData.configType == 3 ? '权益延保按渗透率拿提成' : '5月赛力斯新绩效方案')
      }
      // 保留社招产值原始配置数据
      this.socialConfigItemList = this.setData(this.socialConfigInfo, 'social')
      // 保留社招渗透率原始配置数据
      this.warrantyConfigItemList = this.setData(this.carTypeData, 'warranty')
      // 保留5月赛力斯新绩效配置数据
      this.seresConfigItemList = this.setData(this.seresCarTypeData, 'seres')
      this.isShow = true
    },
    pushBasedOnPriority(a, b, c) {
      let result = ''
      if (!this.isEmpty(c)) {
        result = c
      } else if (!this.isEmpty(b)) {
        result = b
      } else if (!this.isEmpty(a)) {
        result = a
      }
      return result
    },
    // 获取详情
    getDetail(params) {
      this.isShow = false
      this.carTypeData = deepClone(this.copyCarTypeData)
      this.seresCarTypeData = [{ // 初始化数据
        carType: '1',
        carTypeName: '单问界',
        configInfo: {
          seresList: [],
          otherOptionsList: []
        }
      }, {
        carType: '3',
        carTypeName: '鸿蒙',
        configInfo: {
          seresList: [],
          otherOptionsList: []
        }
      }]
      getPerformancePlanDetailApi(params).then(res => {
        this.socialConfigInfo = {}
        this.setDetailInfo(res, params)
      })
    },
    updateData(key, res, params) {
      if (!res) this[`temp${key.charAt(0).toUpperCase() + key.slice(1)}`] = params[key]
      const value = res?.[key]
      if (!this.isEmpty(value)) {
        this[`temp${key.charAt(0).toUpperCase() + key.slice(1)}`] = value
        this.$set(this.copyFormData, key, value)
      } else {
        this.$set(this.copyFormData, key, this[`temp${key.charAt(0).toUpperCase() + key.slice(1)}`])
      }
    },
    isEmpty(data) {
      return (data ?? '') === ''
    },
    compareArrays(arr1, arr2, keys) {
      const getValues = (arr, keys) => {
        return arr.map(obj => keys.map(key => obj[key]))
      }
      const values1 = getValues(arr1, keys)
      const values2 = getValues(arr2, keys)
      if (values1.length !== values2.length) {
        return true // 长度不同,认为有变化
      }
      return values1.some((valueArray, index) => {
        return valueArray.some((value, i) => {
          const valueToCompare = values2[index][i]
          // 处理空字符串与 null/undefined 的比较
          if ((value == "" && (valueToCompare == null || valueToCompare == undefined)) ||
              (valueToCompare == "" && (value == null || value == undefined))) {
            return false
          }
          return value != valueToCompare
        })
      })
    },
    async changePerformance(value, key, oldkey) {
      // 获取绩效配置数据
      let [result, changeFlag, configItemList] = [null, false, []]
      if (this.formData.hireType == 1) { // 校招
        result = await this.$refs.configForm.getFormData()
        configItemList = this.setData(result, 'campus')
        const fields = ['jobType', 'startValue', 'endValue', 'calculateValue', 'grCommissionRatio', 'grCommissionRatio', 'ddCommissionRatio', 'jlcCommissionRatio']
        changeFlag = this.compareArrays(configItemList, this.formData.configInfo?.campusList, fields)
      } else if (this.formData.hireType == 2) { // 社招
        if (this.formData.configType == 1) { // 按月度产值要求拿提成
          const node = this.$refs.perConfigForm_ && this.$refs.perConfigForm_
          if (node?.getFormData) {
            result = await node.getFormData()
            this.socialConfigInfo = result
          }
          configItemList = this.setData(this.socialConfigInfo, 'social')
          const fields = ['jobType', 'performanceType', 'startValue', 'endValue', 'calculateValue', 'goodsType', 'secondaryGoodsType', 'thirdLevelGoodsType']
          changeFlag = this.compareArrays(configItemList, this.socialConfigItemList, fields)
        } else if (this.formData.configType == 3) { // 按延保权益渗透率
          for (var j = 0; j < this.carTypeData?.length; j++) {
            const subVal = this.carTypeData[j]
            const node = this.$refs[`warrantyForm_${subVal.carType}`] && this.$refs[`warrantyForm_${subVal.carType}`][0]
            if (node?.getFormData) {
              result = await node.getFormData()
              this.$set(this.carTypeData[j], 'performanceInfo', result)
            }
          }
          configItemList = this.setData(this.carTypeData, 'warranty')
          const fields = ['configCarType', 'performanceType', 'goodsType', 'secondaryGoodsType', 'thirdLevelGoodsType', 'startValue', 'endValue', 'outputCommissionRatio', 'calculateValue', 'conditionGoodsType', 'conditionSecondaryGoodsType', 'conditionThirdLevelGoodsType', 'conditionStartValue', 'conditionEndValue']
          changeFlag = this.compareArrays(configItemList, this.warrantyConfigItemList, fields)
        } else { // 5月赛力斯新绩效配置
          for (var j = 0; j < this.seresCarTypeData?.length; j++) {
            const subVal = this.seresCarTypeData[j]
            const node = this.$refs[`seresForm_${subVal.carType}`] && this.$refs[`seresForm_${subVal.carType}`][0]
            if (node?.getFormData) {
              result = await node.getFormData()
              this.$set(this.seresCarTypeData[j], 'configInfo', result)
            }
          }
          configItemList = this.setData(this.seresCarTypeData, 'seres')
          const fields = ['configCarType', 'performanceType', 'goodsType', 'secondaryGoodsType', 'thirdLevelGoodsType', 'productDefineId', 'startValue', 'endValue',
            'calculateValue', 'conditionGoodsType', 'conditionSecondaryGoodsType', 'conditionThirdLevelGoodsType', 'conditionProductDefineId', 'conditionStartValue', 'conditionEndValue',
            'outputCommissionRatio', 'conditionCalculateValue'
          ]
          changeFlag = this.compareArrays(configItemList, this.seresConfigItemList, fields)
        }
      }
      if (changeFlag) {
        try {
          await this.$confirm(
            '请保存当前绩效配置',
            '提示',
            {
              confirmButtonText: '保存',
              type: 'warning'
            }
          )
          this.handleConfirm(value, key, oldkey)
        } catch {
          this.resetRadio(key, oldkey)
        }
      } else {
        this.setRadio(value, key, oldkey)
      }
    },
    // 修改radio的值
    setRadio(value, key, oldkey) {
      this.formData[key] = value
      this[oldkey] = value
      // configType 1:按月度产值要求拿提成,2:按渗透率拿提成,3:权益延保按渗透率拿提成
      if (this.formData.hireType == 1) { // 切换到校招默认按渗透率拿提成
        this.formData.configType = 2
        this.tempConfigType = 2
        this.formData.carType = []
      }
      if (this.formData.hireType == 2 && this.formData.sceneType == 0 && (key != 'configType' && value != 1)) { // 切换到社招会员权益默认选中按渗透率拿提成
        this.formData.configType = 3
        this.tempConfigType = 3
      }
      if (this.formData.hireType == 2 && this.formData.sceneType == 1) { // 切换到社招轻改默认选中按月度产值要求拿提成
        this.formData.configType = 1
        this.tempConfigType = 1
        this.formData.carType = []
      }
      const params = this.getParams()
      this.getDetail(params)
    },
    // 重置radio值
    resetRadio(key, oldkey) {
      this.$nextTick(() => {
        this[oldkey] = this.formData[key]
      })
    },
    getParams() {
      return {
        merchantId: this.routerQuery.merchantId,
        sceneType: this.formData.sceneType,
        hireType: this.formData.hireType,
        configType: this.formData.configType
      }
    },
    // 处理数据
    setData(res, type) {
      if (type == 'campus') { // 校招
        return res?.campusList.map(v => ({
          jobType: v.jobType,
          performanceType: 1, // 绩效类型(1:渗透率,2:高产值,3:成交率,4:均客单,5:售后提成)
          startValue: v.startValue,
          endValue: v.endValue,
          calculateValue: v.calculateValue,
          grCommissionRatio: v.grCommissionRatio,
          dsCommissionRatio: v.dsCommissionRatio,
          ddCommissionRatio: v.ddCommissionRatio,
          jlcCommissionRatio: v.jlcCommissionRatio
        }))
      } else if (type == 'social') { // 社招
        const configItemList = []
        const addConfigItems = (items, performanceType) => {
          items?.forEach(v => {
            // 组合选择产品数据
            if (performanceType == 2) {
              res?.productConfigList?.forEach((val, index) => {
                configItemList.push({
                  jobType: 11,
                  performanceType: performanceType,
                  startValue: v.startValue,
                  endValue: v.endValue,
                  calculateValue: v?.productConfig[index]?.calculateValue,
                  goodsType: val.goodsType,
                  goodsTypeName: val.goodsTypeName,
                  secondaryGoodsType: val.secondaryGoodsType,
                  secondaryGoodsTypeName: val.secondaryGoodsTypeName,
                  thirdLevelGoodsType: val.thirdLevelGoodsType,
                  thirdLevelGoodsTypeName: val.thirdLevelGoodsTypeName
                })
              })
            } else {
              configItemList.push({
                jobType: 11,
                performanceType: performanceType, // 绩效类型(1:渗透率,2:高产值,3:成交率,4:均客单,5:售后提成)
                startValue: v.startValue,
                endValue: v.endValue,
                calculateValue: v.calculateValue
              })
            }
          })
        }
        addConfigItems(res?.outputBonusList, 2)
        addConfigItems(res?.upgradeRateBonusList, 4)
        return configItemList
      } else if (type == 'warranty') {
        const configItemList = []
        // 先处理渗透率
        res?.forEach(item => {
          item?.performanceInfo?.campusList?.forEach(v => {
            const conditionFields = v.conditionFlag
              ? {
                conditionGoodsType: v.conditionGoodsType,
                conditionGoodsTypeName: v.conditionGoodsTypeName,
                conditionSecondaryGoodsType: v.conditionSecondaryGoodsType,
                conditionSecondaryGoodsTypeName: v.conditionSecondaryGoodsTypeName,
                conditionThirdLevelGoodsType: v.conditionThirdLevelGoodsType,
                conditionThirdLevelGoodsTypeName: v.conditionThirdLevelGoodsTypeName,
                conditionStartValue: v.conditionStartValue,
                conditionEndValue: v.conditionEndValue
              }
              : {
                conditionGoodsType: '',
                conditionGoodsTypeName: '',
                conditionSecondaryGoodsType: '',
                conditionSecondaryGoodsTypeName: '',
                conditionThirdLevelGoodsType: '',
                conditionThirdLevelGoodsTypeName: '',
                conditionStartValue: '',
                conditionEndValue: ''
              }
            configItemList.push({
              jobType: 11,
              configCarType: item.carType,
              performanceType: 1, // 绩效类型(1:渗透率,2:高产值,3:成交率,4:均客单,5:售后提成)
              goodsType: v.goodsType,
              goodsTypeName: v.goodsTypeName,
              secondaryGoodsType: v.secondaryGoodsType,
              secondaryGoodsTypeName: v.secondaryGoodsTypeName,
              thirdLevelGoodsType: v.thirdLevelGoodsType,
              thirdLevelGoodsTypeName: v.thirdLevelGoodsTypeName,
              startValue: v.startValue,
              endValue: v.endValue,
              outputCommissionRatio: v.outputCommissionRatio,
              calculateValue: v.calculateValue,
              ...conditionFields
            })
          })
        })
        // 处理固定提成
        res?.forEach(item => {
          item?.performanceInfo?.fixedList?.forEach(v => {
            configItemList.push({
              jobType: 11,
              configCarType: item.carType,
              goodsType: v.goodsType,
              goodsTypeName: v.goodsTypeName,
              secondaryGoodsType: v.secondaryGoodsType,
              secondaryGoodsTypeName: v.secondaryGoodsTypeName,
              thirdLevelGoodsType: v.thirdLevelGoodsType,
              thirdLevelGoodsTypeName: v.thirdLevelGoodsTypeName,
              performanceType: 6, // 绩效类型(1:渗透率,2:高产值,3:成交率,4:均客单,5:售后提成,6:固定提成)
              startValue: v.startValue,
              endValue: v.endValue,
              calculateValue: v.calculateValue
            })
          })
        })
        // 再处理售后(为保证与后端数据顺序相同)
        res?.forEach(item => {
          item?.performanceInfo?.customerList?.forEach(v => {
            configItemList.push({
              jobType: 11,
              configCarType: item.carType,
              goodsType: v.goodsType,
              goodsTypeName: v.goodsTypeName,
              secondaryGoodsType: v.secondaryGoodsType,
              secondaryGoodsTypeName: v.secondaryGoodsTypeName,
              thirdLevelGoodsType: v.thirdLevelGoodsType,
              thirdLevelGoodsTypeName: v.thirdLevelGoodsTypeName,
              performanceType: 5, // 绩效类型(1:渗透率,2:高产值,3:成交率,4:均客单,5:售后提成)
              startValue: v.startValue,
              endValue: v.endValue,
              calculateValue: v.calculateValue
            })
          })
        })
        return configItemList
      } else { // 5月赛力斯新绩效方案
        const configItemList = []
        // 处理绩效配置
        res?.forEach(item => {
          item.configInfo?.seresList?.forEach(v => {
            const conditionFields = v.conditionFlag
              ? {
                conditionGoodsType: v.conditionGoodsType,
                conditionGoodsTypeName: v.conditionGoodsTypeName,
                conditionSecondaryGoodsType: v.conditionSecondaryGoodsType,
                conditionSecondaryGoodsTypeName: v.conditionSecondaryGoodsTypeName,
                conditionThirdLevelGoodsType: v.conditionThirdLevelGoodsType,
                conditionThirdLevelGoodsTypeName: v.conditionThirdLevelGoodsTypeName,
                conditionProductDefineId: v.conditionProductDefineId,
                conditionStartValue: v.conditionStartValue,
                conditionEndValue: v.conditionEndValue,
                outputCommissionRatio: v.outputCommissionRatio,
                conditionCalculateValue: v.conditionCalculateValue
              }
              : {
                conditionGoodsType: '',
                conditionGoodsTypeName: '',
                conditionSecondaryGoodsType: '',
                conditionSecondaryGoodsTypeName: '',
                conditionThirdLevelGoodsType: '',
                conditionThirdLevelGoodsTypeName: '',
                conditionProductDefineId: '',
                conditionStartValue: '',
                conditionEndValue: '',
                outputCommissionRatio: '',
                conditionCalculateValue: ''
              }
            configItemList.push({
              jobType: 11,
              configCarType: item.carType,
              performanceType: 1, // 绩效类型(1:渗透率,2:高产值,3:成交率,4:均客单,5:售后提成)
              goodsType: v.goodsType,
              goodsTypeName: v.goodsTypeName,
              secondaryGoodsType: v.secondaryGoodsType,
              secondaryGoodsTypeName: v.secondaryGoodsTypeName,
              thirdLevelGoodsType: v.thirdLevelGoodsType,
              thirdLevelGoodsTypeName: v.thirdLevelGoodsTypeName,
              productDefineId: v.productDefineId,
              productDefineName: v.productDefineName,
              startValue: v.startValue,
              endValue: v.endValue,
              calculateValue: v.calculateValue,
              ...conditionFields
            })
          })
        })
        // 处理其他附属配置
        res?.forEach(item => {
          item?.configInfo?.otherOptionsList?.forEach(v => {
            configItemList.push({
              jobType: 11,
              configCarType: item.carType,
              performanceType: 7,
              startValue: v.startValue,
              endValue: v.endValue,
              calculateValue: v.calculateValue
            })
          })
        })
        return configItemList
      }
    },
    // 清空配置相当于删除当前的绩效方案
    clearConfig() {
      this.$confirm('是否确定清空当前绩效配置方案,清空后无法回退。', '提示', {
        confirmButtonText: '确定',
        type: 'warning'
      }).then(() => {
        const params = this.getParams()
        // 有id后端已保存配置,调接口删除
        if (this.formData.id) {
          deleteStoreSalaryApi({ id: this.formData.id }).then(res => {
            // this.getDetail(params)
            // 返回到列表页
            this.$router.go(-1)
          })
        } else {
          // 获取当前绩效配置,清空数据
          // this.getDetail(params)
          // 返回到列表页
          this.$router.go(-1)
        }
      }).catch(() => {
      })
    },
    handleConfirm(value, key, oldkey) {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          Promise.all([this.checkPerConfig(key, oldkey)]).then((res) => {
            let configItemList = []
            // 社会招聘
            if (this.formData.configType == 1) { // 社招按产值
              const isArrayEmpty = !res[0]?.outputBonusList?.length || !res[0]?.productConfigList?.length
              if (isArrayEmpty) {
                this.resetRadio(key, oldkey)
                return this.$message.warning('请配置个人月均产值提成')
              }
              configItemList = this.setData(res[0], 'social')
            } else if (this.formData.configType == 2) { // 校招
              configItemList = this.setData(res[0], 'campus')
            } else if (this.formData.configType == 3) { // 社招按渗透率
              const arr = []
              this.carTypeData?.forEach(item => {
                const item2 = item.performanceInfo
                if (item2?.campusList?.length || item2?.customerList?.length || item2?.fixedList?.length) arr.push(item2)
              })
              if (!arr.length) {
                this.resetRadio(key, oldkey)
                return this.$message.warning('请配置绩效数据')
              }
              configItemList = this.setData(res[0], 'warranty')
            } else { // 5月赛力斯新绩效方案
              const arr = []
              this.seresCarTypeData?.forEach(item => {
                const item2 = item.configInfo
                if (item2.seresList?.length) arr.push(item2)
              })
              if (!arr.length) {
                this.resetRadio(key, oldkey)
                return this.$message.warning('请配置绩效数据')
              }
              configItemList = this.setData(res[0], 'seres')
            }
            const params = {
              id: this.addOrEdit == 'edit' ? this.formData.id : '',
              merchantId: this.routerQuery.merchantId,
              hireType: this.formData.hireType,
              sceneType: this.formData.sceneType,
              configType: this.formData.configType,
              schemeName: this.formData.schemeName
                ? this.formData.schemeName
                : this.formData.configType == 1 ? '按月度产值要求拿提成' : this.formData.configType == 2 ? '按渗透率拿提成' : this.formData.configType == 3 ? '权益延保按渗透率拿提成' : '5月赛力斯新绩效方案',
              configItemList
            }
            configPerformancePlanApi(params).then(res => {
              this.notice.okTips()
              if (oldkey) {
                return this.setRadio(value, key, oldkey)
              }
              this.$router.go(-1)
            }).catch(err => {
              this.resetRadio(key, oldkey)
            })
          })
        } else {
          this.$nextTick(() => {
            this[oldkey] = this.formData[key]
          })
        }
      })
    },
    // 校验绩效方案配置
    checkPerConfig(key, oldkey) {
      return new Promise(async (resolve, reject) => {
        let valideRes
        if (this.formData.configType == 2) { // 校招
          valideRes = await this.$refs.configForm.validateCustomForm()
          if (valideRes == 'error') {
            this.resetRadio(key, oldkey)
            reject()
          } else {
            resolve(valideRes)
          }
        } else if (this.formData.configType == 1) { // 社招按产值
          const node = this.$refs.perConfigForm_
          if (node?.validateCustomForm) {
            valideRes = await node.validateCustomForm()
            if ((typeof valideRes == 'string') && valideRes.includes('error')) {
              this.resetRadio(key, oldkey)
              reject()
              let message = ''
              switch (valideRes) {
                case 'error1':
                  message = '产值区间重复'
                  break
                case 'error2':
                  message = '请完整配置个人月均产值提成'
                  break
                case 'error3':
                  message = '请选择个人月均产值提成产品'
                  break
              }
              if (message) return this.$message.warning(message)
            } else {
              this.socialConfigInfo = valideRes
            }
          }
          resolve(this.socialConfigInfo)
        } else if (this.formData.configType == 3) { // 社招按渗透率
          // 校验前,将tab的错误提示清除 单独循环处理,下一个循环是一个tab一个tab校验,会跳出循环
          for (var j = 0; j < this.carTypeData?.length; j++) {
            this.$set(this.carTypeData[j], 'validateErrFlag', false)
          }
          for (var j = 0; j < this.carTypeData?.length; j++) {
            const subVal = this.carTypeData[j]
            const node = this.$refs[`warrantyForm_${subVal.carType}`] && this.$refs[`warrantyForm_${subVal.carType}`][0]
            if (node?.validateCustomForm) {
              valideRes = await node.validateCustomForm(key, oldkey)
              if (valideRes == 'error') {
                this.$set(this.carTypeData[j], 'validateErrFlag', true)
                this.resetRadio(key, oldkey)
                reject()
              } else {
                this.$set(this.carTypeData[j], 'performanceInfo', valideRes)
                this.$set(this.carTypeData[j], 'validateErrFlag', false)
              }
            }
          }
          resolve(this.carTypeData)
        } else { // 5月赛力斯新绩效方案
          // 校验前,将tab的错误提示清除 单独循环处理,下一个循环是一个tab一个tab校验,会跳出循环
          for (var j = 0; j < this.seresCarTypeData?.length; j++) {
            this.$set(this.seresCarTypeData[j], 'validateErrFlag', false)
          }
          for (var j = 0; j < this.seresCarTypeData?.length; j++) {
            const subVal = this.seresCarTypeData[j]
            const node = this.$refs[`seresForm_${subVal.carType}`] && this.$refs[`seresForm_${subVal.carType}`][0]
            if (node?.validateCustomForm) {
              valideRes = await node.validateCustomForm(key, oldkey)
              if (valideRes == 'error') {
                this.$set(this.seresCarTypeData[j], 'validateErrFlag', true)
                this.resetRadio(key, oldkey)
                reject()
              } else {
                this.$set(this.seresCarTypeData[j], 'configInfo', valideRes)
                this.$set(this.seresCarTypeData[j], 'validateErrFlag', false)
              }
            }
          }
          resolve(this.seresCarTypeData)
        }
      })
    },
    handleClose() {
      this.$router.go(-1)
    }
  }
}
</script>
<style lang="scss" scoped>
.performanceScheme{
  .warp_box{
    background: #fff;
    margin-bottom: 16px;
    position: relative;
    .title {
      height: 50px;
      line-height: 50px;
      padding: 0 20px;
      border-bottom: 1px solid #e5e5e5;
      font-size: 16px;
      font-weight: 600;
      color: #333333;
      display: flex;
      align-items: center;
      margin-bottom: 16px;
      .line {
        width: 4px;
        height: 16px;
        background: #185efe;
        border-radius: 2px;
        margin-right: 8px;
      }
      .title-wrap {
        display: flex;
        align-items: center;
      }
      .merchant-text {
        font-size: 14px;
        font-weight: normal;
        color: #666666;
      }
    }
    .space-b{
      justify-content: space-between;
    }
    ::v-deep .el-form-item__label{
      padding: 0;
    }
  }
  .warp_content{
    padding: 0 20px 20px;
    .add_btn{
      margin-top: 10px;
    }
    .goods_content{
      width: 432px;
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
      border: 1px solid #E6E6E6;
      padding: 4px;
      border-radius: 3px;
      .goods_item{
        display: inline-block;
        background: #FAFBFE;
        border: 1px solid #E8E8EA;
        border-radius: 4px;
        height: 20px;
        line-height: 20px;
        padding: 3px 8px;
        font-size: 14px;
        color: #666666;
        .del_btn{
          margin-left: 4px;
          cursor: pointer;
        }
      }
    }
  }
  .footer_box {
    text-align: center;
  }
  ::v-deep input[aria-hidden="true"] {
    display: none;
  }
  ::v-deep .el-radio:focus:not(.is-focus):not(:active):not(.is-disabled) .el-radio__inner {
    box-shadow: none !important;
  }
  .custom-tabs {
    ::v-deep .el-tabs__header {
      border-bottom: none;
    }
    ::v-deep .el-tabs__nav {
      border-radius: 4px;
      border: 1px solid #DCDFE6;
      height: 36px;
      overflow: hidden;
    }
    ::v-deep .el-tabs__item {
      height: 36px;
      line-height: 36px;
    }
    ::v-deep .el-tabs__item.is-active {
      background-color: #2A58AD;
      color: #ffffff;
    }
    ::v-deep .el-tabs__item:hover {
      color: #2A58AD;
    }
    ::v-deep .el-tabs__item.is-active:hover {
      color: #ffffff;
    }
  }
}
::v-deep #configType {
  .el-form-item__label:before {
    content: '*';
    color: #F56C6C;
    margin-right: 4px;
  }
}
.copy_btn{
  position: absolute;
  transform: translate(0, -55px);
  right: 0;
  z-index: 2;
}
::v-deep .el-tabs__content{
  overflow: visible;
}
</style>