downloadAccountDialog.vue 27.2 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
<!-- 下载对账单 -->
<template>
    <d2-dialog title="下载对账单"
               :is-visible="accountVisible"
               class="accountDailog"
               width="688px"
               btn-ok-label="下载"
               @closeDialog="handleClose"
               @confirmDialog="handleAddConfirm">
        <el-form ref="accountForm"
                 v-loading="loading"
                 :model="infoForm"
                 :rules="formRules"
                 label-width="120px">
            <el-form-item label="业务线:" prop="sceneType">
                <el-select v-model="infoForm.sceneType" style="width:400px">
                    <el-option v-for="item in baseData.sceneTypeList"
                               :key="item.confId"
                               :label="item.confLabel"
                               :value="item.confId" />
                </el-select>
            </el-form-item>
            <!-- 权益类:多选 +「全部」;:key 避免切换业务线时 el-select 复用导致单选/多选展示层叠 -->
            <el-form-item v-if="!isLightBusinessLine"
                          :key="`biz-scene-equity-${infoForm.sceneType}`"
                          label="业务场景:"
                          prop="baseSceneCodeList"
                          required>
                <el-select :key="`biz-scene-select-equity-${infoForm.sceneType}`"
                           v-model="infoForm.baseSceneCodeList"
                           multiple
                           collapse-tags
                           style="width:400px"
                           @change="handleEquitySceneChange">
                    <el-option v-for="item in equitySceneSelectOptions"
                               :key="item.confId"
                               :label="item.confLabel"
                               :value="item.confId" />
                </el-select>
            </el-form-item>
            <!-- 轻改类:单选、无「全部」,默认第一项 -->
            <el-form-item v-else
                          :key="`biz-scene-light-${infoForm.sceneType}`"
                          label="业务场景:"
                          prop="baseSceneCodeList"
                          required>
                <el-select :key="`biz-scene-select-light-${infoForm.sceneType}`"
                           v-model="lightSceneSelectModel"
                           style="width:400px"
                           @change="handleLightSceneChange">
                    <el-option v-for="item in lightSceneSelectOptions"
                               :key="item.confId"
                               :label="item.confLabel"
                               :value="item.confId" />
                </el-select>
            </el-form-item>
            <el-form-item label="商户类型:" prop="merchantType">
                <el-radio-group v-model="infoForm.merchantType" @change="changeType">
                    <el-radio label="2">
                        流量方
                    </el-radio>
                    <el-radio label="7">
                        服务商
                    </el-radio>
                    <el-radio v-if="yqCheckVisible" label="6">
                        园区店
                    </el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item v-if="infoForm.merchantType == '7'"
                          label="账单类型:"
                          prop="reportType">
                <el-radio-group v-model="infoForm.reportType" @change="judgeTmpl">
                    <el-radio label="1">
                        普通对账单
                    </el-radio>
                    <el-radio label="2">
                        安装费对账单
                    </el-radio>
                    <el-radio label="3">
                        营销费对账单
                    </el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="对账商户:" prop="merchant">
                <el-select v-model="infoForm.merchant"
                           multiple
                           :multiple-limit="multipleLimit"
                           filterable
                           style="width:400px"
                           @change="handleChangeMerchant">
                    <el-option v-for="item in baseData.merchantList"
                               :key="item.merchantId"
                               :label="item.merchantName"
                               :value="item.merchantId" />
                </el-select>
            </el-form-item>
            <el-form-item v-if="isTmpl && infoForm.merchantType == '7'"
                          label="流量方:"
                          prop="shopMerchantId">
                <el-select v-model="infoForm.shopMerchantId" style="width:400px">
                    <el-option v-for="item in baseData.shopMerchantList"
                               :key="item.merchantId"
                               :label="item.merchantName"
                               :value="item.merchantId" />
                </el-select>
            </el-form-item>
            <el-form-item label="对账周期:"
                          class="dateItem"
                          prop="payStartDate">
                <el-date-picker v-model="infoForm.payStartDate"
                                type="date"
                                placeholder="选择开始日期"
                                value-format="yyyy-MM-dd"
                                clearables
                                :picker-options="startDateOptions"
                                style="width:185px"
                                @change="changeStartDate" />
                <div style="margin:0 15px;">
                    -
                </div>
                <el-date-picker v-model="infoForm.payEndDate"
                                type="date"
                                placeholder="选择结束日期"
                                value-format="yyyy-MM-dd"
                                clearable
                                :picker-options="pickerOptions0"
                                style="width:185px" />
            </el-form-item>
            <el-form-item label="对账状态:" prop="reconciliationStatus">
                <el-select v-model="infoForm.reconciliationStatus" style="width:400px">
                    <el-option v-for="item in baseData.reconStatusList"
                               :key="item.confId"
                               :label="item.confLabel"
                               :value="item.confId" />
                </el-select>
            </el-form-item>
            <el-form-item v-if="isTmpl"
                          label="套餐合并"
                          prop="packageMerge">
                <el-radio-group v-model="infoForm.packageMerge">
                    <el-radio v-for="(item, index) in baseData.packageMergeList"
                              :key="index"
                              :label="item.confId">
                        {{ item.confLabel }}
                    </el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item v-if="isTmpl"
                          label="对账模版:"
                          prop="templateId">
                <el-select v-model="infoForm.templateId"
                           style="width:400px"
                           @change="handleTmplChange">
                    <el-option v-for="item in baseData[`${merchantTypeStr}TemplateList`]"
                               :key="item.id"
                               :label="item.templateName"
                               :value="item.id" />
                </el-select>
            </el-form-item>
            <el-form-item v-if="isTmpl"
                          label="对账字段:"
                          prop="fieldsJson">
                <div class="tmpl-box">
                    <el-tooltip v-show="infoForm.fieldsTxt"
                                effect="dark"
                                placement="top"
                                :content="infoForm.fieldsTxt">
                        <span class="fields-txt">{{ infoForm.fieldsTxt }}</span>
                    </el-tooltip>
                    <div v-show="tmplSelectList.length">
                        共{{ tmplSelectList.length }}个字段
                    </div>
                    <el-button v-if="infoForm.templateId"
                               type="text"
                               style="margin-left: 8px;"
                               @click="handleCustTmpl">
                        自定义
                    </el-button>
                </div>
            </el-form-item>
        </el-form>
    </d2-dialog>
</template>

<script>
import { getBillTmplAdapter, getMetaTmpl, getShopList, getTmplList } from "@api/accountManage";
import { getMerchantPageSearch } from "@api/publicAccount";
import { getScenesByParams } from "@api/senseManage";
import dayjs from "dayjs";
import { mapActions, mapState } from "vuex";
import {
	rangePickerOptions,
} from "@/common/constants.js";
import { deepClone } from "@/common/util";
import { localTmplList } from "./constant/baseData";

export default {
	name: "DownloadAccountDialog",
	components: {},

	props: {
		accountVisible: {
			type: Boolean,
			default: false,
		},
		scene: {
			type: String,
			default: "",
		},
	},
	data() {
		const validateLonlat = (rule, value, callback) => {
			if (value) {
				if (!this.infoForm.payEndDate) {
					callback(new Error("请选择结束日期"));
				} else {
					callback();
				}
			} else {
				callback();
			}
		};
		return {
			loading: false,
			multipleLimit: 10,
			/** 权益类业务场景选项(接口原始列表,不含「全部」) */
			equitySceneOptionList: [],
			/** 轻改类业务场景选项(接口原始列表,无「全部」) */
			lightSceneOptionList: [],
			// 判断是否是模版模式
			isTmpl: false,
			localTmplList: deepClone(localTmplList),
			tmplSelectList: [],
			pickerOptions0: {
				disabledDate: (time) => {
					if (this.infoForm.payStartDate) {
						return (
							time.getTime()
							> dayjs(this.infoForm.payStartDate)
								.add(1, "y")
								.valueOf()
								|| time.getTime() > Date.now() - 8.64e6
								|| time.getTime()
								< new Date(this.infoForm.payStartDate).getTime()
								- 1 * 24 * 60 * 60 * 1000
						);
					} else {
						return true;
					}
				},
			},
			startDateOptions: {
				disabledDate: (time) => {
					return time.getTime() > Date.now() - 8.64e6;
				},
			},
			EndDateOptions: {
				disabledDate: (time) => {
					if (this.infoForm.payStartDate) {
						return time.getTime() > Date.now();
					} else {
						return false;
					}
				},
			},
			pickerOption: {
				rangePickerOptions,
			},
			userInfo: this.$store.state.d2admin.user.info,
			infoForm: {
				merchantType: "",
				merchant: [],
				payStartDate: "",
				payEndDate: "",
				reportType: "1",
				shopMerchantId: "",
				sceneType: "",
				baseSceneCodeList: [""],
				reconciliationStatus: "all",
				packageMerge: false,
				templateId: "",
				fieldsJson: "",
				fieldsTxt: "",
			},

			// 1 - traffic; 2 - service
			merchantTypeStr: "traffic",
			typeObj: {
				2: "traffic",
				7: "service",
			},

			formRules: {
				sceneType: [{ required: true, message: "请选择业务线", trigger: "change" }],
				baseSceneCodeList: [
					{
						validator: (rule, value, callback) => {
							if (!Array.isArray(value) || !value.length) {
								callback(new Error("请选择业务场景"));
								return;
							}
							if (String(this.infoForm.sceneType) === "1") {
								const v = value[0];
								if (v === undefined || v === null || `${v}` === "") {
									callback(new Error("请选择业务场景"));
									return;
								}
								callback();
								return;
							}
							callback();
						},
						trigger: "change",
					},
				],
				merchantType: [{ required: true, message: "请选择商户类型", trigger: "change" }],
				merchant: [
					{ required: true, message: "请选择对账商户", trigger: "change" },
				],
				shopMerchantId: [{ required: false, message: "请选择流量方", trigger: "change" }],
				payStartDate: [
					{ required: true, message: "请选择时间", trigger: "change" },
					{ required: true, trigger: "change", validator: validateLonlat },
				],
				reconciliationStatus: [{ required: true, message: "请选择对账状态", trigger: "change" }],
				packageMerge: [{ required: true, message: "请选择套餐合并", trigger: "change" }],
				templateId: [{ required: false, message: "请选择对账模式", trigger: "change" }],
				fieldsJson: [{ required: false, message: "请选择对账字段", trigger: "change" }],
			},
			selectLoading: false,
			// 基本数据
			baseData: {
				sceneTypeList: [{
					confId: "0",
					confLabel: "权益类",
				}, {
					confId: "1",
					confLabel: "轻改类",
				}],
				reconStatusList: [{
					confId: "all",
					confLabel: "全部",
				}, {
					confId: "1",
					confLabel: "未对账",
				}, {
					confId: "2",
					confLabel: "已对账",
				}],
				packageMergeList: [{
					confId: true,
					confLabel: "是",
				}, {
					confId: false,
					confLabel: "否",
				}],
				// payeeTypeList: [{
				//   confId: 'all',
				//   confLabel: '全部'
				// }, {
				//   confId: '0',
				//   confLabel: '嘀加收款'
				// }, {
				//   confId: '1',
				//   confLabel: '门店收款'
				// }],
				merchantList: [],
				// 流量方对账单
				trafficTemplateList: [],
				// 服务商对账单
				serviceTemplateList: [],
				shopMerchantList: [],
			},
			yqCheckVisible: true,
		};
	},

	computed: {
		...mapState({
			dowloadList: state => state.d2admin.user.dowloadList,
		}),
		isLightBusinessLine() {
			return String(this.infoForm.sceneType) === "1";
		},
		/** 轻改类单选:控件绑定标量,与接口统一的 baseSceneCodeList 为单元素数组 */
		lightSceneSelectModel: {
			get() {
				if (!this.isLightBusinessLine) {
					return "";
				}
				const arr = this.infoForm.baseSceneCodeList;
				if (Array.isArray(arr) && arr.length) {
					const v = arr[0];
					if (v !== undefined && v !== null && `${v}` !== "") {
						return v;
					}
				}
				return "";
			},
			set(val) {
				if (!this.isLightBusinessLine) {
					return;
				}
				if (val === undefined || val === null || `${val}` === "") {
					this.infoForm.baseSceneCodeList = [""];
				} else {
					this.infoForm.baseSceneCodeList = [val];
				}
			},
		},
		equitySceneSelectOptions() {
			const rows = Array.isArray(this.equitySceneOptionList)
				? this.equitySceneOptionList
				: [];
			return [{ confId: "", confLabel: "全部" }, ...rows];
		},
		lightSceneSelectOptions() {
			return Array.isArray(this.lightSceneOptionList)
				? this.lightSceneOptionList
				: [];
		},
	},

	watch: {
		"scene": {
			handler(val) {
				const sceneStr = val == null ? "" : String(val);
				const exists = this.baseData.sceneTypeList.some(i => i.confId === sceneStr);
				this.infoForm.sceneType = exists ? sceneStr : (this.baseData.sceneTypeList[0]?.confId || "");
				// 首次打开弹框时,确保能根据当前业务线拉取“业务场景”列表
				this.syncSceneTypeList();
			},
			immediate: true,
		},
		"infoForm.sceneType": {
			handler() {
				this.infoForm.baseSceneCodeList = [""];
				this.syncSceneTypeList();
			},
		},
	},

	created() {
	},

	mounted() {
		this.$EventBus.$on("changeFieldIds", (obj) => {
			console.log(obj, "obj---");
			this.tmplSelectList = obj?.fieldIds || [];
			this.infoForm.fieldsTxt = this.getFieldsTxt();
			this.getMetaTmpl();
		});
		this.getTmplList();
		if (this.scene == "2" || this.scene == "3" || this.scene == "4") {
			/** 新改逻辑:园区店选项只对精品升级/会s员权益可见 */
			this.yqCheckVisible = false;
		}
		// this.selectMerchant()
	},

	methods: {
		...mapActions("d2admin/user", ["actionSetDownloadList"]),
		syncSceneTypeList() {
			const sceneType = Number(this.infoForm?.sceneType);
			if (this.infoForm?.sceneType === "" || this.infoForm?.sceneType === null || this.infoForm?.sceneType === undefined || Number.isNaN(sceneType)) {
				this.equitySceneOptionList = [];
				this.lightSceneOptionList = [];
				return;
			}
			getScenesByParams({ bizTypeCode: sceneType === 0 ? 2 : 1 }).then((res) => {
				const list = Array.isArray(res)
					? res
					: (Array.isArray(res?.data) ? res.data : []);
				const normalized = list
					.map(item => ({
						confId: item?.baseSceneCode,
						confLabel: item?.name,
					}))
					.filter(item => item.confId !== undefined && item.confId !== null && item.confId !== "");
				if (sceneType === 0) {
					this.equitySceneOptionList = normalized;
				} else if (sceneType === 1) {
					this.lightSceneOptionList = normalized;
				}
				this.applyDefaultBusinessScene();
				this.clearBusinessSceneValidate();
			}).catch(() => {
				if (sceneType === 0) {
					this.equitySceneOptionList = [];
				} else if (sceneType === 1) {
					this.lightSceneOptionList = [];
				}
				this.applyDefaultBusinessScene();
				this.clearBusinessSceneValidate();
			});
		},
		applyDefaultBusinessScene() {
			if (String(this.infoForm.sceneType) === "1") {
				const first = this.lightSceneOptionList[0]?.confId;
				if (first !== undefined && first !== null && `${first}` !== "") {
					this.infoForm.baseSceneCodeList = [first];
				} else {
					this.infoForm.baseSceneCodeList = [""];
				}
				return;
			}
			this.infoForm.baseSceneCodeList = [""];
		},
		clearBusinessSceneValidate() {
			this.$nextTick(() => {
				const form = this.$refs.accountForm;
				if (form) {
					form.clearValidate(["baseSceneCodeList"]);
				}
			});
		},
		handleEquitySceneChange(value) {
			if (!Array.isArray(value)) {
				return;
			}
			if (!value.length) {
				this.infoForm.baseSceneCodeList = [""];
				return;
			}
			if (value.includes("") && value.length > 1) {
				this.infoForm.baseSceneCodeList = value[value.length - 1] === ""
					? [""]
					: value.filter(v => v !== "");
			}
		},
		handleLightSceneChange() {
			this.$nextTick(() => {
				this.$refs.accountForm?.validateField("baseSceneCodeList");
			});
		},
		selectMerchant() {
			let params = {};
			this.loading = true;
			params.currentPage = 1;
			params.pageSize = 10000;
			let merchantTypeList = [];
			if (this.infoForm.merchantType) {
				if (this.infoForm.merchantType == 6) {
					merchantTypeList = [6, 8];
				} else {
					merchantTypeList.push(this.infoForm.merchantType);
				}
			}
			params.merchantTypeList = merchantTypeList;
			getMerchantPageSearch(params).then((res) => {
				this.baseData.merchantList = res.list;
				this.infoForm.merchant = [];
			}).finally(() => {
				this.loading = false;
			});
		},

		handleChangeMerchant(e) {
			this.infoForm.shopMerchantId = "";
			const params = {
				currentPage: 1,
				pageSize: 9999,
				partnerMerchantId: e[0],
				scene: this.scene,
			};
			getShopList(params).then((res) => {
				this.baseData.shopMerchantList = res.list;
			});
		},

		clickMerchantType(e) {
			e === this.infoForm.merchantType
				? (this.infoForm.merchantType = "")
				: (this.infoForm.merchantType = e);
		},

		changeType(e) {
			// 对账单是否有模版
			this.judgeTmpl();
			this.selectMerchant();
		},

		/**
		 * 商户类型 - 商户类型value - 是否有模版
		 * 流量方 - 2 - 是
		 * 服务商 - 7 - 仅“服务商对账单”(reportType = 4)时,是有模版
		 * 园区店 - 6 - 否
		 */
		judgeTmpl() {
			this.isTmpl = this.infoForm.merchantType == "2";
			this.merchantTypeStr = this.typeObj[this.infoForm.merchantType];
			this.infoForm.merchant = [];
			this.resetTmplData();
		},

		resetTmplData() {
			this.infoForm.shopMerchantId = "";
			this.infoForm.packageMerge = false;
			this.infoForm.templateId = "";
			this.infoForm.fieldsJson = "";
			this.infoForm.fieldsTxt = "";
			this.infoForm.tmplType = "";
			this.tmplSelectList = [];
			const ruleAttrList = ["packageMerge", "templateId", "fieldsJson"];
			ruleAttrList.forEach((item) => {
				this.formRules[item][0].required = this.isTmpl;
			});
			this.formRules.shopMerchantId[0].required = this.isTmpl && this.infoForm.merchantType == "7";
		},

		getFieldsTxt() {
			let fieldNames = "";
			const tmplName = this.localTmplList.find(item => item.type == this.infoForm.tmplType)?.name || "trafficTmpl";
			console.log(tmplName, "tmplName---");
			let list = JSON.parse(localStorage.getItem(tmplName));
			console.log(list, "list---");
			this.dealFieldsJson(list, true);
		},

		changeStartDate() {
			if (this.infoForm.payEndDate) {
				this.infoForm.payEndDate = "";
			}
		},

		remoteMethod(query) {
			this.selectLoading = true;
			let params = {};
			params.currentPage = 1;
			params.pageSize = 1000;
			params.merchantName = query;
			let merchantTypeList = this.infoForm.merchantType
				? [this.infoForm.merchantType]
				: [];
			params.merchantTypeList = merchantTypeList;
			getMerchantPageSearch(params).then((res) => {
				this.selectLoading = false;
				this.baseData.merchantList = res.list;
			});
		},
		getTmplList() {
			const params = {
				pageSize: 9999,
				currentPage: 1,
			};
			// 流量方
			getTmplList({ ...params, type: 1 }).then((res) => {
				this.baseData.trafficTemplateList = res.list || [];
				this.baseData.trafficTemplateList.unshift({
					id: "all",
					type: 1,
					templateName: "无",
					fieldNames: "",
					fieldIds: [],
				});
			});
			// 服务商
			getTmplList({ ...params, type: 2 }).then((res) => {
				this.baseData.serviceTemplateList = res.list || [];
				this.baseData.serviceTemplateList.unshift({
					id: "all",
					type: 2,
					templateName: "无",
					fieldNames: "",
					fieldIds: [],
				});
			});
		},

		handleTmplChange(e) {
			if (!(Object.keys(this.typeObj)).includes(this.infoForm.merchantType)) {
				return true;
			}
			const item = this.baseData[this.merchantTypeStr + "TemplateList"].find(item => item.id == e);
			this.infoForm.fieldsTxt = item?.fieldNames;
			this.infoForm.tmplType = item?.type;
			this.tmplSelectList = item?.fieldIds;
			this.getMetaTmpl();
		},

		getMetaTmpl() {
			const tmplName = this.localTmplList.find(item => item.type == this.infoForm.tmplType)?.name || "trafficTmpl";
			let list = JSON.parse(localStorage.getItem(tmplName));
			if (list) {
				this.dealFieldsJson(list);
			} else {
				getMetaTmpl({ type: this.infoForm.tmplType }).then((res) => {
					this.dealFieldsJson(res);
					localStorage.setItem(tmplName, JSON.stringify(res));
				});
			}
		},

		dealFieldsJson(list, isFindTxt = false) {
			this.tmplList = [];
			this.moduleSubList = [];
			this.selectedList = [];
			list.forEach((item) => {
				const subLen = this.moduleSubList.length;
				this.moduleSubList.push({
					rowIdx: subLen ? this.moduleSubList[subLen - 1].rowIdx + this.moduleSubList[subLen - 1].rowspan : item.items.length - 1,
					rowspan: item.items.length,
				});
				this.tmplList = this.tmplList.concat(item.items);
				item.items.forEach((k) => {
					if (k.required == 1) {
						this.selectedList.push(k);
					} else if (this.tmplSelectList.includes(k.id)) {
						this.selectedList.push(k);
					}
				});
			});
			this.$nextTick(() => {
				isFindTxt && (this.infoForm.fieldsTxt = this.selectedList.map(item => item.fieldName).join(","));
				this.infoForm.fieldsJson = JSON.stringify(this.selectedList);
			});
		},

		handleCustTmpl() {
			this.infoForm.tmplType = this.infoForm.merchantType == "2" ? "1" : "2";
			this.$emit("custTmpl", {
				tmplType: this.infoForm.tmplType + "",
				tmplSelectList: this.tmplSelectList || [],
			});
		},

		getParams() {
			let infoForm = deepClone(this.infoForm);
			let params = {};
			let merchantList = [];
			let obj;
			infoForm.merchant.forEach((item) => {
				obj = {};
				obj.merchantId = item;
				obj.merchantName = this.baseData.merchantList.find(
					mer => mer.merchantId === item,
				).merchantName;
				merchantList.push(obj);
			});
			params.payStartDate = infoForm.payStartDate + " 00:00:00";
			params.payEndDate = infoForm.payEndDate + " 23:59:59";
			merchantList.forEach((item, index) => {
				const merchantName = `merchantList[${index}].merchantName`;
				const merchantId = `merchantList[${index}].merchantId`;
				params[merchantName] = item.merchantName;
				params[merchantId] = item.merchantId;
			});
			params.merchantType = infoForm.merchantType;
			if (infoForm.merchantType == "7") {
				params.reportType = infoForm.reportType;
			}
			params.sceneType = this.scene;
			(infoForm.baseSceneCodeList || []).forEach((code, index) => {
				params[`baseSceneCodeList[${index}]`] = code;
			});
			// 对账状态
			infoForm.reconciliationStatus == "all" ? "" : (params.reconciliationStatus = infoForm.reconciliationStatus);
			// infoForm.payeeType == 'all' ? '' : (params.payeeType = infoForm.payeeType)
			if (infoForm.shopMerchantId) {
				params.shopMerchantId = infoForm.shopMerchantId;
				params.shopMerchantName = this.baseData.shopMerchantList.find(item => item.merchantId == infoForm.shopMerchantId)?.merchantName;
			}
			if (this.isTmpl) {
				params.packageMerge = infoForm.packageMerge;
				params.templateId = infoForm.templateId == "all" ? "" : infoForm.templateId;
				params.fieldsJson = infoForm.fieldsJson;
			}
			return params;
		},

		// 系统对账 - 单个商户
		handleSystemBill() {
			this.$refs.accountForm.validate((valid) => {
				if (valid) {
					if (this.infoForm.merchant.length == 1) {
						let params = this.getParams();
						params.orderCurrentPage = 1;
						params.orderPageSize = 10;
						getBillTmplAdapter(params).then((res) => {
							console.log(res, "res");
							this.$emit("handleBill", { billTmplInfo: res });
						});
					} else {
						this.$message.warning("仅支持单商户进行系统对账");
					}
				}
			});
		},

		handleAddConfirm() {
			this.$refs.accountForm.validate((valid) => {
				if (valid) {
					this.dowloadApi();
				}
			});
		},

		dowloadApi() {
			let params = this.getParams();
			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" });
			this.handleClose();
		},

		handleClose() {
			this.$emit("accountClose", true);
		},
	},
};
</script>

<style lang="scss" scoped>
.dateItem {
	display: flex;
}
::v-deep .dateItem .el-form-item__content {
	display: flex;
	margin-left: 0 !important;
}
::v-deep .accountDailog {
	/*下拉选择框-多选-内容过长-用...代替    begin    */
	.el-tag.el-tag--info {
		background-color: #f4f4f5;
		border-color: #e9e9eb;
		color: #909399;
		max-width: calc(100% - 50px);
		/* white-space: nowrap;
     text-overflow: ellipsis;
     overflow: hidden;*/
	}
	.el-tag.el-tag--info {
		width: calc(100% - 200px);
	}
	.el-tag.el-tag--info .el-select__tags-text {
		width: calc(100% - 20px);
		float: left;
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
	}
	/*下拉选择框-多选-内容过长-用...代替    end    */
	.accountDailog .el-dialog {
		min-width: 700px;
	}
	.accountDailog .el-select-dropdown__item {
		width: 395px !important;
	}
}
.tmpl-box {
	display: flex;
}
.fields-txt {
	width: 305px;
	display: inline-block;
	white-space: nowrap;
	text-overflow: ellipsis;
	overflow: hidden;
	margin-right: 8px;
}
</style>