<template>
	<view class="uni-column container">
		<view style="margin: 12rpx;">
			<view class="margenTop" style="font-size: 30rpx;font-weight: bold;">批次号：{{product.lotCode}}</view>
			<view class="margenTop" style="font-size: 30rpx;font-weight: bold;">产品描述：{{product.productDescription}}
			</view>
			<view class="margenTop" style="font-size: 30rpx;font-weight: bold;    flex-direction: row;">
				<view>工艺版本：{{product.technologyVersion}}</view>
				<view style="margin-left: 200rpx;">工序：</view>
				<uni-data-select v-model="curSelectedProcesstId" :localdata="selectedProcessList" :clear="false"
					@change="handleSelectedChange"></uni-data-select>
			</view>
		</view>
		<view class='middle'>
			<view class='segment'></view>
			<uni-icons type="paperclip" size="30"></uni-icons>
			<view class='segment'></view>
		</view>
		<view style="overflow: auto;">
			<view :class="{'list-container':true}" v-for="(item, index) in drawingList" :key="item.id">
				<view><text style="text-align: center; font-size: 28rpx; padding: 48rpx 0 24rpx 0;color:  #1684fc;"
						@click="handleOpenDrawing(item)">{{item.drawingName}}</text></view>

			</view>
		</view>

	</view>


</template>

<script setup>
	import {
		getDrawingList,
		getProcessOutsourcedDetail
	} from '@/api/business/drawing.js'
	import {
		ref
	} from 'vue'
	import {
		onLoad,
	} from '@dcloudio/uni-app'
	import {
		store
	} from '../../store';
	const outsourceOrderDetailId = ref("")
	const drawingList = ref([])
	const product = ref({})
	const technologicalProcessDetailList = ref([]);
	const curSelectedProcesstId = ref("");
	const selectedProcessList = ref([]);
	const productId = ref("")
	const technologyVersion = ref("")
	const lotCode = ref("")
	onLoad((options) => {
		console.log(options)
		outsourceOrderDetailId.value = options.param1 //发出单明细id
		lotCode.value = options.param2 //批次号
		productId.value = options.param3 // 产品id
		technologyVersion.value = options.param4 // 工艺版本
		init();

	})

	function init() {
		console.log(product.value)
		//根据外协单明细id查询工艺信息
		getProcessOutsourcedDetail(outsourceOrderDetailId.value).then(response => {
			if (response.code == 200) {
				//产品信息
				product.value = response.data
				//所有外协发出工序信息
				technologicalProcessDetailList.value = response.data.technologicalProcessDetailList;
				product.value.lotCode = lotCode.value
				for (let i = 0; i < technologicalProcessDetailList.value.length; i++) {
					selectedProcessList.value.push({
						text: technologicalProcessDetailList.value[i].processAlias, //工序名称
						value: technologicalProcessDetailList.value[i].processCode, //工序id
						data: selectedProcessList.value[i]
					})
				}
				//默认展示第一条
				curSelectedProcesstId.value = technologicalProcessDetailList.value[0].processCode;
				//根据工序id查询图纸信息
				getDrawingList({
					processCode: curSelectedProcesstId.value,
					productId: productId.value,
					technologyVersion: technologyVersion.value
				}).then(res => {
					if (res.code == 200) {
						drawingList.value = res.data
					}
				})
			}
		})

	}


	//切换工序查询
	function handleSelectedChange(item) {
		getDrawingList({
			processCode: item,
			productId: productId.value,
			technologyVersion: technologyVersion.value
		}).then(res => {
			if (res.code == 200) {
				drawingList.value = res.data
			}
		})
	}

	function handleOpenDrawing(row) {



		// 检查 filteredProcess 是否有元素，并选择第一个元素


		// 对 technologicalProcessDetailId 进行URL编码
		var encodeUrl = row.url;
		console.log(row)
		// 构建查询参数字符串
		var queryParam = `param1=${encodeUrl}`;

		// 使用模板字符串构建完整的URL
		var navigateUrl = `/pages/pdfviewer/index?${queryParam}`;

		// 导航到指定页面
		uni.navigateTo({
			url: navigateUrl
		});

	}
</script>

<style lang="scss">
	.container {
		height: 100%;
		background-color: #f5f5f5;
	}

	.middle {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		margin-top: 20rpx;
	}

	.scroll-container {
		position: absolute;
		top: 24rpx;
		right: 0;
		bottom: 160rpx;
		left: 0;
	}

	.segment {
		width: 280rpx;
		background-color: rgba(213, 213, 213, 1);
		border: 1rpx solid rgba(213, 213, 213, 1);
	}

	.selected {
		border: 1px solid #1684fc;
	}

	.margenTop {
		margin: 20rpx;
	}

	.list-item {
		background-color: #fff;
		position: relative;
		padding: 16rpx;
		padding-bottom: 24rpx;
		margin: 0 24rpx;
		margin-bottom: 24rpx;
		border-radius: 8rpx;

		.title-container {
			justify-content: space-between;
			margin-top: 8rpx;
			margin-bottom: 16rpx;

			.title {
				height: 48rpx;
				align-items: center;

				.label {
					color: #1684fc;
					font-size: 32rpx;
					font-weight: bold;

					&.code {
						color: #000000;
						margin-left: 32rpx;
					}
				}
			}
		}

		.item-info {
			margin-bottom: 16rpx;

			.label {
				font-size: 28rpx;
				width: 152rpx;
				color: #808080;

				&.right {
					flex: 1;
					color: #808080;
				}
			}
		}

		.right-info {
			justify-content: flex-end;
			margin-top: 2rpx;

			.label {
				font-size: 28rpx;
				color: #ff0000;
			}
		}
	}

	.bottom {
		position: fixed;
		right: 0;
		bottom: 0;
		left: 0;
		height: 100rpx;
		padding: 16rpx 24rpx;
		align-items: center;
		background-color: #FFFFFF;
		justify-content: space-between;

		.bottom-btn {
			flex: 1;
			font-size: 28rpx;
			color: #FFFFFF;

			&.left-btn {
				background-color: #1684fc;
			}

			&.right-btn {
				background-color: rgb(255, 121, 1);
				margin-left: 24rpx;

			}
		}
	}
</style>