<template>
	<view class="">
		<view @click="showDetail(item)" @longpress.stop="longpress" class="data" v-for="(item, index) in list" :key="index">
			<view class="top">
				<view class="left">
					<view class="title ">
						<text class="text-bold">访客姓名：</text>
						<text>{{item.guestName}}</text>
					</view>
				</view>
				<view class="right">
					<text style="color: #ea7500;" v-if="item.checkState==0">待审核</text>
					<text class="base-color" v-if="item.checkState==1">已通过</text>
					<text style="color: #da0000;" v-if="item.checkState==2">未通过</text>
				</view>
			</view>
			<view class="item">
				<view class="left">
					<view style="padding: 20rpx 30rpx 0;">
						<view  v-if="item.imageUri"  class="">
							<image @click.stop="$util.preview(item.imageUri)"  style="width: 140rpx;height: 140rpx;" :src="item.imageUri" mode=""></image>
						</view>
						<view class="content">
							<text class="padding-right-10">访问园区：</text>
							<text >{{item.agencyName || '暂无'}}</text>
						</view>
						<view  v-if="item.enterpriseName" class="content">
							<text class="padding-right-10">访问企业：</text>
							<text >{{item.enterpriseName}}</text>
						</view>
						<view class="content">
							<text class="padding-right-10">预约时间：</text>
							<text >{{item.interviewTime}}</text>
						</view>
						<!-- 访客角色不需要看到联系方式，不然卡片太大 -->
						<view class="content" style="padding-top: 10rpx;" v-if="!$isEmpty(loginType)">
							<text class="padding-right-10">联系方式：</text>
							<text>{{item.guestTel}}</text>
							<image @click.stop="call(item.guestTel)" class="call" src="../../../../static/index/call.png" ></image>
						</view>
						<view class="content" v-if="item.opinion">
							<text class="padding-right-10">审核意见：</text>
							<text style="line-height: 50rpx;color: #da0000;">{{item.opinion}}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="bottom" >
				<block v-if="!$isEmpty(loginType)">
					<!-- 待审核，显示取消工单 -->
					<view @click.stop="pass(item)" v-if="item.checkState==0" style="font-size: 22rpx;" class="cu-btn  sm round base-bg-color margin-right-20" >
						审核通过
					</view>
					<view @click.stop="fail(item)" v-if="item.checkState==0" style="font-size: 22rpx;" class="cu-btn  sm round bg-red" >
						审核不通过
					</view>
					<!-- <u-button @click="del(item,index)" size="mini" v-else plain type="error">删除</u-button> -->
				</block>
				
				<block v-else>
					<!-- 访客开门 -->
					<view @click.stop="open(item)" v-if="item.checkState==1" style="font-size: 22rpx;" class="cu-btn  sm round base-bg-color margin-right-20" >
						去开门
					</view>
				</block>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	name: 'card',
	props:{
		list:{
			type:Array,
			default:()=>{
				[]
			}
		},
		loginType:{
			type:String | Boolean,
		}
	},
	data() {
		return {
			
		};
	},
	onLoad() {
		
	},
	methods:{
		async preview(src){
			this.$util.preview('src')
			return
			const urls = typeof src === 'string' ? [src] : src
			const filePath = async src => src.match(/^http/) ? src : (await uni.compressImage({ src, quality: 100 }))[1].tempFilePath
			for (let i = 0; i < urls.length; i++) {
				urls[i] = await filePath(urls[i])
			}
			uni.previewImage({ urls })
		},
		longpress(){
			console.log("我长按了");
		},
		call(phone){
			uni.makePhoneCall({
				phoneNumber:phone
			})
		},
		showDetail(item){
			this.$emit('showDetail',item)
		},
		pass(item){
			this.$emit('pass',item)
		},
		fail(item){
			this.$emit('fail',item)
		},
		del(item){
			this.$emit('delItem',item)
		},
		async open(item){
			let params={
				id:item.agencyId
			}
			//获取当前园区的token并把token存进缓存中
			//因为拉取门禁设备和开门需要用到token
			let res=await this.$api.agency.getAgency(params)
			let data=res.data
			console.log(data);
			let tokenParams={
				tenant_id:data.tenantId,
				username:data.account,
				password:data.password,
				grant_type: "password"
			}
			this.$cache.put('tokenObj',tokenParams)
			let resp=await this.$api.getToken(this.$u.queryParams(tokenParams))
			let token=resp.token_type+" "+resp.access_token
			uni.setStorageSync('token', token)
			uni.navigateTo({
				url:"/pages/guest/open-door/open-door?id="+item.id
			})
			
		}
	}
};
</script>

<style lang="scss">
.bg-blue{
	background-color: #59a5f0;
	color: #FFFFFF;
}	
	
.data {
	width: 710rpx;
	background-color: #ffffff;
	margin: 20rpx auto;
	border-radius: 6rpx;
	box-sizing: border-box;
	padding: 20rpx;
	font-size: 28rpx;
	.top {
		display: flex;
		justify-content: space-between;
		padding-bottom: 20rpx;
		border-bottom: 1rpx solid #EEEEEE;
		.left {
			display: flex;
			align-items: center;
			.title {
				margin: 0 10rpx;
				font-size: 30rpx;
			}
		}
		.right{
			margin-right: 10rpx;
		}
	}
	.item {
		margin: 5rpx 0 20rpx 0;
		.content {
			// border-bottom: 1rpx dashed #DDDDDD;
			padding: 20rpx 0 ;
			
			.call{
				width: 36rpx;
				height: 36rpx;
				margin-left: 20rpx;
				margin-top: 10rpx;
			}
		}
	}
	.bottom {
		display: flex;
		margin-top: 30rpx;
		justify-content: flex-end;
		align-items: center;
	}
}
</style>
