stepOne.vue 37.1 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
/* eslint-disable no-useless-escape */
<!-- 1 - 分账比例设置 -->
<template>
  <div>
    <p class="edit-sub-title">
      分账比例设置
    </p>
    <div class="account-card-block">
      <p class="card-title">
        <span>导流方分润计算<span class="blue" style="font-weight: normal;">(仅针对POS机收款订单)</span>:</span>
        <el-radio-group v-model="accountSetForm.shop4sDeductChargeFlag">
          <el-radio :label="'Y'">
            扣除手续费(按0.6%的标准)
          </el-radio>
          <el-radio :label="'N'">
            不扣除手续费
          </el-radio>
        </el-radio-group>
      </p>
    </div>
    <div class="account-card-block">
      <p class="card-title">
        <span>导流方分润</span>
        <!-- <span class="title-target-obj">{{form.merchantName}}</span> -->
        <!-- <span>(商户号:{{form.merchantId}})</span> -->
        <span style="float: right; margin-top: -8px;">
          <!-- <span
                style="margin-right: 30px;">类型:{{baseData[form.channelType === 2 ? 'ghUserType' : 'userType'][form.userType]}}</span> -->
          <el-button type="text"
                     @click="handleSetEdit('isFirstSetEdit', 'accountValiteForm', 'accountSetForm', 'accountSecondSetForm', 'accountSecondSetStruct')">
            {{ isFirstSetEdit ? '完成' : '编辑' }}</el-button>
        </span>
      </p>
      <el-form :inline="true" :model="accountSetForm" ref="accountValiteForm">
        <p class="account-content p-l-30" v-for="(item, index) in accountSetForm.list" :key="index">
          <el-form-item :prop="'list.' + index + '.goodsType'"
                        :rules="{ required: true, message: '请选择特殊分账品类', trigger: 'change' }">
            <span class="tips-block" slot="label">
              <span class="tips-label">{{ item.goodsTypeName === '全部' ? '分账品类' : '特殊分账品类' }}</span>
              <el-tooltip popper-class="tooltip-class" effect="dark" content="根据商品所需类目进行分账" placement="top">
                <span class="tips-icon" />
              </el-tooltip>:
            </span>
            <el-select v-show="isFirstSetEdit && index !== 0" size="small" v-model="item.goodsType"
                       @change="handleSelectChange($event, index, 'accountSetForm')">
              <el-option v-for="(subItem, subIndex) in baseData.productTypeList" :key="subIndex"
                         :label="subItem.goodsTypeName" :value="subItem.goodsType"
                         :disabled="accountSetForm.list.filter(k => k.goodsType !== item.goodsType).map(i => i.goodsType).includes(subItem.goodsType)" />
            </el-select>
            <span v-show="!isFirstSetEdit || index === 0">{{ item.goodsTypeName }}<span class="blue">{{ item.goodsTypeName
              === '全部' ? '(不包含特殊分账品类)' : '' }}</span></span>
          </el-form-item>
          <el-form-item :prop="'list.' + index + '.merchantSettleType'"
                        :rules="{ required: true, message: '请选择分账模式', trigger: 'change' }">
            <span class="tips-block" slot="label">
              <span class="tips-label">分账模式</span>
              <el-tooltip popper-class="tooltip-class" effect="dark" content="收入分润根据用户支付款项分账,毛利分润指根据产品所得毛利分账"
                          placement="top">
                <span class="tips-icon" />
              </el-tooltip>:
            </span>
            <el-select v-show="isFirstSetEdit" size="small" v-model="item.merchantSettleType">
              <el-option v-for="(subItem, subIndex) in merchantSettleTypeList" :key="subIndex" :label="subItem.confLabel"
                         :value="subItem.confId" />
            </el-select>
            <span v-if="!isFirstSetEdit && item.merchantSettleType">{{ merchantSettleTypeList.find(i => i.confId ===
              item.merchantSettleType).confLabel }}</span>
            <span class="car-error-txt" v-show="!isFirstSetEdit && !item.merchantSettleType">未设置</span>
          </el-form-item>
          <el-form-item :prop="'list.' + index + '.merchantProfitValue'"
                        :rules="[{ required: true, message: '请输入分润比例', trigger: 'change' }, { pattern: /^(\d|[1-9]\d)(\.\d{1,2})?$/, message: '请输入小于100的正整数或两位小数', trigger: ['blur', 'change'] }]">
            <span class="tips-block" slot="label">
              <span class="tips-label">分润比例设定</span>
              <el-tooltip popper-class="tooltip-class" effect="dark" content="账目金额将根据配置的比例计算" placement="top">
                <span class="tips-icon" />
              </el-tooltip>:
            </span>
            <el-input size="small" v-show="isFirstSetEdit" @blur="merchantProfitBlur(item)"
                      @input="mosHandleInput($event, 'merchantProfitValue', index, 1)" v-model="item.merchantProfitValue">
              <i slot="suffix" class="suffix">%</i>
            </el-input>
            <span v-show="!isFirstSetEdit && item.merchantProfitValue">{{ item.merchantProfitValue + '%' }}</span>
            <span class="car-error-txt" v-show="!isFirstSetEdit && !item.merchantProfitValue">未设置</span>
          </el-form-item>
          <el-form-item v-if="isFirstSetEdit && index !== 0" style="width: 3%;">
            <el-button type="text" icon="el-icon-delete" @click="handleAccountDelete('accountSetForm', item, index)" />
          </el-form-item>
        </p>
        <el-form-item class="p-l-30" v-if="isFirstSetEdit" style="width: 63%;">
          <el-button size="small" type="primary"
                     @click="handleAccountAdd('accountSetForm', 'accountValiteForm', 'accountSetStruct')">
            +新增特殊分账品类
          </el-button>
        </el-form-item>
        <el-form-item v-if="!isFirstSetEdit" class="p-l-30 el-item targetObj">
          <span class="title-target-obj">目标分账对象:</span>
          <span>{{ form.merchantName }}(商户号:{{ form.merchantId }})</span>
        </el-form-item>
      </el-form>
    </div>

    <!-- 服务商 -->
    <div v-if="form.partnerMerchants">
      <div class="account-card-block">
        <p class="card-title">
          <span>服务商分润计算<span class="blue" style="font-weight: normal;">(仅针对POS机收款订单)</span>:</span>
          <el-radio-group v-model="accountSetForm.partnerDeductChargeFlag">
            <el-radio :label="'Y'">
              扣除手续费(按0.6%的标准)
            </el-radio>
            <el-radio :label="'N'">
              不扣除手续费
            </el-radio>
          </el-radio-group>
        </p>
      </div>
      <!-- v-if="form.parentMerchantName" -->
      <div class="account-card-block">
        <p class="card-title">
          <span>服务商分润</span>
          <!-- <span>目标分账对象:</span> -->
          <!-- <span class="title-target-obj">{{form.parentMerchantName}}</span> -->
          <!-- <span>(商户号:{{form.parentMerchantId}})</span> -->
          <span style="float: right; margin-top: -8px;">
            <!-- <span style="margin-right: 30px;">类型:服务商</span> -->
            <el-button type="text"
                       @click="handleSetEdit('isSecondSetEdit', 'accountSecondValiteForm', 'accountSecondSetForm', 'accountSetForm', 'accountSetStruct')">
              {{ isSecondSetEdit ? '完成' : '编辑' }}</el-button>
          </span>
        </p>
        <el-form :inline="true" :model="accountSecondSetForm" ref="accountSecondValiteForm">
          <p class="account-content p-l-30" v-for="(item, index) in accountSecondSetForm.list" :key="index">
            <el-form-item :prop="'list.' + index + '.goodsType'"
                          :rules="{ required: true, message: '请选择特殊分账品类', trigger: 'change' }">
              <span class="tips-block" slot="label">
                <span class="tips-label">{{ item.goodsTypeName === '全部' ? '分账品类' : '特殊分账品类' }}</span>
                <el-tooltip popper-class="tooltip-class" effect="dark" content="根据商品所需类目进行分账" placement="top">
                  <span class="tips-icon" />
                </el-tooltip>:
              </span>
              <el-select v-show="isSecondSetEdit && index !== 0" size="small" v-model="item.goodsType"
                         @change="handleSelectChange($event, index, 'accountSecondSetForm')">
                <el-option v-for="(subItem, subIndex) in baseData.productTypeList" :key="subIndex"
                           :label="subItem.goodsTypeName" :value="subItem.goodsType"
                           :disabled="accountSecondSetForm.list.filter(k => k.goodsType !== item.goodsType).map(i => i.goodsType).includes(subItem.goodsType)" />
              </el-select>
              <span v-show="!isSecondSetEdit || index === 0">{{ item.goodsTypeName }}<span class="blue">{{
                item.goodsTypeName === '全部' ? '(不包含特殊分账品类)' : '' }}</span></span>
            </el-form-item>
            <el-form-item :prop="'list.' + index + '.partnerProfitPer'"
                          :rules="[{ required: true, message: '请输入分润比例', trigger: 'change' }, { pattern: /^(\d|[1-9]\d)(\.\d{1,2})?$/, message: '请输入小于100的正整数或两位小数', trigger: ['blur', 'change'] }]">
              <span class="tips-block" slot="label">
                <span class="tips-label">分润比例设定</span>
                <el-tooltip popper-class="tooltip-class" effect="dark" content="账目金额将根据配置的比例计算" placement="top">
                  <span class="tips-icon" />
                </el-tooltip>:
              </span>
              <el-input size="small" v-show="isSecondSetEdit" @blur="merchantProfitBlur(item)"
                        @input="mosHandleInput($event, 'partnerProfitPer', index, 2)" v-model="item.partnerProfitPer">
                <i slot="suffix" class="suffix">%</i>
              </el-input>
              <span v-show="!isSecondSetEdit && item.partnerProfitPer">{{ item.partnerProfitPer + '%' }}</span>
              <span class="car-error-txt" v-show="!isSecondSetEdit && !item.partnerProfitPer">未设置</span>
            </el-form-item>
            <el-form-item v-if="isSecondSetEdit && index !== 0" style="width: 3%;">
              <el-button type="text" icon="el-icon-delete"
                         @click="handleAccountDelete('accountSecondSetForm', item, index)" />
            </el-form-item>
          </p>
          <el-form-item v-if="isSecondSetEdit" class="p-l-30" style="width: 63%;">
            <el-button size="small" type="primary"
                       @click="handleAccountAdd('accountSecondSetForm', 'accountSecondValiteForm', 'accountSecondSetStruct')">
              +新增特殊分账品类
            </el-button>
          </el-form-item>

          <el-form-item class="p-l-30 el-item" prop="partnerSettleAccountModel"
                        :rules="[{ required: true, message: '请勾选分润模式', trigger: 'change' }]">
            <span class="tips-block " slot="label">
              <span class="tips-label">分润模式</span>
              <el-tooltip popper-class="tooltip-class" effect="dark" content="可选单个或多个服务分润" placement="top">
                <span class="tips-icon" />
              </el-tooltip>:
            </span>
            <el-radio-group v-show="isSecondSetEdit" v-model="accountSecondSetForm.partnerSettleAccountModel">
              <el-radio :label="1">
                单方分润
              </el-radio>
              <el-radio :label="2">
                多方分润
              </el-radio>
            </el-radio-group>
            <span v-show="!isSecondSetEdit && accountSecondSetForm.partnerSettleAccountModel">{{
              accountSecondSetForm.partnerSettleAccountModel == 1 ? '单方分润' : '多方分润' }}</span>
            <span class="car-error-txt" style="width:200px"
                  v-show="!isSecondSetEdit && !accountSecondSetForm.partnerSettleAccountModel">未设置</span>
          </el-form-item>

          <!-- 单服务商 -->
          <div v-if="isNoMultiserver == 1 && isSecondSetEdit">
            <el-form-item class="p-l-30 el-item" prop="singlePartnerMerchantId"
                          :rules="[{ required: true, message: '请选择分账对象', trigger: 'change' }, { required: true, message: '请选择分账对象', trigger: 'blur' }]">
              <span class="tips-block " slot="label">
                <span class="tips-label">分账对象</span>
                <el-tooltip popper-class="tooltip-class" effect="dark" content="" placement="top">
                  <span class="tips-icon" />
                </el-tooltip>:
              </span>
              <el-select v-model="accountSecondSetForm.singlePartnerMerchantId" placeholder="请选择服务商">
                <el-option v-for="item in form.partnerMerchants" :key="item.merchantId" :value="item.merchantId"
                           :label="item.merchantName" />
              </el-select>
            </el-form-item>
          </div>

          <!-- 多服务商 -->
          <div v-if="isNoMultiserver == 2">
            <el-form-item class="p-l-30 el-item" prop="installCostValue"
                          :rules="[{ required: true, message: '请输入安装费用', trigger: 'change' }]">
              <span class="tips-block " slot="label">
                <span class="tips-label">安装费用</span>
                <el-tooltip popper-class="tooltip-class" effect="dark" content="商品安装费用" placement="top">
                  <span class="tips-icon" />
                </el-tooltip>:
              </span>
              <div v-if="isSecondSetEdit">
                <el-select class="m-r-15" v-model="accountSecondSetForm.installCostCalculateType"
                           @change="changeSelectLabel(1)" placeholder="请选择分账方式">
                  <el-option v-for="item in installCostCalculateTypeOptions" :key="item.id" :value="item.id"
                             :label="item.label" />
                </el-select>
                <el-select class="m-r-15" v-if="accountSecondSetForm.installCostCalculateType == 2"
                           v-model="accountSecondSetForm.installCostSettleType" placeholder="请选择订单计提方式">
                  <el-option v-for="item in calculationBaseOptions" :key="item.value" :value="item.value"
                             :label="item.label" />
                </el-select>
                <el-input v-model="accountSecondSetForm.installCostValue"
                          @input="handleInput($event, 'installCostValue', accountSecondSetForm.installCostCalculateType)"
                          style="width:150px" :placeholder="accountSecondSetForm.installCostCalculateType == 1 ? '请输入固定金额' : '请输入比例'">
                  <i slot="suffix" v-if="accountSecondSetForm.installCostCalculateType == 2" class="suffix">%</i>
                </el-input>
              </div>

              <span v-if="!isSecondSetEdit">
                <span>{{ accountSecondSetForm.installCostCalculateType |
                  filterCostLabel(accountSecondSetForm.installCostSettleType, accountSecondSetForm.installCostValue)
                }}</span>
                <span class="m-l-lable targetObj">目标分账对象:{{ accountSetForm.installCostPartnerMerchant.merchantName ||
                  filterMerchantName(accountSecondSetForm.installCostMerchantId) }}
                  (商户号:{{ accountSetForm.installCostPartnerMerchant.merchantId || accountSecondSetForm.installCostMerchantId
                  }})</span>
              </span>
            </el-form-item>
            <el-form-item class="p-l-30 el-item" prop="installCostMerchantId" v-if="isSecondSetEdit"
                          :rules="[{ required: true, message: '请选择分账对象', trigger: 'blur' }]">
              <span class="tips-block " slot="label">
                <span class="tips-label">分账对象</span>
                <el-tooltip popper-class="tooltip-class" effect="dark" content="" placement="top">
                  <span class="tips-icon" />
                </el-tooltip>:
              </span>
              <el-select v-model="accountSecondSetForm.installCostMerchantId" placeholder="请选择服务商">
                <el-option v-for="item in form.partnerMerchants" :key="item.merchantId" :value="item.merchantId"
                           :label="item.merchantName" />
              </el-select>
            </el-form-item>
            <el-form-item class="p-l-30 el-item" prop="marketingCostValue"
                          :rules="[{ required: true, message: '请输入营销费用', trigger: 'change' }]">
              <span class="tips-block " slot="label">
                <span class="tips-label">营销费用</span>
                <el-tooltip popper-class="tooltip-class" effect="dark" content="商品营销费用" placement="top">
                  <span class="tips-icon" />
                </el-tooltip>:
              </span>
              <div v-if="isSecondSetEdit">
                <el-select class="m-r-15" v-model="accountSecondSetForm.marketingCostCalculateType"
                           @change="changeSelectLabel(2)" placeholder="请选择分账方式">
                  <el-option v-for="item in installCostCalculateTypeOptions" :key="item.id" :value="item.id"
                             :label="item.label" />
                </el-select>
                <el-select class="m-r-15" v-if="accountSecondSetForm.marketingCostCalculateType == 2"
                           v-model="accountSecondSetForm.marketingCostSettleType" placeholder="请选择订单计提方式">
                  <el-option v-for="item in calculationBaseOptions" :key="item.value" :value="item.value"
                             :label="item.label" />
                </el-select>
                <el-input v-model="accountSecondSetForm.marketingCostValue"
                          @input="handleInput($event, 'marketingCostValue', accountSecondSetForm.marketingCostCalculateType)"
                          style="width:150px"
                          :placeholder="accountSecondSetForm.marketingCostCalculateType == 1 ? '请输入固定金额' : '请输入比例'">
                  <i slot="suffix" v-if="accountSecondSetForm.marketingCostCalculateType == 2" class="suffix">%</i>
                </el-input>
              </div>
              <span v-if="!isSecondSetEdit">
                <span>{{ accountSecondSetForm.marketingCostCalculateType |
                  filterCostLabel(accountSecondSetForm.marketingCostSettleType, accountSecondSetForm.marketingCostValue)
                }}</span>
                <span class="m-l-lable targetObj">目标分账对象:{{ accountSetForm.marketingCostPartnerMerchant.merchantName ||
                  filterMerchantName(accountSecondSetForm.marketingCostMerchantId) }}
                  (商户号:{{ accountSetForm.marketingCostPartnerMerchant.merchantId
                    || accountSecondSetForm.marketingCostMerchantId }})</span>
                <!-- <span>
                    <span class="title-target-obj">目标分账对象:</span>
            <span>{{accountSecondSetForm.parentMerchantName}}(商户号:{{form.parentMerchantId}})</span>
                </span> -->
              </span>
            </el-form-item>
            <el-form-item class="p-l-30 el-item" v-if="isSecondSetEdit" prop="marketingCostMerchantId"
                          :rules="[{ required: true, message: '请选择分账对象', trigger: 'change' }]">
              <span class="tips-block " slot="label">
                <span class="tips-label">分账对象</span>
                <el-tooltip popper-class="tooltip-class" effect="dark" content="" placement="top">
                  <span class="tips-icon" />
                </el-tooltip>:
              </span>
              <el-select v-model="accountSecondSetForm.marketingCostMerchantId" placeholder="请选择服务商">
                <el-option v-for="item in form.partnerMerchants" :key="item.merchantId" :value="item.merchantId"
                           :label="item.merchantName" />
              </el-select>
            </el-form-item>
          </div>

          <!-- 单服务商  -->
          <el-form-item v-if="!isSecondSetEdit && isNoMultiserver == 1" class="p-l-30 el-item targetObj">
            <span class="title-target-obj">目标分账对象:</span>
            <span v-if="accountSetForm.singlePartnerMerchant">{{ accountSetForm.singlePartnerMerchant.merchantName ||
              filterMerchantName(accountSecondSetForm.singlePartnerMerchantId) }}(商户号:{{
              accountSetForm.singlePartnerMerchant.merchantId || accountSecondSetForm.singlePartnerMerchantId }})</span>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
import { BaseData, userType, ghUserType } from '@/common/constants.js'
import { limitPrice } from '@/common/format'
import { getAccountRule, updateRule } from '@api/merchant'
import { returnFloat, deepClone } from '@/common/util'
export default {
  name: 'StepOne',
  props: {
    form: {
      type: Object,
      default: () => { }
    }
  },
  data() {
    return {
      // 编辑按钮
      isFirstSetEdit: false,
      isSecondSetEdit: false,
      isFirst: true,
      // 分账设置
      accountSetStruct: Object.freeze({
        goodsType: '',
        merchantSettleType: '',
        merchantProfitValue: ''
      }),
      accountSetForm: {
        shop4sDeductChargeFlag: 'N',
        partnerDeductChargeFlag: 'Y',
        incentiveType: '1',
        incentiveValue: '0',
        installCostPartnerMerchant: {},
        marketingCostPartnerMerchant: {},
        singlePartnerMerchant: {},
        list: [{
          goodsType: '全部',
          goodsTypeName: '全部',
          merchantSettleType: '',
          merchantProfitValue: ''
        }]
      },

      // 分账设置-服务商(第二个)
      accountSecondSetStruct: Object.freeze({
        goodsType: '',
        goodsTypeName: '',
        partnerProfitPer: ''
      }),
      accountSecondSetForm: {
        list: [{
          goodsType: '全部',
          goodsTypeName: '全部',
          partnerProfitPer: ''
        }],
        partnerSettleAccountModel: '',
        singlePartnerMerchantId: '',
        installCostCalculateType: '',
        marketingCostCalculateType: '',
        marketingCostValue: '',
        installCostValue: '',
        marketingCostMerchantId: '',
        installCostMerchantId: '',
        installCostSettleType: '',
        marketingCostSettleType: ''
      },
      merchantSettleTypeList: [{
        confId: '1',
        confLabel: '毛利分润'
      }, {
        confId: '2',
        confLabel: '收入分润'
      }],
      installCostCalculateTypeOptions: [{
        id: 1,
        label: '按金额'
      }, {
        id: 2,
        label: '按比例'
      }],
      calculationBaseOptions: [{
        value: 1,
        label: '按订单毛利'
      }, {
        value: 2,
        label: '按订单收入'
      }],
      // merchantSelectOptions: [],
      // 基本数据
      baseData: {
        productTypeList: [],
        userType: userType,
        ghUserType: ghUserType
      }
    }
  },

  watch: {
    'form.merchantId': {
      handler(val, oldVal) {
        // console.log(val)
        // console.log(oldVal)
        if (this.isFirst && val) {
          this.isFirst = false
          this.getRule()
        }
      },
      deep: true
    }
  },
  computed: {
    test: function () {
      return this.form.partnerMerchants
    },
    // 判断是否是多服务商 默认不是
    isNoMultiserver: {
      get() {
        const { partnerSettleAccountModel } = this.accountSecondSetForm
        // this.merchantInfo.partnerMerchants.length
        // console.log(partnerMerchants)
        return partnerSettleAccountModel
      }
    }
  },
  // 定义组件过滤器
  filters: {

    filterMerchanName(id, list) {
      // console.log(this.merchantSelectOptions)
      const obj = list.find(item => item.merchantId == id)
      // console.log(obj ? obj.merchantName : 0)
      return obj ? obj.merchantName : ''
    },
    filterCostLabel(op, type, value) {
      // console.log(op, type, value)
      // let a =
      // let a = op ==1? ''
      if (op == 1) {
        return '固定金额' + value + '元'
      } else {
        const name = type == 1 ? '按订单毛利' : '按订单收入'
        return name + value + '%'
      }
    }
  },
  mounted() {
    // this.getRule()
    // console.log(this.form)
    this.getBaseData()
  },

  methods: {
    ...mapActions({
      get: 'd2admin/base/get'
    }),
    filterMerchantName(id) {
      if (id) {
        return this.form.partnerMerchants.find((item) => {
          return item.merchantId == id
        }).merchantName
      }
    },
    merchantProfitBlur(item) { // 分润比例整数处理
      if (item && item.merchantProfitValue) {
        item.merchantProfitValue = returnFloat(item.merchantProfitValue)
      }
      if (item && item.partnerProfitPer) {
        item.partnerProfitPer = returnFloat(item.partnerProfitPer)
      }
    },
    mosHandleInput(newValue, name, index, type) {
      // 只能输入两个小数
      // eslint-disable-next-line no-useless-escape
      newValue = newValue.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')
      if (type == 1) this.accountSetForm.list[index][name] = newValue // 导流方分润
      if (type == 2) this.accountSecondSetForm.list[index][name] = newValue // 导流方分润
    },
    handleInput(newValue, name, type) {
      newValue = newValue.replace(/[^\d.]/g, '') // 清除“数字”和“.”以外的字符
      console.log(newValue)
      // 按金额
      if (type == 1) {
        this.accountSecondSetForm[name] = limitPrice(newValue, this.accountSecondSetForm[name], 10, 2)
        // 按百分比
      } else {
        // console.log(newValue)
        // 验证第一个字符是数字
        newValue = newValue.replace(/^\./g, '')
        // 只保留第一个, 清除多余的
        newValue = newValue.replace(/\.{2,}/g, '.')
        newValue = newValue.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
        // 只能输入两个小数
        // eslint-disable-next-line no-useless-escape
        newValue = newValue.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')
        if (newValue > 100) newValue = 100

        if (newValue < 0) newValue = 0

        this.accountSecondSetForm[name] = newValue
      }
    },
    changeSelectLabel(index) {
      // 处理联动情况
      if (index == 1) {
        this.accountSecondSetForm.installCostValue = ''
        if (this.accountSecondSetForm.installCostCalculateType == 2) {
          this.accountSecondSetForm.installCostSettleType = 1
        }
      }
      if (index == 2) {
        this.accountSecondSetForm.marketingCostValue = ''
        if (this.accountSecondSetForm.marketingCostCalculateType == 2) {
          this.accountSecondSetForm.marketingCostSettleType = 1
        }
      }
    },
    async getBaseData() {
      this.baseData.productTypeList = deepClone(await this.get(BaseData.productType))
      // console.log(this.baseData.productTypeList)
    },

    // getPartnerByYq() {
    //   const { yqMerchantId } = this.form
    //   // console.log(yqMerchantId)
    //   getPartnerByYq({ yqMerchantId }).then((result) => {
    //     // this.merchantSelectOptions = result
    //     console.log(this.merchantSelectOptions)
    //     // 模拟数据用
    //     this.merchantSelectOptions = [{ merchantId: 44209498, merchantName: '牛牛服务商' }, { merchantId: 44209468, merchantName: '明明塘朗服务商' }]
    //   }).catch((err) => {
    //     console.log(err)
    //   })
    // },
    getRule() {
      // console.log(this.form.merchantId)
      getAccountRule({ merchantId: this.form.merchantId }).then(res => {
        // console.log(res)
        if (res) {
          this.accountSetForm.list[0].merchantSettleType = res.merchantSettleType + ''
          this.accountSetForm.list[0].merchantProfitValue = returnFloat(res.merchantProfitValue + '')
          this.accountSetForm.incentiveType = res.incentiveType + ''
          this.accountSetForm.incentiveValue = res.incentiveValue + ''
          const { shop4sDeductChargeFlag, partnerDeductChargeFlag, partnerSettleAccountModel, installCostPartnerMerchant, marketingCostPartnerMerchant, singlePartnerMerchant } = res

          this.accountSetForm.partnerDeductChargeFlag = partnerDeductChargeFlag
          this.accountSetForm.shop4sDeductChargeFlag = shop4sDeductChargeFlag
          this.accountSetForm.installCostPartnerMerchant = installCostPartnerMerchant
          this.accountSetForm.marketingCostPartnerMerchant = marketingCostPartnerMerchant
          this.accountSetForm.singlePartnerMerchant = singlePartnerMerchant
          // this.accountSetForm.deductChargeFlag = res.deductChargeFlag
          // this.accountSetForm. = res
          this.accountSecondSetForm.partnerSettleAccountModel = partnerSettleAccountModel
          // shop4sDeductChargeFlag: 'N',
          //       partnerDeductChargeFlag: 'Y',
          // accountSecondSetForm
          // 多服务商
          if (res.partnerSettleAccountModel == 2) {
            for (const key in this.accountSecondSetForm) {
              // 判断是否有某个属性 有赋值
              // console.log(key)
              if (res.partnerMerchantMultiSettleAccountRule.hasOwnProperty(key)) {
                this.accountSecondSetForm[key] = res.partnerMerchantMultiSettleAccountRule[key]
              }
            }
          }
          if (res.partnerSettleAccountModel == 1) {
            this.accountSecondSetForm.singlePartnerMerchantId = res.singlePartnerMerchantId
          }

          this.form.partnerMerchants && (this.accountSecondSetForm.list[0].partnerProfitPer = returnFloat(res.partnerProfitPer + ''))
          res.goodsTypeSettleRuleList.forEach((item, index) => {
            this.accountSetForm.list.push({
              goodsType: item.goodsType,
              goodsTypeName: item.goodsTypeName,
              merchantSettleType: item.merchantSettleType + '',
              merchantProfitValue: returnFloat(item.merchantProfitValue + '')
            })
            this.form.partnerMerchants && this.accountSecondSetForm.list.push({
              goodsType: item.goodsType,
              goodsTypeName: item.goodsTypeName,
              partnerProfitPer: returnFloat(item.partnerProfitPer + '')
            })
          })
        }
      })
    },
    handleAccountAdd(formAttr, refsAttr, addStructAttr) {
      var validArr = this[formAttr].list.map((i, j) => 'list.' + j + '.goodsType')
      var isEmpty = false
      this.$refs[refsAttr].validateField(validArr, valid => {
        valid && (isEmpty = true)
      })
      !isEmpty && this[formAttr].list.push(deepClone(this[addStructAttr]))
    },
    handleAccountDelete(formAttr, item, index) {
      this.$confirm('是否删除该品类', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this[formAttr].list.splice(index, 1)
      }).catch(err => {
        console.log(err)
      })
    },
    handleSelectChange(value, index, currentItem) {
      this[currentItem].list[index].goodsTypeName = this.baseData.productTypeList.find(item => item.goodsType === value).goodsTypeName
    },

    // 是否编辑;refs绑定的属性值;当前Form属性值;级联Form属性值;添加对象的属性
    handleSetEdit(isEditAttr, refsAttr, formAttr, cascadeChangeAttr, addStructAttr) {
      // 判断是否有服务商 && this.form.parentMerchantName
      if (this[isEditAttr]) {
        // console.log(this.$refs[refsAttr].validate)
        // debugger
        this.$refs[refsAttr].validate(valid => {
          console.log(valid)
          if (valid) {
            this[isEditAttr] = !this[isEditAttr]
            // 设置其中一个表格增删改后,级联另一个表格中的分账品类
            var currentLen = this[formAttr].list.length
            var cascadeLen = this[cascadeChangeAttr].list.length
            if (currentLen < cascadeLen) {
              this[cascadeChangeAttr].list.splice(currentLen, cascadeLen - currentLen)
            }
            this[formAttr].list.forEach((i, idx) => {
              cascadeLen = this[cascadeChangeAttr].list.length
              if (cascadeLen < idx + 1) {
                this[cascadeChangeAttr].list.push(deepClone(this[addStructAttr]))
                var cascadeEditAttr = isEditAttr === 'isFirstSetEdit' ? 'isSecondSetEdit' : 'isFirstSetEdit'
                this[cascadeEditAttr] = !this[cascadeEditAttr]
              }
              this[cascadeChangeAttr].list[idx].goodsType = i.goodsType
              this[cascadeChangeAttr].list[idx].goodsTypeName = i.goodsTypeName
            })
          }
        })
        return true
      }
      this[isEditAttr] = !this[isEditAttr]
    },

    handleConfirm() {
      // this.$refs['form'].validate((valid) => {
      //   if (valid) {
      this.$refs.accountValiteForm.validate((valid2) => {
        if (valid2) {
          if (this.form.partnerMerchants) {
            this.$refs.accountSecondValiteForm.validate((valid3) => {
              valid3 ? this.assignConfirm() : this.handleSetEdit('isSecondSetEdit', 'accountSecondValiteForm', 'accountSecondSetForm', 'accountSetForm', 'accountSetStruct')
            })
          } else {
            this.assignConfirm()
          }
        } else {
          this.handleSetEdit('isFirstSetEdit', 'accountValiteForm', 'accountSetForm', 'accountSecondSetForm', 'accountSecondSetStruct')
        }
      })
      //   } else {
      //     return false
      //   }
      // })
    },
    assignConfirm() {
      // console.log(this.form)
      // console.log(this.accountSetForm)
      // console.log(this.accountSecondSetForm)
      var params = {
        merchantId: this.form.merchantId,
        channelType: this.form.channelType,
        smsCode: this.form.smsCode,
        bizType: this.form.bizType,
        settleAmountType: this.form.settleAmountType,
        // 全部-分账设置
        merchantSettleType: this.accountSetForm.list[0].merchantSettleType,
        merchantProfitValue: this.accountSetForm.list[0].merchantProfitValue,
        shop4sDeductChargeFlag: this.accountSetForm.shop4sDeductChargeFlag,
        incentiveType: this.accountSetForm.incentiveType,
        incentiveValue: this.accountSetForm.incentiveValue,
        // deductChargeFlag: this.accountSetForm.deductChargeFlag,
        goodsTypeSettleRuleList: []

      }

      // 是否配置服务商
      if (this.form.partnerMerchants) {
        params.partnerProfitPer = this.accountSecondSetForm.list[0].partnerProfitPer
        params.partnerDeductChargeFlag = this.accountSetForm.partnerDeductChargeFlag
        params.partnerSettleAccountModel = this.accountSecondSetForm.partnerSettleAccountModel
        if (this.accountSecondSetForm.partnerSettleAccountModel == 1) {
          params.singlePartnerMerchantId = this.accountSecondSetForm.singlePartnerMerchantId
        } else {
          const obj = deepClone(this.accountSecondSetForm)
          delete obj.list
          delete obj.singlePartnerMerchantId
          if (this.accountSecondSetForm.installCostCalculateType == 1) delete obj.installCostSettleType
          if (this.accountSecondSetForm.marketingCostCalculateType == 1) delete obj.marketingCostSettleType

          params = Object.assign(params, obj)
        }
      }

      // this.form.partnerMerchants && ()
      this.accountSetForm.list.forEach((item, index) => {
        if (index !== 0) {
          params.goodsTypeSettleRuleList.push({
            goodsType: item.goodsType,
            goodsTypeName: item.goodsTypeName,
            merchantSettleType: item.merchantSettleType,
            merchantProfitValue: item.merchantProfitValue
          })
          // 是否配置服务商
          this.form.partnerMerchants && (params.goodsTypeSettleRuleList[index - 1].partnerProfitPer = this.accountSecondSetForm.list[index].partnerProfitPer)
        }
      })

      console.log(params)
      // return
      updateRule(params).then((res) => {
        this.isSecondSetEdit = false
        this.isFirstSetEdit = false
        this.notice.okTips('修改成功')
        this.$emit('handleNextStep', 2)
      }).catch(() => { })
    }
  }
}

</script>
<style lang="scss">
.account-card-block {
  width: 100%;
  min-width: 778px;
  border: 1px solid #e8e8e8;
  border-radius: 8px;
  font-size: 12px;
  color: #6c6f71;
  margin-bottom: 22px;

  p {
    margin: 0 0;
  }

  span {
    display: inline-block;
  }

  .card-title {
    font-size: 14px;
    font-weight: bold;
    background: #fafafa;
    border-radius: 8px 8px 0 0;
    padding: 14px 30px;

    .title-target-obj {
      max-width: 250px;
      line-height: 22px;
      vertical-align: top;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }

  .targetObj {
    font-size: 14px;
    font-weight: 600;
    color: #666;
  }

  .p-l-30 {
    padding-left: 30px;
  }

  .el-form-item.el-item {
    display: block;
  }

  .tips-icon {
    top: 11px;
  }

  .account-content {
    .el-form-item {
      width: 30%;
      margin-bottom: 16px;
    }
  }

  .m-r-15 {
    margin-right: 15px;
  }

  .m-l-lable {
    margin-left: 100px;
    // margin-left: 40%;
  }
}
</style>