<template>
	<view>
		<view class="search-bar">
			<uni-easyinput suffixIcon="search" v-model="preIpt" placeholder="请输入关键字" @iconClick="searchKeyword"></uni-easyinput>
		</view>
		<view 
			class="single-fetch"
			v-for="(pre, index) in preCrashList"
			:key="index"
		>
			<view class="fetch-upper">
				<!-- <checkbox-group 
					v-show="pre.taskStatus == 58" 
					style="margin-right: 15rpx;"
					@change="checkClick(pre)"
				>
					<checkbox :checked="pre.checked" />
				</checkbox-group> -->
				<view class="upper-lef">
					{{ pre.createBy == null ? '' : pre.createBy.slice(0, 1) }}
				</view>
				<view class="upper-rig">
					<h4 style="font-size: 16px;">{{ pre.createBy }}</h4>
					<h4 style="color: #989898;">{{ pre.unitName }}</h4>
				</view>
			</view>
			<view class="fetch-lower">
				<view>
					<span>预报废单号</span>
					<h4>{{ pre.scrapNum }}</h4>
				</view>
				<view>
					<span>报废来源</span>
					<h4>{{ pre.projectName }}</h4>
				</view>
				<view>
					<span>设备类型</span>
					<h4>{{ pre.itemType }}</h4>
				</view>
				<view>
					<span>申请时间</span>
					<h4>{{ pre.createTime }}</h4>
				</view>
			</view>
			<view class="fetch-btns">
				<view 
					style="background-color: #3788FF;" 
					@click="seePreDetail(pre.taskId)"
				>
					<uni-icons style="color: #fff;" type="eye"></uni-icons>
					查看
				</view>
				<view 
					style="background-color: #FCA30D;" 
					v-show="pre.taskStatus == '120' && ifRole"
					@click="examPreDetail(pre.taskId)"
				>
					<uni-icons style="color: #fff;" type="auth"></uni-icons>
					审核
				</view>
				<view
					style="background-color: #FCA30D;" 
					v-show="pre.taskStatus == '121' && ifRole"
					@click="examPreDetail(pre.taskId)"
				>
					<uni-icons style="color: #fff;" type="auth"></uni-icons>
					审核
				</view>
			</view>
			<view class="sticky-area">
				<!-- <image src="/static/passed.png" v-show="pre.taskStatus == 59" mode=""></image>
				<image src="/static/noPass.png" v-show="pre.taskStatus == 61" mode=""></image>
				<image src="/static/noExam.png" v-show="pre.taskStatus == 58" mode=""></image> -->
				<h4
					v-show="pre.taskStatus == '120'"
				>
					待审核
				</h4>
				<h4
					v-show="pre.taskStatus == '121'"
				>
					审核中
				</h4>
				<h4
					v-show="pre.taskStatus == '122'"
					style="border: 1px solid #27D870; color: #27D870;"
				>
					已通过
				</h4>
				<h4
					v-show="pre.taskStatus == '123'"
					style="border: 1px solid #EE603D; color: #EE603D;"
				>
					已驳回
				</h4>
			</view>
		</view>
		<!-- <view class="btm-sticky">
			<view class="checked">
				<checkbox-group @tap="checkAll" style="margin-right: 15rpx;">
					<checkbox :checked="allChecked" />
				</checkbox-group>
				<text>全选</text>
			</view>
			<view 
				class="exam"
				@click="toggleExam"
			>
				审核
			</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="modalConfirm">通过</view>
					<view @click="modalReject">驳回</view>
				</view>
			</view>
		</uni-popup> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageNum: 1,
				pageSize: 10,
				pageTotal: 0,
				preCrashList: [],
				preIpt: '',
				roles: uni.getStorageSync('roles'),
				ableRoleArr: ['admin', 'em03', 'dm02'],
				ifRole: false
			}
		},
		methods: {
			searchKeyword () {
				this.fetchPreCrashList(this.preIpt)
			},
			fetchPreCrashList (keyword) {
				let that = this
				that.$api.preCrashExam.fetchPreCrashList({
					keyword,
					pageNum: that.pageNum,
					pageSize: that.pageSize
				}).then(res => {
					console.log(res);
					if (res.data.code == 200) {
						that.pageTotal = res.data.total
						that.preCrashList = [...that.preCrashList, ...res.data.rows]
					}
				}).catch(err => {
					console.log(err);
				})
			},
			seePreDetail (taskId) {
				// uni.setStorageSync('preTaskId', taskId)
				uni.navigateTo({
					url: `/pages/preCrashExamDetail/preCrashExamDetail?taskId=${taskId}`
				})
			},
			examPreDetail (taskId) {
				// uni.setStorageSync('preTaskId', taskId)
				uni.navigateTo({
					url: `/pages/preCrashExamDetail/preCrashExamDetail?showBtn=0&taskId=${taskId}`
				})
			}
		},
		onShow() {
			let that = this
			that.pageNum = 1
			that.preCrashList = []
			that.fetchPreCrashList('')
			console.log(uni.getStorageSync('roles'));
			for (let role of that.roles) {
				if (that.ableRoleArr.includes(role)) {
					that.ifRole = true;
					break;
				}
			}
			console.log(that.ifRole);
		},
		onReachBottom() {
			if (this.preCrashList.length >= this.pageTotal) return;
			this.pageNum++
			this.fetchPreCrashList(this.preIpt)
		}
	}
</script>

<style lang="scss">
	body{
		background-color: #f8f8f8;
		box-sizing: border-box;
		padding-bottom: 10vh;
	}
	.search-bar{
		width: 95%;
		margin: 20rpx auto;
	}
	.single-fetch{
		width: 95%;
		margin: 20rpx auto;
		background-color: #fff;
		border-radius: 15rpx;
		box-sizing: border-box;
		padding: 15rpx;
		position: relative;
		.fetch-upper{
			width: 100%;
			box-sizing: border-box;
			padding: 15rpx;
			border-bottom: 1px solid #D7D7D7;
			display: flex;
			align-items: center;
			.upper-lef{
				width: 12%;
				height: 5vh;
				border-radius: 15rpx;
				overflow: hidden;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 24px;
				background-color: #3788FF;
				color: #fff;
			}
			.upper-rig{
				flex: 1;
				box-sizing: border-box;
				padding: 10rpx 20rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				h4{
					font-weight: normal;
					font-size: 14px;
				}
			}
		}
		.fetch-lower{
			width: 100%;
			box-sizing: border-box;
			padding: 15rpx;
			border-bottom: 1px solid #D7D7D7;
			view{
				width: 100%;
				display: flex;
				align-items: center;
				margin-bottom: 15rpx;
				font-size: 14px;
				span{
					color: #9D9D9D;
					padding-right: 20rpx;
				}
				h4{
					color: #000;
					font-size: 14px;
					font-weight: normal;
				}
			}
			view:last-child{
				margin-bottom: 0;
			}
		}
		.fetch-btns{
			width: 100%;
			box-sizing: border-box;
			padding: 15rpx;
			display: flex;
			justify-content: flex-end;
			view{
				box-sizing: border-box;
				padding: 8rpx 25rpx;
				border-radius: 15rpx;
				margin-right: 15rpx;
				color: #fff;
				font-size: 14px;
			}
		}
		.sticky-area{
			position: absolute;
			top: 20rpx;
			right: 20rpx;
			/* width: 11vh;
			height: 10vh;
			image{
				width: 100%;
				height: 100%;
			} */
			h4{
				box-sizing: border-box;
				padding: 8rpx 20rpx;
				border-radius: 15rpx;
				font-size: 14px;
				font-weight: normal;
				background-color: #fff;
				border: 1px solid #3788FF; 
				color: #3788FF;
			}
		}
	}
</style>
