<template>
	<view>
		<view
			class="single-fetch"
			v-for="(list, index) in detailList"
			:key="index"
		>
			<view>
				<span>机具类型</span>
				<h4>{{ list.typeName }}</h4>
			</view>
			<view>
				<span>规格型号</span>
				<h4>{{ list.specificationType }}</h4>
			</view>
			<view>
				<span>数量</span>
				<h4>{{ list.checkNum }}</h4>
			</view>
			<view>
				<span>编号</span>
				<h4>{{ list.maCode == null ? '-' : list.maCode }}</h4>
			</view>
			<view>
				<span>状态</span>
				<h4>{{ list.taskMark }}</h4>
			</view>
		</view>
		<view class="btm-sticky" v-show="showExam == '0'">
			<view style="display: flex;">
				<view 
					class="exam"
					@click="clickExam"
					style="margin-right: 15rpx;"
				>
					审核
				</view>
			</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" 
						@click="closePopup"
					>
					</uni-icons>
				</view>
				<h4 style="width: 85%; margin: 2vh auto; font-weight: normal; text-align: center;">是否通过审批？</h4>
				<view class="select-area">
					<view @click="modalExam('1')">通过</view>
					<view @click="modalExam('2')">驳回</view>
				</view>
			</view>
		</uni-popup>
		<u-loading-page :loading="showLoading" color="#000" loading-text="提交中,请稍后..."></u-loading-page>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showLoading: false,
				taskId: '',
				detailList: [],
				showExam: ''
			}
		},
		methods: {
			getListDetail (taskId) {
				let that = this
				that.$api.serviceCenterExam.fetchCenterDetail({
					taskId
				}).then(res => {
					console.log(res);
					if (res.data.code == 200) {
						res.data.rows.forEach(item => {
							switch (item.status) {
								case '0':
									item.taskMark = '待审核'
									break;
								case '1':
									item.taskMark = '已入库'
									break;
								case '2':
									item.taskMark = '入库驳回'
									break;
								case '3':
									item.taskMark = '入库待审核'
									break;
								case '4':
									item.taskMark = '已驳回'
									break;
							}
						})
						that.detailList = res.data.rows
					}
				}).catch(err => {
					console.log(err);
				})
			},
			clickExam () {
				this.openPopup()
			},
			modalExam (checkResult) {
				let that = this
				let subObj = {
					checkResult,
					inputRecordList: that.detailList,
					taskId: that.taskId
				}
				that.subExam(subObj)
			},
			subExam (obj) {
				let that = this
				that.showLoading = true
				that.closePopup()
				that.$api.serviceCenterExam.examCenterRecord(obj).then(res => {
					console.log(res);
					if (res.data.code == 200) {
						that.showLoading = false
						uni.showToast({
							icon: 'none',
							title: '提交成功！',
							success: () => {
								uni.navigateBack()
							}
						})
					} else {
						that.showLoading = false
						uni.showToast({
							icon: 'none',
							title: res.data.msg
						})
					}
				}).catch(err => {
					console.log(err);
				})
			},
			openPopup () {
				this.$refs.popup.open()
			},
			closePopup () {
				this.$refs.popup.close()
			}
		},
		onLoad(params) {
			console.log(params);
			this.taskId = params.taskId
			this.showExam = params.showExam
			this.getListDetail(params.taskId)
		}
	}
</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-sticky{
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		box-sizing: border-box;
		padding: 15rpx 30rpx;
		background-color: #fff;
		display: flex;
		justify-content: right;
		align-items: center;
		.exam{
			box-sizing: border-box;
			padding: 10rpx 50rpx;
			border-radius: 30rpx;
			background-color: #3788FF;
			font-size: 14px;
			color: #fff;
		}
	}
	.popup{
		width: 80vw;
		height: 20vh;
		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;
			display: flex;
			justify-content: space-around;
			align-items: center;
			view{
				box-sizing: border-box;
				font-size: 30rpx;
				padding: 12rpx 24rpx;
				background-color: #3788FF;
				color: #fff;
				border-radius: 20rpx;
			}
		}
	}
</style>
