<template>
	<view class="p-bil-index g_w_all g_h_all g_bg_f_5 g_kuaishou" :data-env="ENV_VERSION">
		<scroll-view class="m-list" :style="{ height: `calc(100vh - ${tabbarHeight}px` }" :scroll-y="true" @scrolltolower="reachBottom">
			<view class="m-search flex_center g_bg_f g_p_10 g_mb_10" :class="ENV_VERSION == 'develop' || ENV_VERSION == 'trial' ? '' : 'g_pb_8'">
				<view class="g_flex_row_between">
					<u-search bar-width="0" class="g_flex_1 g_pl_10" @btnSearch="getSearch" height="80" v-model="keyword" :placeholder="placeholder" bg-color="#f5f5f5" :show-action="false" @change="getSearch" @clear="getSearch" @custom="getSearch" @search="getSearch" search-icon-color="#cccccc" :maxlength="20"></u-search>
				</view>
				<!-- <view class="g_bg_f" v-if="ENV_VERSION == 'develop' || ENV_VERSION == 'trial'">
					<u-tabs bg-color="transparent" :list="tabInfo.list" :is-scroll="false" :current="tabInfo.active" :active-color="appid != 'wxb0c590fd696b79be' ? '#3578f6' : '#ff4400'" bar-width="64" bar-height="6" @change="handleUpdateTab" font-size="32" duration="0.1" height="76"></u-tabs>
				</view> -->
			</view>
			<view style="height: 0px" data-loading="loading" data-speed="speed"></view>
			<g-yi-list-job from="tob" class="g_h_all" :list="query.list" @updateList="getList" @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();
		console.log("0901 003", this.show, this.cuindex);
	},
	created() {
		console.log("0901 001", this.show, this.cuindex);
		this.speed = -1;
		this.loading = true;
		this.getList();
	},
	mounted() {
		console.log("0901 002", this.show, this.cuindex);
	},

	props: {
		show: {
			type: Boolean,
			default: () => {
				return false;
			},
		},
		cuindex: {
			type: Number,
			default: () => {
				return 0;
			},
		},
	},
	watch: {
		show: {
			handler(newVal) {
				console.log("是否执行newVal", newVal);
				if (newVal) {
					this.getList();
				}
			},
		},
	},
	// 组件状态值
	data() {
		return {
			ENV_VERSION: uni.getAccountInfoSync().miniProgram.envVersion,
			appid: uni.getAccountInfoSync().miniProgram.appId,
			tabbarHeight: uni.getStorageSync("TABBAR_HEIGHT"),
			// ENV_VERSION: "develop",
			fadanBaseImg: this.G.store().fadanBaseImg,
			whichPage: "home",
			keyword: "",
			loading: false,
			speed: -1,
			applyType: 0,
			query: {
				page: 1,
				size: 50,
				list: [],
				isFinish: -1,
				jobType: 2,
			},
			placeholder: "搜索职位名称",
			navInfo: {},
			tabInfo: {
				list: [
					{
						name: "全部",
						tip: "",
					},
					{
						name: "自有",
						tip: 2,
					},
					{
						name: "平台",
						tip: 1,
					},
				],
				active: 0,
			},
		};
	},
	// 计算属性
	computed: {},

	// 组件方法
	methods: {
		goPage($path) {
			uni.navigateTo({
				url: $path,
			});
		},
		handleUpdateTab(e) {
			this.tabInfo.active = e;
			this.query.jobType = this.tabInfo.list[e].tip;
			this.speed = -1;
			this.query.page = 1;
			this.getList();
		},
		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_myJobList,
				{
					pageNum: that.query.page,
					pageSize: that.query.size,
					keys: that.keyword,
					jobType: that.query.jobType,
					agencyId: uni.getStorageSync("AGENCY_ID"),
				},
				(res) => {
					console.log("一才职位列表：", res);
					that.computeCode = 1;
					if (res.pageBean.recordCount == 0) {
						that.loading = false;
					} else {
						that.loading = true;
					}
					that.speed = res.pageBean.recordCount;
					that.query.isFinish = res.pageBean.recordList.length;
					if (res.pageBean.recordList && res.pageBean.recordList.length > 0) {
						res.pageBean.recordList = that.G.toGetAddressv3(res.pageBean.recordList);
						res.pageBean.recordList = that.G.toGetAge(res.pageBean.recordList);
						res.pageBean.recordList = that.G.yijobCopy(res.pageBean.recordList);
					}
					if ($type == "init") {
						that.query.list = [];
						that.query.list =
							res.pageBean.recordList && res.pageBean.recordList.length > 0
								? res.pageBean.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.pageBean.recordList && res.pageBean.recordList.length > 0
								? res.pageBean.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 lang="less"></style>
