<template>
	<view class="p-bill-index g_w_all  g_bg_page g_kuaishou">
		<view class="m-search g_flex_row_between flex_center g_bg_f g_pl_10 g_pr_10 g_pb_8 g_pt_6 g_mb_10">
			<u-search class="g_flex_1" :focus="true" @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="#999999" :maxlength="20"></u-search>
			<view class="g_ml_8 g_fs_16" style="color: #576b95" hover-class="thover" @click="backPrev">取消</view>
		</view>
		<g-yi-list-job :from="whichPage" class="g_h_all" :list="query.list" @clickCard="goDetail" :loading="loading" :speed="speed" :query="query" emptyText="暂无数据" pt="0" />
	</view>
</template>

<script>
export default {
	onReady() {
		this.G.setNavStyle();
	},
	onShareAppMessage() {
		return this.G.shareFun();
	},
	onLoad(options) {
		console.log(options);
		this.whichPage = options.from;
		if (this.whichPage == "record" || this.whichPage == "home") {
			this.placeholder = "搜索职位名称";
			uni.setNavigationBarTitle({
				title: "搜索职位",
			});
			this.getList();
		} else if (this.whichPage == "apply") {
			// 工单的类型 0 我报的 1 报给我的
			this.applyType = options.active;
			this.placeholder = "搜索姓名/职位/手机号";
			uni.setNavigationBarTitle({
				title: "搜索工单",
			});
			this.getApplyList();
		}
	},
	// 组件名称
	name: "",
	// 局部注册的组件
	components: {},
	// 组件参数 接收来自父组件的数据
	props: {},
	// 组件状态值
	data() {
		return {
			isUseNewJob: getApp().globalData.isUseNewJob,
			appid: getApp().globalData.appId,
			whichPage: "",
			keyword: "",
			loading: false,
			speed: -1,
			applyType: 0,
			query: {
				page: 1,
				size: 50,
				list: [],
				isFinish: -1,
			},
			placeholder: "搜索职位名称",
			navInfo: {},
		};
	},
	// 计算属性
	computed: {},
	// 侦听器
	watch: {},
	created() {},
	mounted() {},
	onShow() {
		let that = this;
		that.navInfo = that.G.getNavInfo();
	},
	// 组件方法
	methods: {
		goDetail($item) {
			uni.navigateTo({
				url: "/root/detail/job?id=" + $item.id,
			});
			// console.log("前往详情页", $item);
			// if (uni.getStorageSync("apply-userinfo")) {
			// 	uni.navigateTo({
			// 		url: "/root/detail/work?id=" + $item.id,
			// 	});
			// } else {
			// 	uni.navigateTo({
			// 		url: "/root/login/index",
			// 	});
			// }
		},
		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;
			let _url = "";
			console.log(that.appid, that.isUseNewJob, "---------------", getApp().globalData);
			_url = that.api.yi_job_list;

			that.G.Post(
				_url,
				{
					pageNum: that.query.page,
					pageSize: that.query.size,
					keys: that.keyword,
					recruitment: 1,
					checkStore: true
				},
				(res) => {
					let resData = {};
					resData = res.pageBean;

					console.log("一才职位列表：", resData);
					that.computeCode = 1;
					if (resData.recordCount == 0) {
						that.loading = false;
					} else {
						that.loading = true;
					}
					that.speed = resData.recordCount;
					that.query.isFinish = resData.recordList.length;
					if (resData.recordList && resData.recordList.length > 0) {
						resData.recordList = that.G.toGetAddressv3(resData.recordList);
						resData.recordList = that.G.toGetAge(resData.recordList);
						resData.recordList = that.G.yijobCopy(resData.recordList);
						resData.recordList.forEach((ita) => {
							ita.addss = that.G.setJobInfoPositionv3(ita.storeAddr);
						});
					}
					if ($type == "init") {
						that.query.list = [];
						that.query.list =
							resData.recordList && resData.recordList.length > 0
								? resData.recordList.map((item, index) => {
										return {
											...item,
											collected: item.collected ? true : false,
											leafCateId: item.id,
											cus_price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValueHtml(item.salaryClassify, item.salaryClassifyValue) : "月薪",
											gender: that.G.getGenderByMinAge(item),
											newadd:that.G.setJobInfoPositionv3(item.storeDistrict || item.storeAddr),
											fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
											newXmf:uni.getStorageSync('apply-agencyId') == uni.getStorageSync('pgy-agency-id') ?
															(item.agencyId == uni.getStorageSync('apply-agencyId') ? (item.upFullName || item.upAgencyName || item.upProviderName) : item.agencyName) : 
															'金马人力',
										};
								  })
								: [];
					} else {
						that.query.list = that.query.list.concat(
							resData.recordList && resData.recordList.length > 0
								? resData.recordList.map((item, index) => {
										return {
											...item,
											leafCateId: item.id,
											collected: item.collected ? true : false,
											cus_price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValueHtml(item.salaryClassify, item.salaryClassifyValue) : "月薪",
											gender: that.G.getGenderByMinAge(item),
											newadd:that.G.setJobInfoPositionv3(item.storeDistrict || item.storeAddr),
											fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
											newXmf:uni.getStorageSync('apply-agencyId') == uni.getStorageSync('pgy-agency-id') ?
															(item.agencyId == uni.getStorageSync('apply-agencyId') ? (item.upFullName || item.upAgencyName || item.upProviderName) : item.agencyName) : 
															'金马人力',
										};
								  })
								: []
						);
					}
				}
			);
		},
	},
};
</script>

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