<template>
	<view class="p-bill-index g_w_all g_bg_f_5 g_kuaishou" style="min-height: 100%">
		<!-- 我的职位 -->
		<view class="m-job" style="min-height: 100%">
			<!-- 筛选项 -->
			<view class="m-search g_bg_f" id="jobList">
				<view class="g_flex_row_between g_pt_12 g_pl_10 g_pr_10 g_pb_6">
					<view class="g_flex_1 g_flex_row_start g_position_rela">
						<u-search style="width: 100%" @btnSearch="getSearch" height="80" 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 class="g_flex_column_center flex_center g_ml_8 g_w_40 g_h_40 g_radius_20 g_bg_f_5" hover-class="thover" @click="goPage('/root/home/jobForm')">
						<g-panel-image :url="cdnBaseImg + 'add_job.svg'" size="80" />
					</view>
				</view>
				<u-sticky>
					<view class="g_bg_f g_pr_10 g_pr_10">
						<u-tabs bg-color="transparent" :list="tabInfo.list" :is-scroll="false" :current="tabInfo.active" active-color="#00b666" bar-width="64" bar-height="6" @change="handleUpdateTab" font-size="32" duration="0.1" height="84"></u-tabs>
					</view>
				</u-sticky>
			</view>
			<!-- 列表 -->
			<view class="m-list g_mt_10 g_pb_60">
				<g-list-job emptyText="暂无职位" emptySubText=" " @uploadList="getList" :list="query.list" :loading="loading" :speed="speed" :query="query" @clickTop="goDetailJob" :showShare="false" from="bill" />
				<!-- <view class="g_flex_row_center" v-if="query.list.length == 0 && tabInfo.active == 0 && !loading">
					<view class="g_flex_row_center flex_center g_mt_24 g_w_123 g_h_40 g_radius_20 g_bg_f_5 g_c_main" style="border: 1px solid #00b666" hover-class="thover" @click="goPage('/root/home/jobForm')"> 发布职位 </view>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
export default {
	onReady() {
		this.G.setNavStyle();
	},
	onShow() {
		let that = this;
		that.getList();
	},
	onShareAppMessage() {
		return this.G.shareFun();
	},
	onReachBottom() {
		let that = this;
		if (that.isLogin) {
			if (that.query.isFinish == -1 || that.query.isFinish == that.query.size) {
				that.query.page++;
				that.getList("concat");
			}
		}
	},
	data() {
		return {
			cdnBaseImg: this.G.store().cdnBaseImg,
			isHaveOrder: false,
			query: {
				page: 1,
				size: 50,
				list: [],
				isFinish: -1,
			},
			keyword: "",

			isLogin: true,
			loading: true,

			tabInfo: {
				list: [
					{
						name: "全部",
						tip: "",
					},
					{
						name: "在招中",
						tip: 1,
					},
					{
						name: "已停招",
						tip: 2,
					},
				],
				active: 0,
			},
			speed: -1,
		};
	},
	onLoad(options) {
		if (options.active == 1) {
			this.tabInfo.active = 1;
		}
	},
	// 组件方法
	methods: {
		getList($type = "init") {
			let that = this;
			that.loading = true;

			that.G.Post(
				that.api.job_list,
				{
					pageNum: that.query.page,
					pageSize: that.query.size,
					agencyId: uni.getStorageSync("apply-agencyId"),
					keys: that.keyword,
					recruitment: that.tabInfo.list[that.tabInfo.active].tip,
				},
				(res) => {
					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) => {
								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.logo,
									fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
									gender: that.G.getGenderByMinAge(item),
									time: that.G.setDeadLine(item.updateTime, "jiaofu"),
									leafCateId: item.id,
									jobId: 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,
									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),
									fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
									gender: that.G.getGenderByMinAge(item),
									time: that.G.setDeadLine(item.updateTime, "jiaofu"),
									leafCateId: item.id,
									jobId: 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,
									isToday: item.today == 0 ? false : true,
									active: 0,
								};
							})
						);
					}
					// that.$forceUpdate()
				}
			);
		},
		/**
		 * 跳转搜索页
		 */
		goSearch() {
			this.G.isLogin();
			if (this.G.isLogin()) {
				uni.navigateTo({
					url: "/root/other/search?from=bill",
				});
			}
		},
		goPage($path) {
			this.G.isLogin();
			if (this.G.isLogin()) {
				uni.navigateTo({
					url: $path,
				});
			}
		},
		handleUpdateTab(e) {
			this.G.isLogin();
			if (this.G.isLogin()) {
				this.tabInfo.active = e;
				this.speed = -1;
				this.query.page = 1;
				this.getList();
			}
		},
		getSearch() {},
		goDetailJob($item) {
			this.G.isLogin();
			if (this.G.isLogin()) {
				uni.navigateTo({
					url: "/root/detail/job?id=" + $item.leafCateId,
				});
			}
		},
	},
};
</script>

<style lang="scss">
.p-bill-index {
	.u-input {
		font-size: 16px !important;
	}
}
</style>
