<template>
	<z-paging ref="paging" v-model="detailItems" @query="queryList">
		<!-- 明细列表 -->
		<view class="detail-section">
			<view class="detail-list" v-if="detailItems.length > 0">
				<view class="detail-item" v-for="(item, index) in detailItems" :key="index">
					<view class="item-header">
						<text class="item-date">{{ formatDate(item.stockDate) }}</text>
						<text class="item-bill">{{ item.billNumber }}</text>
					</view>
					<view class="item-body">
						<view class="info-item">
							<text class="label">仓库名称：</text>
							<text class="value">{{ item.stockName }}</text>
						</view>
						<view class="info-item">
							<text class="label">供应商：</text>
							<text class="value">{{ item.custName }}</text>
						</view>
						<view class="info-item">
							<text class="label">商品名称：</text>
							<text class="value">{{ item.cargoName }}</text>
						</view>
						<view class="info-item">
							<text class="label">商品编号：</text>
							<text class="value">{{ item.hsCode }}</text>
						</view>
						<view class="info-item">
							<text class="label">商品数量：</text>
							<text class="value">{{ item.cargoWt }}</text>
						</view>
						<view class="info-item">
							<text class="label">商品价值：</text>
							<text class="value">{{ item.cargoValue }}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</z-paging>
</template>

<script>
import { getStockDetail } from '@/api/stock';

export default {
	data() {
		return {
			detailItems: [],
			cargoId: '',
			custId: '',
			queryParams: {
				cargoId: null,
				custId: null
			}
		};
	},
	onLoad(options) {
		if (options.cargoId && options.custId) {
			this.cargoId = options.cargoId;
			this.custId = options.custId;
			this.queryParams.cargoId = options.cargoId;
			this.queryParams.custId = options.custId;
			
		}
	},
	methods: {
		// 格式化日期
		formatDate(dateStr) {
			if (!dateStr) return '';
			// 直接取字符串前10位作为日期
			return dateStr.toString().substring(0, 10);
		},
		// 获取明细列表
		queryList(pageNo, pageSize) {
			// 调用API
			getStockDetail({
				...this.queryParams,
				pageNum: pageNo,
				pageSize: pageSize
			}).then((res) => {
				// 将请求结果通过complete传给z-paging处理
				this.$refs.paging.complete(res.data.list);
			}).catch((err) => {
				console.error('获取明细列表失败:', err);
				// 如果请求失败，调用complete(false)
				this.$refs.paging.complete(false);
			});
		},

	}
};
</script>

<style lang="scss">
.detail-section {
	padding: 30rpx;
	
	.detail-list {
		.detail-item {
			background-color: #fff;
			border-radius: 10rpx;
			padding: 20rpx;
			margin-bottom: 20rpx;
			box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
			
			.item-header {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 15rpx;
				padding-bottom: 15rpx;
				border-bottom: 1rpx solid #eee;
				
				.item-date {
					font-size: 24rpx;
					color: #333;
					font-weight: 600;
				}
				
				.item-bill {
					font-size: 22rpx;
					color: #666;
				}
			}
			
			.item-body {
				.info-item {
					display: flex;
					margin-bottom: 10rpx;
					
					.label {
						width: 140rpx;
						font-size: 24rpx;
						color: #666;
					}
					
					.value {
						flex: 1;
						font-size: 24rpx;
						color: #333;
					}
				}
			}
		}
	}
}
</style>