<!-- 待入库 -->
<template>
    <view id="register">
		<view class="title">{{item.airName}}-{{item.configName}}</view>
		<view class="register_li">
			<view class="register_li_min">
				<view></view>
				<view>司机姓名：</view>
				<input v-model="infoForm.user.userName"   type="text" >
			</view>
			<view class="register_li_min">
			    <view></view>
				<view>司机号牌：</view>
				<input v-model="infoForm.car.carCode"   type="text" >
			</view>
			<view class="register_li_min" style="border-bottom:0;">
				<view></view>
				<view>联系方式：</view>
				<input v-model="infoForm.user.phone"   type="text" >
			</view>
		</view>
		<view class="register_li">
			<view class="register_li_min" v-for="(item,index) in list" :key="index">
				<view></view>
				<view>{{item.name}}</view>
				<view class="radio_group">
					<view class="radio" v-for="(item2,index2) in item.radioList" :key="index2" @click="radioClick(item,item2)">
						<img v-if="!item2.checked" :src="imagesUrl('commonality/icon_5.png')">
						<img v-if="item2.checked" :src="imagesUrl('commonality/icon_6.png')">
						<text>{{item2.name}}</text>
					</view>
				</view>
			</view>
			<view class="register_li_min">
				<view>*</view>
				<view>气表压力：</view>
				<input v-model="form.gasPressure" maxlength="4"  type="text" placeholder-style="color:#999;" placeholder="请输入气表压力">
			</view>
			<!-- 检验有效期 -->
			<view class="register_li_min2">
				<view><text  style="color: #f00;margin-right: 10rpx;">*</text>检验有效期:</view>
				<picker mode="date" @change="startChange($event)">
					<input class="picker-text" v-model="form.validateStartTime" disabled  type="text" placeholder-style="color:#999;"  placeholder="开始时间">
				</picker>
				<view>-</view>
				<picker mode="date" @change="endChange($event)">
					<input class="picker-text2" v-model="form.validateEndTime" disabled  type="text"  placeholder-style="color:#999;" placeholder="结束时间">
				</picker>
			</view>
			<view class="register_li_min" >
				<view>*</view>
				<view>电子标签：</view>
				<input v-model="form.electronicTag"   type="text" placeholder-style="color:#999;" placeholder="请输入电子标签ID">
				<img @click.stop="saoCode"  class="code_img" :src="imagesUrl('commonality/icon_aqjc_sm.png')">
			</view>
			<view class="register_li_min" style="border: none;">
			    <view>*</view>
				<view>验收备注：</view>
				<input v-model="form.validateRemark"   type="text" placeholder-style="color:#999;" placeholder="请输入验收备注">
			</view>
		</view>
		<view class="sub_btn">
			<view class="sub_btn_l" @click="rejection()">拒收</view>
			<view class="sub_btn_r" @click="submitForm()">确认信息并入库</view>
		</view>
	</view>
</template>

<script>
    import {gasApplyDetailDrkDetail,gasApplyStorageAdd} from '@/api/apiDemo/index.js'
	import { config } from '@/api/request/config.js'
    export default {
        data() {
            return {
				form:{
					gasPressure:'',
					validateStartTime:'',
					validateEndTime:'',
					electronicTag:'',
					validateRemark:'',
				},
				infoForm:{},
				item:{},
				id:{},
				list:[
					{
						id:'0',
						name:'瓶身颜色：',
						lab:'color',
						radioList:[
							{
								id:1,
								name:'灰',
								checked:true,
							},
							{
								id:2,
								name:'白',
								checked:false,
							},
							{
								id:3,
								name:'蓝',
								checked:false,
							},
						]

					},
					{
						id:'0',
						name:'有无手轮：',
						lab:'isHandwheel',
						radioList:[
							{
								id:1,
								name:'有',
								checked:true,
							},
							{
								id:0,
								name:'无',
								checked:false,
							},
						]

					},
					{
						id:'0',
						name:'是否固定：',
						lab:'isFixed',
						radioList:[
							{
								id:1,
								name:'是',
								checked:true,
							},
							{
								id:0,
								name:'否',
								checked:false,
							},
						]

					},
					{
						id:'0',
						name:'电子标签：',
						lab:'isElectronicTag',
						radioList:[
							{
								id:1,
								name:'有',
								checked:true,
							},
							{
								id:0,
								name:'无',
								checked:false,
							},
						]

					},
					{
						id:'0',
						name:'气瓶状态标牌：',
						lab:'isStatusSign',
						radioList:[
							{
								id:1,
								name:'有',
								checked:true,
							},
							{
								id:0,
								name:'无',
								checked:false,
							},
						]

					},
					{
						id:'0',
						name:'标牌已拍照：',
						lab:'isPhoto',
						radioList:[
							{
								id:1,
								name:'有',
								checked:true,
							},
							{
								id:0,
								name:'无',
								checked:false,
							},
						]

					},
				]
            }
        },
        onLoad(option) {
        	this.item=JSON.parse(decodeURIComponent(option.item));
        },
        onShow(){

        },
		mounted(){
		  this.getInfo()

		},
        methods: {
			//开始时间选中事件
			startChange(e){
				this.form.validateStartTime=e.target.value
			},
			//结束时间选中事件
			endChange(e){
				this.form.validateEndTime=e.target.value
			},
			//单选按钮
			radioClick(p,d){
				d.checked=!d.checked
				if(d.checked){
					//如果有选中的，循环把其他选中的取消
					p.radioList.forEach(function(item){
						if(item.id==d.id){

						}else{
							item.checked=false;
						}
					})
				}else{

				}

			},
			//调用摄像头
			saoCode(){
				let _this = this;
			    uni.scanCode({
			        onlyFromCamera: true,
			        success: function (res) {
			    		_this.form.electronicTag=res.result
			        }
			    });
			},
			//获取列表数据
			async getInfo(){
				let _this = this;
				const {data} = await gasApplyDetailDrkDetail({id:_this.item.id});
				if(data.code==200){
					if(data.code==200){
						let res = data.data;
						_this.infoForm=res
					}

				}
			},
			//拒收
			async rejection(){
				uni.redirectTo({
				     url: '/pages_manage/gasBottle/gasApply/gasApplyReject?item='+encodeURIComponent(JSON.stringify(this.item))+'&item2='+encodeURIComponent(JSON.stringify(this.infoForm))
				 });
			},
			//提交
			async submitForm(){
				let _this = this;
				if(!this.form.gasPressure){
					uni.showToast({
						title: '请输入气表压力',
						icon:"none",
						mask:true,
						duration: 2000
					});
					return
				}
				if(!this.form.validateStartTime || !this.form.validateEndTime){
					uni.showToast({
						title: '请选择检验有效期',
						icon:"none",
						mask:true,
						duration: 2000
					});
					return
				}
				if(!this.form.electronicTag){
					uni.showToast({
						title: '请输入电子标签',
						icon:"none",
						mask:true,
						duration: 2000
					});
					return
				}
				if(!this.form.validateRemark){
					uni.showToast({
						title: '请输入验收备注',
						icon:"none",
						mask:true,
						duration: 2000
					});
					return
				}
				_this.list.forEach(function(item){
					item.radioList.forEach(function(item2){
						if(item.lab=='color' && item2.checked){
							_this.form.color=item2.id;
						}else if(item.lab=='isHandwheel' && item2.checked){
							_this.form.isHandwheel=item2.id;
						}else if(item.lab=='isFixed' && item2.checked){
							_this.form.isFixed=item2.id;
						}else if(item.lab=='isElectronicTag' && item2.checked){
							_this.form.isElectronicTag=item2.id;
						}else if(item.lab=='isStatusSign' && item2.checked){
							_this.form.isStatusSign=item2.id;
						}else if(item.lab=='isPhoto' && item2.checked){
							_this.form.isPhoto=item2.id;
						}
					})
				})
				_this.form.driverName=_this.infoForm.user.userName
				_this.form.driverId=_this.infoForm.user.id
				_this.form.carCode=_this.infoForm.car.carCode
				_this.form.carCodeId =_this.infoForm.car.id
				_this.form.phone=_this.infoForm.user.phone
				_this.form.airStatus=0;
				_this.form.taskId=_this.item.taskId;
				_this.form.taskDetailId=_this.item.id;
				_this.form.airName=_this.item.airName;
				_this.form.parent=_this.item.parent;
				_this.form.specValue=_this.item.specValue;
				_this.form.configName=_this.item.configName;
				_this.form.companyName=_this.item.companyName;
				_this.form.airConstituents=_this.item.airConstituents;
				_this.form.airBottleConfigId=_this.item.airBottleConfigId;
				_this.form.airBottleId =_this.item.airBottleId;

				const {data} = await gasApplyStorageAdd(_this.form);
				if(data.code == 200){
				    uni.showToast({
				        title: '提交成功',
				        icon:"none",
				        mask:true,
				        duration: 2000
				    });
				    setTimeout(function(){
				       uni.redirectTo({
				            url: '/pages_manage/gasBottle/gasApply/gasApply'
				        });
				    },2000);
				}
			},


		}
    }
</script>

<style lang="stylus" scoped>
    #register{
        height:auto;
        width:100%;
        display flex
        flex-direction column;
		padding-bottom: 220rpx;
		.title{
			width: 750rpx;
			height: 100rpx;
			background: #FFFFFF;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
			line-height: 100rpx;
			padding-left: 40rpx;
		}
		.register_li{
			background #fff;
			border-radius:20rpx;
			margin:20rpx 20rpx 0;
			padding:20rpx 0;
			box-sizing: border-box;
			.register_li_min{
				margin:0 26rpx;
				display flex;
				align-items center;
				border-bottom: 1px solid #F5F5F5;
				view{
					line-height:100rpx;
					font-size:28rpx;
				}
				view:nth-child(1){
					color:red;
					line-height:28rpx;
					margin-right: 12rpx;
				}
				view:nth-child(2){
					//width:140rpx;
					flex: 1;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
				}
				.picker-text{
					text-align: right;
					font-size: 28rpx;
				}

				>input{
					width 400rpx;
					text-align: right;
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
				}
				.code_img{
					width: 30rpx;
					height: 28rpx;
					margin-left: 26rpx;
				}
				/* 单选按钮 */
				.radio_group{
					display: flex;
					.radio{
						display: flex;
						margin-left: 80rpx;
						margin-right: 0;
						>img{
							width: 30rpx;
							height: 30rpx;
						}
						>text{
							margin-left: 34rpx;
							font-size: 28rpx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #333333;
							line-height: 28rpx;
						}
					}
				}
			}
			/* 时间 */
			.register_li_min2{
				margin:0 26rpx;
				border-bottom: 1px solid #f5f5f5;
				height: 100rpx;
				display: flex;
				justify-content: flex-start;
				align-items: center;
				>view:nth-child(1){
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
					line-height: 100rpx;
					margin-right: 96rpx;
				}
				.picker-text{
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					line-height: 100rpx;
					width: 188rpx;

				}
				>view:nth-child(2){
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					line-height: 100rpx;
				}
				.picker-text2{
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					line-height: 100rpx;
					width: 188rpx;
					text-align: right;
				}
			}

		}
		/* 按钮 */
		.sub_btn{
			width: 650rpx;
			height: 100rpx;
			display: flex;
			position: fixed;
			bottom: 30rpx;
			left: 50rpx;
			z-index: 1000;
			.sub_btn_l{
				width: 325rpx;
				height: 100rpx;
				background: linear-gradient(-45deg, #FA9901, #F28E26);
				border-radius: 50rpx 0px 0px 50rpx;
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 100rpx;
				text-align: center;
			}
			.sub_btn_r{
				width: 325rpx;
				height: 100rpx;
			    background: linear-gradient(-35deg, #309CFF, #0183FA);
			    border-radius: 0px 50rpx 50rpx 0px;
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 100rpx;
				text-align: center;
			}
		}
	}
	/deep/.input-value-border{
		display :none !important;
	}
</style>
