<template>
	<view class="work-container">
		<!-- 轮播图 -->
		<uni-swiper-dot class="uni-swiper-dot-box" :info="data" :current="current" field="content">
			<swiper class="swiper-box" :current="swiperDotIndex" @change="changeSwiper">
				<swiper-item v-for="(item, index) in data" :key="index">
					<view class="swiper-item" @click="clickBannerItem(item)">
						<image :src="item.image" mode="aspectFill" :draggable="false" />
					</view>
				</swiper-item>
			</swiper>
		</uni-swiper-dot>

		<!-- 宫格组件 -->
		<uni-section v-if="certificationStatus == '1'" class="uni-section" title="系统管理" type="line">
			<template v-slot:right>
				已认证
			</template>
		</uni-section>
		<uni-section v-else class="uni-section" title="系统管理" type="line" @click="certification">
			<template v-slot:right>
				未认证
			</template>
		</uni-section>
		<!-- <uni-section class="uni-section" title="系统管理" type="line"></uni-section> -->
		<view class="grid-body">
			<uni-grid :column="4" :showBorder="false">
				<uni-grid-item>
					<view class="grid-item-box" @tap="changeGrid(0)">
						<uni-icons type="calendar-filled" size="30" color="#327DD7"></uni-icons>
						<text class="text">代办案件</text>
					</view>
				</uni-grid-item>
				<!-- <uni-grid-item>
					<view class="grid-item-box" @tap="changeGrid(1)">
						<uni-icons type="staff-filled" size="30" color="#327DD7"></uni-icons>
						<text class="text">代办案件</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="grid-item-box" @tap="changeGrid(2)">
						<uni-icons type="color" size="30" color="#327DD7"></uni-icons>
						<text class="text">代理立案</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="grid-item-box" @tap="changeGrid(3)">
						<uni-icons type="settings-filled" size="30" color="#327DD7"></uni-icons>
						<text class="text">代理案件进展</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="grid-item-box" @tap="changeGrid(4)">
						<uni-icons type="heart-filled" size="30" color="#327DD7"></uni-icons>
						<text class="text">证据交换</text>
					</view>
				</uni-grid-item> -->
				<uni-grid-item>
					<view class="grid-item-box" @tap="changeGrid(5)">
						<uni-icons type="bars" size="30" color="#327DD7"></uni-icons>
						<text class="text">互联网庭</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="grid-item-box" @tap="changeGrid(6)">
						<uni-icons type="email-filled" size="30" color="#327DD7"></uni-icons>
						<text class="text">查询快递</text>
					</view>
				</uni-grid-item>
				<!-- <uni-grid-item>
					<view class="grid-item-box" @tap="changeGrid(7)">
						<uni-icons type="compose" size="30" color="#327DD7"></uni-icons>
						<text class="text">在线签字</text>
					</view>
				</uni-grid-item> -->
				<!-- <uni-grid-item>
					<view class="grid-item-box" @tap="changeGrid(8)">
						<uni-icons type="wallet-filled" size="30" color="#327DD7"></uni-icons>
						<text class="text">仲裁文书</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="grid-item-box" @tap="changeGrid(9)">
						<uni-icons type="wallet-filled" size="30" color="#327DD7"></uni-icons>
						<text class="text">法规政策</text>
					</view>
				</uni-grid-item> -->
			</uni-grid>
		</view>
	</view>
</template>

<script>
	import {
		startEid
	} from '../../mp_ecard_sdk/main.js'
	import {
		getEidtoken,
		sendEidtoken
	} from "../../api/login.js"
	export default {
		data() {
			return {
				current: 0,
				swiperDotIndex: 0,
				data: [{
						image: 'https://img.tukuppt.com/bg_grid/00/09/96/qWJxN1umma.jpg!/fh/350'
					},
					{
						image: 'https://img.tukuppt.com/bg_grid/00/18/92/JBheZs7ZVK.jpg!/fh/350'
					},
					{
						image: 'https://img.tukuppt.com/bg_grid/00/81/07/DGEl4suqeV.jpg!/fh/350'
					}
				],
				certificationStatus: "",
				eidToken: ""
			}
		},
		methods: {
			clickBannerItem(item) {
				console.info(item)
			},
			changeSwiper(e) {
				this.current = e.detail.current
			},
			changeGrid(e) {
				// this.$modal.showToast('模块建设中~')
				if (this.certificationStatus == "0") {
					uni.showToast({
						title: '请先完成实名认证',
						icon: 'none',
						duration: 1000
					})
					return
				}
				switch (e) {
					case 0:
						uni.navigateTo({
							url: ('/pages/handlecase/index')
						})
						break;
					case 5:
						uni.navigateTo({
							url: ('/pages/im/index')
						})
						break;
					case 6:
						uni.navigateTo({
							url: ('/pages/expressDelivery/index')
						})
						break;
					case 7:
						uni.navigateTo({
							url: ('/pages/signature/index')
						})
						break;	
					default:
						break;
				}
			},
			// 获取eidtoken
			getEidtokenFn() {
				getEidtoken({}).then(res => {
					console.log(res.data.EidToken, "kkkkkkkkk");
					this.eidToken = res.data.EidToken
				})
			},
			// 点击实名认证
			certification() {
				let that = this
				// uni.navigateTo({
				// 	url: ('/mp_ecard_sdk/index/index')
				// })
				startEid({
					data: {
						token: this.eidToken,
					},
					verifyDoneCallback(res) {
						const {
							token,
							verifyDone
						} = res;
						console.log('收到核身完成的res:', res);
						console.log('核身的token是:', token);
						console.log('是否完成核身:', verifyDone);
						sendEidtoken({
							"eidToken": token
						}).then(res => {
							that.certificationStatus = '1'
						})
					},
				});
			}
		},
		onLoad() {
			// sendEidtoken({
			// 	"eidToken": 'C0339AE1-7B30-4DB9-B1E4-35A10F45249B'
			// }).then(res => {
			// 	// that.certificationStatus = '已认证'
			// })
			this.getEidtokenFn()
			this.certificationStatus = uni.getStorageSync('certificationStatus')
		},
	}
</script>

<style lang="scss">
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}

	view {
		font-size: 14px;
		line-height: inherit;
	}

	/* #endif */

	.text {
		text-align: center;
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.uni-margin-wrap {
		width: 690rpx;
		width: 100%;
		;
	}

	.swiper {
		height: 300rpx;
	}

	.swiper-box {
		height: 150px;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		color: #fff;
		height: 300rpx;
		line-height: 300rpx;
	}

	.grid-body {
		// background-image: url('https://img.tukuppt.com/bg_grid/00/18/52/aEicoC2qMI.jpg!/fh/350');
		background-repeat: no-repeat;
		background-size: cover;
		height: 900rpx;
		// color: #fff;
		opacity: 0.9;
	}

	.uni-section {
		background-color: #b90404 !important;
		color: #fff;
	}

	/deep/ .uni-section__content-title {
		color: #fff !important;
	}

	@media screen and (min-width: 500px) {
		.uni-swiper-dot-box {
			width: 400px;
			/* #ifndef APP-NVUE */
			margin: 0 auto;
			/* #endif */
			margin-top: 8px;
		}

		.image {
			width: 100%;
		}
	}
</style>