<template>
	<view class="p-root-detail-apply g_w_all g_bg_f_5 g_kuaishou g_pt_10">
		<g-yi-list-job from="home" class="g_flex_1" :list="query.list" @clickCard="goDetail" :loading="loading" :speed="speed" :query="query" :isShowLoginBtn="isLogin ? false : true" />
	</view>
</template>

<script>
export default {
	onReady() {
		this.G.setNavStyle();
	},
	onShareAppMessage() {
		return this.G.shareFun();
	},
	data() {
		return {
			cdnBaseImg: this.G.store().cdnBaseImg,
			agencyId: uni.getStorageSync("apply-agencyId"),
			isAdmin: uni.getStorageSync("apply-userinfo").admin,
			isCreator: false, //管理人员判断
			speed: -1,
			query: {
				page: 1,
				size: 20,
				list: [],
				isFinish: -1,
				ujc: 0, // 0 全部 1收藏
			},
			isLogin: true,
      loading:false
		};
	},
	onLoad(options) {
		console.log("options", options);
		if (options.scene) {
			console.log("XXXXXXXXXXXX");
			//扫小程序码携带参数
			var sceneStr = decodeURIComponent(options.scene);
			console.log(sceneStr);
			var sceneJson = this.G.sceneToJson(sceneStr);
			console.log("sceneJson===", sceneJson);
			this.sceneStoreJobId = sceneJson.ids;
			uni.setStorageSync("AGENCY_USER_ID", sceneJson.u);
			// app.globalData.sceneStoreJobId = sceneJson.ids
			this.getList();
		}
		if (uni.getStorageSync("apply-userinfo")) {
			this.isLogin = true;
		} else {
			this.isLogin = false;
		}
	},
	onShow() {},
	methods: {
		getList($type = "init") {
			let that = this;
			that.G.Get(
				that.api.get_sharejob_list,
				{
					storeJobIds: that.sceneStoreJobId,
				},
				(res) => {
					console.log("一才职位列表：", res);
					that.speed = res.list.length;
					that.query.isFinish = res.list.length;
					if (res.list && res.list.length > 0) {
						res.list = that.G.toGetAddress(res.list);
						res.list = that.G.toGetAge(res.list);
						res.list = that.G.yijobCopy(res.list);
					}
					if ($type == "init") {
						that.query.list = [];
						that.query.list = res.list.map((item, index) => {
							return {
								...item,
								collected: item.collected ? true : false,
								cus_price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValueHtml(item.salaryClassify, item.salaryClassifyValue) : "月薪",
								salaryClassifyValue: item.salaryClassify != 7 ? that.G.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue) : "月薪",
								jobDesp: item.jobDesp.replaceAll("*****", "").split("————————")[0],
                gender: that.G.getGenderByMinAge(item),
							};
						});
					} else {
						that.query.list = that.query.list.concat(
							res.list.map((item, index) => {
								return {
									...item,
									collected: item.collected ? true : false,
									cus_price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValueHtml(item.salaryClassify, item.salaryClassifyValue) : "月薪",
									salaryClassifyValue: item.salaryClassify != 7 ? that.G.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue) : "月薪",
									jobDesp: item.jobDesp.replaceAll("*****", "").split("————————")[0],
									gender: that.G.getGenderByMinAge(item),
								};
							})
						);
					}
				}
			);
		},
		goDetail($item) {
			console.log("前往详情页", $item);
			if (this.isLogin) {
				uni.navigateTo({
					url: "/root/detail/work?id=" + $item.id,
				});
			} else {
				uni.navigateTo({
					url: "/pages/login/index",
				});
			}
		},
	},
};
</script>

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