<template>
	<view class="p-home-inedx g_w_all g_bg_f_5 g_kuaishou" :class="computeCode == -1 ? 'g_flex_column_center' : ''">
		<view v-show="computeCode == -1" class="g_flex_column_center">
			<rh-loading marginBottom="g_mb_130" />
		</view>
		<view v-show="computeCode > -1">
			<!-- #ifdef APP-PLUS || H5 || MP-KUAISHOU -->
			<u-navbar v-if="false" :is-back="false" :title="globalData.title" :background="background" title-size="36" title-color="#ffffff" :title-bold="false">
				<!-- #ifdef APP-PLUS -->
				<view class="slot-wrap g_flex_column_center g_position_rela" style="padding-left: 16px; padding-top: 10rpx" @click="handleOpenCamera">
					<i class="iconfont icon-saoyisao-hui g_c_3" style="font-size: 40rpx"></i>
				</view>
				<!-- #endif -->
			</u-navbar>
			<!-- #endif -->
			<!-- 搜索区 -->
			<view class="sticky g_bg_f">
				<view class="g_position_rela g_flex_row_center g_pt_10 g_pb_10" @touchmove.stop.prevent>
					<!-- <view class="g_text_c g_c_c g_fs_12" style="width: 100vw; position: absolute; top: -32px; z-index: 9999999">{{ "最近更新" + (jobNum || "-") + "条信息" }}</view> -->
					<view class="the_city g_flex_column_center" style hover-class="thover" @click="goCity">
						<view class="g_flex_row_center">
							<view class="g_fs_16 g_fw_600 g_ml_10" style="min-width: 36px; display: inline-block">{{ selectedCity }} </view>
							<view class="g_flex_column_center">
								<view class="iconfont icon-zhankai g_fs_12" style="display: inline-block"></view>
							</view>
						</view>
					</view>
					<view class="m-search g_p_10 g_pt_8 g_position_abso bg_shawdoc g_flex_1" style="top: 0" id="searchInputBox">
						<u-search v-model="query.keys" class="g_flex_1" placeholder="搜索职位名称" bg-color="#f5f5f5" :show-action="false" placeholder-class="g_c_c" :input-style="{ fontSize: '16px' }" height="80" search-icon-color="#999999" :maxlength="20" @clear="searchJob" @search="searchJob"></u-search>
						<!-- <view class="g_w_all g_h_40 g_position_abso" style="left: 0; z-index: 9999" @click.stop="goSearch"> </view> -->
					</view>
				</view>

				<view class="g_bg_f g_flex_row_between flex_center" @touchmove.stop.prevent style="box-shadow: 0px 2px 3px 0px rgba(214, 214, 214, 0.3)" id="tttop">
					<view class="g_flex_1">
						<u-tabs bg-color="transparent" from="index" :list="tabInfo.list" :is-scroll="true" :current="tabInfo.active" :active-color="globalData.themeColor" bar-width="64" bar-height="6" @change="handleUpdateTab" font-size="34" duration="0.05" height="76"></u-tabs>
					</view>
					<!-- <view v-if="true || (isMember && hasPermission)" class="g_mr_8" @click="goShare" > 批量分享 </view> -->

					<view class="csbf" @click="chooseNl('sort')">
						{{ sortList.list[sortList.active].showName }}
						<span class="iconfont icon-shouqi g_fs_12 g_c_9 fst g_ml_4" v-if="whichOneShow == 'sort'"></span>
						<span class="iconfont icon-zhankai g_fs_12 g_c_9 fst g_ml_4" v-if="whichOneShow != 'sort'"></span>
						<view class="sortMask" v-if="whichOneShow == 'sort'">
							<view class="sortContainer" style="overflow: hidden" @click.stop>
								<view v-for="(item, index) in sortList.list" @click="sortJob(index)" :key="index" :class="sortList.active == index ? 'g_border_main g_c_main' : 'g_border_f'" class="g_fs_16 g_fw_600 g_mt_16 g_bg_f" style="border-radius: 30px; padding: 8px 16px">{{ item.name }}</view>
							</view>
						</view>
					</view>
					<view class="csbf" style="z-index: 99999999" @click="chooseNl('special')" data-type="special">
						筛选
						<span class="iconfont icon-shouqi g_fs_12 g_c_9 fst g_ml_4" v-if="whichOneShow == 'special'"></span>
						<span class="iconfont icon-zhankai g_fs_12 g_c_9 fst g_ml_4" v-if="whichOneShow != 'special'"></span>
						<g-filter :show="whichOneShow" ref="filterChild" top="103px" :getFilterDataNew="getFilterData" @filterObj="receiveFromChild"></g-filter>
					</view>
					<scroll-view class="filterTag bt1" v-if="getFilterData.jobCategoryLabelObjects.length > 0 || getFilterData.jobSpecialLabelObjects.length > 0 || getFilterData.sex != '-1' || (getFilterData.ageRangeStr && getFilterData.ageRangeStr != '16-60')" :scroll-x="true" :scroll-y="false" scroll-top="0" scroll-left="0" scroll-into-view scroll-with-animation="false" enable-flex enable-back-to-top="false">
						<div class="g_flex_row_between flex_center flex_nw g_w_all">
							<div class="g_flex_row_start flex_nw" style="line-height: 44px">
								<div class="tc genderTag f14 por" style="min-width: 60px" v-if="getFilterData.ageRangeStr != '' && getFilterData.ageRangeStr != '16-60'">
									<div class="por" @click.stop="deleteAge">
										{{ getFilterData.ageRangeStr }}
										<div class="clear_icon iconfont icon-dianji"></div>
									</div>
								</div>

								<div class="tc genderTag f14 por" style="min-width: 60px" v-if="getFilterData.sex != '-1'">
									<div class="por" @click.stop="deleteSex">
										{{ getFilterData.sex == 1 ? "收男工" : getFilterData.sex == 2 ? "收女工" : getFilterData.sex == 3 ? "男女都收" : "" }}
										<!-- {{getFilterData.jobCategoryLabelObjects.length > 0}} {{getFilterData.jobSpecialLabelObjects.length > 0}} -->
										<div class="clear_icon iconfont icon-dianji"></div>
									</div>
								</div>
								<div class="brandTag ml8" v-if="getFilterData.jobCategoryLabelObjects.length > 0">
									<block v-for="(item, index) in getFilterData.jobCategoryLabelObjects" :key="index">
										<div class="por" @click.stop="deleteJobCategoryLabel(item.id)">
											{{ item.name }}
											<div class="clear_icon iconfont icon-dianji"></div>
										</div>
									</block>
								</div>

								<div class="specialTag ml8">
									<block v-for="(item, index) in getFilterData.jobSpecialLabelObjects" :key="index">
										<div class="por" @click.stop="deleteJobSpecialLabel(item.id)">
											{{ item.name }}
											<div class="clear_icon iconfont icon-dianji"></div>
										</div>
									</block>
								</div>
								<!-- <div class="specialTag" wx:if="{{selectJobList.length > 0}}">
                  <block wx:for="{{selectJobList}}" wx:key="index">
                    <div class="por" catchtap="deleteMark" data-item="{{item}}">
                      {{item.name}}
                      <div class="clear_icon iconfont icon-qingchu"></div>
                    </div>
                  </block>
                </div> -->
							</div>
							<div class="clear" @click.stop="clearFilter1" data-type="outerClear">
								<span class="iconfont icon-shanchu f14"></span>
								清除
							</div>
						</div>
					</scroll-view>
				</view>
			</view>
			<!-- 列表区 -->
			<scroll-view class="m-list" id="listBox" refresher-default-style="none" refresher-background="#ededed" :refresher-enabled="true" :refresher-triggered="isTrigger" @refresherrefresh="refreshJobList" :scroll-top="resetScroll" :scroll-into-view="scrollTo" style="" :style="{ height: `calc(100vh - ${103}px)` }" :scroll-y="true" @scrolltolower="reachBottom" @scroll="() => (resetScroll != 0 ? (resetScroll = 0) : '')">
				<!-- {{ platform }} -->
				<view class="">
					<!-- 金刚轮播区 -->

					<view class="g_position_rela">
						<!-- :isuse="tabInfo.active == 1 ? 'fujin' : 'rijie'" -->
						<view class="g_h_8"> </view>
						<g-yi-list-job :pt="tabInfo.active == 0 ? 0 : 120" from="home" class="g_h_all" :list="query.list" @clickCard="goDetail" @successLogin="successLogin" :loading="loading" :speed="speed" :reload="reload" :query="query" :isShowLoginBtn="isLogin ? false : true" :emptyText="isLogin ? '没有符合条件的职位' : '您还没有登录，请登录后查看所有职位'" />
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
import filter from "../../pages/home/child/filter.vue";
import gYiListJob from "@/components/list/job.vue";

export default {
	components: {
		filter,
		"g-yi-list-job": gYiListJob,
	},
	onReady() {
		this.G.setNavStyle("home");
	},
	onShareAppMessage() {
		return this.G.shareFun();
	},
	onLoad(options) {
		// console.log("options", options);
		let that = this;
		that.formpage = "";
		that.navInfo = that.G.getNavInfo();

		uni.setNavigationBarTitle({
			title: that.globalData.title,
		});
		if (options.userId) {
			this.userId = options.userId;
			uni.setStorageSync("AGENCY_USER_ID", this.userId);
		}
		if (options.scene) {
			// console.log("XXXXXXXXXXXX");
			//扫小程序码携带参数
			var sceneStr = decodeURIComponent(options.scene);
			var sceneJson = this.G.sceneToJson(sceneStr);
			// console.log("sceneJson===", sceneJson);
			this.userId = sceneJson.i.split("_")[0];
			uni.setStorageSync("AGENCY_USER_ID", this.userId);
		}

		if (options.active) {
			this.tabInfo.active = options.active;
			this.query.picked = this.tabInfo.list[options.active].picked;
		}
		if (options.sortInd) {
			this.sortList.active = options.sortInd;
			this.query.sortTag = this.sortList.list[this.sortList.active].key;
		}
		that.query.page = 1;
		this.isLogin = uni.getStorageSync("apply-userinfo") ? true : false;
		this.query.size = this.isLogin ? 50 : 20;
		this.istype = options.manage ? "manage" : "";
		this.jobType = options.jobtype ? options.jobtype : "";
		this.shareJobIds = options.shareJobIds ? options.shareJobIds : "";
		this.sortTag = options.sortTag ? options.sortTag : "";
		if (options.params) {
			// console.log("options.params", options.params);
			let params = JSON.parse(options.params);
			if (params.keys != "附近热招") {
				this.query = { ...this.query, ...params };
				this.getList();
			} else {
				// 点击附近热招的逻辑
				that.sortList.active = 2;
				this.query.sortTag = 2;
				this.getLocation("setCity").then(() => {
					this.getList();
				});
			}
		} else if (options.jobparams) {
			// 从ai过来的职位不主动请求职位接口,等触发watch自动请求
			that.formpage = "hotjob";
			let params = JSON.parse(options.jobparams);
			// console.log("获取推荐职位参数 修改前：", params);
			this.query = { ...this.query, ...params };
			that.getFilterData = { ...that.getFilterData, ...params };
			that.selectedCity = params["cityName"];
			// console.log("获取推荐职位参数 修改后：", this.query, " == ", that.getFilterData);
		} else if (options.manage) {
			this.istype = "manage";
			// setTimeout(() => {S
			if (options.manage && JSON.parse(options.manage)) {
				let _data = JSON.parse(options.manage);
				// console.log("_data", _data);
				if (_data.city_id == "-1") {
					// 附近
					this.sortList.active = 2;
					this.query.sortTag = 2;
					this.jLabelIds = _data.keys_id;
					this.getLocation("setCity").then(() => {
						this.getList();
					});
				} else {
					// 具体城市
					that.selectedCity = _data.city_name;
					this.jLabelIds = _data.keys_id;
					that.getList();
				}
			}
			let jobFilter = this.$refs.filterChild.filterData.jobFilter;
			// console.log("this.jLabelIds", this.jLabelIds);
			// console.log("this.jLabelIds", JSON.parse(JSON.stringify(jobFilter)));
			let getJobFilter = function () {
				if (jobFilter["tagArray0"].length > 0) {
					let middleList = [];
					for (const k in jobFilter) {
						jobFilter[k].forEach((item) => {
							if (item.id == that.jLabelIds) {
								item.active = that.jLabelIds;
								middleList.push(item);
							}
						});
					}
					that.getFilterData.jobSpecialLabelObjects = JSON.parse(JSON.stringify(middleList));
				} else {
					setTimeout(() => {
						getJobFilter();
					}, 100);
				}
			};
			getJobFilter();
		} else if (options.jobtype) {
			that.jobType = 2;
			that.getList();
		} else if (options.shareJobIds) {
			that.shareJobIds = options.shareJobIds;
			that.getList();
		} else if (options.sortTag || options.sortTag == 0) {
			that.sortTag = options.sortTag;
			that.sortList.list.forEach((item, index) => {
				if (item.key == that.sortTag) {
					that.sortList.active = index;
				}
			});
			if (options.sortTag == 1) {
				that.sortList.active = 0;
			}
			// console.log("sortTagsortTagsortTagsortTag", options.sortTag, that.sortList.active);
			that.getList();
		} else if (options.istop == 1) {
			that.topRecommend = 1;
			that.sortList.active = 1;
			that.getList();
		} else {
			that.getList();
		}
		that.getJobNum();
		// #ifdef MP-WEIXIN
		this.searchAnimate();
		// #endif
	},
	data() {
		return {
			topRecommend: "",
			sortTag: "",
			shareJobIds: "",
			jobType: "",
			jLabelIds: "",
			istype: "",
			formpage: "",
			globalData: getApp().globalData,
			pageTitle: getApp().globalData.title,
			platform: uni.getSystemInfoSync().platform,
			userinfo: uni.getStorageSync("apply-userinfo"),
			resetScroll: 0, // 回到顶部
			isTrigger: false,
			selectedCity: "全国",
			envVersion: uni.getStorageSync("ENV_VERSION"), // 小程序环境判断
			isMember: uni.getStorageSync("IS_MINIAPP_MEMBER"), // 登陆者是否当前小程序成员的判断
			hasPermission: uni.getStorageSync("HAS_PERMISSION") == 1 ? true : false, // 登陆者是否有权限查看
			getFilterData: {
				sex: "-1",
				ageRangeStr: "",
				jobCategoryLabelIds: "",
				jobRequestLabelIds: "",
				jobSpecialLabelObjects: [],
				jobCategoryLabelObjects: [],
			},
			scrollTo: "",
			whichOneShow: "",
			background: {
				backgroundColor: "#3578f6",
			},
			isShowTab: false,
			showPop: false, // 显示关注邀请弹窗显示
			attentionList: [], // 关注列表
			subAttentionList: [],
			attentionConfig: {
				num: 1,
				size: 12,
			},
			checkAll: false, // 全选
			upInfo: {
				num: 0,
				list: [],
			},
			computeCode: 1,
			reload: 0, // 触发组件中数据的更新
			isLogin: true,
			navInfo: {},
			cdnBaseImg: this.G.store().cdnBaseImg,
			localBaseImg: this.G.store().localBaseImg,
			loading: true,
			speed: -1,
			query: {
				page: 1,
				size: 50,
				list: [],
				keys: "",
				isFinish: -1,
				ucj: 0, // 0 全部 1收藏
				sortTag: 2,
				picked: "",
			},
			keyword: "",
			tabInfo: {
				list: [
					{
						name: "全部",
						key: "0",
						picked: "",
					},
				],
				active: 0,
			},
			sortList: {
				list: [
					{
						name: "按工价",
						key: 1,
						showName: "按工价",
					},
					{
						name: "按时间",
						key: 0,
						showName: "按时间",
					},
					{
						name: "按距离",
						key: 2,
						showName: "按距离",
					},
				],
				active: 1,
			},
			// "在这里，使用世界前沿的人工智能技术，为用户甄选海量的高清美图，用更流畅，更快捷，更精准的搜索体验，带你去发现多彩的世界。"
			userId: 0,
			currentInfo: {},
			appInfo: uni.getStorageSync("miniApp-info"),
			jobNum: 0, // 48小时更新职位数
		};
	},
	mounted() {
		// console.log("mountedmountedmountedmountedmountedmounted");
		const query = uni.createSelectorQuery().in(this);
		// console.log("query", query);
		// 选择指定的 DOM 元素
	},
	onShow() {
		let that = this;
		// console.log("=========", that);

		that.loadSelectedCityFromCache();

		that.isShowTab = true;
		that.reload++;

		if (that.topRecommend == 1) {
			that.tabInfo = {
				list: [
					{
						name: "主推",
						key: "0",
						picked: "",
					},
				],
				active: 0,
			};
		} else {
			if (that.globalData.appId == "wxb0c590fd696b79be") {
				that.tabInfo = {
					list: [
						{
							name: "全部",
							key: "0",
							picked: "",
						},
						// {
						// 	name: "甄选",
						// 	key: "1",
						// 	picked: "1",
						// },
						// {
						// 	name: "三方",
						// 	key: "2",
						// 	picked: "0",
						// },
					],
					active: 0,
				};
			} else {
				that.tabInfo = {
					list: [
						{
							name: "全部",
							key: "0",
							picked: "",
						},
					],
					active: 0,
				};
			}
		}
	},
	onReachBottom() {
		let that = this;
		if ((!uni.getStorageSync("apply-token") && that.tabInfo.active == 1) || that.shareJobIds) {
			return false;
		}
		if (that.query.isFinish == -1 || that.query.isFinish == that.query.size) {
			that.query.page++;
			that.getList("concat");
		}
	},
	methods: {
		// 获取48小时内职位更新数
		getJobNum() {
			// let url = this.data.choiceCollect ==
			let that = this;
			that.G.Get(that.api.get_jobList_num, {}, (res) => {
				// console.log("res", res);
				that.jobNum = res;
			});
		},
		loadSelectedCityFromCache() {
			// 假设缓存中的键名为 'selectedCity'
			const cachedCity = wx.getStorageSync("selectedCity");
			if (cachedCity) {
				if (this.selectedCity != cachedCity) {
					this.selectedCity = cachedCity;
					this.getList();
				}
			}
		},
		deleteSex() {
			// console.log("deleteSex");
			this.getFilterData.sex = -1;
			this.getList();
		},
		deleteAge() {
			// console.log("deleteAge");
			this.getFilterData.ageRangeStr = "";
			this.getList();
		},

		deleteJobCategoryLabel(id) {
			// console.log(id);
			this.getFilterData.jobCategoryLabelObjects = this.getFilterData.jobCategoryLabelObjects.filter((obj) => obj.id != id);

			const idsArray = this.getFilterData.jobCategoryLabelObjects.map((obj) => obj.id);
			// 将数组转换为字符串
			this.getFilterData.jobCategoryLabelIds = idsArray.join(",");
			// console.log("deleteJobCategoryLabel", this.getFilterData);

			this.getList();
		},
		deleteJobSpecialLabel(id) {
			this.query.page = 1;
			this.getFilterData.jobSpecialLabelObjects = JSON.parse(JSON.stringify(this.getFilterData.jobSpecialLabelObjects.filter((obj) => obj.id != id)));
			const idsArray = this.getFilterData.jobSpecialLabelObjects.map((obj) => obj.id);
			// 将数组转换为字符串
			this.getFilterData.jobRequestLabelIds = idsArray.join(",");
			this.jLabelIds = id;
			// console.log("deleteJobSpecialLabel", this.getFilterData);
			this.getList();
		},
		clearFilter1() {
			var that = this;
			this.query.page = 1;
			this.getFilterData.jobCategoryLabelIds = "";
			this.getFilterData.jobRequestLabelIds = "";
			that.jLabelIds = "";
			this.getFilterData.jobCategoryLabelObjects = [];
			this.getFilterData.jobSpecialLabelObjects = [];
			this.scrollTo = "";
			this.getFilterData.sex = -1;
			this.getFilterData.ageRangeStr = "";
			// console.log("this.getFilterData", this.getFilterData);
			this.$refs.filterChild.clearFilter();
			this.getList();

			setTimeout(() => {
				that.scrollTo = "listBox";
				// console.log("aaaaaaaaa");
			}, 1);
		},
		receiveFromChild(data) {
			// console.log(data);
			this.whichOneShow = "";
			this.getFilterData = JSON.parse(JSON.stringify(data));
			// console.log("getFilterData in receiveFromChild", this.getFilterData);
			this.getList();
			// this.messageFromChild = data.message;
		},
		chooseNl(type) {
			let that = this;
			that.scrollTo = "";
			that.whichOneShow = that.whichOneShow == type ? "" : type;
			setTimeout(() => {
				that.scrollTo = "tttop";
			}, 1);
		},
		handleOpenCamera() {
			let that = this;
			that.G.handleScanCode();
		},
		goPage($path) {
			uni.navigateTo({
				url: $path,
			});
		},
		reachBottom() {
			let that = this;
      // console.log('that.speed ',that.speed );
      // console.log('that.query.list.length ',that.query.list.length );
			if ((!uni.getStorageSync("apply-token") && that.tabInfo.active == 1) || !this.isLogin || that.speed <= that.query.list.length) {
				return false;
			}
			that.query.page++;
			that.getList("concat");
		},
		searchJob() {
			this.query.list = [];
			this.query.page = 1;
			this.getList();
		},
		refreshJobList() {
			let that = this;
			this.query.page = 1;
			this.isTrigger = true;
			this.getList().then(() => {
				// console.log("that.isTrigger", that.isTrigger);
				that.isTrigger = false;
				that.getJobNum();
			});
		}, 
		getList($type = "init") {
			let that = this,
				params = {};
			// uni.showLoading({
			// 	title: "加载中...",
			// });
			if ($type != "concat") {
				that.speed = -1;
			}
			params = {
				...that.getFilterData,
				pageNum: that.query.page,
				pageSize: that.query.size,
				keys: that.query.keys,
				sortTag: that.query.sortTag,
				picked: that.query.picked,
				recruitment: 1,
				classify: 1,
				workTypeStr: "",
				jobClassify: "",
				cityName: that.selectedCity == "全国" ? "" : that.selectedCity,
				brandIds: "",
			};
			// console.log("查看更多筛选that.istype:", that.istype, " jLabelIds:", that.jLabelIds, " params", params);
			if (that.istype == "manage") {
				params.jobRequestLabelIds = that.jLabelIds;
				that.istype = "";
			}
			if (!params.jobRequestLabelIds) {
				params.jobRequestLabelIds = that.jLabelIds;
			}

			if (that.query.sortTag !== 2) {
				params.lat = "";
				params.lng = "";
			} else {
				params.lat = that.currentInfo.latitude ? that.currentInfo.latitude : "";
				params.lng = that.currentInfo.longitude ? that.currentInfo.longitude : "";
			}

			// if (that.jobType == 2) {
			// 	params.jobType = 2;
			// }

			if (that.shareJobIds) {
				params.shareJobIds = that.shareJobIds;
				// that.shareJobIds = "";
			}

			if (that.sortTag) {
				params.sortTag = that.sortTag;
				// that.sortTag = "";
			}

			if (that.sortTag == -1) {
				params.sortTag = -1;
				params.topRecommend = -1;
				// that.sortTag = "";
			}

			if (that.topRecommend == 1) {
				params.topRecommend = 1;
			}

			return new Promise((resolve, reject) => {
				let _url = that.api.yi_job_list;

				if (that.jobType == 2) {
					_url = that.api.job_share;
				} else {
					_url = that.api.yi_job_list;
				}

				// console.log("_url", _url);
				that.G.Post(_url, params, (res) => {
					// console.log("一才职位列表：", res);
					that.computeCode = 1;
					let resData = {};
					resData = res.pageBean;
					// uni.hideLoading();
					if (resData.recordCount == 0) {
						that.loading = false;
					} else {
						that.loading = true;
					}
					that.speed = resData.recordCount;
					that.query.isFinish = resData.recordList.length;
					new Promise((reso) => {
						// console.log("resData.recordList123123", resData.recordList);
						try {
							// console.log("resData.recordList", resData.recordList);
							if (resData.recordList && resData.recordList.length > 0) {
								// console.log("resData.recordList7786787", resData.recordList);
								if (that.tabInfo.active == 1) {
									// 根据 distance 进行从小到大排序
									resData.recordList.sort((a, b) => a.distance - b.distance);
								}

								resData.recordList = that.G.toGetAddressv3(resData.recordList);
								resData.recordList = that.G.toGetAge(resData.recordList);
								that.G.Post("/yishoudan/labels/type/app/80", {}, (res) => {
									// console.log("els/type/app/80", res);
									uni.setStorageSync("JOB_REQUIRE_LIST", { data: res.labels, time: Date.now() });
									resData.recordList = that.G.yijobCopy(resData.recordList);
									reso();
								});
							} else {
								// console.log("resData.recordList123090890123", resData.recordList);
							}
						} catch (error) {
							// console.log("error", error);
						}
					}).then((res) => {
						// console.log("res123123", res);
						if ($type == "init") {
							that.query.list = [];
							uni.setStorageSync("lin-liu", 0);
							uni.setStorageSync("lin-bao", 0);
							that.query.list = resData.recordList.map((item, index) => {
								item.liuNum = uni.getStorageSync("lin-liu") ? uni.getStorageSync("lin-liu") : Math.floor(Math.random() * 1000);

								return {
									...item,
									liuNum: item.liuNum,
									baoNum: uni.getStorageSync("lin-bao") ? uni.getStorageSync("lin-bao") / 10 : Math.ceil(item.liuNum / 10),
									collected: item.collected ? true : false,
									cus_price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValueHtml(item.salaryClassify, item.salaryClassifyValue) : "月薪",
									gender: that.G.getGenderByMinAge(item),
									fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
									newadd:that.G.setJobInfoPositionv3(item.storeDistrict || item.storeAddr)
								};
							});
							// console.log("that.query.list", that.query.list);
						} else {
							that.query.list = that.query.list.concat(
								resData.recordList.map((item, index) => {
									return {
										...item,
										liuNum: item.liuNum,
										baoNum: uni.getStorageSync("lin-bao") ? uni.getStorageSync("lin-bao") / 10 : Math.ceil(item.liuNum / 10),
										collected: item.collected ? true : false,
										cus_price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValueHtml(item.salaryClassify, item.salaryClassifyValue) : "月薪",
										gender: that.G.getGenderByMinAge(item),
										fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
										newadd:that.G.setJobInfoPositionv3(item.storeDistrict || item.storeAddr)
									};
								})
							);
						}
						// console.log("that.query.list", that.query.list);
						resolve();
					});
					// console.log("resData.recordList1111111", resData.recordList);
				});
			});
		},
		goDetail($item) {
			// console.log("前往详情页", $item);
			uni.navigateTo({
				url: "/root/detail/job?id=" + $item.id,
			});
		},

		/**
		 * 搜索框的滚动监听变化
		 */
		searchAnimate() {
			return;
			let that = this;
			uni
				.createSelectorQuery()
				.select("#listBox")
				.fields(
					{
						scrollOffset: true,
						size: true,
					},
					(res) => {
						that.$mp.page.animate(
							"#searchInputBox",
							[
								{
									top: "10px",
									width: "100%",
								},
								{
									top: "-48px",
									width: "70%",
								},
							],
							800,
							{
								scrollSource: "#listBox",
								timeRange: 1000,
								startScrollOffset: 0,
								endScrollOffset: 60,
							}
						);
						that.$mp.page.animate(
							".the_city",
							[
								{
									color: "#333",
								},
								{
									color: "#fff",
								},
							],
							500,
							{
								scrollSource: "#listBox",
								timeRange: 1000,
								startScrollOffset: 0,
								endScrollOffset: 90,
							}
						);
					}
				)
				.exec();
		},
		shareJob(e) {
			// console.log(e);
			this.currentJob = e;
		},
		goSearch() {
			// this.G.isLogin();
			// if (this.G.isLogin()) {
			uni.navigateTo({
				url: "/root/other/search?from=home",
			});
			// }
		},
		goCity() {
			uni.navigateTo({
				url: "/root/other/city",
			});
		},
		getLocation(type) {
			let that = this;
			return new Promise((resolve, reject) => {
				uni.authorize({
					// 检测是否授权位置信息
					scope: "scope.userLocation",
					success() {
						// console.log("用户成功授权位置信息");
						uni.getLocation({
							type: "wgs84",
							success(res) {
								that.currentInfo = {
									latitude: res.latitude,
									longitude: res.longitude,
								};
								// console.log("type", type);
								if (type == "setCity") {
									that.getCity().then((res) => {
										// console.log("res", res);
										resolve();
									});
								}
							},
							fail(err) {
								// console.log(err);
							},
							complete() {
								resolve();
							},
						});
					},
					fail(err) {
						// console.log(err);
						// console.log("用户拒绝授权位置信息，再次提示用户授权");
						uni.showToast({
							title: "请在右上角设置中开启定位权限以显示距职位距离",
							icon: "none",
						});
						resolve();
						// that.showRefuseLocationPermission();
					},
					complete() {
						// console.log();
						// resolve();
					},
				});
			});
		},
		getCity() {
			let that = this;
			return new Promise((reso) => {
				this.G.Get(this.api.getCityNameByLatLng, { lng: this.currentInfo.longitude, lat: this.currentInfo.latitude }, (res) => {
					if (res) {
						that.selectedCity = res.replace("市", "");
						reso();
					}
					// console.log("res");
				});
			});
		},
		handleUpdateTab(e) {
			// console.log("获取tab数据：", e);
			let that = this;
			that.loading = true;
			that.speed = -1;
			that.tabInfo.active = e;
			switch (that.tabInfo.active) {
				case 0:
					that.query.picked = "";
					break;
				case 1:
					that.query.picked = 1;
					break;
				case 2:
					that.query.picked = 0;
					break;

				default:
					break;
			}
			this.resetScroll = 1;
			this.query.page = 1;
			that.getList();
			/* 如需登录：
				 this.tabInfo.active = e;
				 this.query.ucj = e;
				 this.speed = 0;
				 this.query.page = 1;
				 this.query.isFinish = 0;
				 this.loading = false;
				 this.query.list = [];
				 */
		},
		// 打开弹窗
		openPop() {
			uni.navigateTo({
				url: "/root/detail/select",
			});
		},

		// 批量分享
		goShare() {
			if (this.isLogin) {
				uni.navigateTo({
					url: "/root/detail/shareJob",
				});
			} else {
				uni.showModal({
					title: "登录提示",
					content: "该页面需要登录才能查看,是否登录",
					success(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: "/pages/login/index",
							});
						} else {
						}
					},
				});
			}
		},
		successLogin() {
			uni.reLaunch({
				url: "/pages/home/index",
			});
		},
		sortJob(ind) {
			let that = this;
			this.sortList.active = ind;
			this.query.sortTag = this.sortList.list[ind].key;
			this.whichOneShow = "";
			if (this.query.sortTag === 2) {
				// 60 * 60 * 24
				if (that.currentInfo.latitude && new Date().getTime() - that.currentInfo.timestamp < 1000 * 10) {
					// console.log("inTime");
					this.getList();
				} else {
					// console.log("outTime");
					this.getLocation().then(() => {
						this.getList();
					});
				}
			} else {
				this.getList();
			}
		},
	},
};
</script>

<style lang="scss">
.ml8 {
	margin-left: 8px;
}

.por {
	position: relative;
}

.csbf {
	padding: 0px 8px;
	height: 28px;
	background-color: #f5f5f5;
	border-radius: 16px;
	text-align: center;
	font-size: 14px;
	font-weight: 400;
	color: #333333;
	line-height: 28px;
	box-sizing: border-box;
	// margin-top: 6px;
	margin-right: 12px;
}

.p-home-inedx {
	min-height: 100%;

	.m-more {
		position: absolute;
		left: 12rpx;
		bottom: -44rpx;
		width: 154px;
		background-color: #696969;
		box-shadow: 0px 2px 19px 0px rgba(179, 179, 179, 0.5);
		border-radius: 8px;
	}

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

	.u-border {
		border-color: #fff !important;
		background-color: #fff;
	}

	.navigatorBar .tabs {
		position: relative;
		left: 50%;
		color: #fff;
		transform: translateX(-50%);
		justify-content: center;
		box-sizing: border-box;
	}

	.sticky {
		position: sticky;
		top: 0px;
		left: 0;
		z-index: 100;
	}

	#searchInputBox {
		display: flex;
		justify-content: space-between;
		padding: 0 10px;
		top: 10px;
		box-sizing: border-box;
		position: relative;
		z-index: 9999;
		width: 100vw;
	}
}


.specialnum {
	height: 16px;
	min-width: 16px !important;
	line-height: 16px;
	padding: 0px;
	font-size: 12px;
	color: #fff;
	text-align: center;
	border-radius: 999px;
	background-color: #3578f6;
}

.quickapply {
	/* position: relative; */
	display: flex;
	justify-content: space-between;
	height: 80px;
	margin: 0 10px 0;
	padding-top: 10px;
	margin-bottom: 0;
	/* background-color: #fff; */
	overflow: hidden;
}

.quickapply button {
	display: flex;
	height: 100%;
	width: 100%;
	padding: 0;
	margin: 0;
}

.sticky {
	position: sticky;
	top: 0px;
	left: 0;
	z-index: 999;
}

.quickapply button > view {
	position: relative;
	display: flex;
	justify-content: space-between;
	align-items: center;
	width: 50%;
	padding: 20px 24px;
	border-radius: 8px;
	background-color: #fff;
}

.quickapply button > view:last-child {
	margin-left: 10px;
}

.display-flex {
	display: flex;
	justify-content: space-between;
}

/* .quickapply button > view:first-child::after {
	content: "";
	width: 1px;
	height: 20px;
	position: absolute;
	right: 0;
	top: 50%;
	transform: translateY(-50%);
	background-color: #eee;
} */
.quickapply button > view .t-icon {
	width: 38px;
	height: 38px;
}

.quickapply button > view .info > view {
	text-align: left;
	line-height: 1.6;
}

.clear {
	position: sticky;
	right: 0px;
	top: 0px;
	height: 44px;
	min-width: 60px;
	text-align: center;
	line-height: 44px;
	font-size: 14px;
	background: linear-gradient(180deg, #f5f5f5, #ffffff 23%, #ffffff 79%, #f5f5f5);
	box-shadow: -12px 0px 8px -4px rgba(206, 206, 206, 0.6);
}

.clear_icon {
	position: absolute;
	display: inline-block;
	width: 12px;
	height: 12px;
	line-height: 10px;
	border-radius: 50%;
	background-color: #fff;
	right: -2px;
	top: -2px;
	color: #aaa;
	/* font-size: 12px; */
}

.u-notice-box {
	margin-left: 0 !important;
}
.sortMask {
	position: absolute;
	top: 43px;
	left: 0;
	width: 100vw;
	height: 100vh;
	z-index: 999999;
	background-color: rgba(0, 0, 0, 0.8);
}
.sortContainer {
	padding: 0 24px;
	animation: filterBox 0.35s;
	animation-fill-mode: forwards;
	animation-timing-function: ease-in;
	box-sizing: border-box;
	background-color: #f5f5f5;
	padding-bottom: 4px;
	border-radius: 0 0 8px 8px;
	height: 40% !important;
}
@keyframes filterBox {
	0% {
		height: 0;
		/* opacity: 0; */
	}
}
.gjFixed {
	position: absolute;
	top: 43px;
	// top: 0px;
	left: 0;
	width: 100vw;
	height: 100vh;
	/* right:0;
	  bottom:0; */
	z-index: 99999999;
	background-color: rgba(0, 0, 0, 0.8);
}

.sortMask {
	position: absolute;
	top: 103px;
	left: 0;
	width: 100vw;
	height: 100vh;
	z-index: 999999;
	background-color: rgba(0, 0, 0, 0.8);
}
</style>
