<template>
	<view>
		<!-- 顶部导航栏 -->
		<!-- <view class="navbar">
			<text class="navbar-title">收款详情</text>
		</view> -->
		<view class="container">
			<!-- 跟进详情卡片 -->
			<view class="detail-card">
				<!-- 联系人信息 -->
				<view class="info-item">
					<text class="label">收款单号：</text>
					<text class="value">{{ receiveData.Receive_num }}</text>
				</view>

				<view class="info-item">
					<text class="label">收款金额：</text>
					<text class="value">{{ receiveData.Receive_amount }}</text>
				</view>

				<view class="info-item">
					<text class="label">支付方式：</text>
					<text class="value">{{ receiveData.PayType && receiveData.PayType.params_name  }}</text>
				</view>

				<view class="info-item">
					<text class="label">收款日期：</text>
					<text class="value">{{ receiveData.Receive_date }}</text>
				</view>

				<view class="info-item">
					<text class="label">收款人：</text>
					<text class="value">{{ receiveData.Payee&&receiveData.Payee.name }}</text>
				</view>

				<view class="info-item">
					<text class="label">备注：</text>
					<text class="value">{{ receiveData.Remarks }}</text>
				</view>

				<!-- 编辑按钮 -->
				<button class="edit-btn" @click="onEdit">编辑</button>
			</view>

			<view class="detail-card">
				<view class="info-item">
					<view class="info-label">订单编号:</view>
					<view class="info-value">{{ receiveData.Order.Serialnumber }}</view>
				</view>

				<view class="info-item">
					<view class="info-label">客户名称:</view>
					<view class="info-value">{{ receiveData.Order && receiveData.Order.customer.cus_name }}</view>
				</view>

				<view class="info-item">
					<view class="info-label">订单日期:</view>
					<view class="info-value">{{ receiveData.Order.Order_date }}</view>
				</view>

				<view class="info-item total-amount">
					<view class="info-label">订单总金额:</view>
					<view class="info-value">{{ receiveData.Order.total_amount | formatPrice }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 跟进数据示例，实际项目中可通过接口获取
				receiveData: {}
			};
		},
		onLoad(options) {
			// 将接收的字符串解析为JSON对象
			const receivedData = JSON.parse(decodeURIComponent(options.data));

			receivedData.Receive_date = this.formatDate(receivedData.Receive_date);

			this.receiveData = receivedData;

			console.log(this.receiveData);
		},

		filters: {
			// 价格格式化过滤器
			formatPrice(price) {
				if (price) {
					return '¥' + (price).toFixed(2);
				}
			}
		},
		methods: {
			// 格式化日期为YYYY-MM-DD
			formatDate(value) {
				if (!value) return ''
				// 转换为Date对象
				const date = new Date(value)

				const year = date.getFullYear();
				const month = (date.getMonth() + 1).toString().padStart(2, '0');
				const day = date.getDate().toString().padStart(2, '0');
				return `${year}-${month}-${day}`;
			},
			// 编辑按钮点击事件
			onEdit() {
				// 跳转到编辑页面或打开编辑弹窗
				// 实际项目中可使用uni.navigateTo或自定义弹窗
				console.log("进入编辑模式");
				// 示例：uni.navigateTo({ url: '/pages/followUp/edit?id=' + this.receiveData.id })
				// 将JSON对象转为字符串（encodeURIComponent处理特殊字符）
				const cusinfo = encodeURIComponent(JSON.stringify(this.receiveData));

				setTimeout(() => {
					uni.reLaunch({
						url: '/pages/Receive/edit?data=' + cusinfo
					});
				}, 500);
			}
		}
	};
</script>

<style scoped>
	/* 导航栏样式 */
	.navbar {
		height: 44px;
		background-color: #1677ff;
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;
	}

	.navbar-title {
		color: #fff;
		font-size: 18px;
		font-weight: 500;
	}

	.container {
		padding: 16px;
		background-color: #f5f5f5;
		min-height: 100vh;
	}

	/* 详情卡片样式 */
	.detail-card {
		background-color: #ffffff;
		border-radius: 12px;
		padding: 20px;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
		margin-bottom: 10px;
	}

	/* 信息项样式 */
	.info-item {
		display: flex;
		padding: 12px 0;
		border-bottom: 1px solid #f0f0f0;
		align-items: flex-start;
	}

	/* 最后一项去掉下边框 */
	.info-item:last-child:not(.content-item) {
		border-bottom: none;
	}

	/* 标签样式 */
	.label {
		color: #666666;
		width: 100px;
		font-size: 14px;
		line-height: 22px;
	}

	/* 值样式 */
	.value {
		flex: 1;
		color: #333333;
		font-size: 14px;
		line-height: 22px;
	}

	.info-label {
		font-size: 14px;
		color: #666;
		width: 80px;
		flex-shrink: 0;
	}

	.info-value {
		font-size: 14px;
		color: #333;
		text-align: right;
		flex: 1;
		margin-left: 20px;
		word-break: break-all;
	}

	/* 跟进内容项特殊样式 */
	.content-item {
		align-items: flex-start;
	}

	.content-item .value {
		white-space: pre-line;
	}

	/* 编辑按钮样式 */
	.edit-btn {
		width: 100%;
		height: 44px;
		line-height: 44px;
		background-color: #1677ff;
		color: #ffffff;
		border-radius: 8px;
		font-size: 16px;
		margin-top: 20px;
		border: none;
	}

	/* 按钮激活状态样式 */
	.edit-btn::after {
		border: none;
	}

	.edit-btn:active {
		background-color: #0e65d9;
	}

	.call-icon {
		/* border:1px solid #ddd;
		border-radius: 5px;
		padding: 5px; */
	}
</style>