<!--
 * @Author: 张涛
 * @Date: 2023-02-17 14:35:18
 * @LastEditors: 张涛
 * @LastEditTime: 2023-03-03 17:01:27
 * @FilePath: \liaoning-uniapp\pages\company-home\index.vue
-->
<template>
	<view class="container-main">
		<view class="header-bg">
			<view class="header-logo"></view>
			<view class="user-data">
				<text>{{ userName }}</text>
				<!--<text>{{ code }}</text> -->
			</view>
		</view>
		<view class="main">
			<view class="grid">
				<view class="grid-item" v-for="(item, index) in gridList" :key="index">
					<view class="item-child" :style="{ background: item.bg }" @click="goPath(item)">
						<image :src="baseImgUrl + item.icon" mode=""></image>
						<text>{{ item.name }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getSelfInfo
	} from "@/api/system/user.js";
	import {
		setToken
	} from "@/utils/auth";
	import {
		ControllerLogin,
		loginRemote
	} from "@/api/login.js";
	export default {
		data() {
			return {
				baseImgUrl: getApp().globalData.config.iamgeBaseUrl,
				gridList: [{
						name: "产品评价",
						icon: "liao-ning/icon_cppj.png",
						path: "/sub-enterprise/product-Appraise/product-Appraise",
						bg: "#F2F6FF",
					},
					{
						name: "主体评价",
						icon: "liao-ning/icon_ztpj.png",
						path: "/sub-enterprise/company-eval/company-eval",
						bg: "#FCF7F1",
					},
					{
						name: "政策指南",
						icon: "liao-ning/icon_zczn.png",
						path: "/sub-enterprise/policy-guide/policy-guide",
						bg: "#FCF7F1",
					},
					{
						name: "检测机构",
						icon: "liao-ning/icon_jcjg.png",
						path: "/sub-enterprise/testing-organizations/testing-organizations",
						bg: "#EFF9ED",
					},
					{
						name: "食责险投保",
						icon: "liao-ning/icon_szxtb.png",
						path: "/sub-enterprise/food-toubao/food-toubao",
						bg: "#F9F7FF",
					},
					{
						name: "食责险理赔",
						icon: "liao-ning/icon_szxlp.png",
						path: "/sub-public/food-lipei/food-lipei",
						bg: "#F2F6FF",
					},
					{
						name: "企业调查单",
						icon: "liao-ning/icon_qydcd@2x.png",
						path: "/sub-public/survey/survey",
						bg: "#EFF9ED",
					},
					{
						name: "示范企业申请",
						icon: "liao-ning/icon_sfqysq@2x.png",
						path: "/sub-enterprise/modelRequest/modelRequest",
						bg: "#FCF7F1",
					},
					{
						name: "企业标准公示",
						icon: "liao-ning/icon_qybzgs@2x.png",
						path: "/sub-interaction/publicity/publicity",
						bg: "#F9F7FF",
					},
					{
						name: "食品安全红黑榜",
						icon: "liao-ning/icon_spaqhhb@2x.png",
						path: "/sub-interaction/bang-dan/bang-dan",
						bg: "#F2F6FF",
					},
					{
						name: "食安辽宁线上播放",
						icon: "liao-ning/icon_xsbf@2x.png",
						path: "/sub-interaction/online-video/online-video",
						bg: "#FCF7F1",
					},
					{
						name: "名优展示",
						icon: "liao-ning/icon_myzs@2x.png",
						path: "/sub-interaction/excellent/excellent",
						bg: "#EFF9ED",
					},
					{
						name: "消费者咨询",
						icon: "liao-ning/icon_xfzzx@2x.png",
						path: "/sub-interaction/consumer-consult/consumer-consult",
						bg: "#F2F6FF",
					},
				],
				code: "",
				userName: "",
				loginForm: {
					pdma: "UEBzc3dvcjY=",
					urne: "2100002310090",
				},
			};
		},
		onLoad(option) {
			/**企业端不需要登录页 嵌入到外部系统内，取本地信息（企业名称，企业统一社会代码）后，写死登录获取token */
			this.getenterpriseInfo();
		},
		methods: {
			// 企业信息 + token
			getenterpriseInfo() {
				let enterpriseData = uni.getStorageSync("subjectUser");
				if (enterpriseData) {
					enterpriseData = JSON.parse(enterpriseData);
				} else {
					enterpriseData = {
						fEntname: "沈阳市辽中区嘉毅白酒坊",
						fUniscid: "91210122MA0TWNGB2G",
					};
				}
				ControllerLogin({
						pdma: "UEBzc3dvcjY=",
						// pdma: "MTExMTEx",
						urne: "2100002310090",
					})
					.then((res) => {
						setToken(res.data.result.userToken);
						//调selfInfo方便后台拿到登录账号信息
						getSelfInfo();
						//保存信息
						this.userName = enterpriseData.fEntname;
						this.code = enterpriseData.fUniscid;
						uni.setStorage({
							key: "USER_DATA",
							data: {
								userDto: {
									enterpriseName: this.userName,
									code: this.code,
								},
							},
						});
					})
					.catch(() => {
						uni.showToast({
							title: "获取信息失败",
							icon: "error",
						});
					});
			},
			// 跳转
			goPath(item) {
				if (item.name == "食责险理赔") {
					uni.navigateTo({
						url: item.path + `?showBtn=${2}`,
					});
					return;
				}
				if (item.name == "食品安全红黑榜" || item.name == "企业标准公示") {
					uni.navigateTo({
						url: item.path + `?code=${this.code}`,
					});
					return;
				}
				uni.navigateTo({
					url: item.name == "企业调查单" ?
						item.path + `?name=${item.name}&code=${this.code}` : item.path,
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	uni-page-body,
	page {
		// height: 100%;
		background: #e4ecff;
	}

	.container-main {
		position: relative;
		padding-bottom: 100rpx;
	}

	.header-bg {
		position: relative;
		z-index: 10;
		width: 100%;
		height: 416rpx;
		background: url("https://yth.scjg.ln.gov.cn/sgfs-enterprise/liaoning-app-file/file/liao-ning/home-header.png");
		background-size: 100% 100%;

		.header-logo {
			position: absolute;
			left: 25rpx;
			top: 114rpx;
			width: 370rpx;
			height: 63rpx;
			background: url("https://yth.scjg.ln.gov.cn/sgfs-enterprise/liaoning-app-file/file/liao-ning/home-bg.png");
			background-size: 100% 100%;
		}

		.user-data {
			position: absolute;
			left: 25rpx;
			top: 220rpx;
			font-size: 34rpx;
			font-weight: 500;
			color: #ffffff;
			letter-spacing: 2rpx;
			font-family: "PingFang SC-中黑体";
		}
	}

	.main {
		position: absolute;
		left: 0;
		z-index: 20;
		top: 300rpx;
		min-height: 100rpx;
		width: 100%;
		box-sizing: border-box;
		padding: 0 20rpx;
		padding-bottom: 150rpx;

		.grid {
			box-sizing: border-box;
			padding: 30rpx;
			margin-top: 20rpx;
			background: #ffffff;
			box-shadow: 0px 0px 20rpx 0px rgba(57, 118, 241, 0.102);
			border-radius: 16rpx;
			border: 2rpx solid #dce3ec;
			display: flex;
			flex-wrap: wrap;

			&>view {
				width: 50%;
				height: 180rpx;
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;

				.item-child {
					width: 315rpx;
					height: 180rpx;
					border-radius: 16rpx;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;

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

					text {
						font-size: 28rpx;
						font-weight: 550;
						font-family: "PingFang SC-中黑体";
						color: #34373b;
					}
				}
			}

			&>view:nth-child(even) {
				justify-content: flex-end;
			}

			&>view:last-child,
			&>view:nth-last-child(2) {
				margin-bottom: 0;
			}
		}
	}

	.firm-survey {
		margin-top: 20rpx;

		.survey-main {
			background: #ffffff;
			box-shadow: 0px 0px 20px 0px rgba(57, 118, 241, 0.102);
			border-radius: 32rpx;
			border: 4rpx solid #dce3ec;
			display: flex;
			padding: 6rpx 90rpx 6rpx 53rpx;
			box-sizing: border-box;
			align-items: center;
			justify-content: space-between;

			&>image {
				width: 152rpx;
				height: 168rpx;
			}

			.survey-left {
				margin-right: 127rpx;
				display: flex;
				flex-direction: column;

				&>text:nth-child(1) {
					font-family: PingFang SC-中黑体, PingFang SC;
					width: 200rpx;
					font-weight: 600;
					color: #34373b;
					line-height: 46rpx;
					font-size: 40rpx;
				}

				&>text:nth-child(2) {
					font-family: PingFang SC-常规体, PingFang SC;
					width: 288rpx;
					margin-top: 10rpx;
					font-weight: 400;
					color: #616367;
					line-height: 46rpx;
					font-size: 32rpx;
				}
			}
		}
	}
</style>