<template>
	<view class="content">
		<view class="topbar" v-show="isIphone">
		</view>
		<view class="status_bar">
			<view class="left" @click="goBack"><u-icon name="arrow-left"></u-icon>返回</view>
			<span style="font-size: 36rpx;">确认验收</span>
			<view class="right"></view>
		</view>
		<view class="mainCont">
			<view class="pcTop">{{ options.batchName }} ({{ options.num }})<span style="float: right">24.5kg</span>
			</view>
			<u-cell-group style="margin-b<u-icon name="arrow-left"></u-icon>ottom: 10px">
				<u-cell-item :arrow="false" :value-style="{textAlign: 'right',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>收&ensp;集&ensp;人：</view>
					{{ options.name }}
				</u-cell-item>
				<u-cell-item :arrow="false" :value-style="{textAlign: 'right',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>收集时间：</view>
					{{ time }}
				</u-cell-item>
				<u-cell-item :arrow="false" :value-style="{textAlign: 'right',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>收集重量：</view>
					{{ options.weight }}kg
				</u-cell-item>
				<u-cell-item :arrow="false" :value-style="{textAlign: 'right',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>验收重量：</view>
					<view style="display: flex;justify-content: space-between;">
						<u-input input-align="right" placeholder="重量" v-model="weight" type="number"
							style="width: calc(100% - 30px);" />
						<span style='width: 30px;line-height: 35px;'>kg</span>
					</view>
				</u-cell-item>
			</u-cell-group>
		</view>
		<view class="bottomButton" @click="confirmCheck">
			<view>确认</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	const NET = require('@/utils/request')
	const API = require('@/config/api')
	export default {
		data() {
			return {
				tableList: [{}],
				time: "",
				options: {},
				weight: 0,
				isIphone: false,
			}
		},
		onLoad(options) {
			uni.getSystemInfo({
				success: (res) => {
					console.log(res)
					if (res.model == 'iPhone') {
						this.isIphone = true;
					}
				},
				fail: (err) => {
					console.log(err)
				}
			})
			this.options = options
			let date = new Date;
			//获取年份
			let yy = date.getFullYear();
			//获取月份
			let mm = date.getMonth() + 1;
			//如果月份小于10 前面加0
			mm = (mm < 10 ? "0" + mm : mm);
			let dd = date.getDate();
			dd = (dd < 10 ? "0" + dd : dd);
			//返回日期 
			this.time = `${yy}-${mm}-${dd}`
		},
		onReady() {
			if (this.isIphone) {
				document.getElementsByClassName('mainCont')[0].style.height = document.getElementsByClassName('mainCont')[
					0].clientHeight - 25 + 'px'
			}
		},
		methods: {
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			confirmCheck() {
				if (!this.weight) {
					this.$refs.uToast.show({
						title: '请填写验收重量',
						type: 'warning',
					})
					return false
				}
				let postData = {
					// id: this.options.id,
					weight: this.weight
				}
				NET.request(API.receiveBatch + '/' + this.options.id, postData).then(res => {
					this.$refs.uToast.show({
						title: res.msg,
						type: 'success',
					})
					uni.navigateBack({
						delta: 2
					});
				}).catch(error => {
					this.$refs.uToast.show({
						title: error.msg,
						type: 'warning',
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	.mainCont {
		height: calc(100% - 80rpx);
		padding-bottom: 60px;
		overflow-y: scroll;
	}

	.pcTop {
		width: calc(100% - 20px);
		padding: 0 10px;
		height: 20px;
		line-height: 20px;
		margin: 0 auto;
		margin-top: 10px;
		margin-bottom: 10px;
		position: relative;

		&:after {
			content: '';
			position: absolute;
			height: 20px;
			top: 0;
			left: 0;
			width: 2px;
			background-color: #6aa0f7;
		}
	}

	/deep/ .u-cell__value {
		color: #1c1c1c;
	}
</style>
