addDialog.vue 37.7 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
<!-- 新增转账 -->
<template>
  <baseDialog :dialog-config="dialogConfig"
              :is-show.sync="visible"
              class="accountDailog"
              @handleClick="handleAddConfirm">
    <div class="add-dialog">
      <glsx-combi-form class="edit-form-container"
                       ref="editFormRef"
                       label-width="150px"
                       default-width="400px"
                       :form-ref="editChildRef"
                       :form-obj="infoForm"
                       :form-data="editFormData"
                       :form-rules="formRules">
        <div slot="expenseTypeHtml"
             slot-scope="scope">
          <el-checkbox-group v-model="infoForm.expenseType"
                             @change="handleCheckChange">
            <el-checkbox v-for="(item, index) in baseData.expenseTypes"
                         :key="index"
                         :label="item.confId">{{
                           item.confValue }}</el-checkbox>
          </el-checkbox-group>
        </div>
        <div slot="expenseTypeHtml2"
             slot-scope="scope"
             style="width:400px">
          <el-checkbox-group v-model="infoForm.expenseType"
                             @change="handleCheckChange2">
            <el-checkbox v-for="(item, index) in baseData.expenseTypes2"
                         :key="index"
                         :label="item.confId">
              {{ item.confValue }}
            </el-checkbox>
          </el-checkbox-group>
        </div>
        <div slot="installCostHtml"
             slot-scope="scope">
          <el-input v-model="infoForm.installCost"
                    style="width:400px"
                    disabled
                    placeholder="选择场景、对账方、对账周期、费用类型后自动获取" />
          <el-button type="text"
                     class="down-cla"
                     @click="downloadDetail('7', '2')">下载明细</el-button>
        </div>
        <div slot="marketingCostHtml"
             slot-scope="scope">
          <el-input v-model="infoForm.marketingCost"
                    style="width:400px"
                    disabled
                    placeholder="选择场景、对账方、对账周期、费用类型后自动获取" />
          <el-button type="text"
                     class="down-cla"
                     @click="downloadDetail('7', '3')">下载明细</el-button>
        </div>
        <div slot="rewardAndPenaltyCostHtml"
             slot-scope="scope">
          <el-input v-model="infoForm.rewardAndPenaltyCost"
                    style="width:400px"
                    disabled
                    placeholder="选择场景、对账方、对账周期、费用类型后自动获取" />
          <el-button type="text"
                     class="down-cla"
                     @click="downloadDetail('7', '3')">下载明细</el-button>
        </div>
        <div slot="shopTrafficMoneyHtml"
             slot-scope="scope">
          <el-input v-model="infoForm.shopTrafficMoney"
                    style="width:400px"
                    disabled
                    placeholder="选择场景、对账方、对账周期、费用类型后自动获取" />
          <el-button type="text"
                     class="down-cla"
                     @click="downloadDetail('2')">下载明细</el-button>
        </div>
        <div slot="transferTotalAmountHtml"
             slot-scope="scope">
          <el-input placeholder="请输入转账金额"
                    v-model="infoForm.transferTotalAmount"
                    style="width:400px"
                    clearable
                    @input="handleUpgradeNum">
          </el-input>
        </div>
        <!-- <div slot="voucherListHtml"
             slot-scope="scope">

        </div> -->
        <template slot="voucherListHtml"
                  slot-scope="scope">
          <el-upload action=""
                     accept=".xlsx,.xls"
                     class="upload-file"
                     drag
                     :show-file-list="false"
                     :file-list="uploadFileList"
                     :limit="5"
                     :auto-upload="false"
                     :on-remove="importFileChange"
                     :on-change="(file, fileList) => handleFileChange(file, fileList, scope.scope)"
                     :on-exceed="hanldeOnExceed"
                     multiple>
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">点击或将文件拖拽到此区域上传</div>
            <div class="item-tips text-tips">支持格式:.xlsx .xls,单个文件不能超过10M </div>
            <div class="item-tips">最多上传5个文件</div>
          </el-upload>
          <!-- 文件列表区域 -->
          <div class="file-box">
            <div v-for="(subItem, subIndex) in infoForm.voucherList"
                 :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(scope.scope, subIndex)"></i>
                <i v-if="subItem.voucherFileUrl"
                   class="el-icon-delete"
                   @click="handleFileDelete(scope.scope, subIndex)"></i>
              </div>
            </div>
          </div>
        </template>
      </glsx-combi-form>
    </div>
  </baseDialog>
</template>

<script>
import { sceneCodeList, transferTypeList } from '@/common/constants.js'
import { getAmount, transferAccountsRecordAdd, getPreviousRecord } from '@api/transferAccountsManage'
import { getList } from '@api/serviceManage'
import { getListApi } from '@api/publicAccount'
import { getDjzhySubMerchant, listShop4sByRef } from '@api/merchant'
import { Util, deepClone, downLoadFile } from '@/common/util'
import { mapActions, mapState } from 'vuex'
import { limitPrice } from '@/common/format'
import { uploadPDF, uploadExcel } from '@/api/sys.base'
import { getServiceStore } from '@api/editCustomer'
import { getPlatformMerchantList } from '@api/index'
export default {
  name: 'AddDialog',
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      infoForm: {
        platformMerchantId: '',
        sceneType: '',
        transferType: 1,
        partnerMerchantId: '',
        yqMerchantId: '',
        shopMerchantId: '',
        reconciliationDate: '',
        expenseType: [1, 2],
        installCost: '',
        marketingCost: '',
        rewardAndPenaltyCost: '',
        shopTrafficMoney: '',
        transferTotalAmount: '',
        transferInMerchantId: '',
        remark: '',
        voucherList: []
      },
      oldVal: {
        transferTotalAmount: ''
      },
      dialogConfig: {
        title: '新增转账',
        width: '860px'
      },
      editChildRef: 'editChildRef',
      formRules: {
        platformMerchantId: [{ required: true, message: '请选择平台方', trigger: 'change' }],
        sceneType: [{ required: true, message: '请选择业务场景', trigger: 'change' }],
        transferType: [{ required: true, message: '请选择转账类型', trigger: 'change' }],
        partnerMerchantId: [{ required: true, message: '请选择对账服务商', trigger: 'change' }],
        // yqMerchantId: [{ required: true, message: '请选择对账园区店', trigger: 'change' }],
        // shopMerchantId: [{ required: true, message: '请选择对账流量方', trigger: 'change' }],
        reconciliationDate: [{ required: true, message: '请选择对账周期', trigger: 'change' }],
        // expenseType: [{ required: true, message: '请选择费用类型', trigger: 'change' }],
        transferInMerchantId: [{ required: true, message: '请选择转入方', trigger: 'change' }]
      },
      editFormData: [{
        label: '业务场景',
        name: 'sceneType',
        type: 'select',
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confValue',
        optionsName: 'sceneTypeList',
        changeAttr: (value, targetItem) => {
          this.getAmount()
          // if (this.infoForm.transferType == 2) { //流量方款项时改变业务场景会重新获取对账方数据
          //   this.getListShop4sByRef()
          // }
        }
      }, {
        label: '转账类型',
        name: 'transferType',
        type: 'select',
        // isDisabled: true,
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confValue',
        optionsName: 'transferTypeList',
        changeAttr: (value, targetItem) => {
          if (value == 1) {
            // 转账类型不同时费用类型不同,因此用两个不同的插槽内容显示区分开来
            this.showOrHideAttr_transferType('editFormData', 'expenseTypeHtml', false)
            this.showOrHideAttr_transferType('editFormData', 'expenseTypeHtml2', true)
            // 服务商款项时对账服务商和对账园区店显示
            this.showOrHideAttr('editFormData', '对账服务商', false)
            this.showOrHideAttr('editFormData', '对账园区店', false)
            this.editFormData[this.findFormIdx('shopMerchantId')].rules = [] // 删除对账流量方为必填项
            this.infoForm.expenseType = [1, 2]
            this.handleCheckChange([1, 2])
            this.handleCheckChange2([])
            // 切换转账类型时清空对账流量方的选项及数据源
            this.baseData.shopMerchantList = []
            this.infoForm.shopMerchantId = ''
            this.getOptionsList('editFormData', true, 'shopMerchantId')
          } else {
            this.showOrHideAttr_transferType('editFormData', 'expenseTypeHtml', true)
            this.showOrHideAttr_transferType('editFormData', 'expenseTypeHtml2', false)
            // 流量方款项时对账服务商和对账园区店隐藏
            this.showOrHideAttr('editFormData', '对账服务商', true)
            this.showOrHideAttr('editFormData', '对账园区店', true)
            this.editFormData[this.findFormIdx('shopMerchantId')].rules = [{ required: true, message: '请选择对账流量方', trigger: 'change' }]// 增加对账流量方为必填项
            // 切换转账类型时清空对账园区店和对账流量方的选项及数据源
            this.baseData.yqMerchantList = []
            this.infoForm.partnerMerchantId = ''
            this.infoForm.yqMerchantId = ''
            this.getOptionsList('editFormData', false, 'yqMerchantId')
            this.getListShop4sByRef() // 流量方款项时对账方数据来源
            this.infoForm.expenseType = [3]
            this.handleCheckChange([])
            this.handleCheckChange2([3])
          }
          this.getPreviousRecord_Validate()
        }
      },
      {
        label: '对账服务商',
        name: 'partnerMerchantId',
        type: 'select',
        isClear: true,
        isHide: false,
        optionList: [],
        optionId: 'partnerMerchantId',
        optionLabel: 'partnerMerchantName',
        optionsName: 'merchantList',
        changeAttr: (value, targetItem) => {
          this.infoForm.yqMerchantId = ''
          this.baseData.shopMerchantList = [{ merchantId: '', merchantName: '全部' }]
          this.infoForm.shopMerchantId = ''
          this.getOptionsList('editFormData', true, 'shopMerchantId')
          this.baseData.yqMerchantList = targetItem.optionList.find(item => item.partnerMerchantId == value).ymerchants
          this.getOptionsList('editFormData', true, 'yqMerchantId')
          this.getAmount()
          this.getPreviousRecord_Validate()
        }
      }, {
        label: '对账园区店',
        name: 'yqMerchantId',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'ymerchantId',
        optionLabel: 'ymerchantName',
        optionsName: 'yqMerchantList',
        changeAttr: (value, targetItem) => {
          if (value) {
            // 获取流量方
            this.getServiceStore(value)
            this.getAmount()
          }
        }
      }, {
        label: '对账流量方',
        name: 'shopMerchantId',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'merchantId',
        optionLabel: 'merchantName',
        optionsName: 'shopMerchantList',
        changeAttr: (value, targetItem) => {
          this.getAmount()
          this.getPreviousRecord_Validate()
        }
      }, {
        label: '所属平台方',
        name: 'platformMerchantId',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'merchantId',
        optionLabel: 'merchantName',
        optionsName: 'PlatformMerchantList'
      }, {
        label: '对账周期',
        name: 'reconciliationDate',
        type: 'datePicker',
        isClear: true,
        pickerOptions: 'rangePickerOptions'
      }, {
        label: '费用类型',
        name: 'expenseType',
        isHide: false,
        addHtml: 'expenseTypeHtml',
        rules: [{ required: true, message: '请选择费用类型', trigger: 'change' }]
      }, {
        label: '费用类型',
        name: 'expenseType',
        isHide: true,
        addHtml: 'expenseTypeHtml2',
        rules: [{ required: true, message: '请选择费用类型', trigger: 'change' }]
      }, {
        label: '安装费',
        name: 'installCost',
        isHide: false,
        addHtml: 'installCostHtml',
        rules: [{ required: true, message: '未计算安装费', trigger: 'change' }]
      }, {
        label: '营销费',
        name: 'marketingCost',
        isHide: false,
        addHtml: 'marketingCostHtml',
        rules: [{ required: true, message: '未计算营销费', trigger: 'change' }]
      }, {
        label: '奖惩费',
        name: 'rewardAndPenaltyCost',
        isHide: false,
        addHtml: 'rewardAndPenaltyCostHtml',
        rules: [{ required: true, message: '未计算奖惩费', trigger: 'change' }]
      }, {
        label: '流量费',
        name: 'shopTrafficMoney',
        isHide: true,
        addHtml: 'shopTrafficMoneyHtml',
        rules: [{ required: true, message: '未计算流量费', trigger: 'change' }]
      }, {
        label: '转账金额/元',
        name: 'transferTotalAmount',
        isHide: false,
        addHtml: 'transferTotalAmountHtml',
        rules: [{ required: true, message: '请输入金额,支持输入0~999999的数字,支持小数点后2位', trigger: 'change' }]
      }, {
        label: '转入方',
        name: 'transferInMerchantId',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'merchantId',
        optionLabel: 'merchantName',
        optionsName: 'transferInMerchantList'
      }, {
        label: '备注',
        name: 'remark',
        type: 'input',
        maxlength: 50,
        inputType: 'textarea',
        showLimit: true,
        rows: 4
      }, {
        label: '对账凭证',
        name: 'voucherList',
        isHide: false,
        addHtml: 'voucherListHtml'
      }],
      baseData: {
        sceneTypeList: deepClone(sceneCodeList),
        transferTypeList: deepClone(transferTypeList),
        merchantList: [],
        yqMerchantList: [],
        shopMerchantList: [],
        transferInMerchantList: [],
        expenseTypes: [
          { confId: 1, confValue: "安装费" },
          { confId: 2, confValue: "营销费及奖惩费" }
        ],
        expenseTypes2: [
          { confId: 3, confValue: "流量费" }
        ],
        PlatformMerchantList: []
      },
      uploadFileList: []
    }
  },

  props: {
    addVisible: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    'infoForm.reconciliationDate': {
      handler(val) {
        if (val) {
          this.getAmount()
        }
      },
      immediate: true
    },
    'infoForm.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('.xlsx') || v.voucherFileUrl.includes('xls')))
          // this.imageFileArr = imageFileArr.map(item => { return item.voucherFileUrl })
        }
      },
      deep: true
    }
  },
  computed: {
    visible: {
      get() {
        return this.addVisible
      },
      set(newVal) {
        this.$emit('dialogClose', { flag: newVal, attrName: 'addVisible' })
      }
    },
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },

  mounted() {
    this.getPlatformMerchantList()
    this.getMerchantList()
    this.getInMerchantList()
    this.getOptionsList('editFormData', false)
  },

  methods: {
    ...mapActions('d2admin/user', ['actionSetDownloadList']),
    getOptionsList(formName, hasAll = true, refreshSigle) {
      if (refreshSigle) {
        var item = this[formName].find(k => k.name == refreshSigle)
        var index = this[formName].findIndex(k => k.name == refreshSigle)
        this.$set(this[formName][index], 'optionList', deepClone(this.baseData[item.optionsName]))
        if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
          const temp = {}
          temp[this[formName][index].optionId] = ''
          temp[this[formName][index].optionLabel] = '全部'
          this[formName][index].optionList.unshift(temp)
        }
      } else {
        this[formName].forEach((item, index) => {
          if (item.type === 'select' && this.baseData[item.optionsName].length) {
            this.$set(this[formName][index], 'optionList', deepClone(this.baseData[item.optionsName]))
            if (this[formName][index].label == '业务场景') { // 业务场景默认选中第一项
              console.log(this.baseData[item.optionsName])

              this.infoForm.sceneType = this.baseData[item.optionsName][0].confId
            }
            if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
              const temp = {}
              temp[this[formName][index].optionId] = ''
              temp[this[formName][index].optionLabel] = '全部'
              this[formName][index].optionList.unshift(temp)
            }
          }
        })
      }
    },

    showOrHideAttr(formName, label, isHide) {
      const idx = this[formName].findIndex(item => item.label == label)
      console.log('idx', idx)
      console.log('this[formName][idx].isHide', this[formName][idx].isHide)
      this[formName][idx].isHide = isHide
    },

    showOrHideAttr_transferType(formName, addHtml, isHide) {
      const idx = this[formName].findIndex(item => item.addHtml == addHtml)
      console.log('idx', idx)
      console.log('this[formName][idx].isHide', this[formName][idx].isHide)
      this[formName][idx].isHide = isHide
    },

    getMerchantList() {
      this.baseData.merchantList = []
      var params = {}
      params.currentPage = 1
      params.pageSize = 10000
      getList(params).then(res => {
        this.baseData.merchantList = res.list
        this.getOptionsList('editFormData', false)
        // this.infoForm.merchantId = ''
      })
    },

    getInMerchantList() {
      var params = {}
      params.currentPage = 1
      params.pageSize = 10000
      params.accountStatus = 3 // 生效
      params.merchantTypeList = [2, 7, -1]
      getListApi(params).then(res => {
        this.baseData.transferInMerchantList = res.list
        // 获取获取嘀加智慧云子商户信息
        getDjzhySubMerchant({}).then(res => {
          // 转入方选项中去除嘀加智慧云子商户
          this.baseData.transferInMerchantList = this.baseData.transferInMerchantList.filter((item) => item.merchantId != res.merchantId)
          this.getOptionsList('editFormData', false)
        })
      })
    },

    getListShop4sByRef() {
      this.baseData.shopMerchantList = []
      this.infoForm.shopMerchantId = ''
      listShop4sByRef({
        // scene: this.infoForm.sceneType
      }).then(res => {
        this.baseData.shopMerchantList = deepClone(res)
        // this.baseData.merchantList = this.baseData.merchantList.map(item => {
        //   item.partnerMerchantId = item.merchantId
        //   item.partnerMerchantName = item.merchantName
        //   return item
        // })
        this.getOptionsList('editFormData', false, 'shopMerchantId')
        // this.infoForm.merchantId = ''
      })
    },

    getServiceStore(merchantId) {
      getServiceStore({
        yqMerchantId: merchantId
      }).then(res => {
        this.infoForm.shopMerchantId = ''
        this.baseData.shopMerchantList = res || []
        this.getOptionsList('editFormData', true, 'shopMerchantId')
      })
    },

    handleCheckChange(val) {
      console.log('val', val)
      if (val.length > 0) {
        if (val.includes(1)) { // 选中安装费
          this.showOrHideAttr('editFormData', '安装费', false)
        } else {
          this.showOrHideAttr('editFormData', '安装费', true)
        }
        if (val.includes(2)) { // 选中营销费及奖惩费
          this.showOrHideAttr('editFormData', '营销费', false)
          this.showOrHideAttr('editFormData', '奖惩费', false)
        } else {
          this.showOrHideAttr('editFormData', '营销费', true)
          this.showOrHideAttr('editFormData', '奖惩费', true)
        }
        this.getAmount()
      } else {
        this.showOrHideAttr('editFormData', '安装费', true)
        this.showOrHideAttr('editFormData', '营销费', true)
        this.showOrHideAttr('editFormData', '奖惩费', true)
      }
    },

    handleCheckChange2(val) {
      console.log('val', val)
      if (val.length > 0) {
        this.showOrHideAttr('editFormData', '流量费', false)
        this.getAmount()
      } else {
        this.showOrHideAttr('editFormData', '流量费', true)
      }
    },

    // 下载明细
    downloadDetail(merchantType, reportType) {
      var infoForm = deepClone(this.infoForm)
      console.log('infoForm', infoForm)

      var params = {}
      var merchantList = []
      var obj = {}
      if (infoForm.transferType == 1) {
        if (!infoForm.partnerMerchantId || !infoForm.reconciliationDate || !infoForm.sceneType) {
          this.notice.warningTips('请选择业务场景、对账服务商及对账周期才能下载明细')
          return
        }
        obj.merchantId = infoForm.partnerMerchantId
        obj.merchantName = this.baseData.merchantList.find(
          mer => mer.partnerMerchantId === infoForm.partnerMerchantId
        ).partnerMerchantName
        merchantList.push(obj)

        if (infoForm.yqMerchantId) {
          params.yqMerchantId = infoForm.yqMerchantId
        }
        if (infoForm.shopMerchantId) {
          params.shopMerchantId = infoForm.shopMerchantId
        }
      } else {
        if (!infoForm.shopMerchantId || !infoForm.reconciliationDate || !infoForm.sceneType) {
          this.notice.warningTips('请选择业务场景、对账流量方及对账周期才能下载明细')
          return
        }
        obj.merchantId = infoForm.shopMerchantId
        obj.merchantName = this.baseData.shopMerchantList.find(
          mer => mer.merchantId === infoForm.shopMerchantId
        ).merchantName
        merchantList.push(obj)
      }
      if (infoForm.reconciliationDate) {
        params.payStartDate = Util.dateFormate(this.infoForm.reconciliationDate[0], 'YYYY-MM-DD') + ' 00:00:00'
        params.payEndDate = Util.dateFormate(this.infoForm.reconciliationDate[1], 'YYYY-MM-DD') + ' 23:59:59'
        // delete this.infoForm.reconciliationDate
      }
      const merchantName = `merchantList[0].merchantName`
      const merchantId = `merchantList[0].merchantId`
      params[merchantName] = obj.merchantName
      params[merchantId] = obj.merchantId
      params.merchantType = merchantType
      if (merchantType == '7') { // 服务商
        params.reportType = reportType
      }
      params.filterTransferAccounts = true // 后端要求固定传
      params.sceneType = infoForm.sceneType
      params.method = 'dj.api.smartcarlife.goodsOrderProfitAllocation.exportAccountStatementForAudit.async'
      console.log('params', params)
      const list = [
        ...this.dowloadList,
        {
          name: '对账单',
          // uuid: JSON.parse(res).data,
          // ifSuccess: false
          exportParam: JSON.stringify(params),
          status: 'waiting',
          timeid: new Date().getTime()
        }
      ]
      this.actionSetDownloadList({ list, type: 'dowloadList' })
    },

    handleUpgradeNum(newVal) {
      this.infoForm.transferTotalAmount = limitPrice(newVal, this.oldVal.transferTotalAmount, 6, 2, 0, 999999)
      this.oldVal.transferTotalAmount = this.infoForm.transferTotalAmount
    },

    // 获取转账金额
    getAmount() {
      var infoForm = deepClone(this.infoForm)
      // if (!infoForm.merchantId || !infoForm.reconciliationDate || (!infoForm.sceneType && infoForm.sceneType != '0') || infoForm.expenseType.length == 0) {
      //   return
      // }
      if (infoForm.transferType == 1 && !infoForm.partnerMerchantId) { // 服务商款项时,判断对账服务商是否已选
        if (!infoForm.reconciliationDate || (!infoForm.sceneType && infoForm.sceneType != '0') || infoForm.expenseType.length == 0) {
          return
        }
      } else if (infoForm.transferType == 2 && !infoForm.shopMerchantId) { // 流量方款项时,判断对账流量方是否已选
        if (!infoForm.reconciliationDate || (!infoForm.sceneType && infoForm.sceneType != '0') || infoForm.expenseType.length == 0) {
          return
        }
      }

      var params = {}
      params.sceneType = infoForm.sceneType
      // if (infoForm.transferType == 1) { //服务商款项时
      //   params.partnerMerchantId = infoForm.partnerMerchantId
      // } else if (infoForm.transferType == 2) { //流量方款项时
      //   params.shopMerchantId = infoForm.shopMerchantId
      // }
      params.partnerMerchantId = infoForm.partnerMerchantId
      params.yqMerchantId = infoForm.yqMerchantId
      params.shopMerchantId = infoForm.shopMerchantId
      params.startTime = Util.dateFormate(this.infoForm.reconciliationDate[0], 'YYYY-MM-DD')
      params.endTime = Util.dateFormate(this.infoForm.reconciliationDate[1], 'YYYY-MM-DD')
      var expenseTypeList = []
      if (infoForm.expenseType.includes(1)) { // 选中安装费
        expenseTypeList.push(5)
      }
      if (infoForm.expenseType.includes(2)) { // 选中营销费及奖惩费
        expenseTypeList.push(6)
        expenseTypeList.push(7)
      }
      if (infoForm.expenseType.includes(3)) { // 选中流量费
        expenseTypeList.push(1)
      }
      params.expenseTypeList = expenseTypeList
      params.transferType = infoForm.transferType
      getAmount(params).then(res => {
        this.infoForm.installCost = res.installCost
        this.infoForm.marketingCost = res.marketingCost
        this.infoForm.rewardAndPenaltyCost = res.rewardAndPenaltyCost
        this.infoForm.shopTrafficMoney = res.shopTrafficMoney
        this.infoForm.transferTotalAmount = res.totalAmount || ''
      })
    },
    // 获取文件
    importFileChange(file, fileList) {
      this.uploadFileList = fileList
      this.infoForm.voucherList = deepClone(fileList)
      console.log(fileList, 'fileList')
    },
    handleFileChange(file, fileList, targetItem) {
      // setTimeout(() => {
      var reader = new FileReader()
      var fileInfo = file.raw
      if (!fileInfo.name.includes('.xlsx') && !fileInfo.name.includes('.xls')) {
        this.$message({
          message: '文件格式不支持上传',
          type: 'error'
        })
        return false
      }
      // 默认10MB
      const limitSize = 10
      const isLt = fileInfo.size / 1024 / 1024 < limitSize
      if (!isLt) {
        this.$message({
          message: '上传文件大小不能超过' + limitSize + 'MB!',
          type: 'error'
        })
        this.uploadFileList = this.uploadFileList.filter((item) => {
          return item.size / 1024 / 1024 < 10
        })
        return false
      }
      reader.readAsDataURL(fileInfo)
      reader.onload = e => {
        // const _voucherList = this.infoForm.voucherList
        const _formData = this.infoForm
        _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 : uploadExcel

        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) // 上传失败将内容清空 不删除数组 防止其它上传进度 找不到对应下标
        })
        console.log('_formData[targetItem.name]', _formData[targetItem.name])
      }
      // }, 50)
    },
    hanldeOnExceed(files, fileList) {
      this.$message({
        message: '最多可上传5个文件',
        type: 'error'
      })
    },
    // 删除文件
    handleFileDelete(targetItem, subIndex) {
      // this.clearItem(targetItem, subIndex)
      console.log(subIndex)
      this.infoForm.voucherList.splice(subIndex, 1)
      // this.infoForm.voucherList = []
    },
    // 预览文件
    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.infoForm
      const cancelUploadObj = _formData[targetItem.name][subIndex].cancelAxios
      cancelUploadObj && cancelUploadObj.cancel && cancelUploadObj.cancel()
      this.clearItem(targetItem, subIndex)
    },
    filterEmpty(data) {
      return (data ?? '') === ''
    },
    // 清空上传文件数组项内容
    clearItem(targetItem, subIndex) {
      this.$set(this.infoForm[targetItem.name][subIndex], 'voucherFileUrl', '')
      this.$set(this.infoForm[targetItem.name][subIndex], 'uploadProgress', '')
    },

    handleAddConfirm() {
      this.$refs.editFormRef.$refs[this.editChildRef].validate(valid => {
        if (valid) {
          var infoForm = deepClone(this.infoForm)
          var params = {}
          params.sceneType = infoForm.sceneType
          params.transferType = infoForm.transferType
          if (infoForm.transferType == 1) { // 服务商款项
            params.partnerMerchantId = infoForm.partnerMerchantId
            params.yqMerchantId = infoForm.yqMerchantId
          }
          params.shopMerchantId = infoForm.shopMerchantId
          params.startTime = Util.dateFormate(this.infoForm.reconciliationDate[0], 'YYYY-MM-DD')
          params.endTime = Util.dateFormate(this.infoForm.reconciliationDate[1], 'YYYY-MM-DD')
          params.transferInMerchantId = infoForm.transferInMerchantId
          if (infoForm.transferTotalAmount > 0) {
            params.transferTotalAmount = infoForm.transferTotalAmount
          } else {
            this.$message({
              message: "转账金额必须大于0",
              type: "warning",
              showClose: true
            })
            return
          }

          params.remark = infoForm.remark
          var expenseTypeList = []
          if (infoForm.expenseType.includes(1)) { // 选中安装费
            expenseTypeList.push(5)
          }
          if (infoForm.expenseType.includes(2)) { // 选中营销费及奖惩费
            expenseTypeList.push(6)
            expenseTypeList.push(7)
          }
          if (infoForm.expenseType.includes(3)) { // 选中流量费
            expenseTypeList.push(1)
          }
          params.expenseTypeList = expenseTypeList
          if (infoForm.voucherList.length > 0) {
            infoForm.voucherList = infoForm.voucherList.map(item => {
              return {
                fileName: item.fileName,
                fileUrl: item.voucherFileUrl
              }
            })
          }
          params.voucherList = infoForm.voucherList
          params.platformMerchantId = infoForm.platformMerchantId

          transferAccountsRecordAdd(params).then(res => {
            this.notice.okTips('操作成功')
            this.visible = true
          })
        }
      })
    },

    // 找到在formList的位置,通过name来匹配
    findFormIdx(name) {
      return this.editFormData.findIndex(item => item.name === name)
    },

    // 获取平台方数据
    getPlatformMerchantList() {
      getPlatformMerchantList({}).then(res => {
        res.unshift({
          merchantId: -1,
          merchantName: '嘀加智慧云'
        })
        this.baseData.PlatformMerchantList = res
        this.getOptionsList('editFormData', false, 'platformMerchantId')
      })
    },

    getPreviousRecord_Validate() {
      if ((this.infoForm.transferType == 1 && this.infoForm.partnerMerchantId) || (this.infoForm.transferType == 2 && this.infoForm.shopMerchantId)) {
        this.getPreviousRecord_Confirm()
      }
    },

    // 获取上一条转账记录
    getPreviousRecord_Confirm() {
      var params = {}
      params.transferType = this.infoForm.transferType
      if (this.infoForm.transferType == 1) { // 服务商款项
        params.partnerMerchantId = this.infoForm.partnerMerchantId
      } else { // 流量方款项
        params.shopMerchantId = this.infoForm.shopMerchantId
      }
      getPreviousRecord(params).then(res => {
        console.log(res)
        const obj = deepClone(res)
        if (obj) {
          if (obj.platformMerchantId) {
            this.infoForm.platformMerchantId = this.baseData.PlatformMerchantList.find(o => o.merchantId == obj.platformMerchantId) ? obj.platformMerchantId : ''
          }
          if (obj.transferInMerchantId) {
            this.infoForm.transferInMerchantId = this.baseData.transferInMerchantList.find(o => o.merchantId == obj.transferInMerchantId) ? obj.transferInMerchantId : ''
          }
        } else {
          this.infoForm.platformMerchantId = ''
          this.infoForm.transferInMerchantId = ''
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.add-dialog {
  margin: 20px 0;

  .reject-input {
    ::v-deep .el-textarea__inner {
      height: 70px;
    }
  }

  .el-textarea .el-input__count {
    right: 90px;
    bottom: -10px;
    font-size: 12px;
    color: #999999;
  }

  .tips {
    color: #999999;
  }

  .down-cla {
    width: 56px;
    height: 32px;
    font-family: PingFangSC-Regular;
    font-weight: 400;
    font-size: 14px;
    color: #185efe;
    text-align: right;
    line-height: 32px;
    padding-left: 8px;
    // cursor: pointer;
  }

  .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;
      }
    }
  }
}
</style>