<!-- 不通过原因 -->
<template>
	<view id="approve">
		<view class="approve-title">驳回原因</view>
		<textarea v-model="rejectCause" placeholder="请输入未通过原因" maxlength="50"></textarea>
		<view class="button-view" @click="accessButtonClick">提交</view>
	</view>
</template>

<script>
	import {
		laboratoryAppletEditApp
	} from '@/pages_manage/api/index.js'
	export default {
		data() {
			return {
				itemData: {},
				rejectCause: "",
				checkList: [],
			}
		},
		onLoad(option) {
			let self = this;
			console.log(this.itemData)
			this.itemData = JSON.parse(decodeURIComponent(option.item));
			for (let i = 0; i < self.itemData.rejectCause.length; i++) {
				self.itemData.rejectCause[i].type = false
			}
			// this.itemData = JSON.parse(decodeURIComponent(option.item));
		},
		methods: {
			accessButtonClick() {
				let self = this;
				let num = 0;
				this.$set(this, 'checkList', [])
				for (let i = 0; i < self.itemData.rejectCause.length; i++) {
					if (self.itemData.rejectCause[i].type) {
						num++
						this.checkList.push(self.itemData.rejectCause[i].materialId);
					}
				}
				if (!self.rejectCause) {
					uni.showToast({
						title: '请输入驳回原因',
						icon: "none",
						mask: true,
						duration: 2000
					});
					return
				}
				uni.showModal({
					content: '确认拒绝通过吗?',
					cancelColor: "#999",
					confirmColor: "#0183FA",
					success: function(res) {
						if (res.confirm) {
							self.laboratoryApply();
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			//审核接口
			async laboratoryApply() {
				let obj = {
					applyId: this.itemData.applyId,
					auditStatus: 1,
					rejectCause: this.rejectCause,
					//rejectMaterial: this.checkList + '',
				};
				const {
					data
				} = await laboratoryAppletEditApp(obj)
				if (data.code == 200) {
					uni.showToast({
						title: '提交成功!',
						icon: "none",
						mask: true,
						duration: 2000
					});
					setTimeout(function() {
						uni.navigateBack({
							delta: 2
						});
					}, 2000);
				}

			},
			checkItem(item) {
				item.type = !item.type;
				this.$forceUpdate();
			},
		}
	}
</script>

<style lang="stylus" scoped>
	#approve {
		height: 100%;

		background #fff;
		overflow hidden;
		textarea {
			width: 670rpx;
			height: 200rpx;
			margin: 20rpx 30rpx 0;
			font-size: 28rpx;
			border: 1rpx solid #E0E0E0;
			border-radius: 10rpx;
			padding: 20rpx;
		}
		.approve-title {
			font-weight: 700;
			color: #333;
			font-size: 30rpx;
			font-weight: 700;
			margin: 20rpx 30rpx;

		}

		.approve-for-box {
			display flex;
			height: 60rpx;
			padding-left: 40rpx;

			img {
				width: 30rpx;
				height: 30rpx;
				margin: 15rpx;
			}

			view {
				font-size: 28rpx;
				height: 60rpx;
				line-height: 60rpx;
			}
		}

		.button-view {
			width: 600rpx;
			height: 80rpx;
			background: #0183FA;
			border-radius: 20rpx;
			font-size: 30rpx;
			line-height: 80rpx;
			text-align center;
			color: #fff;
			margin: 90rpx auto;
		}
	}
</style>
