<template>
	<!-- <u-navbar title="签收扫描" placeholder border=true :autoBack="true" leftIconSize='35'></u-navbar> -->
	<u-navbar title="签收扫描" bgColor='#D3832A' leftIconColor='#ffffff' titleStyle='color:#ffffff' placeholder
		:autoBack="true" leftIconSize='35'></u-navbar>
	<view class="tabbmiax">
		<view @click="setstates(1)" :class="checkstate==1?'xz':''">
			<view>商配</view>
			<view></view>
		</view>
		<view @click="setstates(2)" :class="checkstate==2?'xz':''">
			<view>市配</view>
			<view></view>
		</view>
	</view>
	<view class="schbox">
		<view>配送日期：</view>
		<view @click='showtime(true)' class="inputsr">
			<input :value='datatime' disabled placeholder="请选择时间" />
			<view @click.stop.prevent>
				<u-icon @click='showtime(true)' style="margin-right: 10rpx;" v-if="!datatime" name="calendar"
					color="#999999" size="50"></u-icon>
				<u-icon @click="cleartime" style="margin-right: 10rpx;" v-else name="close-circle" color="#999999"
					size="40"></u-icon>
			</view>
		</view>
		<view @click="init">
			查询
		</view>
	</view>

	<scroll-view scroll-y="true" class="scvbx" @scrolltolower="jiazai">
		<view class="mabxslist">
			<view class="item" v-for="item in datalist">
				<view class="headtop">
					<view class="type1s">
						<view>
							<text style="color: #90A0AF;">配送任务号：</text>{{item?.noteNumber}}
						</view>
					</view>
					<view class="type1s">
						<view>
							<text style="color: #90A0AF;">配送类型：</text>{{item?.type_name}}
						</view>
						<view>
							<text style="color: #90A0AF;">配送状态：</text>{{item?.deliStatus_name}}
						</view>
					</view>
					<view class="type1s">
						<view>
							<text style="color: #90A0AF;">车牌号：</text>{{item?.vehicleName}}
						</view>
						<view>
							<text style="color: #90A0AF;">司机：</text>{{item?.driverName}}
						</view>
					</view>
					<view class="type1s">
						<view>
							<text style="color: #90A0AF;">装卸班组：</text>{{item?.loadingTeamName}}
						</view>
						<view class="bhcolor">
							<text style="color: #90A0AF;">备货是否完成：</text>{{item?.isstock}}
						</view>
					</view>
					<view class="type1s">
						<view>
							<text style="color: #90A0AF;">客户：</text>{{item?.consignee}}
						</view>
					</view>
					<view class="type1s">
						<view>
							<text style="color: #90A0AF;">配送日期：</text>{{item?.taskTime}}
						</view>
					</view>
					<view class="liebs">
						<view @click="gocustomersign(item)">
							<view>配送客户数</view>
							<view class="golink">{{ item?.customersNumber||0 }}</view>
						</view>
						<view @click="goSignDetailScan(item)">
							<view>订单总数</view>
							<view class="golink">{{ item?.orderNumber||0 }}</view>
						</view>
						<view>
							<view>计划件数</view>
							<view>{{ item?.deliveryNumber||0 }}</view>
						</view>
						<view>
							<view>签收件数</view>
							<view>{{ item?.signNub||0 }}</view>
						</view>
						<view>
							<view>库存品数</view>
							<view>{{ item?.inventoryNub||0 }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</scroll-view>
	<!-- 	<u-datetime-picker :show="show" mode="datetime" @cancel="showtime(false)" @confirm="checktime"
		itemHeight='80'></u-datetime-picker> -->
	<l-calendar v-model:value="show" :initStartDate='date[0]' :initEndDate='date[1]' @hide='showCalendar'
		@change="onConfirm"></l-calendar>
</template>

<script lang="ts" setup>
	import {
		signforpage
	} from '@/api/user.js'
	import {
		onLoad,
		onShow,
		onHide,
		onUnload,
		onPullDownRefresh
	} from '@dcloudio/uni-app'
	import { reactive, toRefs, ref, watchEffect } from "vue";
	import utils from '../../../utils/utils';
	let details = reactive({
		datatime: '',
		show: false,
		taskTime_start: '',
		taskTime_end: '',
		datalist: [] as any,
		current: 1,
		size: 5,
		checkstate: 1,

	})
	onPullDownRefresh(() => {
		setTimeout(() => {
			uni.stopPullDownRefresh()
		}, 500)
	})
	const date = ref<number | string[]>([])
	function showCalendar() {
		details.show = !details.show
	}
	watchEffect(() => {
		if ((date.value as []).length != 0) {
			details.datatime = date.value[0] + ' 至 ' + date.value[1]
		}
	})
	function setstates(state : number) {
		if (details.checkstate == state) {
			return
		}
		details.checkstate = state
		init()
	}
	function onConfirm(e : any) {
		console.log(e);
		date.value[0] = e.startDate
		date.value[1] = e.endDate
		details.datatime = date.value[0] + ' 至 ' + date.value[1]
		init()
		// details.datatime=(uni as any).$u.timeFormat(date.value[0], 'yyyy-mm-dd')+' 至 '+(uni as any).$u.timeFormat(date.value[1], 'yyyy-mm-dd')
	}
	onLoad(() => {
		// #ifdef APP
		utils.ttsspke('请选择签收车次')
		// #endif

		date.value[0] = (uni as any).$u.timeFormat((new Date().valueOf() - 1000 * 60 * 60 * 24 * 3), 'yyyy-mm-dd')
		date.value[1] = (uni as any).$u.timeFormat((new Date().valueOf()), 'yyyy-mm-dd')
		details.current = 1
		// init()
	})
	onShow(() => {
		init()
	})
	function init() {
		details.current = 1
		initpage()
	}
	function jiazai() {
		details.current++
		initpage()
	}
	async function initpage() {
		let data = {
			current: details.current,
			size: details.size,
			taskTime_start: date.value[0],
			taskTime_end: date.value[1],
			type: details.checkstate
		}
		let response = await signforpage(data)
		console.log('111 :>> ', 111);
		if (response.code !== 200) return
		console.log('response :>> ', response);
		if (details.current == 1) {
			details.datalist = response.data.records
		} else {
			if (response.data.records.lngth == 0) {
				uni.showToast({
					title: '已经到底了。',
					icon: 'none'
				})
				details.current--
				return
			}
			details.datalist = details.datalist.concat(response.data.records)
		}

	}
	function showtime(value : boolean) {
		console.log(value);
		details.show = value
	}
	function checktime(event : any) {
		console.log(event);
		details.datatime = (uni as any).$u.timeFormat(event.value, 'yyyy-mm-dd');
		details.show = false
		console.log(details.datatime);
	}
	function gocustomersign(item : { id : string }) {
		uni.navigateTo({
			url: '/pagesHome/pages/CustomerSign/CustomerSign?item=' + JSON.stringify(item)
		})
	}
	function goSignDetailScan(item) {
		console.log('item :>> ', item);
		uni.navigateTo({
			url: '/pagesHome/pages/SignDetailScan/SignDetailScan?item=' + JSON.stringify(item)
		})
	}
	function cleartime() {
		// console.log(cleartime);
		details.datatime = ''
		date.value = []
		init()
	}
	const { checkstate, datatime, datalist, show } = toRefs(details)
</script>

<style lang="scss">
	.tabbmiax {
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #ffffff;

		.xz {
			>view:nth-of-type(1) {
				color: #FA8C16 !important;
			}

			>view:nth-of-type(2) {
				background-color: #FA8C16 !important;
			}
		}

		>view {
			width: 50%;
			height: 80upx;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			border-bottom: 1upx solid #EEEEEE;

			&:nth-of-type(1) {
				border-right: 1upx solid #EEEEEE;
			}

			>view:nth-of-type(1) {
				font-size: 34upx;
				color: #092C4D;
			}

			>view:nth-of-type(2) {
				width: 58upx;
				height: 8upx;

				margin-top: 10upx;
				border-radius: 20upx;
			}
		}
	}

	.inputsr {
		width: 400upx !important;
		height: 64upx;
		background: #F5F5F6;
		border-radius: 8upx 8upx 8upx 8upx;
		opacity: 1;
		border: 2upx solid #EEEEEE;
		padding: 16upx 18upx;
		box-sizing: border-box;
		padding-right: 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 26upx;
		font-weight: 400;
		color: #092C4D;

		>input {
			flex: 1;
			font-size: 26upx;
		}
	}

	.scvbx {
		width: 100%;
		height: 74vh;
		margin-top: 20upx;

		.mabxslist {
			display: flex;
			flex-direction: column;
			align-items: center;

			>.item {
				width: 686upx;
				// height: 610upx;
				background: #FFFFFF;
				border-radius: 8upx;
				padding: 20upx 0;
				box-sizing: border-box;
				margin-bottom: 20upx;

				>.headtop {
					display: flex;
					flex-direction: column;
					padding: 24upx;

					>.type1s {
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-bottom: 20upx;
						box-sizing: border-box;
						font-size: 28upx;
						font-weight: 400;
						color: #092C4D;

						>view {
							flex: 1;
						}

						// .bhcolor{
						// 	color: #0086F1;
						// }
					}

					>.liebs {
						display: flex;
						align-items: center;
						justify-content: space-around;

						>view {
							display: flex;
							flex-direction: column;
							align-items: center;
							margin-top: 20upx;

							&:nth-of-type(1) {
								>view:nth-of-type(2) {
									color: #092C4D;
								}
							}

							&:nth-of-type(2) {
								>view:nth-of-type(2) {
									color: #0086F1;
								}
							}

							&:nth-of-type(3) {
								>view:nth-of-type(2) {
									color: #3AD8BC;
								}
							}

							&:nth-of-type(4) {
								>view:nth-of-type(2) {
									color: #FA8C16;
								}
							}

							&:nth-of-type(5) {
								>view:nth-of-type(2) {
									color: #092C4D;
								}
							}

							>view:nth-of-type(1) {
								font-size: 28upx;
								font-weight: 400;
								color: #092C4D;
							}

							>view:nth-of-type(2) {
								font-size: 36upx;
								font-weight: 400;
								margin-top: 20upx;

							}
						}
					}
				}

				>.buts {
					border-top: 3upx solid #EEEEEE;
					display: flex;
					align-items: center;
					justify-content: space-around;
					padding-top: 20upx;

					>view {
						width: 204upx;
						height: 64upx;
						border-radius: 8upx;
						opacity: 1;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28upx;
					}

					>view:nth-of-type(1) {
						border: 2upx solid #0086F1;
						color: #0086F1;
					}

					>view:nth-of-type(2) {
						border: 2upx solid #D3832A;
						color: #D3832A;
					}
				}
			}
		}
	}

	.schbox {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 15upx 32upx;
		box-sizing: border-box;
		background-color: #ffffff;

		>view:nth-of-type(1) {
			// width: 150upx;
			font-size: 28upx;
			font-weight: 400;
			color: #092C4D;
		}

		>view:nth-of-type(2) {
			width: 380upx;
			// height: 64upx;
		}

		>view:nth-of-type(3) {
			width: 128upx;
			height: 64upx;
			background: #D3832A;
			border-radius: 8upx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 32upx;
			font-weight: 400;
			color: #FFFFFF;
		}
	}
</style>