<template>
	<view class="">
		<view class="mask">
			<view hover-class="hover" @click="goBack" style="position:absolute;left:15px;top:60px;display: flex;flex-direction: row;">
				<image class="goback" src="../../static/common/back.png"/>
			</view>
			<view hover-class="hover" @click="showAction" style="position:absolute;right:15px;top:60px;display: flex;flex-direction: row;">
				<view class="dots"></view>
				<view class="dots"></view>
				<view class="dots"></view>
			</view>
			<swiper @change="changeSwiper" class="my_swiper" :current="current" :circular="circular" :indicator-dots="indicatorDots" :autoplay="autoplay" :duration="duration">
				<swiper-item v-for="(x, y) in picList" :key="y">
					<view class="bg_img" :style="{ backgroundImage: 'url('+x+')'}">
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="page" v-if="picList.length>0">{{ current + 1 }} / {{ picList.length }}</view>
		<ActionSheet :show="showActionSheet" :tips="tips" :item-list="actionList" :mask-closable="maskClosable"
			:color="color" :size="size" :is-cancel="isCancel" @click="itemClick" @cancel="closeActionSheet"></ActionSheet>
	</view>
</template>
<script>
import ActionSheet from "../actionsheet/actionsheet.vue"
export default { 
	data() {
		return {
			picList: [],
			indicatorDots: true,
			autoplay: false,
			duration: 500,
			circular: true,
			current: 0,
			isShowSwiper: false,
			showActionSheet: false,
			maskClosable: true,
			tips: "请选择",
			color: "#9a9a9a",
			size: 26,
			isCancel: true,
			actionList: [{text:"删除照片"}],
		};
	},
	onLoad() {
		var that = this;
		uni.$on('previewPhoto',function(data){
			that.picList= data[0];
			that.current= data[1];
		})
	}, 
	onUnload(){
		uni.$off('previewPhoto',function(data){
							
		})
	},
	methods: {
		clickPic(index) {
			this.current = index;
			this.isShowSwiper = true;
		},
		showAction(){
			this.showActionSheet = true;
		},
		closeActionSheet: function() {
			this.showActionSheet = false
		},
		goBack(){
			uni.navigateBack({
				
			})
		},
		changeSwiper(e) {
			this.current = e.target.current;
		},
		itemClick(){
			this.picList.splice(this.current,1);
			uni.navigateBack({
				
			})
			uni.$emit("securitySubmitPicChange",[this.picList])
		},
	},
	components: {
		ActionSheet,
	},
};
</script>

<style lang="scss" scoped>
.page {
	position: fixed;
	z-index: 6;
	color: #fff;
	bottom: 20rpx;
	text-align: center;
	width: 100%;
}
.mask {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
	background-color: #000;
	z-index: 5;
	> .my_swiper {
		width: 100%;
		height: 60vh;
		.bg_img {
			background-size: 100% auto;
			background-repeat: no-repeat;
			background-position:center;
			width: 100%;
			height: 100%;
			display: flex;
			justify-content: flex-end;
			align-items: flex-start;
		}
	}
}

.pic_list {
	display: flex;
	flex-flow: row wrap;
	> view {
		flex: 0 0 33.3vw;
		height: 33.3vw;
		padding: 1vw;
		> image {
			width: 100%;
			height: 100%;
		}
	}
}
.dots {
	width:7px;
	height:7px;
	background-color: #FFFFFF;
	border-radius: 7px;
	margin-right: 4px;
}
.goback{
	width:45rpx;
	height: 45rpx;
}
.hover {
	opacity: 0.7;
}
</style>
