index.vue 3.82 KB
<template>
  <d2-container v-loading="pageLoading" class="customer-group-rel-page">
    <div class="page-content">
      <CustomerBasicInfoCard :basic-info="groupData.basicInfo"
                             :customer-row="customerRow" />

      <section class="detail-card">
        <h3 class="detail-card__title">
          群关联
        </h3>
        <div v-for="item in groupFieldList"
             :key="item.prop"
             class="field-row">
          <span class="field-label">{{ item.label }}:</span>
          <span class="field-value">{{ displayGroupInfo[item.prop] || "-" }}</span>
        </div>
      </section>

      <div class="footer-actions">
        <el-button size="medium"
                   type="primary"
                   @click="handleBack">
          返回
        </el-button>
      </div>
    </div>
  </d2-container>
</template>

<script>
import { queryCustomerGroups } from "@api/customerDetail";
import CustomerBasicInfoCard from "../components/CustomerBasicInfoCard.vue";
import { loadCustomerSnapshot, mapGroupAssocResponse, resolveCustomerRowFromRoute } from "../utils/customerSnapshot";

export default {
	name: "CustomerGroupRel",
	components: { CustomerBasicInfoCard },
	data() {
		return {
			pageLoading: false,
			customerId: "",
			customerRow: {},
			groupData: {
				basicInfo: {},
				groupRelStatus: "",
				groupName: "",
				groupMemberCustomer: "",
			},
		};
	},
	computed: {
		groupFieldList() {
			return [
				{ label: "群关联状态", prop: "groupRelStatus" },
				{ label: "群名称", prop: "groupName" },
				{ label: "群成员-客户", prop: "groupMemberCustomer" },
			];
		},
		displayGroupInfo() {
			return {
				groupRelStatus: this.groupData.groupRelStatus || "未关联",
				groupName: this.groupData.groupName || "",
				groupMemberCustomer: this.groupData.groupMemberCustomer || "",
			};
		},
	},
	created() {
		this.customerId = this.$route.query.customerId;
		if (!this.customerId) {
			this.$message.warning("缺少客户参数");
			this.$router.back();
			return;
		}
		this.customerRow = resolveCustomerRowFromRoute(
			this.$route,
			loadCustomerSnapshot(),
		);
		this.loadGroupInfo();
	},
	methods: {
		async loadGroupInfo() {
			this.pageLoading = true;
			try {
				const res = await queryCustomerGroups({
					id: this.customerId,
				});
				this.applyGroupData(mapGroupAssocResponse(res || {}, this.customerRow));
			} catch (err) {
				this.$message.error(err.message || "加载群关联失败");
				this.applyGroupData(mapGroupAssocResponse({}, this.customerRow));
			} finally {
				this.pageLoading = false;
			}
		},
		applyGroupData(res) {
			this.groupData = {
				basicInfo: res.basicInfo || {},
				groupRelStatus: res.groupRelStatus || "未关联",
				groupName: res.groupName || "",
				groupMemberCustomer: res.groupMemberCustomer || "",
			};
		},
		handleBack() {
			this.$router.push({ name: "customerList" });
		},
	},
};
</script>

<style lang="scss" scoped>
.customer-group-rel-page {
	::v-deep .d2-container-full__body {
		padding: 0 !important;
		background: #f0f2f5;
	}

	.page-content {
		width: 100%;
		box-sizing: border-box;
		padding: 12px 20px 32px;
	}

	.detail-card {
		background: #fff;
		border: 1px solid #ebeef5;
		border-radius: 4px;
		padding: 16px 20px;
		margin-bottom: 12px;

		&__title {
			margin: 0 0 16px;
			padding-left: 10px;
			border-left: 3px solid #409eff;
			font-size: 14px;
			font-weight: 600;
			color: #303133;
			line-height: 20px;
		}
	}

	.field-row {
		display: flex;
		align-items: flex-start;
		margin-bottom: 14px;
		font-size: 14px;
		line-height: 22px;

		&:last-child {
			margin-bottom: 0;
		}
	}

	.field-label {
		flex-shrink: 0;
		min-width: 110px;
		color: #606266;
	}

	.field-value {
		flex: 1;
		color: #303133;
		word-break: break-all;
	}

	.footer-actions {
		margin-top: 8px;
		padding: 16px 0 8px;
		text-align: center;
	}
}
</style>