<template>
	<view class="p-bill-index g_w_all g_h_all g_bg_f_5 g_kuaishou">
		<scroll-view class="m-list" :style="{ height: `calc(100vh - 0px)` }" :scroll-y="true" @scrolltolower="reachBottom">
			<view class="m-search g_flex_row_between flex_center g_bg_f g_pl_10 g_pr_10 g_pb_8 g_pt_8 g_mb_10">
				<u-search class="g_flex_1" @btnSearch="getSearch" height="80" v-model="keyword" :placeholder="placeholder" bg-color="#f5f5f5" :show-action="false" @clear="getSearch" @custom="getSearch" @search="getSearch" search-icon-color="#999999" :maxlength="20"></u-search>
				 <!-- @change="getSearch" -->
				<!-- <view class="g_ml_8 g_fs_16" style="color: #576b95" hover-class="thover" @click="backPrev">取消</view> -->
			</view>
			<g-yi-list-job from="tob" class="g_h_all" :list="query.list" @clickCard="goDetail" :loading="loading" :speed="speed" :query="query" emptyText="暂无数据" pt="0" />
		</scroll-view>
	</view>
</template>

<script>
export default {
	onReady() {
		this.G.setNavStyle();
	},
	onShareAppMessage() {
		return this.G.shareFun();
	},
	onLoad(options) {
		console.log(options);
		this.navInfo = this.G.getNavInfo();
		// this.placeholder = "搜索职位名称";
	},
	onShow() {
		let that = this;
		that.navInfo = that.G.getNavInfo();
	},
	created() {
		console.log(this.show);
		this.loading = true;
		this.speed = -1;
		this.getList();
	},
	mounted() {},

	props: {
		show: {
			type: Boolean,
			default: () => {
				return false;
			},
		},
	},
	watch: {
		show: {
			handler(newVal) {
				console.log(newVal);
				if (newVal) {
					this.getList();
				}
			},
		},
	},
	// 组件状态值
	data() {
		return {
			whichPage: "home",
			keyword: "",
			loading: false,
			speed: -1,
			applyType: 0,
			query: {
				page: 1,
				size: 20,
				list: [],
				isFinish: -1,
			},
			placeholder: "搜索职位名称",
			navInfo: {},
		};
	},
	// 计算属性
	computed: {},

	// 组件方法
	methods: {
		goDetail($item) {
			console.log("前往详情页", $item);
			if (uni.getStorageSync("apply-userinfo")) {
				uni.navigateTo({
					url: "/root/detail/job?id=" + $item.id,
				});
			} else {
				uni.navigateTo({
					url: "/root/login/index",
				});
			}
		},
		reachBottom() {
			let that = this;
			console.log("tolow");
			// if (!uni.getStorageSync("apply-token") && that.tabInfo.active == 1) {
			// 	return false;
			// }
			that.query.page++;
			that.getList("concat");
		},
		getSearch(e) {
			console.log(e);
			this.speed = -1;
			this.keyword = e;
			this.query.page = 1;
			console.log(this.whichPage);
			this.getList();
		},
		backPrev() {
			console.log("backPrev");
			uni.navigateBack({
				delta: 1,
			});
		},
		getList($type = "init") {
			let that = this;
			that.G.Post(
				// that.api.job_list,
				that.api.new_job_list,
				{
					pageNum: that.query.page,
					pageSize: that.query.size,
					keys: that.keyword,
					// agencyId: uni.getStorageSync("AGENCY_ID"),
				},
				(res) => {
					console.log("一才职位列表：", res);
					that.computeCode = 1;
					if (res.recordCount == 0) {
						that.loading = false;
					} else {
						that.loading = true;
					}
					that.speed = res.recordCount;
					that.query.isFinish = res.recordList.length;
					if (res.recordList && res.recordList.length > 0) {
						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 = [];
						that.query.list =
							res.recordList && res.recordList.length > 0
								? res.recordList.map((item, index) => {
										return {
											...item,
											collected: item.collected ? true : false,
											cus_price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValueHtml(item.salaryClassify, item.salaryClassifyValue) : "月薪",
											fuWuFei: that.G.setReturnFee(item.returnFee / 100, item.returnFeeType, 1),
											gender: that.G.getGenderByMinAge(item),
											recruitmentValue: item.recruitment == 1 ? true : false,
										};
								  })
								: [];
					} else {
						that.query.list = that.query.list.concat(
							res.recordList && res.recordList.length > 0
								? res.recordList.map((item, index) => {
										return {
											...item,
											collected: item.collected ? true : false,
											cus_price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValueHtml(item.salaryClassify, item.salaryClassifyValue) : "月薪",
											fuWuFei: that.G.setReturnFee(item.returnFee / 100, item.returnFeeType, 1),
											gender: that.G.getGenderByMinAge(item),
											recruitmentValue: item.recruitment == 1 ? true : false,
										};
								  })
								: []
						);
					}
					console.log("that.query.list ", that.query.list);
				}
			);
		},
	},
};
</script>

<style scoped lang="less"></style>
