<template>
	<view class="p-root-home-ignore g_w_pull g_bg_f_5 g_kuaishou">
		<view style="background-color: #fff; position: fixed; left: 0; top: 0; width: 100vw; height: 112rpx; z-index: 1">
			<view class="m-select">
				<view style="height: 112rpx">
					<view class="m-search g_p_10 g_pb_0 g_position_rela" style="padding-bottom: 0">
						<u-search @btnSearch="getSearch" height="80" v-model="keyword" placeholder="搜索职位" bg-color="#ededed" :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: 12px; z-index: 9999" @click.stop="goSearch"></view>
					</view>
				</view>
			</view>
		</view>
		<view class="" style="height: 112rpx"></view>
		<view class="g_mt_10">
			<rh-job-list bg="#ededed" class="g_h_all" :list="query.list" @shareJob="shareJob" :loading="loading" :speed="speed" :query="query" emptyText="暂无忽略职位" emptySubText=" " @uploadList="getList" />
		</view>
	</view>
</template>

<script>
export default {
	onShareAppMessage() {
		return this.G.shareFun();
	},
	data() {
		return {
			loading: true,
			speed: -1,
			query: {
				page: 1,
				size: 50,
				list: [],
				isFinish: -1,
			},
			keyword: "",
		};
	},
	onReachBottom() {
		let that = this;
		if (that.query.isFinish == -1 || that.query.isFinish == that.query.size) {
			that.query.page++;
			that.getList("concat");
		}
	},
	onShow() {
		this.getList();
	},
	methods: {
		getList($type = "init") {
			let that = this;
			that.G.Post(
				that.api.job_list,
				{
					pageNum: that.query.page,
					pageSize: that.query.size,
					// agencyId: uni.getStorageSync("apply-agencyId"),
					classify: 4,
					keys: that.keyword,
				},
				(res) => {
					that.computeCode = 1;

					// res.recordCount  = 0;
					// res.recordList = [];

					if (res.recordCount == 0) {
						that.loading = false;
					} else {
						that.loading = true;
					}
					that.speed = res.recordCount;
					that.query.isFinish = res.recordList.length;
					res.recordList = that.G.toGetAddressv3(res.recordList);
					res.recordList = that.G.toGetAge(res.recordList);
					res.recordList = that.G.yijobCopy(res.recordList);
					if ($type == "init") {
						that.query.list = [];
						if (res.recordList.length > 0) {
							that.query.list = res.recordList.map((item, index) => {
								// console.log(item)
								return {
									...item,
									title: item.jobName,
									address: item.district + item.age,
									price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue) : that.G.getSalaryClassifyValue(item.salaryClassify, item.minMonthlyPay, item.maxMonthlyPay),
									logo: item.agencyLogo,
									fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
									gender: that.G.getGenderByMinAge(item),
									time: that.G.setDeadLine(item.updateTime, "jiaofu"),
									leafCateId: item.id,
									// serverPrice: that.G.setReturnFee(item.returnFee, item.returnFeeType),
									serverPrice: that.G.setReturnFee(item.agencyReturnFee, item.agencyReturnFeeType),
									agencyId: item.agencyId,
									recruitmentSwitch: item.recruitment == 1 ? true : false,
									recruitmentImage: item.recruitment,
									tip: 3,
									isToday: item.today == 0 ? false : true,
									active: 0,
								};
							});
						}
					} else {
						that.query.list = that.query.list.concat(
							res.recordList.map((item, index) => {
								return {
									...item,
									title: item.jobName,
									address: item.district + item.age,
									price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue) : that.G.getSalaryClassifyValue(item.salaryClassify, item.minMonthlyPay, item.maxMonthlyPay),
									logo: item.agencyLogo,
									fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
									gender: that.G.getGenderByMinAge(item),
									time: that.G.setDeadLine(item.updateTime, "jiaofu"),
									leafCateId: item.id,
									// serverPrice: that.G.setReturnFee(item.returnFee, item.returnFeeType),
									serverPrice: that.G.setReturnFee(item.agencyReturnFee, item.agencyReturnFeeType),
									recruitmentSwitch: item.recruitment == 1 ? true : false,
									recruitmentImage: item.recruitment,
									tip: 3,
									isToday: item.today == 0 ? false : true,
									active: 0,
								};
							})
						);
					}
					console.log("首页 列表：", that.query.list);
				}
			);
		},
		getSearch(e) {
			if (e == "string") {
				this.keyword = e;
			}
			this.speed = -1;
			this.query.page = 1;
			this.getList();
		},
		/**
		 * 跳转搜索页
		 */
		goSearch() {
			this.G.isLogin();
			if (this.G.isLogin()) {
				uni.navigateTo({
					url: "/root/other/search?from=home",
				});
			}
		},
	},
};
</script>

<style lang="scss">
.p-root-home-ignore {
	min-height: 100%;
}
</style>
