<template>
	<view class="p-apply-inedx g_w_all g_h_all g_bg_f_5 g_kuaishou g-apply-tab">
		<!-- #ifdef MP-TOUTIAO  -->
		<view class="g_flex_row_center apply-header" v-if="isHaveOrder == 1">
			<view class="g_flex_row_between box">
				<view v-for="(item, index) in tabInfo" :key="index" class="item g_flex_column_center" :class="tabActive == index ? 'item-active' : ''" @click="handleUpdateTab(index)">
					<view class="btn g_flex_c g_fw_600">{{ item.name }}</view>
				</view>
			</view>
		</view>
		<!-- #endif -->

		<view class="g_h_all">
			<!-- #ifdef APP-PLUS || H5 || MP-KUAISHOU || MP-WEIXIN -->
			<view class="" :style="{ height: `calc(${from == 'tob' ? '58px + 50px' : '10px'})` }"></view>
			<!-- #endif -->
			<view class="">
				<view class="m-box-fixed" :style="{ top: 0 }" v-if="isLogin && from == 'tob'">
					<view style="background-color: #fff" class="">
						<view class="m-select">
							<view style="height: 52px" class="g_flex_row_between flex_center">
								<view class="m-search g_pb_0 g_position_rela g_flex_1" style="padding-bottom: 0; padding-left: 12px; padding-right: 12px">
									<u-search @btnSearch="getSearch" height="40" v-model="keyword" placeholder="搜索姓名/职位/手机号" bg-color="#f5f5f5" :show-action="false" @change="getSearch" @clear="getSearch" @custom="getSearch" @search="getSearch" search-icon-color="#999999" :maxlength="20"></u-search>
									<view class="g_w_all g_h_40 g_position_abso" style="left: 0; top: 0px; z-index: 9999" @click.stop="goSearch"></view>
								</view>
							</view>
						</view>
						<!-- <view class="g_h_10 g_bg_f_5"></view> -->
					</view>
					<view style="width: 100vw" class="g_border_e_b">
						<!-- item-width="126"  itemWidth="auto"  -->
						<u-tabs :list="tabInfo" :current="menuActive" active-color="#6A81FF" bar-width="60" bar-height="6" font-size="32" @change="handleUpdateMenu" :gutter="22" duration="0.1" height="84"></u-tabs>
					</view>
				</view>
				<!-- <view class="g_h_10" v-if="isLogin"> </view> -->
				<!-- 面板 -->
				<g-list-bill :from="from" @uploadList="getList('concat')" bg="#f5f5f5" class="g_h_all" :classify="tabInfo[menuActive].classify" :list="query.list" :active="tabInfo.active" @shareJob="shareJob" :loading="loading" :speed="speed" :query="query" :isShowLoginBtn="isLogin ? false : true" :emptyText="isLogin ? (tabInfo.active == 0 || tabInfo.active == 2 ? '嘿，这里还没有数据呢' : '嘿，这里还没有数据呢') : '您还有没有登录，请登录后查看'" :emptySubText="isLogin ? (tabInfo.active == 0 ? '关注发单号，我们会第一时间通知您新的动态' : tabInfo.active == 2 ? '快去试试发布职位吧' : '') : ''" />
				<!-- <g-list-apply from="home" @uploadList="getList('concat')" bg="" class="" :tabActive="tabActive" :loading="loading" :speed="speed" :isLogin="isLogin" :query.sync="query" :navInfo="navInfo" /> -->
			</view>
		</view>
	</view>
</template>

<script>
import { reData } from "../../../utils/mock.js";
export default {
	onReady() {
		let that = this;
		this.G.setNavStyle();
		uni.$on("goNew", (res) => {
			console.log("goNew", res);
			console.log("goNewgoNewgoNewgoNew");
			that.menuActive = 0;
			if (res) {
				that.menuActive = res;
			}
		});
	},
	onShow() {
		that.getList();
	},
	onLoad(options) {
		console.log(options);
	},
	props: {
		from: {
			type: String,
			default: "",
		},
	},
	// onShareAppMessage() {
	// 	return this.G.shareFun();
	// },
	data() {
		return {
			isHaveOrder: -1,
			loading: true,
			speed: -1,
			query: {
				page: 1,
				size: 50,
				list: [],
				isFinish: -1,
			},
			GZHInfo: 0,
			cdnBaseImg: this.G.store().cdnBaseImg,
			keyword: "",

			tabActive: 0,
			tabTip: "",
			tabInfo: [
				{
					name: "新简历",
					classify: "50",
				},
				{
					name: "推工作",
					classify: "60",
				},
				{
					name: "审核中",
					classify: "40",
				},
				{
					name: "跟面试",
					classify: "70",
				},
				{
					name: "跟入职",
					classify: "80",
				},
				{
					name: "跟在职",
					classify: "90",
				},
				{
					name: "已完成",
					classify: "110",
				},
				// {
				// 	name: "已放弃",
				// 	classify: "120",
				// },
			],
			menuActive: 0,
			isLogin: false,
			loginInfo: {},
			navInfo: {},
		};
	},
	onHide() {
		let that = this;
	},
	mounted() {
		let that = this;
		// 导航栏高度信息
		that.isLogin = uni.getStorageSync("apply-token") ? true : false;
		console.log("that.isLogin", that.isLogin);
		that.loginInfo = uni.getStorageSync("apply-userinfo");
		if (!that.isLogin) {
			that.loading = false;
			that.speed = 0;
		} else {
			this.query.page = 1;
			this.getList();
		}
		this.getGZHInfo();
		if (that.isLogin) {
			this.getNum();
		}
	},
	onReachBottom() {
		let that = this;
		this.G.isLogin();
		if (this.G.isLogin()) {
			if (that.query.isFinish == -1 || that.query.isFinish == that.query.size) {
				that.query.page++;
				that.getList("concat");
			}
		}
	},
	methods: {
		getNum() {
			let that = this;
			if (that.from == "tob") {
				that.tabInfo = [
					{
						name: "新简历",
						classify: "50",
					},
					{
						name: "推工作",
						classify: "60",
					},
					{
						name: "审核中",
						classify: "40",
					},
					{
						name: "跟面试",
						classify: "70",
					},
					{
						name: "跟入职",
						classify: "80",
					},
					{
						name: "跟在职",
						classify: "90",
					},
					{
						name: "已完成",
						classify: "110",
					},
					// {
					// 	name: "已放弃",
					// 	classify: "120",
					// },
				];
			} else {
				that.tabInfo = [
					{
						name: "已报名",
						classify: "50",
					},
					{
						name: "待审核",
						classify: "60",
					},
					{
						name: "待面试",
						classify: "40",
					},
					{
						name: "待入职",
						classify: "70",
					},
					{
						name: "已入职",
						classify: "80",
					},
					{
						name: "已离职",
						classify: "90",
					},
				];
			}
			// that.tabInfo = [
			// 	{
			// 		name: "新简历",
			// 		classify: "50",
			// 	},
			// 	{
			// 		name: "推工作",
			// 		classify: "60",
			// 	},
			// 	{
			// 		name: "审核中",
			// 		classify: "40",
			// 	},
			// 	{
			// 		name: "跟面试",
			// 		classify: "70",
			// 	},
			// 	{
			// 		name: "跟入职",
			// 		classify: "80",
			// 	},
			// 	{
			// 		name: "跟在职",
			// 		classify: "90",
			// 	},
			// 	{
			// 		name: "已完成",
			// 		classify: "110",
			// 	},
			// 	// {
			// 	// 	name: "已放弃",
			// 	// 	classify: "120",
			// 	// },
			// ];
			that.G.Post(
				that.api.status_num_list,
				{
					keys: that.keyword,
				},
				(res) => {
					that.tabInfo.forEach((item) => {
						for (const key in item) {
							if (key == "classify") {
								item.num = res.statusMap[key + item[key]];
							}
						}
						if (that.from == "tob") {
							item.name = `${item.name}(${item.num})`;
						} else if (that.from == "toc") {
							item.name = `${item.name}`;
						}
					});
					that.$forceUpdate();
					console.log("that.tabInfo", that.tabInfo);
				}
			);
		},
		getList($type = "init") {
			let that = this;
			console.log("是否登录", that.isLogin);
			if (!that.isLogin) {
				return false;
			}
			// tob使用的数据
			if (that.from == "tob") {
				that.G.Post(
					that.api.task_list,
					{
						pageNum: that.query.page,
						pageSize: that.query.size,
						// agencyId: that.tabInfo.active == 2 ? uni.getStorageSync("apply-agencyId") : "",
						// that.tabInfo.list[that.tabActive].classify
						classify: that.tabInfo[that.menuActive].classify,
						// classify: that.from == "tob" ? that.tabInfo[that.menuActive].classify : 0,
						keys: that.keyword,
					},
					(res) => {
						that.computeCode = 1;
						let classify = that.tabInfo[that.menuActive].classify;
						// console.log('reData',reData.data)
						// res = reData.data;
						res.recordList.forEach((item) => {
							item.status_notify = that.G.setDeadLine(item.notifyTime || new Date().getTime());
							item.status_after = that.G.setDeadLine(item.willEntryTime || new Date().getTime(), "后入职");
							item.intervie_Time = that.G.getPointTime(item.interviewTime || new Date().getTime(), "MM--DD HH:MM");
							item.willEntry_Time = that.G.getPointTime(item.willEntryTime || new Date().getTime(), "MM--DD HH:MM");
							item.update_Time = that.G.getPointTime(item.updateTime || new Date().getTime(), "YY--MM--DD HH:MM");
							item.entry_Time = that.G.getPointTime(item.entryTime || new Date().getTime(), "MM--DD HH:MM");
							item.status_text = that.G.setDeadLine(item.entryTime || new Date().getTime(), "在职");
							//  || classify == 120
							if (classify == 110) {
								if (item.statusFailOperateTime) {
									item.statusFailOperate_Time = that.G.getPointTime(item.statusFailOperateTime || new Date().getTime(), "MM--DD HH:MM");
								} else if (item.leaveTime) {
									item.statusFailOperate_Time = that.G.getPointTime(item.leaveTime || new Date().getTime(), "MM--DD HH:MM");
								} else {
									item.statusFailOperate_Time = "";
								}
							}
						});
						if (res.recordCount == 0) {
							that.loading = false;
						} else {
							that.loading = true;
						}
						that.speed = res.recordCount;
						that.query.isFinish = res.recordList.length;
						console.log("$type", $type);
						console.log("res.recordList", res.recordList);
						if ($type == "init") {
							that.query.list = [];
							if (res.recordList.length > 0) {
								that.query.list = res.recordList;
							}
						} else {
							that.query.list = that.query.list.concat(res.recordList);
						}
						console.log("首页 列表：", that.query.list);
					}
				);
			} else if (that.from == "toc") {
				that.G.Post(
					that.api.yi_my_apply_list,
					{
						pageNum: that.query.page,
						pageSize: that.query.size,
					},
					(res) => {
						console.log("我的报名：", res);
						that.computeCode = res.length;
						if (res.length == 0) {
							that.loading = false;
						} else {
							that.loading = true;
						}
						that.speed = res.length;
						that.query.isFinish = res.length;
						if (res && res.length > 0) {
							res = that.G.toGetAddress(res);
							res = that.G.toGetAge(res);
							res = that.G.yijobCopy(res);
						}
						if ($type == "init") {
							that.query.list = [];
							that.query.list = res.map((item, index) => {
								return {
									...item,
									createTime: that.G.getPointTime(item.createTime, "YY--MM--DD HH:MM"),
									ageStr: that.setAge(item),
									addresa: item.storeDistrict
										.split(",")
										.filter((sub, i) => i <= 0 || i >= 2)
										.join(" | "),
									cus_price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValueHtml(item.salaryClassify, item.salaryClassifyValue) : "月薪",
									no_style_price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue) : "月薪",
									status_text: that.G.getOrderStatusNew().filter((itm, inx) => {
										return itm.id == item.status;
									})[0].name,
									jobSpecialLabelNames: item.jobSpecialLabelNames ? item.jobSpecialLabelNames.split(",").filter((sub, i) => i < 3) : "",
								};
							});
						} else {
							that.query.list = that.query.list.concat(
								res.map((item, index) => {
									return {
										...item,
										createTime: that.G.getPointTime(item.createTime, "YY--MM--DD HH:MM"),
										ageStr: that.setAge(item),
										addresa: item.storeDistrict
											.split(",")
											.filter((sub, i) => i <= 0 || i >= 2)
											.join(" | "),
										cus_price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValueHtml(item.salaryClassify, item.salaryClassifyValue) : "月薪",
										no_style_price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue) : "月薪",
										status_text: that.G.getOrderStatusNew().filter((itm, inx) => {
											return itm.id == item.status;
										})[0].name,
										jobSpecialLabelNames: item.jobSpecialLabelNames ? item.jobSpecialLabelNames.split(",").filter((sub, i) => i < 3) : "",
									};
								})
							);
						}
					}
				);
			}
		},
		setAge(item) {
			let str = "";
			if (item.minAge && item.maxAge) {
				item["age"] = item.minAge + "-" + item.maxAge + "岁";
			} else if (item.minAge) {
				item["age"] = item.minAge + "岁以上";
			} else if (item.maxAge) {
				item["age"] = item.maxAge + "岁以下";
			} else {
				let newArr = [item.minAgeMan, item.maxAgeMan, item.minAgeWoman, item.maxAgeWoman];
				newArr.sort();
				// console.log('newArr', newArr)
				let minAge = newArr[0] == 0 ? newArr[2] : newArr[0];
				let maxAge = newArr[3];
				item["age"] = minAge + "-" + maxAge + "岁";
			}
			return item["age"];
		},
		goTel($item) {
			console.log($item);
			if ($item) {
				uni.makePhoneCall({
					phoneNumber: $item,
				});
			}
		},
		getGZHInfo() {
			let that = this;
			if (that.isLogin) {
				that.G.Get(that.api.user_getGZHstatus, { type: "BMZS" }, (res) => {
					console.log(res);
					that.GZHInfo = res;
				});
			}
		},
		/**
		 * 跳转搜索页
		 */
		goSearch() {
			this.G.isLogin();
			if (this.G.isLogin()) {
				uni.navigateTo({
					url: `/root/other/search?from=task&classify=${this.tabInfo[this.menuActive].classify}`,
				});
			}
		},
		// 一级tab切换
		handleUpdateTab(e) {
			let that = this;
			this.tabActive = e;
			this.menuActive = 0;
			this.speed = -1;
			this.query.page = 1;
			that.G.isLogin();
			if (that.G.isLogin()) {
				this.getList();
			}
		},
		// 二级tab切换
		handleUpdateMenu($item, $index) {
			let that = this;
			this.menuActive = $item;
			this.speed = -1;
			this.query.page = 1;
			that.G.isLogin();
			if (that.G.isLogin()) {
				this.getList();
			}
		},
		getSearch(e) {},
		goDetail($item, $index) {
			let that = this;
			console.log("$item", $item);
			// return
			uni.navigateTo({
				// url: "/root/detail/apply?id=" + $item.id + "&type=" + (that.tabActive + 1),
				url: `/root/detail/applyTob?id=${$item.id}&type=${that.tabActive + 1}&relationId=${$item.relationId}`,
			});
		},
		goLogin() {
			uni.reLaunch({
				url: "/pages/login/index",
			});
		},
		toMessage() {
			uni.navigateTo({
				url: "/root/person/message",
			});
		},
		addResume() {
			uni.navigateTo({
				url: "/root/detail/fellow?resumeFlag=1&type=add",
			});
		},
	},
	onShareAppMessage: function () {
		return this.G.shareFun();
	},
};
</script>

<style lang="scss">
.apply-header {
	position: fixed;
	left: 50%;
	transform: translateX(-50%);
	.box {
		padding: 0 2px;
		width: 148px;
		height: 32px;
		background-color: #eeeeee;
		border-radius: 4px;
		.item {
			width: 72px;
			height: 28px;
			margin-top: 2px;
			border-radius: 4px;
			.btn {
				font-size: 14px;
				color: #333;
			}
		}
		.item-active {
			background-color: #fff;
		}
	}
}
.p-apply-inedx {
	width: 100vw;
	background-color: #f5f5f5;
	overflow-x: hidden;
	min-height: 100%;

	.bg_shawdoc {
		background: linear-gradient(180deg, #caf1e0 1%, rgba(249, 249, 249, 0));
	}

	.suffix {
		position: absolute;
		right: 20rpx;
		top: 10px;
		z-index: 1;
		border-top-right-radius: 110rpx;
		border-bottom-right-radius: 110rpx;
	}

	.tab-fixed {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: calc(112rpx + 36px);
		background-color: #fff;
		z-index: 1;
	}

	.m-search {
		.u-icon-wrap {
		}
	}

	.m-search-active {
		.u-icon-wrap {
			position: inherit;
			left: 0rpx;
		}
	}

	.m-select {
		.u-tab-bar {
			bottom: 5px !important;
		}

		.link {
			.item {
				.doc {
					bottom: 0;
					left: 50%;
					transform: translateX(-50%);
				}
			}
		}

		.showdoc {
			// box-shadow: 0 2px 4px rgba(0, 0, 0, .04), 0 0 6px rgba(0, 0, 0, .02);
			border-bottom: 1rpx solid #eee;
			overflow-x: "auto";
			width: 100vw;

			.menu-obj {
				min-width: 422px;

				.menu-btn {
					margin-right: 8px;

					.btn {
						background: rgba(204, 204, 204, 0.2);
						color: #666666;
					}

					&:first-child {
						margin-left: 12px;
					}
				}

				.menu-active {
					.btn {
						background: rgba(0, 182, 102, 0.1);
						color: #6a81ff;
					}
				}
			}
		}
	}
	.m-login-false {
		height: calc(100% - 92px);
		.m-panel,
		.link {
			height: 100%;
			.m-log {
				height: 100%;
			}
		}
	}
	.m-panel {
		min-height: 100%;
	}
	.m-box-fixed {
		position: fixed;
		left: 0;
		// top: 92px;
		width: 100vw;
		background-color: #fff;
		z-index: 999;
	}
}
</style>
