<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="curSelectedProcessCode" :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,
		getTechnologicalProcess,
		getDeptProcess
	} from '@/api/business/drawing.js'
	import {
		ref
	} from 'vue'
	import {
		onLoad,
	} from '@dcloudio/uni-app'
	import {
		store
	} from '../../store';
	const technologicalProcessId = ref("")
	const drawingList = ref([])
	const processCode = ref("")
	const productId = ref("")
	const product = ref({})
	const lotCode = ref("")
	const selectedProcessList = ref([]);
	const curSelectedProcessCode = ref("");
	const processAlias = ref("")
	onLoad((options) => {
		console.log(options, 1111)
		technologicalProcessId.value = options.param4
		lotCode.value = options.param2
		productId.value = options.param1
		processCode.value = options.param3
		curSelectedProcessCode.value = processCode.value
		processAlias.value = decodeURIComponent(options.param5)
		init();

	})
	// 获取所有的本工段可加工工序

	function getProcesses(data) {
		console.log(data)
		getDeptProcess(data).then(res => {
			selectedProcessList.value = res.data.map(v => ({
				text: v.processAlias,
				value: v.processCode
			}))
			curSelectedProcessCode.value = processCode.value
		})
	}

	function init() {
		console.log(product.value)
		getTechnologicalProcess(technologicalProcessId.value).then(response => {
			console.log(response, 1123)
			if (response.code == 200) {
				product.value = response.data
				product.value.lotCode = lotCode.value
				product.value.processAlias = processAlias.value
				getProcesses({
					productVersion: product.value.technologyVersion,
					deptId: store.curDeptDetails.deptId,
					productId: productId.value
				})
				getDrawingList({
					productVersion: product.value.technologyVersion,
					processCode: processCode.value,
					productId: productId.value
				}).then(res => {
					if (res.code == 200) {
						drawingList.value = res.data
						// product.value = drawingList.value[0].product
						// product.value.technologyVersion = drawingList.value[0].technologyVersion
						// product.value.processAlias = drawingList.value[0].processAlias
						// product.value.lotCode = lotCode.value

					}
				})
			}
		})

	}


	function handleOpenDrawing(row) {



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



		var encodeUrl = row.url;
		console.log(row)
		// 构建查询参数字符串
		var queryParam = `param1=${encodeUrl}`;

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

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

	}
	//切换工序查询
	function handleSelectedChange(item) {
		getDrawingList({
			productVersion: product.value.technologyVersion,
			processCode: curSelectedProcessCode.value,
			productId: productId.value
		}).then(res => {
			if (res.code == 200) {
				drawingList.value = res.data
			}
		})
	}
</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>