packageForm.vue 44.4 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
<!-- 表单 -->
<template>
  <div class="package-form">
    <el-form :model="formData" :rules="rules" :ref="formRef + 'd2FormRuleForm'">
      <slot name="title" />
      <div v-for="(i, idx) in formList" :key="idx" class="package-form-block">
        <div class="title">
          <span v-show="i.title">{{ i.title }}</span>
          <el-button v-if="i.addBtn" type="primary" @click="addGroundingGoods">{{ i.addBtn }}</el-button>
        </div>
        <div style="padding: 20px;">
          <!-- 商品信息块 -->
          <div v-if="idx == 1">
            <div v-for="(ele, eleIndex) in formData['groundingGoodsList']" :key="eleIndex" class="groundingGoods-item">
              <div v-for="(item, index) in i.formBlock[eleIndex]" :key="index">
                <!-- 上架部位 -->
                <div v-if="item.type === 'radio' && ele['goodsType'] == 1 && !item.index">
                  <el-form-item :prop="`groundingGoodsList[${eleIndex}][${item.name}]`" :rules="rules[item.name]" :label="item.label ? item.label + ':' : ''"
                                :id="`groundingGoodsList[${eleIndex}][${item.name}]`"
                                :label-width="item.label ? '180px' : '0px'" class="dis-in-block"
                                :style="{ 'margin-bottom': !item.type ? '0px' : '22px' }">
                    <el-radio-group v-model="ele[item.name]">
                      <el-radio v-for="(subItem, subIndex) in ele.positionNamesArr" :key="subIndex" :label="subItem.position">{{
                        subItem.confName }}</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </div>
                <div
                  v-if="item.type === 'radio' && item.index && (ele['goodsType'] == 1 || (formData['sceneType'] && formData['sceneType'] == 3))">
                  <el-form-item :prop="`groundingGoodsList[${eleIndex}][${item.name}]`" :rules="rules[item.name]" :label="item.label ? item.label + ':' : ''" 
                                :id="`groundingGoodsList[${eleIndex}][${item.name}]`"
                                :label-width="item.label ? '180px' : '0px'" class="dis-in-block"
                                :style="{ 'margin-bottom': !item.type ? '0px' : '22px' }">
                    <el-radio-group v-model="ele[item.name]" @change="($event, index) => upgradeSupplyModeChange($event, eleIndex)">
                      <el-radio v-for="(subItem, subIndex) in item.radioGroupList" :key="subIndex" :label="subItem.confId">{{
                        subItem.confName }}</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </div>
                <!-- 商品附带信息 -->
                <div v-if="ele['upgradeGoodsId'] && item.type === 'incidBox'">
                  <div class="incid_box">
                    <div class="item" v-for="(subItem, subIndex) in item.detailInfo" :key="subIndex">
                      <div class="label">{{ subItem.unit ? (membraneTypeList.includes(ele[item.key]) ? subItem.label +
                    `(元)/${subItem.value == 'purchasePrice' ? '卷' : '车'}` : (subItem.label + '(元)/件')) : subItem.label }}:
                      </div>
                      <div class="value">
                        <ellipsis-popover :content="subItem.unit ? priceFilter(ele.upgradeGoods[subItem.value]) : ele.upgradeGoods[subItem.value] || ''"></ellipsis-popover>
                      </div>
                    </div>
                    <!-- 权益/延保非第三方展示 -->
                    <div class="item" v-if="(equitySceneType.includes(ele[item.key]) || extendedPosiType.includes(ele[item.key])) && !baseConfig.supplierCode.includes(`${ele.supplierCode}`)">
                      <div class="label">嘀加成本元/件:</div>
                      <div class="value">
                        <ellipsis-popover :content="priceFilter(ele.upgradeGoods['djCost'])"></ellipsis-popover>
                      </div>
                    </div>
                    <!-- 商品分类 1太阳膜/延保类 -->
                    <div class="item" v-if="ele[item.key] == 1">
                      <div class="label">部位:</div>
                      <div class="value">
                        <ellipsis-popover :content="ele.upgradeGoods['positionNames'] || ''"></ellipsis-popover>
                      </div>
                    </div>
                    <!-- 商品分类 权益服务 非第三方 -->
                    <div class="item" v-if="equitySceneType.includes(ele[item.key]) && !baseConfig.supplierCode.includes(`${ele['supplierCode']}`)">
                      <div class="label">服务项目:</div>
                      <div class="value">
                        <ellipsis-popover :content="ele.upgradeGoods['serviceItemNames'] || ''"></ellipsis-popover>
                      </div>
                    </div>
                    <!-- 商品分类 权益服务 -->
                    <div class="item" v-if="equitySceneType.includes(ele[item.key])">
                      <div class="label">实体卡:</div>
                      <div class="value">
                        <ellipsis-popover :content="ele.upgradeGoods['entityCardFlag'] == 'Y' ? '是' : '否'"></ellipsis-popover>
                      </div>
                    </div>
                    <!-- 质保年限 膜类展示-->
                    <div class="item" v-if="membraneTypeList.includes(ele[item.key])">
                      <div class="label">质保年限/年:</div>
                      <div class="value">
                        <ellipsis-popover :content="`${ele.upgradeGoods['warrantyPeriod']}年` || ''"></ellipsis-popover>
                      </div>
                    </div>
                  </div>
                </div>
                <!-- 下拉框/输入框 -->
                <div v-if="item.type === 'input' || item.type === 'select' || item.type === 'searchSelect'">
                  <el-form-item :prop="`groundingGoodsList[${eleIndex}][${item.name}]`"
                                :rules="item.name == 'minSellPrice' ? rules[item.name + eleIndex] : rules[item.name]"
                                :label="item.label ? (item.unit ? (membraneTypeList.includes(ele['goodsType']) ? item.label + `(元)/车` : (item.label + '(元)/件')) : item.label) + ':' : ''"
                                :id="`groundingGoodsList[${eleIndex}][${item.name}]`" :label-width="item.label ? '180px' : '0px'" class="dis-in-block"
                                :style="{ 'margin-bottom': !item.type ? '0px' : '22px' }">
                    <template v-if="item.type === 'input'">
                      <el-input v-model.trim="ele[item.name]" :placeholder="item.label"
                                :maxlength="item.maxlength" :style="{ 'width': item.width || formItemWidth }" :disabled="item.isDisabled"
                                clearable @input="input($event, item, eleIndex)" @blur="blur(item)">
                      </el-input>
                    </template>
                    <template v-if="item.name == 'minSellPrice'">
                      <el-checkbox v-model="ele['validMinSellPriceFlag']" class="check-min-price"></el-checkbox>
                      <span class="tips-text">勾选时提单校验最低价</span>
                    </template>
                    <el-select v-else-if="item.type === 'select'" v-model="ele[item.name]" :clearable="item.isClear"
                           :ref="'selectRefs_' + item.name" :placeholder="'请选择' + item.label" @change="selectAddAttr($event, item)"
                           :style="{ 'width': item.width || formItemWidth }" filterable>
                      <el-option v-for="subItem in item.optionList" :key="subItem[item.optionId]"
                                :label="subItem[item.optionLabel]" :value="subItem[item.optionId]" />
                    </el-select>
                    <!-- 上架商品 -->
                    <el-button v-else-if="item.type === 'searchSelect'" icon="el-icon-plus" @click="handleSelectGoods(eleIndex)">选择商品</el-button>
                    <el-button type="text" style="float: right;" @click="delGroundingGoods(eleIndex)" v-if="item.name == 'upgradeGoodsId' && formData['groundingGoodsList'].length > 1">删除</el-button>
                  </el-form-item>
                </div>
              </div>
            </div>
          </div>
          <!-- 套餐信息/门店信息 -->
          <div v-else>
            <div v-for="(item, index) in i.formBlock" :key="index">
              <!-- 下拉框/输入框 -->
              <div v-if="(item.type === 'input' || item.type === 'select')">
                <el-form-item :prop="item.isDisabled ? '' : item.name"
                              :label="item.label ? (item.unit ? (item.label + '(元)/件') : item.label) + ':' : ''"
                              :id="item.name" :label-width="item.label ? '180px' : '0px'" :class="item.isDisabled ? 'dis-in-block is-required' : 'dis-in-block'"
                              :style="{ 'margin-bottom': !item.type ? '0px' : '22px' }">
                  <template v-if="item.type === 'input'">
                    <el-input v-model.trim="formData[item.name]" :placeholder="item.placeholder || item.label"
                              :maxlength="item.maxlength" :style="{ 'width': item.width || formItemWidth }" :disabled="item.isDisabled"
                              clearable @input="input($event, item)" @blur="blur(item)">
                    </el-input>
                  </template>
                  <template v-if="item.type == 'select'">
                    <el-select v-model="formData[item.name]" :clearable="item.isClear"
                               :ref="'selectRefs_' + item.name" :placeholder="'请选择' + item.label" @change="selectAddAttr($event, item)"
                               :style="{ 'width': item.width || formItemWidth }" filterable>
                      <el-option v-for="subItem in item.optionList" :key="subItem[item.optionId]"
                                 :label="subItem[item.optionLabel]" :value="subItem[item.optionId]"
                                 :disabled="item.name == 'sceneType' && subItem[item.optionId] != 0 && subItem[item.optionId] != 1" />
                    </el-select>
                  </template>
                </el-form-item>
              </div>
              <!-- 财务校验 -->
              <div v-if="item.type === 'flagRadio'">
                <el-form-item :prop="item.name"
                            :label="item.label ? item.label + ':' : ''"
                            :id="item.name" :label-width="item.label ? '180px' : '0px'" class="dis-in-block"
                            :style="{ 'margin-bottom': !item.type ? '0px' : '22px' }">
                  <el-radio-group v-model="formData[item.name]">
                    <el-radio v-for="(subItem, subIndex) in item.radioGroupList" :key="subIndex" :label="subItem.value">{{
                      subItem.label }}</el-radio>
                  </el-radio-group>
                  <el-tooltip class="item" effect="dark" placement="top">
                    <template slot="content">
                      <p style="width: 260px;"><i class="el-icon-info"></i>开启财务规则校验,该商品的清分及对账规则只能应用具体商品规则,若不满足所在订单自动挂单,需进行手动发起清分及对账计算</p>
                    </template>
                    <i class="el-icon-info" style="margin-left: 20px;"></i>
                  </el-tooltip>
                </el-form-item>
              </div>
              <!-- 按钮 -->
              <div v-if="item.type === 'button'">
                <el-form-item :prop="item.name" :label="item.label ? item.label + ':' : ''" :id="item.name"
                              :label-width="item.label ? '180px' : '0px'" class="dis-in-block"
                              :style="{ 'margin-bottom': !item.type ? '0px' : '22px' }">
                  <el-button icon="el-icon-plus" @click="handleClick">选择上架门店</el-button>
                  <relateStoreTable v-if="$$(formData['merchantGoodsRefList'], 'length')"
                                    :merchant-goods-ref-list="formData['merchantGoodsRefList']" @handleDelete="handleDelete">
                  </relateStoreTable>
                </el-form-item>
              </div>
              <!-- 上传凭证 -->
              <div v-if="item.type === 'upload'" class="upload-box">
                <el-form-item :prop="item.name" :label="item.label ? item.label + ':' : ''" :id="item.name"
                              class="dis-in-block" :label-width="item.label ? '180px' : '0px'"
                              :style="{ 'margin-bottom': !item.type ? '0px' : '22px' }">
                  <template>
                    <el-upload action="" accept=".jpg,.png,.pdf" class="upload-file" drag :show-file-list="false"
                               :file-list="uploadFileList" :limit="30" :auto-upload="false"
                               :on-change="e => handleFileChange(e, item)" :on-exceed="hanldeOnExceed" multiple>
                      <i class="el-icon-upload"></i>
                      <div class="el-upload__text">点击或将文件拖拽到此区域上传</div>
                      <div class="item-tips text-tips">{{ item.topTips }}</div>
                      <div class="item-tips">{{ item.tips }}</div>
                    </el-upload>
                    <!-- 文件列表区域 -->
                    <div class="file-box">
                      <div v-for="(subItem, subIndex) in formData[item.name]" :key="subIndex">
                        <div class="file-item" v-if="!filterEmpty(subItem.uploadProgress) || subItem.voucherFileUrl">
                          <div class="file-content" @click="handleFileView(subItem)">
                            <el-progress define-back-color="#F5F7FA" :text-inside="true" text-color="#333333"
                                         :show-text="false" :stroke-width="26" stroke-linecap="butt"
                                         :percentage="subItem.uploadProgress"></el-progress>
                            <div class="file-name">{{ subItem.fileName }}</div>
                          </div>
                          <i v-if="!subItem.voucherFileUrl" class="el-icon-close del-icon"
                             @click="doCancel(item, subIndex)"></i>
                          <i v-if="subItem.voucherFileUrl" class="el-icon-delete"
                             @click="handleFileDelete(item, subIndex)"></i>
                        </div>
                      </div>
                    </div>
                  </template>
                </el-form-item>
              </div>
            </div>
          </div>
        </div>
      </div>
      <el-form-item style="margin-top: 40px;text-align: center;">
        <el-button type="primary" @click="handleUp(1)" :disabled="$store.state.d2admin.loading.value">
          保存并上架
        </el-button>
        <!-- 草稿状态/已下架/新增显示 -->
        <el-button type="primary" plain class="width_100" @click="handleUp(2)"
                   :disabled="$store.state.d2admin.loading.value" v-if="filterEmpty(formData.status) || formData.status == 3">
          存草稿
        </el-button>
        <el-button class="width_100 cancel-btn" @click="handleClose">
          取消
        </el-button>
      </el-form-item>
    </el-form>
    <!-- store-api (1精品升级 2次新车转化 3售后众筹 查询嘀加的门店数据 getList)(0会员/权益升级 4积分商城 查询账户中心所有4s店 getAccountMerchantList  -->
    <relate-store-dialog v-if="relateStoreVisible" ref="formRelateStore" :relate-store-visible="relateStoreVisible"
                         :store-api="[1, 2, 3].includes(formData.sceneType) ? getList : getAccountMerchantList"
                         :store-search-form="storeSearchForm" :store-selected="storeSelected" :selected-scene="formData.sceneType"
                         @handleRelateStoreConfirm="handleRelateStoreConfirm" @handleRelateStoreClose="handleRelateStoreClose">
      <el-row slot>
        <el-form :model="storeSearchForm" ref="relate" :inline="true">
          <el-form-item label="门店名称:">
            <el-input v-model.trim="storeSearchForm.merchantName" placeholder="门店名称" @keydown.native="handleStoreInput"
                      clearable />
          </el-form-item>
          <el-form-item label="门店商户号:">
            <el-input v-model.trim="storeSearchForm.merchantId" placeholder="门店商户号" @keydown.native="handleStoreInput"
                      clearable />
          </el-form-item>
          <el-form-item label="服务对接:">
            <el-input v-model.trim="storeSearchForm.yqMerchantName" placeholder="服务对接" @keydown.native="handleStoreInput"
                      clearable />
          </el-form-item>
          <el-form-item label="服务对接商户号:">
            <el-input v-model.trim="storeSearchForm.yqMerchantId" placeholder="服务对接商户号" @keydown.native="handleStoreInput"
                      clearable />
          </el-form-item>
          <el-button type="primary" @click="handleSearchStore">搜索</el-button>
        </el-form>
      </el-row>
    </relate-store-dialog>
    <el-image-viewer v-if="imgViewerVisible" :on-close="closeImgViewer" :url-list="imageFileArr"
                     :initial-index="initialIndex" />
    <select-goods-dialog v-if="selectGoodsVisible" :select-goods-visible="selectGoodsVisible" @handleSelectGoodsConfirm="handleSelectGoodsConfirm" 
      @handleSelectGoodsClose="handleSelectGoodsClose" :upgrade-goods-id="formData['groundingGoodsList'][selectGoodIndex].upgradeGoodsId" :package-select-ids="packageSelectIds"></select-goods-dialog>
  </div>
</template>

<script>
import { deepClone } from '@/common/util'
import { limitPrice } from '@/common/format'
import { mapActions } from 'vuex'
import { uploadImg, uploadPDF } from '@/api/sys.base'
import { baseConfig } from "@/main"
import relateStoreDialog from "../../grounding/components/relateStoreDialog.vue"
import relateStoreTable from '../../grounding/components/relateStoreTable.vue'
import { getList, getAccountMerchantList } from '@/api/merchant'
import { upgradeSupplyModeList, crowdUpgradeSupplyModeList, packageGoodsForm } from "../../grounding/constants/data"
import selectGoodsDialog from '../../components/selectGoodsDialog.vue'
import ellipsisPopover from '../../components/ellipsisPopover.vue'
import { filterSpecsStr } from '../../filterOption'
export default {
  name: 'GroundingForm',
  components: {
    relateStoreDialog,
    relateStoreTable,
    'el-image-viewer': () => import('element-ui/packages/image/src/image-viewer'),
    selectGoodsDialog,
    ellipsisPopover
  },
  data() {
    return {
      getList,
      getAccountMerchantList,
      equitySceneType: baseConfig.equitySceneType || [],
      extendedPosiType: baseConfig.extendedPosiType || [], // 延保类
      membraneTypeList: baseConfig.membraneTypeList,
      formData: {},
      reg: {
        numReg: /^[1-9]\d*$/,
        priceReg: /^\d[\d\.]*$/
      },
      show: false,
      rules: {
        packageName: [{ required: true, message: '请输入套餐名称', trigger: 'blur' }],
        merchantGoodsRefList: [{ required: true, message: '请选择上架门店', trigger: 'change' }],
        sceneType: [{ required: true, message: '请选择业务场景', trigger: 'change' }],
        upgradeGoodsId: [{ required: true, message: '请选择上架商品', trigger: 'change' }],
        position: [{ required: true, message: '请选择上架部位', trigger: 'change' }],
        sellPrice: [{ required: true, message: '请输入售价', trigger: 'blur' }],
        upgradeSupplyMode: [{ required: true, message: '请选择升级/产品供应模式', trigger: 'change' }],
        upgradeProductCost: [{ required: true, message: '请输入产品、升级成本', trigger: 'blur' }],
        recoveryCost: [{ required: true, message: '请输入回收成本', trigger: 'blur' }],
        virtualAccountCost: [{ required: true, message: '请输入虚拟对账成本', trigger: 'blur' }],
        djCost: [{ required: true, message: '请输入嘀加成本', trigger: 'blur' }],
        thirdPartyCost: [{ required: true, message: '请输入第三方成本', trigger: 'blur' }],
        financeCheckFlag: [{ required: true, message: '请选择是否开启财务规则校验', trigger: 'change' }],
      },
      storeSelected: [],
      relateStoreVisible: false,
      storeSearchForm: {
        merchantName: '',
        merchantId: '',
        yqMerchantName: '',
        yqMerchantId: ''
      },
      uploadFileList: [],
      imageFileArr: [],
      imgViewerVisible: false,
      initialIndex: 0,
      selectGoodsVisible: false,
      selectGoodIndex: null,
      filterSpecsStr
    }
  },

  props: {
    // add - 新增;edit - 编辑
    addOrEdit: {
      type: String,
      default: 'add'
    },
    formItemWidth: {
      type: String,
      default: '100%'
    },
    formRef: {
      type: String,
      default: ''
    },
    originData: {
      type: Object,
      default: () => {
        return {}
      }
    },
    formList: {
      type: Array,
      default: () => { }
    },
    positionTypeList: { // 太阳膜商品部位
      type: Array,
      default: () => []
    },
    goodsSelectList: {
      type: Array,
      default: () => []
    }
  },

  watch: {
    'formData.sceneType': {
      handler(newVal, oldVal) {
        this.oldSceneType = oldVal || newVal
      }
    },
    'formData.voucherList': {
      handler(newVal) {
        if (newVal) {
          this.uploadFileList = newVal.filter(v => !this.filterEmpty(v.uploadProgress) || v.voucherFileUrl) // 文件列表
          const imageFileArr = newVal.filter(v => v.voucherFileUrl && (v.voucherFileUrl.includes('.png') || v.voucherFileUrl.includes('jpg')))
          this.imageFileArr = imageFileArr.map(item => { return item.voucherFileUrl })
        }
      },
      deep: true
    },
    'formData.groundingGoodsList': {
      handler(newVal) {
        if (newVal) {
          // 建议售价,最低售价,升级产品成本,回收成本,虚拟对账成本,嘀加成本,第三方成本合计计算
          const acc = { sellPrice: '', minSellPrice: '', upgradeProductCost: '', recoveryCost: '', virtualAccountCost: '', djCost: '', thirdPartyCost: '' }
          newVal.forEach((val, index) => {
            acc.sellPrice = !this.filterEmpty(val.sellPrice) || !this.filterEmpty(acc.sellPrice) ? this.subStr(acc.sellPrice, Number(val.sellPrice)) : ''
            acc.minSellPrice = !this.filterEmpty(val.minSellPrice) || !this.filterEmpty(acc.minSellPrice) ? this.subStr(acc.minSellPrice, Number(val.minSellPrice)) : ''
            acc.djCost = !this.filterEmpty(val.djCost) || !this.filterEmpty(acc.djCost) ? this.subStr(acc.djCost, Number(val.djCost)) : ''
            acc.thirdPartyCost = !this.filterEmpty(val.thirdPartyCost) || !this.filterEmpty(acc.thirdPartyCost) ? this.subStr(acc.thirdPartyCost, Number(val.thirdPartyCost)) : ''
            acc.upgradeProductCost = !this.filterEmpty(val.upgradeProductCost) || !this.filterEmpty(acc.upgradeProductCost) ? this.subStr(acc.upgradeProductCost, Number(val.upgradeProductCost)) : ''
            acc.recoveryCost = !this.filterEmpty(val.recoveryCost) || !this.filterEmpty(acc.recoveryCost) ? this.subStr(acc.recoveryCost, Number(val.recoveryCost)) : ''
            acc.virtualAccountCost = !this.filterEmpty(val.virtualAccountCost) || !this.filterEmpty(acc.virtualAccountCost) ? this.subStr(acc.virtualAccountCost, Number(val.virtualAccountCost)) : ''
            this.$set(this.formList[1].formBlock, index, packageGoodsForm)
            this.filterForm(index)
          })
          this.formData.sellPrice = acc.sellPrice
          this.formData.minSellPrice = acc.minSellPrice
          this.formData.djCost = acc.djCost
          this.formData.thirdPartyCost = acc.thirdPartyCost
          this.formData.upgradeProductCost = acc.upgradeProductCost
          this.formData.recoveryCost = acc.recoveryCost
          this.formData.virtualAccountCost = acc.virtualAccountCost
          this.checkMinPrice()
        }
      },
      deep: true
    }
  },

  directives: {
    'el-select-loadmore': {
      bind(el, binding) {
        const SELECTWRAP_DOM = el.querySelector(
          '.el-select-dropdown .el-select-dropdown__wrap'
        )
        SELECTWRAP_DOM.addEventListener('scroll', function () {
          const condition =
            this.scrollHeight - this.scrollTop <= this.clientHeight
          if (condition) {
            binding.value()
          }
        })
      }
    }
  },

  mounted() {
    this.formData = deepClone(this.originData)
    this.checkMinPrice()
  },

  methods: {
    ...mapActions({
      get: 'd2admin/base/get'
    }),
    checkMinPrice() {
      let _rules = this.rules
      this.formData?.groundingGoodsList?.forEach((item, index) => {
        _rules['minSellPrice' + index] = [
          { required: true, message: '请输入最低售价', trigger: 'blur' },
          {
            required: true,
            trigger: 'blur',
            validator: (rule, value, callback) => {
              (+value > +item.sellPrice) ? callback(new Error('最低售价不能大于售价')) : callback()
            }
          }
        ]
      })
    },
    handleSelectGoods(eleIndex) {
      this.selectGoodIndex = eleIndex
      this.selectGoodsVisible = true
      this.packageSelectIds = this.formData.groundingGoodsList?.map(v => v.upgradeGoodsId) || []
    },
    handleSelectGoodsConfirm(selectedData) {
      const _formData = this.formData.groundingGoodsList[this.selectGoodIndex]
      const _valueObj = selectedData
      const _positionNamesArr = deepClone(this.positionTypeList).filter(val => (_valueObj?.position?.split(','))?.includes(val.position + '')) || []
      const { goodsTypeName, secondaryGoodsTypeName, thirdLevelGoodsTypeName } = _valueObj?.goodsInfo || {}
      const types = [goodsTypeName, secondaryGoodsTypeName, thirdLevelGoodsTypeName]
      const result = types.filter(type => type).join('-')
      _formData.upgradeGoods = {
        ..._valueObj,
        goodsName: _valueObj.goodsInfo.goodsName,
        tempGoodsTypeName: result,
        serviceItemNames: _valueObj?.upgradeGoodsServiceItemsList?.map(item => { return this.extendedPosiType.includes(_valueObj?.goodsInfo?.goodsType) ? item.serviceName : `${item.serviceName}-${item.serviceGrade}/${item.servicePeriod}` })?.join(','), // 服务项目
        positionNames: _positionNamesArr.length ? _positionNamesArr.map(subItem => { return subItem?.confName }).join('/') : '',
        specificationData: this.filterSpecsStr(_valueObj),
        djCost: _valueObj?.djCost,
        carTypeConfigName: _valueObj?.carTypeConfigList?.map(item => item.seriesName).join('/'),
        upgradeCommodityCode: _valueObj?.commodityCode
      }
      _formData.goodsType = _valueObj?.goodsInfo?.goodsType,
      _formData.upgradeGoodsId = _valueObj.id
      _formData.positionNamesArr = _positionNamesArr
      _formData.productType = [] // 切换上架商品 将服务类型清空
      _formData.baseSupplyMode = '' // 切换上架商品 将基础供货模式清空
      _formData.upgradeSupplyMode = '' // 切换上架商品 将升级/产品供货模式清空
      _formData.supplierCode = _valueObj?.goodsInfo?.supplierCode // 供应方 判断是否需要走审核流程
      if (!this.filterEmpty(_valueObj?.djCost)) _formData.djCost = _valueObj?.djCost // 嘀加成本 商品信息自带数据
      this.handleSelectGoodsClose()
    },
    handleSelectGoodsClose() {
      this.selectGoodsVisible = false
    },
    filterForm(index) {
      const { formList, formData } = this
      const itemData = formData?.groundingGoodsList[index]
      // 1 太阳膜 2 (1.3场景商品)
      const shopType = itemData?.goodsType == 1 ? '1' : itemData?.sceneType == 3 ? '2' : ''
      const shopForm = deepClone(formList[1].formBlock[index])
      const spliceForm = shopType == '1' ? ['giftCost', 'recoveryCost', 'virtualAccountCost', 'djCost', 'thirdPartyCost'] :
        shopType == '2' ? ['warrantyType', 'giftCost', 'recoveryCost', 'virtualAccountCost', 'djCost', 'thirdPartyCost'] :
          // 权益/延保类 无升级成本 新增嘀加成本和第三方成本
          this.equitySceneType.includes(itemData?.goodsType) || this.extendedPosiType.includes(itemData?.goodsType) ?
            ['warrantyType', 'upgradeSupplyMode', 'giftCost', 'recoveryCost', 'virtualAccountCost', 'upgradeProductCost'] :
            ['warrantyType', 'upgradeSupplyMode', 'giftCost', 'recoveryCost', 'virtualAccountCost', 'djCost', 'thirdPartyCost']
      // 回收成本:升级/产品供货模式选择“门店回收原厂+嘀加”时展示
      if (itemData.upgradeSupplyMode == 4) {
        spliceForm.indexOf('recoveryCost') > -1 && spliceForm.splice(spliceForm.indexOf('recoveryCost'), 1)
      }
      // 虚拟对账成本:升级/产品供货模式选择“门店套码+嘀加”“ 服务商自采+嘀加”时展示
      if (itemData.upgradeSupplyMode == 3 || itemData.upgradeSupplyMode == 5) {
        spliceForm.indexOf('virtualAccountCost') > -1 && spliceForm.splice(spliceForm.indexOf('virtualAccountCost'), 1)
      }
      const newForm = shopForm.filter(v => !spliceForm?.includes(v.name))
      this.$set(this.formList[1].formBlock, index, newForm)
      this.$nextTick(() => {
        const _formBlock = this.formList[1].formBlock[index]
        // 1.3场景 升级产品供货模式
        const formIndex = _formBlock.findIndex(subItem => subItem.name == 'upgradeSupplyMode')
        if (itemData.sceneType == 3) {
          if (formIndex >= 0) this.$set(_formBlock[formIndex], 'radioGroupList', crowdUpgradeSupplyModeList)
        }
        // 太阳膜类 升级产品供货模式(优先级高)
        if (shopType == 1) {
          // 由1.3场景 切换到太阳膜 已选升级供货模式为2 的清除掉 太阳膜供货模式没有2
          if (itemData.upgradeSupplyMode == 2) this.itemData.upgradeSupplyMode = ''
          if (formIndex > -1) this.$set(_formBlock[formIndex], 'radioGroupList', upgradeSupplyModeList)
          // 上架部位
          itemData?.positionNamesArr?.forEach(val => {
            val.confId = val.position
          })
          this.$set(_formBlock[_formBlock.findIndex(subItem => subItem.name == 'position')], 'radioGroupList', itemData?.positionNamesArr || [])
        }
        // 延保类
        if (this.extendedPosiType.includes(itemData?.goodsType)) {
          itemData?.positionNamesArr?.forEach(val => {
            val.confId = val.position
          })
          this.$set(_formBlock[_formBlock.findIndex(subItem => subItem.name == 'position')], 'radioGroupList', itemData?.positionNamesArr || [])
        }
        // 非权益/延保类,将滴加成本和第三方成本情况
        if (!this.equitySceneType.includes(itemData?.goodsType) && !this.extendedPosiType.includes(itemData?.goodsType)) {
          this.$set(this.formData.groundingGoodsList[index], 'djCost', '')
          this.$set(this.formData.groundingGoodsList[index], 'thirdPartyCost', '')
        } else { 
          this.$set(this.formData.groundingGoodsList[index], 'warrantyType', '')
          this.$set(this.formData.groundingGoodsList[index], 'upgradeSupplyMode', '')
          this.$set(this.formData.groundingGoodsList[index], 'recoveryCost', '')
          this.$set(this.formData.groundingGoodsList[index], 'virtualAccountCost', '')
          this.$set(this.formData.groundingGoodsList[index], 'upgradeProductCost', '')
        }
        // 当商品信息自带嘀加成本时,将输入框置灰
        if (!this.filterEmpty(this.formData.groundingGoodsList[index]?.upgradeGoods?.djCost)) {
          this.$set(_formBlock[_formBlock.findIndex(subItem => subItem.name == 'djCost')], 'isDisabled', true)
        }
        this.show = true
        this.$refs[this.formRef + 'd2FormRuleForm'] && this.$refs[this.formRef + 'd2FormRuleForm'].clearValidate()
      })
    },
    // 上传上架凭证
    handleFileChange(e, targetItem) {
      setTimeout(() => {
        var reader = new FileReader()
        var fileInfo = e.raw
        if (!fileInfo.name.includes('.pdf') && !fileInfo.name.includes('.png') && !fileInfo.name.includes('.jpg')) {
          return this.$message({
            message: '文件格式不支持上传',
            type: 'warning'
          })
        }
        reader.readAsDataURL(fileInfo)
        reader.onload = e => {
          const _formData = this.formData
          _formData[targetItem.name].push({
            voucherFileUrl: '',
            uploadProgress: 0,
            fileName: fileInfo.name?.substring(0, 128),
            fileSize: fileInfo.size,
            cancelAxios: {}
          })
          const index = _formData[targetItem.name].length - 1
          const fileData = e.target.result
          const base64 = fileInfo.name.split('.')[fileInfo.name.split('.').length - 1] + '@' + fileData.split(',')[1]
          const requestEvent = fileInfo.type == 'application/pdf' ? uploadPDF : uploadImg
          requestEvent({
            file: base64,
            onProcess: (e) => { // 上传进度
              const { loaded, total } = e
              const uploadPrecent = ((loaded / total) * 100) | 0
              _formData[targetItem.name][index].uploadProgress = uploadPrecent
            },
            cancelFun: _formData[targetItem.name][index].cancelAxios // 取消上传
          }).then(res => {
            _formData[targetItem.name][index].voucherFileUrl = res // 文件地址
          }).catch(() => {
            this.clearItem(targetItem, index) // 上传失败将内容清空 不删除数组 防止其它上传进度 找不到对应下标
          })
        }
      }, 50)
    },
    // 修改升级产品供货模式
    upgradeSupplyModeChange(e, index) {
      this.$set(this.formData.groundingGoodsList[index], 'recoveryCost', '')
      this.$set(this.formData.groundingGoodsList[index], 'virtualAccountCost', '')
    },
    // 限制上传文件个数
    hanldeOnExceed() {
      this.$message({
        message: '最多可上传30个文件',
        type: 'warning'
      })
    },
    // 添加商品
    addGroundingGoods() {
      const groundingGoodsList = this.formData.groundingGoodsList
      groundingGoodsList?.unshift({
        upgradeGoodsId: '', // 商品id
        goodsAlias: '', // 商品别名
        position: '', // 上架部位
        sellPrice: '', // 参考售价
        minSellPrice: '', // 最低售价
        upgradeProductCost: '', // 产品升级成本
        recoveryCost: '', // 回收成本
        virtualAccountCost: '', // 虚拟对账成本
        warrantyType: '', // 质保卡类型
        upgradeSupplyMode: '', // 升级/产品供货模式
        djCost: '', // 嘀加成本
        thirdPartyCost: '', // 第三方成本
        validMinSellPriceFlag: false
      })
      let arr = this.formList[1].formBlock
      arr?.unshift(packageGoodsForm)
      this.$set(this.formList[1], 'formBlock', arr)
    },
    delGroundingGoods(index) {
      const groundingGoodsList = this.formData.groundingGoodsList
      groundingGoodsList?.splice(index, 1)
    },
    // 删除文件
    handleFileDelete(targetItem, subIndex) {
      this.clearItem(targetItem, subIndex)
    },
    // 预览文件
    handleFileView(item) {
      if (!item.voucherFileUrl) return
      if (item?.voucherFileUrl.includes('.pdf')) { // pdf文件直接打开新窗口预览
        window.open(item.voucherFileUrl)
      } else {
        this.imgViewerVisible = true
        this.imageFileArr.forEach((val, index) => {
          if (val == item.voucherFileUrl) this.initialIndex = index
        })
      }
    },
    // 关闭文件预览
    closeImgViewer() {
      this.imgViewerVisible = false
    },
    // 取消上传
    doCancel(targetItem, subIndex) {
      const _formData = this.formData
      const cancelUploadObj = _formData[targetItem.name][subIndex].cancelAxios
      cancelUploadObj && cancelUploadObj.cancel && cancelUploadObj.cancel()
      this.clearItem(targetItem, subIndex)
    },
    // 清空上传文件数组项内容
    clearItem(targetItem, subIndex) {
      this.$set(this.formData[targetItem.name][subIndex], 'voucherFileUrl', '')
      this.$set(this.formData[targetItem.name][subIndex], 'uploadProgress', '')
    },
    // 选择上架门店
    handleClick() {
      const _this = this
      if (_this.filterEmpty(_this.formData.sceneType)) {
        return this.$message.warning('请选择业务场景')
      }
      _this.storeSelected = deepClone(_this.formData.merchantGoodsRefList)
      _this.relateStoreVisible = true
    },
    handleRelateStoreConfirm(selectedData) {
      if (!selectedData.length) {
        this.$message({
          message: '请选择关联门店',
          type: 'warning',
          showClose: true
        })
        return true
      }
      this.formData.merchantGoodsRefList = selectedData
      this.relateStoreVisible = false
    },
    handleRelateStoreClose() {
      this.relateStoreVisible = false
    },
    handleStoreInput(e) {
      (e.keyCode === 13) && this.handleSearchStore()
    },
    // 门店搜索
    handleSearchStore() {
      this.$refs.formRelateStore.handleCurrentChange(1)
    },
    // 删除上架门店
    handleDelete(item) {
      const filterArr = this.formData.merchantGoodsRefList.filter(i => i.merchantId !== item.merchantId)
      this.$set(this.formData, 'merchantGoodsRefList', filterArr)
    },
    // 下拉加载更多 下拉框显示隐藏触发
    visibleChange(data) {
      this.$emit('visibleChange', data)
    },
    interestsLoadmore() {
      this.$emit('interestsLoadmore')
    },
    remoteMethod(query) {
      this.$emit('remoteMethod', query)
    },
    // 修复直接调用可以会因为没有对应方法报错的问题
    input(event, item, eleIndex) {
      item.handleInput && this.handleInput(event, item, eleIndex)
    },
    blur(item) {
    },
    // 价格计算精度丢失处理
    subStr(num1, num2) {
      var r1, r2, m, n
      try {
        r1 = num1.toString().split('.')[1].length
      } catch (e) {
        r1 = 0
      }
      try {
        r2 = num2.toString().split(".")[1].length
      } catch (e) {
        r2 = 0
      }
      m = Math.pow(10, Math.max(r1, r2))
      n = (r1 >= r2) ? r1 : r2
      return ((num1 * m + num2 * m) / m).toFixed(n)
    },
    // 价格过滤
    handleInput(e, item, eleIndex) {
      e = e.replace(/[^\d.]/g, '')
      let oldValue = `${this.formData['groundingGoodsList'][eleIndex]['old' + item.name]}`
      this.$set(this.formData['groundingGoodsList'][eleIndex], `${item.name}`, limitPrice(e, oldValue, 6, 2, 0))
      this.$set(this.formData['groundingGoodsList'][eleIndex], `old${item.name}`, this.formData['groundingGoodsList'][eleIndex][item.name])
    },
    // 选择框-添加其他属性
    selectAddAttr(value, targetItem, eleIndex) {
      const _formData = this.filterEmpty(eleIndex) ? this.formData : this.formData.groundingGoodsList[eleIndex]
      if (targetItem.name == 'merchantId') {
        var _tempVal = targetItem.optionList.find(item => item.merchantId === value)
        _formData.merchantName = _tempVal.merchantName
      }
      // 切换业务场景 将选中的上架门店清空
      if (targetItem.name === 'sceneType') {
        const _formData = this.formData
        if (!this.filterEmpty(this.oldSceneType)) {
          // 清空门店弹窗搜索条件
          this.storeSearchForm = {
            merchantName: '',
            merchantId: '',
            yqMerchantName: '',
            yqMerchantId: ''
          }
          if (_formData.merchantGoodsRefList?.length) {
            this.$confirm('切换业务场景,将清空上架门店,是否继续', '提示', {
              confirmButtonText: '确定',
              type: 'warning'
            }).then(() => {
              _formData.sceneType = value
              this.$nextTick(() => {
                this.$refs.selectRefs_sceneType[0].blur()
                _formData.merchantGoodsRefList = []
                this.$forceUpdate()
              })
            }).catch(() => {
              _formData.sceneType = this.oldSceneType
              this.$nextTick(() => {
                this.$refs.selectRefs_sceneType[0].blur()
              })
            })
          }
        }
      }
    },
    handleClose() {
      this.$emit('handleClose')
    },
    jumpScroll(idName) {
      document.getElementById(idName).scrollIntoView()
    },
    filterEmpty(data) {
      return (data ?? '') === ''
    },
    // 处理金额补零
    priceFilter(num) {
      var pow = Math.pow(10, 2)
      if (this.filterEmpty(num)) return '-'
      return `${(Math.round(num * pow) / pow).toFixed(2)}元`
    },
    handleUp(e) {
      console.log(this.formData)
      this.$refs[this.formRef + 'd2FormRuleForm'].validate((valid, options) => {
        if (valid) {
          this.$emit('handleAddConfirm', { ...this.formData, num: e })
        } else {
          var needRuleList = Object.keys(options)
          this.jumpScroll(needRuleList[0])
          return true
        }
      })
    }
  }
}

</script>
<style lang="scss" scoped>
.package-form {
  .package-form-block {
    margin: 20px 0px;
    background: #ffffff;

    .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;
      justify-content: space-between;
    }
    .groundingGoods-item{
      padding-top: 15px;
      border-bottom: 1px solid #E5E5E5;
    }
    .groundingGoods-item:last-child{
      border: none;
    }

    .dis-in-block {
      display: inline-block;
      width: 100%;
    }

    .upload-file {
      ::v-deep .el-upload-dragger {
        display: flex;
        flex-flow: column;
        justify-content: center;
        align-items: center;
        width: 300px;
        height: 160px;
        background: #F7F7F7;

        .el-icon-upload {
          margin: 0;
        }

        .el-upload__text {
          font-size: 14px;
          color: #000000;
        }

        .item-tips {
          font-size: 12px;
          color: #999999;
          height: 22px;
          line-height: 22px;
        }

        .text-tips {
          font-size: 14px;
        }
      }
    }

    .file-box {
      width: 350px;

      .file-item {
        margin-top: 6px;
        position: relative;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        align-items: center;
        cursor: pointer;

        ::v-deep .el-progress-bar {
          width: 320px;
          background: #FFFFFF;
          border: 1px solid #F4F6FC;
          border-radius: 4px;

          .el-progress-bar__outer {
            background: transparent;
            border-radius: 4px;

            .el-progress-bar__inner {
              background: #F5F7FA;
              border-radius: 4px;
            }
          }
        }

        ::v-deep .el-image-viewer__wrapper {
          width: 100vw;
          height: 100vh;
        }

        .file-name {
          position: absolute;
          left: 12px;
          top: 6px;
          transform: translateY(-50%);
          color: #333333;
          font-size: 14px;
          max-width: 300px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .image-file {
          z-index: -1;
        }
      }

      .file-item:first-child {
        margin-top: 15px;

        .file-name {
          position: absolute;
          left: 12px;
          top: 15px;
          transform: translateY(-50%);
          color: #333333;
          font-size: 14px;
        }
      }
    }
    .check-min-price{
      margin: 0 6px 0 15px;
    }
    .tips-text{
      color: #999999;
    }
  }
}

.incid_box {
  margin-left: 180px;
  background: #F9F9F9;
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  padding: 15px;
  margin-bottom: 22px;
  font-size: 14px;
  color: #333333;

  .item {
    width: 33%;
    display: flex;
    align-items: center;
    margin: 10px 0;

    .label {
      flex-shrink: 0;
      color: #666666;
      width: 150px;
      text-align: right;
    }
    .value{
      width: calc(100% - 150px);
    }
    .text-hide {
      width: calc(100% - 150px);
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  .flex_1 {
    flex: 0 0 100%;
  }
}

.width_100 {
  display: inline-block;
  width: 100px;
}

.el-select-dropdown__item {
  .goodName {
    color: #333333;
  }

  .typeName {
    margin-left: 8px;
    font-size: 12px;
    color: #999999;
  }
}

.el-select-dropdown__item.selected {
  span {
    color: #2A58AD;
  }
}
::v-deep .el-radio__original {
  display: none !important;
}

::v-deep .el-radio:focus:not(.is-focus):not(:active):not(.is-disabled)
  .el-radio__inner {
  box-shadow: none !important;
}
</style>