<script setup lang="ts">
	import { onLoad } from '@dcloudio/uni-app';
	import { ref } from 'vue';

	const form = ref({} as any)
	const showDialog = ref(false)
	const show = ref(false)
	onLoad((option : any) => {
		form.value = JSON.parse(option.item)
		console.log(form.value);
	})

	const onClickLeft = () => {
		uni.navigateBack()
	}

	const onConfirmDate = (val : any) => {
		console.log(val);
	}
	const onSubmit = () => {

	}
</script>

<template>
	<view class="flex">
		<van-nav-bar title="现货需求单" left-text="返回" left-arrow @click-left="onClickLeft" />
		<view class="content">
			<van-form @submit="onSubmit">
				<van-cell-group inset>
					<van-field v-model="form.id" name="需求单号" label="需求单号" colon class="bor" label-width="5em" readonly
						:rules="[{ required: true, message: '请填写' }]" />
					<van-field v-model="form.makeTime" name="做单日期" label="做单日期" colon class="bor" label-width="5em"
						readonly :rules="[{ required: true, message: '请填写' }]" />
					<van-field v-model="form.makeUser" name="订单归属" label="订单归属" colon label-width="5em"
						:rules="[{ required: true, message: '请填写' }]" readonly />
					<van-field v-model="form.color" name="颜色色号" label="颜色色号" colon class="bor" readonly
						:rules="[{ required: true, message: '请填写' }]" label-width="5em" />
					<van-field v-model="form.craft" name="工艺" label="工艺" colon
						:rules="[{ required: true, message: '请填写' }]" label-width="5em" readonly class="bor" />
					<van-field v-model="form.craft" name="备注" label="备注" colon
						:rules="[{ required: true, message: '请填写' }]" label-width="5em" readonly class="bor" />
					
					<view class="grid-container">
						<view class="grid-item">面料名称</view>
						<view class="grid-item">匹数</view>
						<view class="grid-item">谁定</view>
						<view class="grid-item">面料编号/米数</view>
					</view>
					<view class="grid-container" v-for="(item,index) in form.fabric" :key="index">
						<view class="grid-item">面料名称</view>
						<view class="grid-item">匹数</view>
						<view class="grid-item">谁定</view>
						<view class="grid-item">面料编号/米数</view>
					</view>
					
					<van-field v-model="form.id" name="第1次配货日期" label="第1次配货日期" colon class="bor" label-width="5em" readonly
						:rules="[{ required: true, message: '请填写' }]" />
					<van-field v-model="form.makeTime" name="染厂选择" label="染厂选择" colon class="bor" label-width="5em"
						readonly :rules="[{ required: true, message: '请填写' }]" />
					<van-field v-model="form.makeUser" name="进厂匹数" label="进厂匹数" colon label-width="5em"
						:rules="[{ required: true, message: '请填写' }]" readonly />
					<van-field v-model="form.color" name="进厂米数" label="进厂米数" colon class="bor" readonly
						:rules="[{ required: true, message: '请填写' }]" label-width="5em" />
				</van-cell-group>
				<view style="margin: 16px;">
					<van-button round block type="primary" native-type="submit">
						部分配货
					</van-button>
					<van-button round block type="primary" native-type="submit">
						已配全
					</van-button>
				</view>
			</van-form>
		</view>
	</view>

	<van-dialog v-model:show="showDialog">
		<view>
			<van-cell-group inset>
				<view v-for="(item,index) in fabric" :key="index">
					<view class="a-c">
						<van-icon name="add" color="red" size="25" v-if="index===0"
							@click="fabric.push({belongTo:'门店'})" />
						<van-icon name="clear" color="red" size="25" v-if="index!=0" @click="fabric.splice(index,1)" />
						<van-field v-model="item.name" name="面料名称" label="面料名称" colon readonly label-width="5em"
							@click="selectChoose(index)" class="bor" />
					</view>
					<van-field v-model="item.quantity" name="需求匹数" label="需求匹数" type="number" colon
						label-width="6.5em" />
					<!-- <van-field v-model="item.storageQuantity" name="库存匹数" label="库存匹数" colon label-width="6.5em"
						readonly /> -->
					<van-field v-model="item.belongTo" name="订单归属人" label="订单归属人" colon label-width="6.5em" />
				</view>
			</van-cell-group>
		</view>
		<template #footer>
			<view class="footer-button">
				<van-button plain size="small" native-type="button" style="width: 25vw;" @click="showDialog=false">
					取消
				</van-button>
				<van-button size="small" type="success" native-type="submit" style="width: 25vw;"
					@click="confirmSecond">
					确认
				</van-button>
			</view>
		</template>
	</van-dialog>


	<van-calendar v-model:show="show" @confirm="onConfirmDate" :min-date="new Date(2010, 0, 1)"
		:max-date="new Date(2050, 0, 31)" />
</template>

<style lang="scss" scoped>
	.flex {
		display: flex;
		flex-direction: column;
		height: 100vh;
		width: 100vw;

		.van-nav-bar {
			width: 100%;
		}

		.content {
			flex: 1;
			padding: 0 10px;

			.grid-container {
				display: grid;
				grid-template-columns: 2fr 1fr 1.5fr 1fr;

				.grid-item {
					border: 1px solid #f2f2f2;
					text-align: center;
					padding: 15rpx 0;

					::v-deep .van-cell {
						padding: 0 5px;
					}
				}
			}
		}
	}

	.footer-button {
		margin: 20px;
		display: flex;
		justify-content: space-around;
	}

	::v-deep .van-field {
		font-size: 16px;
	}

	.a-b {
		margin: 10rpx;

		::v-deep .van-button--normal {
			padding: 5px 8px;
			height: 30px;
		}
	}

	.a-c {
		display: flex;
		align-items: center;

		::v-deep .van-button--normal {
			padding: 8rpx;
			height: 50rpx;
			width: 7em;
		}
	}

	.bor {
		::v-deep .van-field__control {
			border: 1px solid #d7d7d7;
		}
	}

	::v-deep .van-field__control {
		border-bottom: 1px solid #d7d7d7;
		text-align: center;
	}

	::v-deep .van-field__label {
		text-align: end;
	}
</style>