<template>
	<uni-popup ref="popup" type="bottom" :mask-click="false">
		<view class="customer-profile-modal">
			<!-- 顶部栏 -->
			<view class="profile-header">
				<view class="profile-close" @click="close">
					<uni-icons type="close" size="24" color="#333"></uni-icons>
				</view>
				<text class="profile-title">客户档案</text>
			</view>
			
			<scroll-view class="profile-content" scroll-y>
				<!-- 客户基本信息 -->
				<view class="profile-section">
					<view class="profile-name-row">
						<text class="profile-name">{{ profile.name }}</text>
						<view class="profile-intent-badge" :class="profile.intent === '高' ? 'intent-high' : 'intent-medium'">
							<text>意向{{ profile.intent }}</text>
						</view>
					</view>
					<view class="profile-service-info">
						<text>服务{{ profile.serviceCount }}次 {{ profile.lastService }}</text>
					</view>
					<view class="profile-details">
						<view class="detail-row">
							<text class="detail-label">电话:</text>
							<text class="detail-value">{{ profile.phone }}</text>
						</view>
						<view class="detail-row">
							<text class="detail-label">服务人员:</text>
							<text class="detail-value">{{ profile.serviceStaff }}</text>
						</view>
						<view class="detail-row">
							<text class="detail-label">微信状态:</text>
							<text class="detail-value">{{ profile.wechatStatus }}</text>
						</view>
						<view class="detail-row">
							<text class="detail-label">客户地址:</text>
							<text class="detail-value">{{ profile.address }}</text>
						</view>
						<view class="detail-row">
							<text class="detail-label">客户来源:</text>
							<text class="detail-value">{{ profile.source }}</text>
							<view class="collapse-btn" @click="toggleCollapse">
								<text>{{ collapsed ? '展开' : '收起' }}</text>
								<uni-icons :type="collapsed ? 'down' : 'up'" size="14" color="#666"></uni-icons>
							</view>
						</view>
					</view>
				</view>
				
				<!-- 跟进阶段 -->
				<view class="profile-section" v-if="!collapsed">
					<view class="section-header">
						<text class="section-title">跟进阶段</text>
						<view class="stage-info">
							<text>当前: {{ profile.followStage }}</text>
							<uni-icons type="right" size="16" color="#999"></uni-icons>
						</view>
					</view>
				</view>
				
				<!-- 客户画像 -->
				<view class="profile-section" v-if="!collapsed">
					<view class="section-header">
						<view class="section-icon">
							<uni-icons type="person" size="20" color="#007AFF"></uni-icons>
						</view>
						<text class="section-title">客户画像</text>
					</view>
					<view class="profile-tags">
						<view 
							class="profile-tag tag-blue" 
							v-for="(tag, index) in profile.systemTags" 
							:key="'system-' + index">
							<text>{{ tag }}</text>
						</view>
					</view>
					<view class="custom-label" v-if="profile.customTags && profile.customTags.length > 0">
						<text>自定义</text>
					</view>
					<view class="profile-tags" v-if="profile.customTags && profile.customTags.length > 0">
						<view 
							class="profile-tag tag-yellow" 
							v-for="(tag, index) in profile.customTags" 
							:key="'custom-' + index">
							<text>{{ tag }}</text>
						</view>
					</view>
				</view>
				
				<!-- 客户意向 -->
				<view class="profile-section" v-if="!collapsed">
					<view class="section-header">
						<view class="section-icon">
							<uni-icons type="star" size="20" color="#007AFF"></uni-icons>
						</view>
						<text class="section-title">客户意向</text>
						<view class="intent-level">
							<text>意向{{ profile.intent }}</text>
						</view>
					</view>
					<view class="intent-description">
						<text>{{ profile.intentDescription }}</text>
					</view>
				</view>
			</scroll-view>
		</view>
	</uni-popup>
</template>

<script>
	export default {
		name: 'CustomerProfileModal',
		props: {
			profile: {
				type: Object,
				default: () => ({})
			}
		},
		data() {
			return {
				collapsed: false
			}
		},
		methods: {
			open() {
				this.$refs.popup.open();
			},
			close() {
				this.$refs.popup.close();
				this.$emit('close');
			},
			toggleCollapse() {
				this.collapsed = !this.collapsed;
			}
		}
	}
</script>

<style scoped>
	.customer-profile-modal {
		background-color: #FFFFFF;
		border-radius: 32rpx 32rpx 0 0;
		max-height: 90vh;
		display: flex;
		flex-direction: column;
		overflow: hidden;
	}
	
	.profile-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 32rpx;
		border-bottom: 1px solid #F0F0F0;
		position: relative;
	}
	
	.profile-close {
		width: 48rpx;
		height: 48rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.profile-title {
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		font-size: 36rpx;
		font-weight: 600;
		color: #333;
	}
	
	.profile-content {
		flex: 1;
		padding: 32rpx;
		background-color: #FFFFFF;
	}
	
	.profile-section {
		margin-bottom: 32rpx;
	}
	
	.profile-name-row {
		display: flex;
		align-items: center;
		margin-bottom: 16rpx;
	}
	
	.profile-name {
		font-size: 36rpx;
		font-weight: 600;
		color: #333;
		margin-right: 16rpx;
	}
	
	.profile-intent-badge {
		padding: 6rpx 16rpx;
		border-radius: 8rpx;
	}
	
	.profile-intent-badge.intent-high {
		background-color: #E3F2FD;
	}
	
	.profile-intent-badge.intent-high text {
		font-size: 24rpx;
		color: #1976D2;
		font-weight: 500;
	}
	
	.profile-intent-badge.intent-medium {
		background-color: #FFF3E0;
	}
	
	.profile-intent-badge.intent-medium text {
		font-size: 24rpx;
		color: #F57C00;
		font-weight: 500;
	}
	
	.profile-service-info {
		margin-bottom: 24rpx;
	}
	
	.profile-service-info text {
		font-size: 26rpx;
		color: #999;
	}
	
	.profile-details {
		background-color: #F5F5F5;
		border-radius: 16rpx;
		padding: 24rpx;
	}
	
	.detail-row {
		display: flex;
		align-items: center;
		margin-bottom: 16rpx;
		position: relative;
	}
	
	.detail-row:last-child {
		margin-bottom: 0;
	}
	
	.detail-label {
		font-size: 28rpx;
		color: #666;
		width: 160rpx;
		flex-shrink: 0;
	}
	
	.detail-value {
		font-size: 28rpx;
		color: #333;
		flex: 1;
	}
	
	.collapse-btn {
		display: flex;
		align-items: center;
		margin-left: 16rpx;
		padding: 4rpx 8rpx;
	}
	
	.collapse-btn text {
		font-size: 24rpx;
		color: #666;
		margin-right: 4rpx;
	}
	
	.section-header {
		display: flex;
		align-items: center;
		margin-bottom: 24rpx;
	}
	
	.section-icon {
		margin-right: 8rpx;
	}
	
	.section-title {
		font-size: 30rpx;
		font-weight: 500;
		color: #333;
		flex: 1;
	}
	
	.stage-info {
		display: flex;
		align-items: center;
	}
	
	.stage-info text {
		font-size: 28rpx;
		color: #333;
		margin-right: 8rpx;
	}
	
	.profile-tags {
		display: flex;
		flex-wrap: wrap;
		gap: 12rpx;
		margin-bottom: 24rpx;
	}
	
	.profile-tag {
		padding: 8rpx 16rpx;
		border-radius: 8rpx;
	}
	
	.profile-tag.tag-blue {
		background-color: #E3F2FD;
	}
	
	.profile-tag.tag-blue text {
		font-size: 24rpx;
		color: #1976D2;
	}
	
	.profile-tag.tag-yellow {
		background-color: #FFF3E0;
	}
	
	.profile-tag.tag-yellow text {
		font-size: 24rpx;
		color: #F57C00;
	}
	
	.custom-label {
		margin-bottom: 16rpx;
	}
	
	.custom-label text {
		font-size: 26rpx;
		color: #666;
	}
	
	.intent-level {
		padding: 6rpx 16rpx;
		background-color: #E3F2FD;
		border-radius: 8rpx;
	}
	
	.intent-level text {
		font-size: 24rpx;
		color: #1976D2;
		font-weight: 500;
	}
	
	.intent-description {
		background-color: #F5F5F5;
		border-radius: 16rpx;
		padding: 24rpx;
	}
	
	.intent-description text {
		font-size: 28rpx;
		color: #333;
		line-height: 1.8;
	}
</style>

