<template>
	<div class="" style="overflow:hidden">
		<!-- 今日数据 -->
		<div class="g_bg_f g_radius_8 g_ml_10 g_mr_10 g_mt_10" v-if="isAdmin">
			<div class="content g_flex_row_start g_h_92">
				<div v-for="(i, index) in userNum" :key="i.type" :class="index > 0 ? 'g_border_f5_l' : ''" class="g_flex_1 g_text_c g_flex_column_center" @click="goDetail('/root/merchantManagement/todayData')">
					<div class="g_fs_20 g_fw_600 g_c_3 g_mb_4">
						{{ i.num || 0 }}
					</div>
					<div>
						{{ i.label || "-" }}
					</div>
				</div>
			</div>
		</div>
		<!-- 今日数据 -->
		<div class="g_bg_f g_radius_8 g_ml_10 g_mr_10 g_mt_10" v-if="isAdmin">
			<!-- <div class="title g_flex_row_between g_h_46 flex_center g_pl_12 g_pr_10 g_border_f5_b">
				<div class="g_fw_600 g_fs_16">今日数据</div>
				<div class="iconfont icon-gengduo11 g_c_9 g_fs_12 g_w_120 g_text_r" @click="goDetail('/root/merchantManagement/todayData')"></div>
			</div> -->
			<div class="content g_flex_row_start g_h_74">
				<div v-for="(i, index) in todayData" :key="i.type" :class="index > 0 ? 'g_border_f5_l' : ''" class="g_flex_1 g_text_c g_flex_column_center" @click="goDetail('/root/merchantManagement/todayData')">
					<div class="g_fs_20 g_fw_600 g_c_3 g_mb_4">
						{{ map.agencyData[i.type] || 0 }}
					</div>
					<div>
						{{ i.label || "-" }}
					</div>
				</div>
			</div>
		</div>
		<div class="g_mt_10">
			<g-panel-card-num :list="applyData" subhead="全部" titleNav="/root/person/enrollList?from=tob" :speed="1" :marginBottom="16" :height="26" :num="4" cusTitle="当前工单" @clickItem="handleClickNum">
				<view v-if="hasNewResume > 0" style="font-size: 12px; color: #ffffff; background-color: #fa3534; display: inline-flex; justify-content: center; align-items: center; line-height: 24rpx; padding: 4rpx 8rpx; border-radius: 100rpx; z-index: 9">
					{{ hasNewResume }}
				</view>
			</g-panel-card-num>
		</div>
		<div class="g_bg_f g_radius_8 g_mt_10 g_ml_10 g_mr_10" v-if="false">
			<div class="title g_flex_row_between g_h_46 flex_center g_pl_12 g_pr_10 g_border_f5_b">
				<div class="g_fw_600 g_fs_16">当前工单</div>
				<div class="g_fs_14 g_flex_row_between flex_center g_position_rela" @click="goDetail('/root/person/enrollList?from=tob')">全部<i class="iconfont icon-gengduo11 g_c_9 g_fs_12 g_ml_4"></i><u-badge v-if="hasNewResume > 0" :offset="[-10, -10]" :count="hasNewResume"></u-badge></div>
			</div>
			<div class="content g_flex_row_start">
				<div v-for="(i, index) in applyData" :key="i.classify" :class="index > 0 ? 'g_border_f5_l' : ''" @click="goDetail('/root/person/enrollList?from=tob', i)" class="g_text_c g_flex_column_center g_border_f5_b g_h_74" style="width: 25%; box-sizing: border-box">
					<div class="g_fs_20 g_fw_600 g_c_3 g_mb_4">
						{{ i.num || 0 }}
					</div>
					<div>
						{{ i.name || "" }}
					</div>
				</div>
			</div>
		</div>
		<!-- <div class="g_bg_f g_radius_8 g_mt_10 g_ml_10 g_mr_10">
			<div class="title g_flex_row_between g_h_46 flex_center g_pl_12 g_pr_10 g_border_f5_b">
				<div class="g_fw_600 g_fs_16">我的老乡</div>
				<div class="g_fs_14 g_flex_row_between flex_center" @click="goDetail('/root/other/empty?type=我的老乡')">全部<i class="iconfont icon-gengduo11 g_c_9 g_fs_12 g_ml_4"></i></div>
			</div>
			<div class="content g_flex_row_start g_h_74">
				<div v-for="(i, index) in townsManData" :key="i.type" :class="index > 0 && index < 4 ? 'g_border_f5_l' : ''" class="g_flex_1 g_text_c g_flex_column_center">
					<div class="g_fs_20 g_fw_600 g_c_3 g_mb_4">
						{{ i.type == "total" ? map.userBinded0 + map.userBinded1 : map[i.type] || map[i.type] === 0 ? map[i.type] : "" }}
					</div>
					<div>
						{{ i.label || "" }}
					</div>
				</div>
			</div>
		</div> -->
		<div class="g_mt_10 g_pb_40" v-if="isAdmin">
			<g-panel-card-num :list="serverList" class="" :marginBottom="20" :height="32" :speed="1" :num="4" cusType="image" cusTitle="商家服务" @clickItem="handleClickNum" />
		</div>
	</div>
</template>

<script>
export default {
	onLoad() {
		this.getData();
	},
	data() {
		return {
			hasPermission: uni.getStorageSync("HAS_PERMISSION") == 1 ? true : false, // 登陆者是否有权限查看
			isAdmin: uni.getStorageSync("IS_MINIAPP_ADMIN"), // 管理员判断
			userNum: [
				{
					type: "total",
					label: "总用户",
					num: 320,
					path: "/root/merchantManagement/todayData?type=数据报表",
				},
				{
					type: "todayAdd",
					label: "今日新增",
					num: 23,
					path: "/root/merchantManagement/todayData?type=数据报表",
				},
				{
					type: "dua",
					label: "今日活跃",
					num: 42,
					path: "/root/merchantManagement/todayData?type=数据报表",
				},
				{
					type: "apply",
					label: "今日报名",
					num: 12,
					path: "/root/merchantManagement/todayData?type=数据报表",
				},
			],
			todayData: [
				{
					type: "signUps",
					label: "约面",
					path: "/root/merchantManagement/todayData?type=数据报表",
				},
				{
					type: "arrived",
					label: "到面",
					path: "/root/merchantManagement/todayData?type=数据报表",
				},
				{
					type: "passed",
					label: "通过",
					path: "/root/merchantManagement/todayData?type=数据报表",
				},
				{
					type: "entry",
					label: "入职",
					path: "/root/merchantManagement/todayData?type=数据报表",
				},
				{
					type: "obJob",
					label: "在职",
					path: "/root/merchantManagement/todayData?type=数据报表",
				},
			],
			applyData: [
				{
					name: "新简历",
					path: "/root/person/enrollList?from=tob&active=0",
					classify: 50,
					active: 0,
				},
				{
					name: "推工作",
					path: "/root/person/enrollList?from=tob&active=1",
					classify: 60,
					active: 1,
				},
				{
					name: "审核中",
					path: "/root/person/enrollList?from=tob&active=2",
					classify: 40,
					active: 2,
				},
				{
					name: "跟面试",
					path: "/root/person/enrollList?from=tob&active=3",
					classify: 70,
					active: 3,
				},
				{
					name: "跟入职",
					path: "/root/person/enrollList?from=tob&active=4",
					classify: 80,
					active: 4,
				},
				{
					name: "跟在职",
					path: "/root/person/enrollList?from=tob&active=5",
					classify: 90,
					active: 5,
				},
				{
					name: "已完成",
					path: "/root/person/enrollList?from=tob&active=6",
					classify: 110,
					active: 6,
				},
			],
			// townsManData: [
			// 	{
			// 		type: "total",
			// 		label: "全部",
			// 	},
			// 	{
			// 		type: "userBinded1",
			// 		label: "属于我",
			// 	},
			// 	{
			// 		type: "userBinded0",
			// 		label: "服务过",
			// 	},
			// 	{},
			// 	{},
			// ],
			map: {
				agencyData: {},
				userBinded0: 0,
				userBinded1: 0,
			},
			serverList: [],
			hasNewApply: 0,
		};
	},
	props: {
		hasNewResume: {
			default: 0,
		},
	},
	created() {
		let that = this;
		let appId = getApp().globalData.appId;
		uni.$on("updateMember", () => {
			this.getMemberNum();
		});
		console.log("appId", appId);
		// if (appId == "wx57e965905e6b4530") {
		// 	this.serverList = [
		// 		{
		// 			name: "平台职位",
		// 			icon: "cloud",
		// 			iconType: 1,
		// 			path: "/root/merchantManagement/platformJobList?type=平台职位",
		// 		},
		// 		{
		// 			name: "联系我们",
		// 			icon: "comment",
		// 			iconType: 1,
		// 			path: "/root/merchantManagement/relationUs?type=联系我们",
		// 		},
		// 		// {
		// 		// 	name: "动态公告",
		// 		// 	icon: "sound",
		// 		// 	iconType: 1,
		// 		// 	path: "/root/merchantManagement/dynamicNotice?type=动态公告",
		// 		// },
		// 		{
		// 			name: "团队管理",
		// 			icon: "team",
		// 			iconType: 1,
		// 			path: "/root/other/empty?type=团队管理",
		// 		},
		// 		{
		// 			name: "门店管理",
		// 			icon: "apartment",
		// 			iconType: 1,
		// 			path: "/root/other/empty?type=门店管理",
		// 		},
		// 		{
		// 			name: "站内消息",
		// 			icon: "bell",
		// 			iconType: 1,
		// 			path: "/root/merchantManagement/message?type=站内消息",
		// 		},
		// 		{
		// 			name: "频道管理",
		// 			icon: "earth",
		// 			iconType: 1,
		// 			path: "/root/other/empty?type=频道管理",
		// 		},
		// 		// {
		// 		// 	name: "数据报表",
		// 		// 	icon: "barchart",
		// 		// 	iconType: 1,
		// 		// 	path: "/root/merchantManagement/todayData?type=数据报表",
		// 		// },
		// 		{
		// 			name: "海报管理",
		// 			icon: "file-image",
		// 			iconType: 1,
		// 			path: "/root/merchantManagement/posterShare?type=海报管理",
		// 		},
		// 		{
		// 			name: "配置",
		// 			icon: "setting",
		// 			iconType: 1,
		// 			path: "/root/merchantManagement/setting?type=配置",
		// 		},
		// 	];
		// } else {

		// }
		this.getUserData();
		this.getApplyNum();
		this.getMemberNum();
		this.setService();
	},

	methods: {
		getMemberNum() {
			let that = this;
			that.G.Get(that.api.order_getNewApplyNumNotViewed, {}, (resapply) => {
				that.hasNewApply = resapply;
				that.setService();
				that.$forceUpdate();
			});
		},
		setService() {
			// 获取完数据后刷新商家服务的小红点
			this.serverList = [
				{
					name: "平台职位",
					icon: "cloud",
					iconType: 1,
					path: "/root/merchantManagement/platformJobList?type=平台职位",
				},
				{
					name: "海报分享",
					icon: "file-image",
					iconType: 1,
					path: "/root/merchantManagement/posterShare?type=海报分享",
				},
				{
					name: "团队管理",
					icon: "team",
					iconType: 1,
					path: "/root/merchantManagement/teamManage",
					tip: this.hasNewApply,
				},
				{
					name: "动态公告",
					icon: "sound",
					iconType: 1,
					path: "/root/merchantManagement/dynamicNotice?type=动态公告",
				},
				// {
				// 	name: "联系我们",
				// 	icon: "comment",
				// 	iconType: 1,
				// 	path: "/root/merchantManagement/relationUs?type=联系我们",
				// },
				// {
				// 	name: "数据报表",
				// 	icon: "barchart",
				// 	iconType: 1,
				// 	path: "/root/merchantManagement/todayData?type=数据报表",
				// },
				{
					name: "谁看过我",
					icon: "eye",
					iconType: 1,
					path: "/root/merchantManagement/watchedMe",
				},
				{
					name: "配置",
					icon: "setting",
					iconType: 1,
					path: "/root/merchantManagement/setting?type=配置",
				},
			];
		},
		getApplyNum() {
			console.log("getApplyNum");
			let that = this;
			that.G.Post(
				that.api.status_num_list,
				{
					keys: "",
				},
				(res) => {
					console.log("res.statusMap", res.statusMap);
					that.applyData.forEach((item) => {
						for (const key in item) {
							if (key == "classify") {
								item.num = res.statusMap[key + item[key]];
							}
						}
					});

					that.$forceUpdate();
					console.log("that.applyData", that.applyData);
				}
			);
		},
		getData() {
			this.G.Get(this.api.person_dataValue, {}, (res) => {
				console.log(res);
				// 空值测试
				// for (var k in res) {
				// 	if (typeof res[k] != "object") {
				// 		res[k] = 0;
				// 	} else {
				// 		for (var j in res[k]) {
				// 			res[k][j] = 0;
				// 		}
				// 	}
				// }
				this.map = res;
			});
		},
		goDetail(e, _item) {
			console.log("_item", _item);
			if (_item) {
				uni.navigateTo({
					url: `${e}&active=${_item.active}`,
				});
			} else {
				uni.navigateTo({
					url: e,
				});
			}
		},
		handleClickNum(e) {
			console.log("我的服务：", e);
			this.G.isLogin();
			if (this.G.isLogin()) {
				uni.navigateTo({
					url: e.item.path,
				});
			}
		},
		getUserData() {
			let that = this;
			this.G.Get(this.api.merchantManagement_userData, {}, (res) => {
				console.log(res);
				that.userNum.forEach((i) => {
					i.num = res[i.type];
				});
				console.log("that.userNum", that.userNum);
			});
		},
	},
};
</script>

<style></style>
