<template>
	<view>
		<view 
			class="single-fetch"
			v-for="(fetch, index) in fetchList"
			:key="index"
		>
			<view>
				<span>类型名称</span>
				<h4>{{ fetch.typeNum }}</h4>
			</view>
			<view>
				<span>规格型号</span>
				<h4>{{ fetch.specNo }}</h4>
			</view>
			<view>
				<span>申请数量</span>
				<h4>{{ fetch.num }}</h4>
			</view>
			<view>
				<span>设备编号</span>
				<h4>{{ fetch.num }}</h4>
			</view>
			<view>
				<span>入库时间</span>
				<h4>{{ fetch.num }}</h4>
			</view>
		</view>
		<view class="btm-exam">
			<view 
				class="exam"
				@click="seeExam"
			>
				审核
			</view>
		</view>
		<uni-popup
			ref="popup" 
			type="center"
			:mask-click="false"
		>
			<view class="popup">
				<view class="pop-top">
					<h4>审批</h4>
					<uni-icons 
						style="color: #AAAAAA; font-weight: bold;" 
						type="closeempty" 
						size="32"
						@click="closePopup"
					>
					</uni-icons>
				</view>
				<view class="select-area">
					<uni-forms ref="examForm" :modelValue="examFormData" :rules="rules" label-position="top">
						<uni-forms-item name="ifPass" required label="是否通过" label-width="150">
							<uni-data-select
							  v-model="examFormData.ifPass"
							  :localdata="ifPassRange"
							  :clear="false"
							  @change="ifPassChange"
							></uni-data-select>
						</uni-forms-item>
						<uni-forms-item required v-show="examFormData.ifPass == '1'" name="noPassReason" label="不通过原因" label-width="150">
							<uni-easyinput type="textarea" v-model="examFormData.noPassReason" placeholder="请输入内容"></uni-easyinput>
						</uni-forms-item>
						<button class="submit-btn" @click="formSubmit">确认</button>
					</uni-forms>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fetchList: [
					{
						typeNum: '手扶机绞磨',
						specNo: 'sjm-5',
						num: '2'
					},
					{
						typeNum: '机动绞磨',
						specNo: 'cjm-3',
						num: '2'
					},
					{
						typeNum: '卸扣',
						specNo: 'dg-5',
						num: '11'
					},
					{
						typeNum: '大理石',
						specNo: 'ym-5',
						num: '88'
					}
				],
				examFormData: {
					ifPass: '',
					noPassReason: ''
				},
				ifPassRange: [
					{ text: '是', value: '0' },
					{ text: '否', value: '1' }
				],
				rules: {
					ifPass: {
						rules: [
							{
								required: true,
								errorMessage: '请选择是否通过！'
							}
						]
					}
				}
			}
		},
		methods: {
			seeExam () {
				this.$refs.popup.open()
			},
			closePopup () {
				this.$refs.popup.close()
			},
			formSubmit () {
				let that = this
				that.$refs.examForm.validate().then(formData => {
					console.log(formData);
					that.$refs.popup.close()
				})
			},
			ifPassChange (e) {
				let that = this
				console.log(e);
				if (e == 1) {
					that.rules = {
						ifPass: {
							rules: [
								{
									required: true,
									errorMessage: '请选择是否通过！'
								}
							]
						},
						noPassReason: {
							rules: [
								{
									required: true,
									errorMessage: '请填写不通过原因！'
								}
							]
						}
					}
				} else {
					that.examFormData.noPassReason = ''
					that.rules = {
						ifPass: {
							rules: [
								{
									required: true,
									errorMessage: '请选择是否通过！'
								}
							]
						}
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	body{
		box-sizing: border-box;
		padding-bottom: 10vh;
	}
	.single-fetch{
		width: 100%;
		box-sizing: border-box;
		padding: 20rpx 35rpx;
		border-bottom: 1px solid #DDDDDD;
		view{
			display: flex;
			align-items: center;
			margin-bottom: 25rpx;
			span{
				color: #A7A7A7;
				padding-right: 20rpx;
			}
			h4{
				font-size: 14px;
				font-weight: normal;
			}
		}
		view:last-child{
			margin-bottom: 0;
		}
	}
	.btm-exam{
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		box-sizing: border-box;
		padding: 20rpx 40rpx;
		display: flex;
		justify-content: flex-end;
		border-top: 2px solid #F6F8FF;
		.exam{
			box-sizing: border-box;
			padding: 10rpx 50rpx;
			border-radius: 30rpx;
			background-color: #3788FF;
			font-size: 14px;
			color: #fff;
		}
	}
	.popup{
		width: 80vw;
		height: 60vh;
		background-color: #fff;
		border-radius: 15rpx;
		overflow: hidden;
		background: linear-gradient(#D9E7FE, #fff, #fff, #fff);
		.pop-top{
			width: 100%;
			height: 5vh;
			box-sizing: border-box;
			padding: 0 25rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
		.select-area{
			width: 85%;
			margin: 40rpx auto;
			.submit-btn{
				background-color: #409EFF;
				color: #fff;
			}
		}
	}
</style>
