<template>
	<view >
		<view class="fixedheader">
			
		
		<headers  :showBack="true">
			<view class="headerName">
				{{pageTitle}}
			</view>
		</headers>
	</view>
		<scroll-view class="smallHeight" :style="{ 'padding-top': ((statusBarHeight * 2) + 45) * 1.5 + 'rpx' }" scroll-y>
		<view class="formBox">
			<form @submit="formSubmit">
				<!-- <view class="uni-form-item">
					<view class="uni-form-label">
						混泥土标号<text class="star">*</text>
					</view>
					<view class="uni-form-input">
						<input class="uni-input" placeholder-class="cl" name="concreteTab" :value="form.concreteTab" placeholder="请输入" />
					</view>
				</view> -->
				<view class="uni-form-item">
					<view class="uni-form-label">
						实验室<text class="star">*</text>
					</view>
					<view class="uni-form-input">
						<picker @change="bindPickerChange" :value="buildIndex" :range="buildList" range-key="laboratoryName">
							<view class="uni-input uni-select cl" v-if="buildIndex==null">
								请选择 <image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
							</view>
							<view class="uni-input uni-select" v-else>{{form.laboratoryName}}
								<image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
							</view>
						</picker>
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						实验负责人<text class="star">*</text>
					</view>
					<view class="uni-form-input">
						<picker disabled @change="bindPickerChange2" :value="floorIndex" :range="floorList" range-key="floorName">
							<!-- <view class="uni-input uni-select cl" v-if="floorIndex==null">
								请选择 <image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
							</view> -->
							<view class="uni-input uni-select">
								{{form.laboratoryDirector}}
								<!-- {{floorList[floorIndex].floorName}} -->
								<!-- <image class="icon-down" src="/static/icon-down-black.png" mode=""></image> -->
							</view>
						</picker>
					</view>
				</view>
				
				<view class="uni-form-item">
					<view class="uni-form-label">
						试块/组名称<text class="star">*</text>
					</view>
					<view class="uni-form-input">
						<input class="uni-input" placeholder-class="cl" name="sampleName" v-model="form.sampleName"  placeholder="请输入" />
					</view>
				</view>
				
				<view class="uni-form-item">
					<view class="uni-form-label">
						混凝土标号<text class="star">*</text>
					</view>
					<view class="uni-form-input">
						<input class="uni-input" placeholder-class="cl" name="concreteLabel" v-model="form.concreteLabel"  placeholder="示例：C30" />
					</view>
				</view>
				
				<view class="uni-form-item">
					<view class="uni-form-label">
						入库时间<text class="star">*</text>
					</view>
					<view class="uni-form-input">
						<picker mode="date" :value="form.putStorageTime" @change="bindDateChange">
							<view class="uni-input uni-select cl" v-if="form.putStorageTime==''">
								请选择 <image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
							</view>
							<view class="uni-input uni-select" v-else>{{form.putStorageTime}}
								<image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
							</view>
						</picker>
					</view>
				
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						是否需要按照标准28天养护周期<text class="star">*</text>
					</view>
					<radio-group @change="radioChange">
						<label class="uni-list-cell uni-list-cell-pd" style="margin-right: 40px">
					        <view>
								<radio value="2" :checked="form.standardCycleType == 2" />
					        </view>
					        <view>是</view>
					    </label>
						<label class="uni-list-cell uni-list-cell-pd">
						    <view>
								<radio value="1" :checked="form.standardCycleType == 1" />
						    </view>
						    <view>否</view>
						</label>
					</radio-group>
				</view>
				<view class="uni-form-item" v-if="form.standardCycleType == 1">
					<view class="uni-form-label">
						养护周期(天)<text class="star">*</text>
					</view>
					<view class="uni-form-input">
						<input class="uni-input" placeholder-class="cl" name="curingPeriod" v-model="form.curingPeriod"  placeholder="请输入" />
					</view>
				</view>
				
				<div class="submitBtn_warp">
					<button form-type="submit" type="primary" class="btn submitBtn big">保存并生成试块二维码</button>
				</div>
				
			</form>
		</view>
		</scroll-view>
	</view>
</template>

<script>

	export default {
		data() {
			return {
				pageTitle: '入库',
				buildIndex: null,
				floorIndex:null,
				selectList: [{name:'C15'}, {name:'C20'}, {name:'C25'}, {name:'C30'}, {name:'C35'}, 
				{name:'C40'}, {name:'C45'}, {name:'C50'}, {name:'C55'}, {name:'C60'}],
				selectArr:[],
				buildList:[],
				floorList:[],
				tableData:[{
					num: '',
					No: '',
					type: ''
				}],
				form: {
					laboratoryDirector: '',
					laboratoryName: '',
					concreteLabel: '',
					projectSn: "",
					sampleName: '',
					putStorageTime: '',
					standardCycleType: 1,
					curingPeriod: ''
				},
				personList: [],
				projectDetail: {},
				isAdd: true,
				statusBarHeight: 0,
				projectSn: ''
			}
		},
		onLoad(options) {
			
			this.detailId = options.id
			
		},
		onShow() {
			this.statusBarHeight = uni.getStorageSync('systemInfo').statusBarHeight;
			this.projectSn = JSON.parse(uni.getStorageSync('userInfo')).sn
			this.loadData()
		},
		methods: {
			radioChange(e){
				console.log(e)
				this.form.standardCycleType = e.detail.value
			},
			deleteTableData(index){
				if(this.tableData.length>1){
					this.tableData.splice(index,1)
				}
			},
			addTableData(val){
				this.tableData.push({
					num: '',
					No: '',
					type: ''
				})
			},
			loadData(id){
				let that = this
				this.sendRequest({
					url: 'xmgl/standardDev/list',
					data: {projectSn:this.projectSn},
					method: "POST",
					success:(res)=>{
						this.buildList =  res.result
						
					}
				})
			},
			goSelectPersonFn() {
				uni.navigateTo({
					url: './personList'
					// url:'../../selectPerson/selectPerson2'
				})
			},
			
			bindPickerChange: function(e) {
				this.buildIndex = e.target.value
				this.form.laboratoryDirector =this.buildList[e.target.value].laboratoryDirector
				this.form.laboratoryName =this.buildList[e.target.value].laboratoryName
				
				this.floorIndex=null
			},
			bindPickerChange2: function(e) {
				this.floorIndex = e.target.value
			},
			bindDateChange: function(e) {
				this.form.putStorageTime = e.target.value
			},
			checkboxChange: function (e) {
				// var items = this.selectList,
				// 	values = e.detail.value;
				this.selectArr=e.detail.value;
				// for (var i = 0, lenI = items.length; i < lenI; ++i) {
				// 	const item = items[i]
				// 	if(values.includes(item.value)){
				// 		this.$set(item,'checked',true)
				// 	}else{
				// 		this.$set(item,'checked',false)
				// 	}
				// }
			},
			formSubmit(e) {
				var that = this
				// console.log(e)
				console.log(this.form)
				var params = this.form
				params.projectSn = this.projectSn
				if (params.laboratoryName == '') {
					uni.showToast({
						title: '请选择实验室',
						icon: 'none'
					})
					return false;
				}
				if (params.sampleName == '') {
					uni.showToast({
						title: '请输入试块/组名称',
						icon: 'none'
					})
					return false;
				}
				if (params.concreteLabel == '') {
					uni.showToast({
						title: '请输入混凝土标号',
						icon: 'none'
					})
					return false;
				}
				if (params.putStorageTime == '') {
					uni.showToast({
						title: '请选择入库时间',
						icon: 'none'
					})
					return false;
				}
				
				if (params.standardCycleType == 1 && params.curingPeriod == '') {
					uni.showToast({
						title: '请输入养护周期(天)',
						icon: 'none'
					})
					return false;
				}
				
				if(params.standardCycleType == 2){
					params.curingPeriod = 28
				}
				params.pouringId = this.detailId
				params.createUser = JSON.parse(uni.getStorageSync('userInfo')).userId
				console.log(params)
				this.sendRequest({
					url: 'xmgl/massReboundSampleStorageRecord/add',
					data: params,
					method: "POST",
					success(res) {
						uni.showToast({
							title: '保存成功！'
						})
						uni.navigateBack({
							
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.personListBox {
		// background-color: #f7f7f7;
		border-radius: 4px;
		overflow: hidden;
		border-left: 1px dashed #e6e6e6;
		position: relative;

		.personLeft {
			width: calc(100% - 20rpx);
		}

		.personItem {
			float: left;
			width: calc(33.33% - 21px);
			height: 54px;
			text-align: center;
			font-size: 24rpx;
			border-bottom: 1px dashed #e6e6e6;
			padding: 0px 20rpx 0;
			border-right: 1px dashed #e6e6e6;
			border-top: 1px dashed #e6e6e6;
			background-color: #f7f7f7;

			.name {
				font-size: 30rpx;
				padding-top: 16rpx;
			}

			.txt {
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}

			&.total {
				display: inline-flex;
				align-items: center;
				font-size: 30rpx;
				justify-content: center;
			}

			// &:nth-child(3n){
			// 	border-right: none;
			// }
		}

		.icon-right {
			position: absolute;
			right: 0;
			top: calc(50% - 7px);
			width: 16rpx;
			height: 28rpx;
		}
	}
	.designBox{
		background-color: #f9f9f9;
		border-radius: 4px;
		padding: 20rpx 20rpx 0;
		overflow: hidden;
		margin-bottom: 40rpx;
		.uni-list-cell{
			width: 20%;
			float: left;
			margin-bottom: 20rpx;
		}
	}
	.submitBtn{
		width: 90%;
		margin: 0 auto;
		font-size: 40rpx;
		// margin-top: 200rpx;
	}
	.formBox{
		margin: 0;
		.uni-form-item{
			padding: 0 30rpx;
			height: 90rpx;
			border-bottom: 0.5rpx solid #E7E7E7;
			font-size: 28rpx;
			margin-bottom: 0;
			.uni-form-input .uni-input {
				border: 0;
				padding: 0;
			}
			.icon-down{
				transform: rotate(-90deg);
			}
			.uni-input-placeholder{
				font-size: 28rpx;
			}
			uni-radio-group{
				display: flex;
				flex: 1;
				padding-left: 80rpx;
				.uni-list-cell{
					display: flex;
					align-items: center;
					font-size: 28rpx;
					:deep(.uni-radio-input){
						height: 28rpx;
						width: 28rpx;
						font-size: 28rpx;
					}
				}
			}
		}
		.n-bottom{
			border-bottom: 0;
		}
	}
	.tables{
		padding: 0 50rpx;
		font-size: 28rpx;
		margin-bottom: 32rpx;
		.t_header{
			display: flex;
			font-size: 24rpx;
			.t_title{
				flex: 1;
				text-align: center;
				line-height: 48rpx;
			}
		}
		.t_content{
			border-top: 1px solid #e7e7e7;
			border-left: 1px solid #e7e7e7;
			.t_td{
				display: flex;
				.t_input{
					flex: 1;
					height: 60rpx;
					text-align: center;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;
					uni-input{
						height: 100%;
						font-size: 28rpx;
					}
					.delete_btn{
						display: flex;
						align-items: center;
						justify-content: center;
						height: 100%;
						line-height: 60rpx;
						uni-text{
							margin-right: 10rpx;
						}
					}
				}
			}
		}
	}
	.add_btn{
		margin: 0 auto;
		width: 252rpx;
		height: 56rpx;
		border: 1px solid #5181F6;
		border-radius: 50rpx;
		text-align: center;
		font-size: 28rpx;
		color: #5181F6;
		line-height: 52rpx;
	}
	.fixedheader{
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 2;
	}
	.smallHeight{
		padding-bottom: 180rpx;
	}
	.submitBtn_warp{
		width: 100%;
		height: 130rpx;
		background: #fff;
		padding-top: 20rpx;
		position: fixed;
		bottom: 0rpx;
		left: 50%;
		transform: translateX(-50%);
	}
</style>
