<template>
	<view class="">
		<!-- 休息日 -->
		<u-empty  v-if="status==0" margin-top="300" icon-size="300" text="今天不上班，要好好休息哟~" src="/punch/static/icon/rest.png" ></u-empty>
		
		<!-- 工作日-未打卡 -->
		<view class="card" v-else-if="status==1">
			<view class="location" @click="chooseLocation">
				 <map :enable-scroll="false" class="map" :enable-zoom="false"></map>
				 <view class="label" style="position: relative;">
					 <u-icon name="map-fill" size="80" color="#5064eb"></u-icon>
				 	<view class="text-bold text-cut-1 margin-top-10">{{vuex_location.address}}</view>
					
					<view v-if="$isEmpty(remark) && $isEmpty(imgList)"   @click.stop="remarkShow=true" class="add-remark">添加备注...</view>
					
					<view @click.stop="remarkShow=true" class="remark-content" v-else>
						<view class="content text-cut-1">
							<text class="text-cut-1">{{remark}}</text>
						</view>
						<image  :src="imgList[0]" mode=""></image>
					</view>
				 </view>
			</view>
			<view class="" style="position: fixed;bottom: 20%;left: 50%;margin-left: -130rpx;">
				<view @click="punch" class="btn-open">
					<text>{{time}}</text>
					<text>第一次人脸打卡</text>
				</view>
			</view>
			
			<u-popup mode="center" borderRadius="10" v-model="remarkShow" height="52%" width="80%">
				<view style="padding: 15rpx 15rpx 30rpx;height: 100%;" class="flex flex-direction justify-between">
					<view class="" style="border: 1rpx solid #d0d0d0;">
						<view class="padding-30">
							<u-input :clearable="false" height="200"  v-model="remark" placeholder="请添加备注" type="textarea"  borderColor="#dedede"/>
						</view>
						<view class="cu-form-group">
							<view class="grid col-4 grid-square flex-sub">
								<view class="bg-img" v-for="(item,index) in imgList" :key="index" @click="viewImage" :data-url="imgList[index]">
									<image :src="imgList[index]" mode="aspectFill"></image>
									<view class="cu-tag bg-red" @tap.stop="delImg" :data-index="index">
										<text class='cuIcon-close' ></text>
									</view>
								</view>
								<view  style="background-color: #f2f2f2;"  @tap="chooseImage" v-if="imgList.length<4 || $isEmpty(imgList)">
									<view  class="flex justify-center align-center" style="padding-top: 30rpx;">
										<u-icon name="camera-fill" size="55" color="#d9d9d9"></u-icon>
									</view>
								</view>
							</view>
						</view>
					</view>
					
					<view @click="remarkShow=false" class="cu-btn round base-bg-color" style="width: 100%;height: 85rpx;">
						确认
					</view>
				</view>
			</u-popup>
		</view>

		<!-- 工作日-去打卡 -->
		<view class="form" v-else-if="status==2">
			<view class="face">
				<image src="http://n.sinaimg.cn/front/724/w1078h1246/20190406/YVxr-hvhrcxm4045228.jpg" mode="scaleToFill"></image>
				<view >
					<text>人脸照片</text>
				</view>
			</view>
			
			<view class="desc">
				<view class="item">
					<text>时间</text>
					<text>16:03</text>
				</view>
				
				<view class="item">
					<text>位置</text>
					<text>保利世界贸易中心</text>
				</view>
				
				<view class="item">
					<text>备注</text>
					<view class="">
						<text>我是备注</text>
					</view>
				</view>
			</view>
			
			<view class="submit">
				<view class="cu-btn base-bg-color round" style="width: 100%;padding: 40rpx;">
					确认打卡
				</view>
			</view>
		</view>
		
		<view class="result" v-else-if="status==3">
			<image  src="../../static/icon/success.png" mode=""></image>
			<text class="tips">外出打卡成功</text>
			
			<view class="desc">
				<view class="item">
					<text>时间</text>
					<text>16:03</text>
				</view>
				
				<view class="item">
					<text>位置</text>
					<text>保利世界贸易中心</text>
				</view>
				
				<view class="item">
					<text>备注</text>
					<text>我是备注</text>
				</view>
			</view>
		</view>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				remark:'',
				imgList:[],
				face:'',
				remarkShow:false,
				
				time:'',
				latitude: 39.909,
				longitude: 116.39742,
			}
		},
		props:{
			faceImg:String
		},
		created() {
			this.getNowTime()
		},
		computed:{
			status:{
				get(){
					//0休息日,1工作日-未打卡 2工作日-去打卡 3工作日-打卡成功
					return 3
				}
			}
		},
		methods:{
			getNowTime(){
				let that=this
				setInterval(()=>{
					that.time=that.$dateTime.format(new Date(),'MM:SS')
				},1000)
			},
			chooseLocation(){
				let that=this
				uni.chooseLocation({
				    success: function (res) {
				        console.log('位置名称：' + res.name);
				        console.log('详细地址：' + res.address);
				        console.log('纬度：' + res.latitude);
				        console.log('经度：' + res.longitude);
						let distance= that.$util.calculateDistance(res.latitude,res.longitude,
												that.vuex_location.latitude,that.vuex_location.longitude)
						console.log(distance);
						if (distance>500) {
							that.$dialog.showModal('只可选500米范围内的地点',false)
						}
						
				    }
				});
			},
			//添加备注
			chooseImage(){
				this.$mpi.chooseImage().then(res=>{
					this.imgList.push(res[0])
				})
			},
			viewImage(e) {
				uni.previewImage({
					urls: this.remark.imgList,
					current: e.currentTarget.dataset.url
				});
			},
			delImg(e) {
				this.$dialog.showModal('确定删除？').then(res=>{
					this.remark.imgList.splice(e.currentTarget.dataset.index, 1)
				})
			},
			//打卡
			punch(){
				uni.navigateTo({
					url:"/pages/my-camera/my-camera"
				})
			}
			
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #FFFFFF;
	}
	
	.card{
		display: flex;
		flex-direction: column;
		align-items: center;
		height: 100%;
		width: 100%;
		
		.location{
			font-size: 38rpx;
			color: #0d6d3a;
			text-align: center;
			
			.map{
				width: 100vw; 
				height: 500rpx;
				opacity: 0.2;
			}
			.label{
				margin-top: -300rpx;
				
				image{
					width: 80rpx;
					height: 80rpx;
				}
				
				.add-remark{
					font-weight: 800;
					padding-top: 60rpx;
					color: #4a70c8;
					font-size: 28rpx;
				}
				
				.remark-content{
					display: flex;
					justify-content: space-between;
					background-color: #FFFFFF;
					color: #666666;
					width: 90%;
					margin: 0 auto;
					margin-top: 60rpx;
					padding: 15rpx;font-size: 30rpx;
					border: 1rpx solid #e7e7e7;
					border-radius: 4rpx;
					
					.content{
						width: 85%;
						display: flex;
						justify-content: flex-start;
						align-items: center;
					}
					
					image{
						width: 75rpx;
						height: 75rpx;
					}
				}
			}
		}
		
		.btn-open{
			border: 18rpx solid $base-color;
			text-align: center;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			border-radius: 50%;
			height: 260rpx;
			width: 260rpx;
			
			text:first-child{
				color: #000000;
				font-size: 56rpx;
			}
			text:last-child{
				padding-top: 10rpx;
				font-size: 26rpx;
			}
		}
	}
	
	.empty{
		width: 100%;
		padding-top: 300rpx;
		background-color: #FFFFFF;
	}
	.form{
		position: relative;
		width: 100%;
		height: 75vh;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		padding-bottom: 80rpx;
		
		.face{
			
			image{
				border-radius: 10rpx;
				height: 260rpx;
				width: 240rpx;
			}
			
			view{
				padding-top: 10rpx;
				text-align: center;
				color: $base-color;
			}
		}
		
		.desc{
			border-top: 1rpx solid $dt-border-color-sm;
			margin-top: 100rpx;
			padding: 10rpx;
			width: 70%;
			.item{
				display: flex;
				justify-content: space-between;
				padding: 30rpx 0;
				
				text:first-child{
					color: #8c8d8d;
				}
			}
		}
		
		.submit{
			position: absolute;
			bottom: 0;
			left: 10%;
			right: 10%;
			margin: auto;
		}
		
	}
	
	.result{
		display: flex; 
		flex-direction: column;
		align-items: center;
		padding-top: 180rpx;
		
		image{
			width: 180rpx;
			height: 180rpx;
		}
		
		.tips{
			padding-top: 50rpx;
			font-size: 36rpx;
			color: #18b566;
			font-weight: 800;
		}
		
		.desc{
			border-top: 1rpx solid $dt-border-color-sm;
			margin-top: 100rpx;
			padding: 10rpx;
			width: 70%;
			.item{
				display: flex;
				justify-content: space-between;
				padding: 30rpx 0;
				
				text:first-child{
					color: #8c8d8d;
				}
			}
		}
	}
	
</style>
