<template>
	<view v-show="!is_loading">
		<!-- 胶囊 -->
		<mvBar :mysNavConfig="mysNavConfig"></mvBar>
		<view :style="{paddingTop:navH}" style="background-color: #fff;"></view>


		<view class="logistics1">
			<view>
				<p style="margin-bottom: 10rpx;">物流公司：{{logistics_company}}</p>
				<p>物流单号：{{logistics_number}}
					<image :src="picture.icon_copy" mode="" class="copy-img" @click="handleCopy(logistics_number)" />
				</p>
			</view>
		</view>

		<view class="logistics-detail" v-for="item in logisticsData">
			<view class="logistics-item">
				<p>{{ item.context }}</p>
				<p>{{ item.time }}</p>
			</view>
		</view>
		<view style="height: 100rpx;"></view>
	</view>
</template>

<script>
	import region from '@/components/pca-code.json';
	import mvBar from "@/components/mys_navBar/mysNavBar";
	export default {
		components: {
			mvBar,
		},
		data() {
			return {
				navH: getApp().globalData.navHeight,
				picture: getApp().globalData.picture,
				mysNavConfig: {
					/* 开启单页显示首页图标 */
					isHome: true,
					/* 固定导航  */
					navFixed: true,
					/* 标题 （屏幕中心居中 两边图标中心居中使用slot center1） */
					navTitle: {
						text: "物流信息",
						color: "",
						fontSize: "32rpx", // px upx rpx
						fontWeight: "normal", // 100 - 700
					},
					btnType: "type2",
					onLeftClick: '',
					/* type2 按钮 */
					type2Config: {
						// 左图标
						leftPath: "/static/img/png2.png",
						// 右图标
						rightPath: "/static/img/png4.png",
						// 圆角
						radius: "40rpx",
					},
				},
				task_id: "",
				logistics_number: "",
				logistics_company: "",
				logisticsData: [{
					context: "",
					time: ""
				}],
				address: {},
				is_loading: true,
			}
		},
		async onLoad(options) {
			try {
				const dataStr = options.textObj.replace(/""/g, "");
				const data = JSON.parse(decodeURIComponent(dataStr));
				this.task_id = data.taskId;
				uni.showLoading({ title: '加载中' });
				this.is_loading = true;
				await this.getLogisticsDetail(this.task_id);
			} catch (error) {
				console.error('加载物流信息失败:', error);
			} finally {
				this.is_loading = false;
				uni.hideLoading();
			}
		},
		methods: {
			getLogisticsDetail(secTaskId) {
				// 获取物流信息
				return this.$https.get('/youngee/c/api/t/secTask/logistics/detail?task_id=' + secTaskId).then(res => {
					console.log(res)
					let resData = res.data.data
					this.logistics_number = resData.logistics_number
					this.logistics_company = resData.logistics_company
					this.logisticsData = resData.logistics_context.data

					// 地址解析
					this.address = JSON.parse(resData.address_snap);
					let a = this.address.region_code.toString().slice(0, 2)
					let b = this.address.region_code.toString().slice(0, 4)
					let c = 0
					for (var i = 0; i < region.length; i++) {
						if (region[i].code == a) {
							a = region[i].name
							for (var j = 0; j < region[i].children.length; j++) {
								if (region[i].children[j].code == b) {
									b = region[i].children[j].name
									for (var o = 0; o < region[i].children[j].children.length; o++) {
										if (region[i].children[j].children[o].code == this.address
											.region_code) {
											c = region[i].children[j].children[o].name
										}
									}
								}

							}
						}
					}
					this.address.full_detail_addr = a + b + c + this.address.detail_addr
				})
			}
		}
	}
</script>


<style lang="scss" scoped>
	p {
		font-size: 30rpx;
	}

	.address {
		display: flex;
		margin: 20rpx 0;
		// padding: 20rpx 20rpx;
		background-color: #FFFFFF;
		justify-content: flex-start;
		align-items: center;

		.address_icon {
			width: 15%;
			vertical-align: middle;
			display: flex;
			justify-content: center;
		}

		.address_edit {
			width: 15%;
		}

		.address_edit image {
			vertical-align: middle;
			width: 50rpx;
			height: 50rpx;
			display: inline-block;
			padding-right: 14rpx;
		}

		.ipon {
			color: #333333;
			font-size: 30rpx;
			font-weight: 500;
			margin-bottom: 10rpx;
		}
	}

	.logistics1 {
		margin: 50rpx;
		display: flex;
		flex-flow: column;
		align-items: flex-start;
		justify-content: center;
	}

	.logistics-detail {
		padding: 20rpx 30rpx;
	}

	.logistics-item {
		background-color: #f1f1f1;
		padding: 10rpx 30rpx;
	}
</style>