channelConfigDialog.vue 5.72 KB
<!-- 渠道配置弹框 -->
<template>
    <d2-dialog class="channel-config-dialog"
               :is-visible="channelConfigVisible"
               title="渠道配置"
               width="800px"
               @closeDialog="handleClose"
               @confirmDialog="handleConfirm">
        <div v-loading="loading" class="channel-config-content">
            <el-table border
                      class="channel-config-table"
                      :data="tableData">
                <el-table-column align="center"
                                 label="支付渠道"
                                 prop="paymentChannel"
                                 width="200" />
                <el-table-column align="center"
                                 label="收款主体"
                                 prop="payeeSubjectName"
                                 width="180" />
                <el-table-column align="center" label="可用子公司">
                    <template #default="scope">
                        <div class="select-cell">
                            <el-select v-model="scope.row.platformMerchantIds"
                                       collapse-tags
                                       filterable
                                       multiple
                                       placeholder="请选择"
                                       style="width: 100%">
                                <el-option v-for="item in platformMerchantList"
                                           :key="item.merchantId"
                                           :label="item.merchantName"
                                           :value="item.merchantId" />
                            </el-select>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="channel-config-tips">
                <p class="tips-title">
                    说明:
                </p>
                <p>设置支付渠道&收款主体的可用子公司后,使用该子公司的门店+业务仅可以对对应支付渠道&收款主体产生的流水进行补单</p>
            </div>
        </div>
    </d2-dialog>
</template>

<script>
import {
	getPaymentChannelConfigList,
	savePaymentChannelConfig,
} from "@api/grounding";
import { getPlatformMerchantList } from "@api/index";

// 前两列固定数据:支付渠道、收款主体(设计稿固定展示)
const FIXED_ROWS = [
	{ payeeSubject: 1, paymentChannel: "银盛&嘀加智慧云", payeeSubjectName: "嘀加智慧云" },
	{ payeeSubject: 2, paymentChannel: "银盛&嘀加智慧云", payeeSubjectName: "欢腾" },
	{ payeeSubject: 3, paymentChannel: "通联&广联数科", payeeSubjectName: "广联数科" },
];

export default {
	name: "ChannelConfigDialog",
	props: {
		channelConfigVisible: {
			type: Boolean,
			default: false,
		},
	},
	data() {
		return {
			loading: false,
			tableData: [],
			platformMerchantList: [],
		};
	},
	watch: {
		channelConfigVisible: {
			handler(val) {
				if (val) {
					this.initData();
				}
			},
			immediate: true, // 弹框初始化时即调用两个查询接口
		},
	},
	methods: {
		initData() {
			this.loading = true;
			Promise.all([this.fetchPlatformMerchantList(), this.fetchChannelConfigList()])
				.finally(() => {
					this.loading = false;
				});
		},
		// 获取平台方/子公司下拉选项(第三列下拉依赖此接口)
		fetchPlatformMerchantList() {
			return getPlatformMerchantList({}).then((res) => {
				const list = res || [];
				list.unshift({ merchantId: -1, merchantName: "嘀加智慧云" });
				this.platformMerchantList = list;
			});
		},
		// 获取渠道配置:仅第三列绑定的值依赖此接口
		fetchChannelConfigList() {
			return getPaymentChannelConfigList({}).then((res) => {
				const apiList = res || [];
				const mapByPayee = {};
				apiList.forEach((item) => {
					const key = item.payeeSubject;
					if (!mapByPayee[key])
						mapByPayee[key] = [];
					const ids = item.platformMerchantIds ?? (item.platformMerchantId != null ? [item.platformMerchantId] : []);
					if (Array.isArray(ids)) {
						ids.forEach(id => id != null && id !== "" && mapByPayee[key].push(id));
					}
				});
				this.tableData = FIXED_ROWS.map(row => ({
					...row,
					platformMerchantIds: mapByPayee[row.payeeSubject] || [],
				}));
			});
		},
		handleClose() {
			this.$emit("dialogClose");
		},
		handleConfirm() {
			const list = [];
			this.tableData.forEach((row) => {
				const ids = row.platformMerchantIds || [];
				ids.forEach((id) => {
					list.push({
						platformMerchantId: String(id),
						payeeSubject: String(row.payeeSubject ?? ""),
					});
				});
			});
			const params = { dataString: JSON.stringify({ list }) };
			this.loading = true;
			savePaymentChannelConfig(params)
				.then(() => {
					this.$message.success("保存成功");
					this.handleClose();
				})
				.catch(() => {
					this.$message.error("保存失败");
				})
				.finally(() => {
					this.loading = false;
				});
		},
	},
};
</script>

<style lang="scss" scoped>
.channel-config-content {
	padding: 0 20px;
}

/* 排除全局 element.scss 对表格的影响 */
.channel-config-table {
	::v-deep .el-table--medium td {
		padding: 12px 0 !important;
	}
}

.select-cell {
	padding: 0 20px;
	/* 取消全局 .el-tag 固定宽度,el-select 多选标签在 .el-select__tags 内 */
	::v-deep .el-select__tags .el-tag {
		width: auto !important;
		min-width: auto !important;
		font-size: 12px !important;
	}
}

.channel-config-tips {
	margin-top: 20px;
	padding: 12px 16px;
	background: #f6f8fa;
	border-radius: 4px;
	color: #666;
	font-size: 14px;

	.tips-title {
		font-weight: 500;
		color: #333;
		margin-bottom: 8px;
	}

	p {
		margin: 4px 0;
		line-height: 1.6;
	}
}
</style>