<template>
	<view class="content">
		<view class="nav">
			<view class="item" v-for="(item,index) in iconList.arr" :key="index">
				<view class="icon">
					<image :src="item.icon" mode=""></image>
				</view>
				<view class="name">{{item.title}}</view>
			</view>
		</view>
		<view class="section" v-for="(item,index) in iconList.data" :key="index">
			<view v-if="item.data.length > 0">
				<view class="title">{{item.category_name}}</view>
				<view class="list">
					<view class="item" v-for="(item_2,index_2) in item.data" :key="index_2" @click="go_link(item_2)">
						<view class="icon">
							<image :src="item_2.icon" mode=""></image>
						</view>
						<view class="name">{{item_2.title}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "t-i-icon",
		props: [
			"iconList",
			"mine_code"
		],
		data() {
			return {

			};
		},
		methods: {

			go_link(item) {
				let link = item.link
				console.log(link)

				// OA系统
				if (link.indexOf("oa_system.nxjiewei.com") != -1) {
					uni.navigateTo({
						url: "../../origanization/OA/h5/h5",
						success: (res) => {
							// 通过eventChannel向被打开页面传送数据
							res.eventChannel.emit('acceptDataFromOpenerPage', {
								url: link,
								title: item.title
							})
						}
					})

					return
				}

				// 二维码
				if (link.indexOf("pageId") != -1 && link.indexOf("app:") == -1) {
					let pageId = ""

					function GetQueryString(name) {
						var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
						var r = link.match(reg);
						if (r != null) return unescape(r[2]);
						return null;
					}
					console.log(GetQueryString("pageId"))
					if (GetQueryString("pageId")) {
						pageId = GetQueryString("pageId")
					} else {
						pageId = link.split('=')[1]
					}

					uni.navigateTo({
						url: "../../index/record/record?pageId=" + pageId + "&mine_code=" + this.mine_code,
					})
				}
				// h5
				if (link.indexOf("pageId") == -1 && link.indexOf("app:") == -1) {
					uni.navigateTo({
						url: "../../index/h5/h5?url=" + link
					})
				}

			}
		}
	}
</script>

<style lang="scss">
	.content {
		margin-bottom: 30rpx;
		background-color: #FFFFFF;

		box-sizing: border-box;
		padding: 50rpx 25rpx 15rpx;
	}

	.nav {
		overflow: hidden;

		.item {
			float: left;
			width: 120rpx;

			margin-right: 25rpx;
			margin-bottom: 30rpx;

			.icon {
				width: 120rpx;
				text-align: center;

				image {
					width: 100rpx;
					height: 100rpx;
				}
			}

			.name {
				width: 120rpx;
				text-align: center;
				font-size: 30rpx;

				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}

		.item:nth-child(5n) {
			margin-right: 0;
		}
	}

	.section {
		margin-top: 20rpx;

		.title {
			font-size: 36rpx;
			margin-bottom: 40rpx;
		}

		.list {
			overflow: hidden;

			.item {
				float: left;
				width: 148rpx;

				margin-right: 36rpx;
				margin-bottom: 30rpx;

				.icon {
					width: 148rpx;
					text-align: center;

					image {
						width: 104rpx;
						height: 104rpx;
					}
				}

				.name {
					width: 148rpx;
					text-align: center;
					font-size: 30rpx;

					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}

			.item:nth-child(4n) {
				margin-right: 0;
			}
		}

	}
</style>
