<template>
	<view class="contain">
		<view class="contain-left">
			<view class="title-input-father">
				<input class="title-input" type="text" v-model="searchValue" maxlength="15"
					placeholder="采购单号/采购日期/供应商" />
				<image v-show="searchValue" class="right-img" src="@/static/x.png" @click="searchValue=''" />
				<view class="title-input-button">
					检索
				</view>
			</view>
			<view class="left-menu-father">
				<scroll-view scroll-y="true" scroll-with-animation class="left-menu-scroll" :scroll-top="leftscrolltop"
					@scrolltolower="plsbuytolower" :lower-threshold="400">
					<view class="pls-card" v-for="(v,i) in plsbuy" :key='i' @click="clickLeftMenu(i)"
						:style="{borderColor: i==lefttarget? ``:`#fff` }">
						<view class="pls-card-title">
							<view class="title-left">
								{{ v.cgdNo }}
							</view>
							<view class="title-right">
								<text style="position: absolute;bottom: 4rpx;left: -30rpx;">
									￥
								</text>

								<view class="title-right-big">
									{{ v.totalPrice }}
								</view>

								<image class="title-right-img" src="/static/more.png" />

							</view>
						</view>
						<view class="pls-card-middle">
							<view class="pls-card-middle-one">
								<view class="middle-title">
									{{ v.updateTime?.split(' ')[0] }}
								</view>
								<view class="middle-heng-father">
									<view class="middle-heng"
										style="border-top-left-radius: 20rpx;border-bottom-left-radius: 20rpx;"></view>
									<view class="middle-heng" v-if="Number(v.status)<3 "
										style="border-radius: 20rpx;background-color: #1083F8;"></view>
									<view class="middle-ball"
										:style="Number(v.status)<3?{backgroundColor: `#1083F8`}:{} "></view>
								</view>
								<view class="end-font">
									<view class="" :style="Number(v.status)<3?{color: `#1083F8`}:{} ">
										采购
									</view>
									<view class="">
										[ {{ v.createBy_dictText }} ]
									</view>
								</view>
							</view>
							<view class="pls-card-middle-one">
								<view class="middle-title">
									<!-- 2025.10.03 -->
								</view>
								<view class="middle-heng-father">
									<view class="middle-heng"></view>
									<view class="middle-heng" v-if="Number(v.status)<3 && Number(v.status)>0 "
										style="border-radius: 20rpx;background-color: #1083F8;width: 105%;margin-left: -5%;">
									</view>
									<view class="middle-ball"
										:style="Number(v.status)<3 && Number(v.status)>0?{backgroundColor: `#1083F8`}:{} ">
									</view>
								</view>
								<view class="end-font">
									<view class=""
										:style="Number(v.status)<3 && Number(v.status)>0?{color: `#1083F8`}:{} ">
										拣货
									</view>
									<view class="">
										<!-- [ 梁嘉豪 ] -->
									</view>
								</view>
							</view>
							<view class="pls-card-middle-one">
								<view class="middle-title">
									<!-- 2025.10.03 -->
								</view>
								<view class="middle-heng-father">
									<view class="middle-heng"
										style="border-top-right-radius: 20rpx;border-bottom-right-radius: 20rpx;">
									</view>
									<view class="middle-heng" v-if="Number(v.status)<3 && Number(v.status)>1 "
										style="border-radius: 20rpx;background-color: #1083F8;width: 105%;margin-left: -5%;">
									</view>
									<view class="middle-ball"
										:style="Number(v.status)<3 && Number(v.status)>1?{backgroundColor: `#1083F8`}:{} ">
									</view>
								</view>
								<view class="end-font">
									<view class=""
										:style="Number(v.status)<3 && Number(v.status)>1?{color: `#1083F8`}:{} ">
										完结
									</view>
									<view class="">
										<!-- [ 梁嘉豪 ] -->
									</view>
								</view>
							</view>
						</view>
						<view class="pls-card-end">
							<view class="end-left">
								<image class="end-left-img" src="/static/shili.png" />
								<view class="end-left-font">
									{{ v.gysName }}
								</view>
							</view>
							<view :class="v?.cgdType=='9' ?`tag-fail`:`tag-success`">
								{{ v?.cgdType=='9' ?`已作废`:`已确定` }}
							</view>
						</view>
					</view>

				</scroll-view>
			</view>
		</view>
		<view class="white-zhezhao"></view>
		<view class="contain-right">
			<view class="contain-right-title">
				<view class="contain-right-button" style="border-color: #D9DADC;box-shadow: 0 1rpx 3rpx #D9DADC;">
					<image class="buttont-img" src="/static/index/purchaseorder/select.png" />
					<view class="button-font">
						筛选
					</view>
				</view>
				<view class="contain-right-button" @click="goback()">
					<image class="buttont-img" style="margin-top: 4rpx;" src="/static/index/purchaseorder/back.png" />
					<view class="button-font">
						返回
					</view>
				</view>
			</view>
			<view class="contain-right-middle">
				<scroll-view scroll-y="true" class="middle-Y" @scrolltolower="getmore">
					<view class="middle-Y-father">
						<view class="middle-one" v-for="(v,i) in InvoicingList" :key='i'
							:style="{border: middletarget === i? '4rpx dashed #1083F8': '4rpx solid transparent'}"
							@click="clickmiddle(i)">
							<image class="middle-img"
								:src="v.materialImg?serverUrl + v.materialImg : '/static/index/warehouse/procurement/k.png'"
								mode="aspectFill"></image>
							<view class="middle-right">
								<view class="right-title">
									{{ v.wlName }}
								</view>
								<view class="right-middle">
									{{ v.wlSpecificationModel }}
								</view>
								<view style="color: #888888;">
									采购数量: {{ v.kcsl + v.wlUnits }}
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
				<view class="wuliao-title">
					物料详情
					<view class="wuliao-heng"></view>
				</view>
				<view class="right-bottom">
					<view class="right-bottom-left">
						<image class="left-img"
							:src="showvalue?.materialImg?serverUrl + showvalue?.materialImg : '/static/index/warehouse/procurement/k.png'"
							mode="aspectFill"></image>
						<view class="left-tags">
							<view class="tags-one">
								{{ showvalue?.categoryId_dictText }}
							</view>
							<view class="tags-one">
								{{ showvalue?.typeId_dictText }}
							</view>
							<view class="tags-one">
								{{ showvalue?.tagName }}
							</view>

						</view>
					</view>
					<view class="right-bottom-right">
						<view class="bottom-right-title">
							<view class="title-left">
								{{ showvalue?.wlName }}
							</view>
							<view class="title-right">
								<text
									style="position: absolute;top: 8rpx;left: -35rpx;font-weight: 300;font-size: 28rpx;">
									￥
								</text>
								{{ (showvalue?.procurementPrice * showvalue?.purchaseQuantity).toFixed(2) }}
							</view>
						</view>
						<view class="bottom-right-middle">
							<view class="middle-onecard">
								<view class="threeone">
									<view class="gray-text">
										物料编号
									</view>
									<view class="right-text">
										{{ showvalue?.wlMaterialNo }}
									</view>
								</view>
								<view class="threeone">
									<view class="gray-text">
										规格型号
									</view>
									<view class="right-text">
										{{ showvalue?.wlSpecificationModel }}
									</view>
								</view>
								<view class="gray-heng"></view>
							</view>

							<view class="middle-onecard">
								<view class="threeone">
									<view class="gray-text">
										采购单价
									</view>
									<view class="right-text">
										￥{{ showvalue?.procurementPrice }}
									</view>
								</view>
								<view class="threeone">
									<view class="gray-text">
										采购数量
									</view>
									<view class="right-text">
										{{ showvalue?.purchaseQuantity }}
									</view>
								</view>
								<view class="threeone">
									<view class="gray-text">
										采购单位
									</view>
									<view class="right-text">
										{{ showvalue?.wlUnits }}
									</view>
								</view>
								<view class="gray-heng"></view>
							</view>
							<!-- <view class="gray-heng"></view> -->
							<view class="middle-onecard">
								<view class="threeone">
									<view class="gray-text">
										库存数量
									</view>
									<view class="right-text">
										{{ showvalue?.kcsl }}
									</view>
								</view>
								<view class="threeone">
									<view class="gray-text">
										物料上限 ↑
									</view>
									<view class="right-text">
										{{ showvalue?.wlUpperLimit }}
									</view>
								</view>
								<view class="threeone">
									<view class="gray-text">
										物料下限 ↓
									</view>
									<view class="right-text">
										{{ showvalue?.wlLowerLimit }}
									</view>
								</view>
								<view class="gray-heng"></view>
							</view>
							<!-- <view class="gray-heng"></view> -->
							<view class="middle-onecard">
								<view class="threeone" style="width: 100%;">
									<view class="gray-text">
										供应商
									</view>
									<view class="right-text">
										{{ showvalue?.suppliersName }}
									</view>
								</view>


							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { ref, onMounted, reactive, onBeforeUnmount, computed, nextTick, defineProps } from 'vue';
	import { queryInvoicingList, getCgdMaterialTreeData, queryNuInfoByNuId, updateKfstatus, queryCgdList, queryCgdInfoList, queryWlInfoByWlId, voidedCgdMain } from './api/lunpan.js'
	import { onShow, onLoad, onHide, onPageScroll } from "@dcloudio/uni-app"
	import shadowview from './components/ShadowView.vue';
	import calculator from './components/calculator.vue';

	const serverUrl = ref("")
	onLoad(() => {
		firstgetqueryCgdList();

		serverUrl.value = uni.getStorageSync('serverUrl') + '/sys/common/static/';

	})

	const searchValue = ref("");
	const middletarget = ref(0);

	const plzinfo = reactive({
		pageNo: 1,
		pageSize: 10,
		canpull: true
	})
	const leftscrolltop = ref(0)

	const plsbuy = ref([])

	const firstgetqueryCgdList = () => {
		queryCgdList(plzinfo).then((res : any) => {
			plsbuy.value.push(...res.result.records)
			console.log("zzzz",plsbuy.value)
			if (res.result.records.length) {
				form.cgdId = plsbuy.value[0].id
				queryInvo();
			}

			if (res.result.records.length < plzinfo.pageSize) {
				plzinfo.canpull = false;
			}

		})
	}

	const setout = ref(true)
	let times = null
	const plsbuytolower = () => {
		if (!setout.value) { return }
		plzinfo.pageNo++;
		getqueryCgdList()
		setout.value = false
		times = setTimeout(() => {
			setout.value = true
		}, 500)
	}
	//获得采购单列表
	const getqueryCgdList = () => {
		if (!plzinfo.canpull) return
		queryCgdList(plzinfo).then((res : any) => {
			// console.log("请购单", res.result.records)
			plsbuy.value.push(...res.result.records)
			// console.log("records",...res.result.records)

			if (res.result.records.length < plzinfo.pageSize) {
				plzinfo.canpull = false;
			}
		})
	}
	const lefttarget = ref(0);
	const clickLeftMenu = (index : any) => {
		let num = Math.ceil((index + 1))
		leftscrolltop.value = (num - 2) * 186;
		lefttarget.value = index;
		form.cgdId = plsbuy.value[index].id
		queryCgdInfoList(form).then(res => {
			// console.log("zzz",form)
			InvoicingList.value = []
			InvoicingList.value.push(...res.result.records);
			if (form.pageNo) {
				clickmiddle(0);
			}
		})
	}
	const showvalue = ref({
		materialImg: ""
	})


	const goback = () => {
		uni.navigateBack()
	}
	const form = reactive({
		nuId: '',
		pageNo: 1,
		pageSize: 9,
		categoryId: '',
		typeId: '',
		medicationId: '',
		wlParamInfo: '',
		cgdId: "",
		isWaring: 0,
		canpull: true
	})
	const mobanform = {
		nuId: '',
		pageNo: 1,
		pageSize: 9,
		categoryId: '',
		typeId: '',
		medicationId: '',
		wlParamInfo: '',
		cgdId: "",
		isWaring: 0
	}
	const clickmiddle = (index : number) => {
		middletarget.value = index;
		showvalue.value = InvoicingList.value[index];
		Object.assign(form, mobanform)

	}
	const InvoicingList = ref([])
	const queryInvo = () => {
		queryCgdInfoList(form).then(res => {
			InvoicingList.value.push(...res.result.records);
			// console.log("加载", res.result.records)
			clickmiddle(0);
		})
	}
	const getmore = () => {
		if (form.canpull) {
			form.pageNo++
			queryCgdInfoList(form).then(res => {
				InvoicingList.value.push(...res.result.records);
				if (res.result.records.length != 10) {
					form.canpull = false
				}
			})
		}

	}
	// const getMaterial = () => {
	// 	getCgdMaterialTreeData(form).then(res => {
	// 		// console.log(form)
	// 		// console.log(res)
	// 		// TreeData.value = res.result;
	// 		console.log("TreeData.value",res)
	// 	})
	// }
</script>

<style lang="less" scoped>
	.contain {
		background-color: rgb(239, 240, 244);
		width: 100vw;
		height: 100vh;
		padding: 5vh 2vw 0 2vw;
		display: flex;

		.contain-left {
			height: 95vh;
			width: 30%;
			overflow: hidden;
			// background-color: green;

			.title-input-father {
				height: 6vh;
				width: 100%;
				display: flex;
				align-items: center;

				.title-input {
					width: 71%;
					height: 5vh;
					background-color: #E2E4E9;
					font-size: 30rpx;
					padding-left: 45rpx;
					border-radius: 40rpx;
				}

				.title-input-button {
					width: 20%;
					margin-left: 2%;
					height: 5vh;
					border-radius: 40rpx;
					font-size: 30rpx;
					background: linear-gradient(to bottom, #e7f4ff, #c5e5ff);
					border: 2rpx solid #9AD1FF;
					color: #007CFF;
					display: flex;
					justify-content: center;
					align-items: center;
					-webkit-tap-highlight-color: transparent;
				}
			}

			.left-menu-father {
				margin-top: 1.3vh;
				width: 100%;
				height: 84vh;

				.left-menu-scroll {
					height: 100%;
					width: 100%;

					.pls-card {
						width: 100%;
						height: 26.5vh;
						border: #0f9fff 3rpx solid;
						background-color: #fff;
						border-radius: 40rpx;
						margin-bottom: 2vh;
						padding: 0 30rpx;

						.pls-card-title {
							height: 7vh;
							width: 100%;
							display: flex;
							justify-content: space-between;
							align-items: flex-end;

							.title-left {
								font-weight: 600;
								font-size: 32rpx;
							}

							.title-right {
								display: flex;
								align-items: flex-end;
								font-size: 30rpx;
								position: relative;

								.title-right-big {
									font-weight: 600;
									font-size: 40rpx;
									margin-right: 35rpx;
								}

								.title-right-img {
									position: absolute;
									right: -10rpx;
									bottom: 6rpx;
									width: 40rpx;
									height: 40rpx;
								}
							}
						}

						.pls-card-middle {
							width: 100%;
							height: 11vh;
							margin-top: 1vh;
							// background-color: blue;
							display: flex;

							.pls-card-middle-one {
								width: 33.3%;
								height: 100%;

								// background-color: yellow;
								.middle-title {
									width: 100%;
									height: 2vh;
									// background-color: #007CFF;
									color: #888888;
									text-align: center;
									font-size: 25rpx;
								}

								.middle-heng-father {
									width: 100%;
									height: 4vh;
									position: relative;

									.middle-heng {
										width: 100%;
										height: 1vh;
										position: absolute;
										left: 0;
										top: 50%;
										transform: translateY(-50%);
										background-color: #EEEEEE;

									}

									.middle-ball {
										width: 30rpx;
										height: 30rpx;
										background-color: #EEEEEE;
										position: absolute;
										top: 50%;
										left: 50%;
										transform: translate(-50%, -50%);
										border-radius: 50%;
									}
								}

								.end-font {
									width: 100%;
									height: 6vh;
									text-align: center;
									color: #666666;
									overflow: hidden;
									text-overflow: ellipsis;
									white-space: nowrap;
								}
							}
						}

						.pls-card-end {
							width: 100%;
							height: 7vh;

							display: flex;
							justify-content: space-between;
							position: relative;

							.end-left {
								height: 100%;
								display: flex;
								align-items: center;

								.end-left-img {
									width: 30rpx;
									height: 30rpx;
								}

								.end-left-font {
									margin-top: 3rpx;
									width: 400rpx;
									// background-color: #007CFF;
									// font-size: 26rpx;
									color: #666666;
									margin-left: 10rpx;
									overflow: hidden;
									white-space: nowrap;
									text-overflow: ellipsis;
								}
							}

							.tag-fail {
								width: 120rpx;
								height: 50rpx;
								border-radius: 30rpx;
								display: flex;
								align-items: center;
								justify-content: center;
								background-color: #FDEBEC;
								color: #FF5757;
								position: absolute;
								right: -5rpx;
								bottom: 20rpx;
							}

							.tag-success {
								width: 120rpx;
								height: 50rpx;
								border-radius: 30rpx;
								display: flex;
								align-items: center;
								justify-content: center;
								background-color: #ECF6FF;
								color: #1083F8;
								position: absolute;
								right: -5rpx;
								bottom: 20rpx;
							}
						}
					}
				}
			}
		}

		.contain-right {
			z-index: 1;
			height: 95vh;
			width: 70%;
			margin-left: 2%;
			overflow: hidden;

			.contain-right-title {
				width: 100%;
				height: 80rpx;
				display: flex;
				justify-content: flex-end;

				.contain-right-button {
					display: flex;
					justify-content: center;
					align-items: center;
					height: 100%;
					padding: 0 40rpx;
					border-radius: 40rpx;
					border: 1rpx solid #555555;
					margin-left: 20rpx;

					.buttont-img {
						width: 40rpx;
						height: 40rpx;
						margin-right: 10rpx;
						// margin-top: 4rpx;
					}

					.button-font {
						font-size: 30rpx;
						color: #555555;
					}
				}
			}

			.contain-right-middle {
				width: 100%;
				height: 460rpx;
				margin-top: 20rpx;

				.middle-Y {
					width: 100%;
					height: 100%;

					.middle-Y-father {
						display: flex;
						flex-wrap: wrap;
						width: 100%;
						padding-left: 20rpx;

						.middle-one {
							width: 440rpx;
							height: 200rpx;
							background-color: #F9F9F9;
							border-radius: 30rpx;
							margin-left: 20rpx;
							margin-bottom: 30rpx;
							display: flex;
							align-items: center;
							justify-content: space-around;

							.middle-img {
								width: 150rpx;
								height: 150rpx;
							}

							.middle-right {
								width: 250rpx;

								.right-title {
									width: 100%;
									white-space: nowrap;
									/* 不换行 */
									overflow: hidden;
									/* 超出隐藏 */
									text-overflow: ellipsis;
									/* 显示省略号 */
									display: block;
									font-weight: 600;
									font-size: 30rpx;
									margin-bottom: 7rpx;
								}

								.right-middle {
									margin-bottom: 7rpx;

								}
							}
						}
					}
				}
			}
		}
	}

	.white-zhezhao {
		position: fixed;
		height: 100%;
		background-color: #fff;
		width: 68%;
		top: 0;
		left: 32%;
	}

	.wuliao-title {
		margin-top: 40rpx;
		margin-left: 30rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 32rpx;
		font-weight: 600;
		width: 200rpx;

		.wuliao-heng {
			background-color: #1083F8;
			width: 40rpx;
			height: 5rpx;
			border-radius: 5rpx;
			margin-top: 10rpx;
		}
	}

	.right-bottom {
		width: 100%;
		height: 600rpx;
		display: flex;

		.right-bottom-left {
			height: 100%;
			width: 30%;
			padding-left: 30rpx;

			.left-img {
				width: 300rpx;
				height: 300rpx;
			}

			.left-tags {
				width: 100%;
				display: flex;
				flex-wrap: wrap;
			}

			.tags-one {
				width: 130rpx;
				height: 60rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 30rpx;
				border: 1rpx solid #D2D2D2;
				margin-left: 20rpx;
				margin-top: 20rpx;
				font-size: 25rpx;
				color: #555555;
			}
		}

		.right-bottom-right {
			height: 100%;
			width: 70%;

			.bottom-right-title {
				width: 100%;
				height: 100rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				// background-color: red;
				.title-left {
					font-weight: 600;
					font-size: 35rpx;
				}

				.title-right {
					font-weight: 600;
					font-size: 35rpx;
					position: relative;
					margin-right: 20rpx;
				}
			}

			.bottom-right-middle {
				width: 100%;

				.threeone {
					width: 33%;
				}

				.middle-onecard {
					width: 100%;
					height: 120rpx;
					display: flex;
					position: relative;

					.gray-text {
						color: #999999;
						margin-bottom: 3rpx;
						font-size: 25rpx;
					}

					.right-text {
						font-size: 32rpx;
					}
				}
			}
		}
	}

	.gray-heng {
		position: absolute;
		left: 0;
		bottom: 20%;
		background-color: #eff1f3;
		height: 0.5rpx;
		width: 80%;

	}
</style>