<template>
	<view class="app-page">
		<view class="handle-wrap">
			<view class="title">快捷操作</view>
			<view class="tabs">
				<view class="tab-item" v-for="(item,quickIdx) in quickList" :key="quickIdx" @click="linkTo(item)">
					<div class="icon-box">
						<image class="icon" :src="item.miniLogo" mode="widthFix"></image>
					</div>
					<view class="name">{{item.miniTitle}}</view>
				</view>
			</view>				
		</view>
		<view class="app-category" v-for="(appList,appIdx) in items" :key="appIdx">
			<view class="title">{{appList.miniCatTitle}}</view>
			<view class="applist">
				<view class="app" v-for="(app,index) in appList.miniList" :key="index" @click="linkTo(app)">
					<image class="icon" :src="app.miniLogo"></image>
					<view class="info">
						<view class="app-title">{{app.miniTitle}}</view>
						<view class="tag" v-if="app.miniDesc">{{app.miniDesc}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {getAppList,getQuickList} from '@/api/system/app.js'
	export default {
		data() {
			return {
				items:[],
				quickList:[]
			}
		},
		onShow() {
			this.getData()
		},
		methods: {
			getData(){
				getAppList().then((res)=>{
					this.items=res.data
				})
				getQuickList().then((res)=>{
					this.quickList=res.data
				})				
			},
			linkToTab(id,name){
				let href=""
				if(id===1){href="http://h5.xazhyc.com/danger/index.html"}
				if(id===2){href="http://h5.xazhyc.com/task/index.html"}
				if(id===3){href="http://h5.xazhyc.com/checkRecord/index.html"}
				if(id===4){href="http://h5.xazhyc.com/problem_feedback/problem_feedback.html"}
				uni.navigateTo({
					url:`/pages/webview/webview?href=${href}&name=${name}`
				})	
			},
			linkTo(app){
				if(app.miniUrl===""||app.miniUrl==undefined||app.miniUrl===null){
					uni.showToast({
						icon:"none",
						title:"请联系管理员开放应用地址"
					})
					return
				}
				if(app.miniUrl.includes('http')){
					uni.navigateTo({
						url:`/pages/webview/webview?href=${app.miniUrl}&name=${app.miniTitle}`
					})					
				}else{
					uni.showToast({
						icon:"none",
						title:"请联系管理员配置应用地址"
					})					
				}

			}
		}
	}
</script>

<style lang="scss" scoped>
.app-page{
	padding: 32rpx;
	background-color: rgba(243, 244, 247, 1);
	box-sizing: border-box;
	min-height: 100vh;
	.handle-wrap{
		background: linear-gradient(159.65deg, #FFF8E8 11.95%, #FFFFFF 20.49%, #FFFFFF 86.47%),
		linear-gradient(0deg, #FFFFFF, #FFFFFF);
		border-radius: 12rpx;
		padding: 32rpx 0;
		.title{
			color: #000;
			font-size: 32rpx;	
			padding-left:24rpx;
		}
		.tabs{
			display: flex;
			justify-content: space-around;
			align-items: center;
			padding:0 32rpx;
			margin-top: 32rpx;
			.tab-item{
				width: 112rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				flex-direction: column;
				.icon-box{
					width: 96rpx;
					height: 96rpx;
					border-radius: 26rpx;
					background-color: #2a60f3;
					.icon{
						width: 96rpx;
						height: 96rpx;
					}					
				}

				.name{
					width: 100%;
					padding-top: 12rpx;
					color: rgba(0, 0, 0, 0.9);
					font-size: 28rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					word-break: break-all;
				}
			}
		}
	}	
	.app-category{
		.title{
			color: #000;
			font-size: 32rpx;
			line-height: 1;
			padding: 48rpx 24rpx 32rpx 24rpx;
		}
		.applist{
			display: flex;
			flex-wrap: wrap;
			.app{
				width: 330rpx;
				height: 160rpx;
				background-color: #fff;
				border-radius: 16rpx;
				margin-bottom: 20rpx;
				display: flex;
				padding: 32rpx 0 0 28rpx;
				box-sizing: border-box;
				&:nth-child(2n){
					margin-left: 18rpx;
				}
				.icon{
					width: 66rpx;
					height: 66rpx;
					border-radius: 50%;
					background-color:rgba(151, 179, 255, 1);
					img{
						border: 1px solid red;
					}
				}
				.info{
					padding-left: 20rpx;
					padding-top: 4rpx;
					.app-title{
						width: 200rpx;
						color: rgba(34, 34, 34, 1);
						font-size: 32rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
					.tag{
						max-width: 202rpx;
						height: 48rpx;
						display:inline-block;
						margin-top: 6rpx;
						color: rgba(255, 171, 8, 1);
						font-size:24rpx;
						background: rgba(255, 171, 8, 0.1);
						border-radius: 12rpx;
						padding: 4rpx 10rpx;
						box-sizing: border-box;
						text-overflow: ellipsis;
						overflow: hidden;
						white-space: nowrap;
					}
				}
			}
		}
	}
}

</style>
