<template>
	<view class="p-root-sharejob g_w_all g_bg_f_5" hover-class="none" hover-stop-propagation="false">
		<scroll-view class="m-list" id="listBox" :style="{ height: `calc(100vh - 74px)` }" :scroll-y="true" @scrolltolower="reachBottom">
			<!-- <div class="g_kuaishou"> -->
			<div>
				<div class="sticky g_bg_f">
					<div class="m-search g_pt_10 g_pb_10 g_pr_10 bg_shawdoc g_position_rela g_flex_row_center" style="" id="searchInputBox">
						<view class="the_city g_flex_column_center g_mr_10" style hover-class="thover" @click="goCity">
							<view class="g_flex_row_center">
								<view class="g_fs_16 g_fw_600 g_ml_10" style="width: 36px; display: inline-block">{{ selectedCity }} </view>
								<view class="g_flex_column_center">
									<view class="iconfont icon-zhankai g_fs_12" style="display: inline-block"></view>
								</view>
							</view>
						</view>
						<u-search height="80" @search="searchJob" @clear="searchJob" v-model="keyword" class="g_flex_1" placeholder="搜索职位名称" bg-color="#ededed" :show-action="false" placeholder-class="g_c_c" search-icon-color="#999999" :maxlength="20"></u-search>
						<!-- <div class="g_w_all g_h_40 g_position_abso" style="left: 0; z-index: 9999" @click.stop="searchJob"></div> -->
					</div>
					<view class="g_flex_row_between flex_center" id="tttop">
						<view class="g_flex_1">
							<u-tabs bg-color="transparent" from="index" gutter="20" :list="tabInfo.list" :is-scroll="true" :current="tabInfo.active" :active-color="globalData.themeColor" bar-width="64" bar-height="6" @change="handleUpdateTab" font-size="32" duration="0.05" height="76"></u-tabs>
						</view>
						<!-- <view v-if="isMember && hasPermission" class="g_mr_8" @click="goShare"> 批量分享 </view> -->

						<view class="g_flex_row_end flex_center">
							<view class="csbf" @click="chooseNl('sort')">
								{{ sortList.list[sortList.active].showName }}
								<span class="iconfont icon-shouqi g_fs_12 g_c_9 fst g_ml_4" v-if="whichOneShow == 'sort'"></span>
								<span class="iconfont icon-zhankai g_fs_12 g_c_9 fst g_ml_4" v-if="whichOneShow != 'sort'"></span>
								<view class="sortMask" v-if="whichOneShow == 'sort'">
									<view class="sortContainer" style="overflow: hidden" @click.stop>
										<view v-for="(item, index) in sortList.list" @click="sortJob(index)" :key="index" :class="sortList.active == index ? 'g_border_main g_c_main' : 'g_border_f'" class="g_fs_16 g_fw_600 g_mt_16 g_bg_f" style="border-radius: 30px; padding: 8px 16px">{{ item.name }}</view>
									</view>
								</view>
							</view>
							<view class="csbf" @click="chooseNl('special')" data-type="special">
								筛选
								<span class="iconfont icon-shouqi g_fs_12 g_c_9 fst g_ml_4" v-if="whichOneShow == 'special'"></span>
								<span class="iconfont icon-zhankai g_fs_12 g_c_9 fst g_ml_4" v-if="whichOneShow != 'special'"></span>
								<g-filter :show="whichOneShow" ref="filterChild" top="101px" :getFilterDataNew="getFilterData" @filterObj="receiveFromChild"></g-filter>
							</view>
						</view>
					</view>
					<scroll-view class="filterTag bt1" v-if="getFilterData.jobCategoryLabelObjects.length > 0 || getFilterData.jobSpecialLabelObjects.length > 0 || getFilterData.sex != '-1' || (getFilterData.ageRangeStr && getFilterData.ageRangeStr != '16-60')" :scroll-x="true" :scroll-y="false" scroll-top="0" scroll-left="0" scroll-into-view scroll-with-animation="false" enable-flex enable-back-to-top="false">
						<div class="g_flex_row_between flex_center flex_nw g_w_all">
							<div class="g_flex_row_start flex_nw" style="line-height: 44px">
								<div class="tc genderTag f14 por" style="min-width: 60px" v-if="getFilterData.ageRangeStr != '' && getFilterData.ageRangeStr != '16-60'">
									<div class="por" @click.stop="deleteAge">
										{{ getFilterData.ageRangeStr }}
										<div class="clear_icon iconfont icon-dianji"></div>
									</div>
								</div>

								<div class="tc genderTag f14 por" style="min-width: 60px" v-if="getFilterData.sex != '-1'">
									<div class="por" @click.stop="deleteSex">
										{{ getFilterData.sex == 1 ? "收男工" : getFilterData.sex == 2 ? "收女工" : getFilterData.sex == 3 ? "男女都收" : "" }}
										<!-- {{getFilterData.jobCategoryLabelObjects.length > 0}} {{getFilterData.jobSpecialLabelObjects.length > 0}} -->
										<div class="clear_icon iconfont icon-dianji"></div>
									</div>
								</div>
								<div class="brandTag ml8" v-if="getFilterData.jobCategoryLabelObjects.length > 0">
									<block v-for="(item, index) in getFilterData.jobCategoryLabelObjects" :key="index">
										<div class="por" @click.stop="deleteJobCategoryLabel(item.id)">
											{{ item.name }}
											<div class="clear_icon iconfont icon-dianji"></div>
										</div>
									</block>
								</div>

								<div class="specialTag ml8">
									<block v-for="(item, index) in getFilterData.jobSpecialLabelObjects" :key="index">
										<div class="por" @click.stop="deleteJobSpecialLabel(item.id)">
											{{ item.name }}
											<div class="clear_icon iconfont icon-dianji"></div>
										</div>
									</block>
								</div>
							</div>
							<div class="clear" @click.stop="clearFilter1" data-type="outerClear">
								<span class="iconfont icon-shanchu f14"></span>
								清除
							</div>
						</div>
					</scroll-view>
				</div>
				<div class="g_h_10"></div>
				<g-list-job from="share" class="g_flex_1" :list="query.list" @clickCard="goDetail" @checkJob="checkJob" :loading="loading" :speed="speed" :query="query" :isShowLoginBtn="isLogin ? false : true" :emptyText="isLogin ? (tabInfo.list[tabInfo.active].classify == 2 ? '您还未收藏职位，快去试试收藏职位吧' : '嘿，这里还没有数据呢') : '您还有没有登录，请登录后查看职位'" />
			</div>
		</scroll-view>
		<div class="shareBottom g_flex_row_between flex_center" hover-class="none" hover-stop-propagation="false">
			<div class hover-class="none" hover-stop-propagation="false">
				已选
				<span class="g_c_main">{{ checkedList.length }}</span>
			</div>
			<div class="g_flex_row_end" hover-class="none" hover-stop-propagation="false">
				<!-- bindtap="shareJobList" -->
				<button :hover-class="checkedList.length > 0 ? 'btnHover' : ''" :open-type="checkedList.length > 0 ? 'share' : ''" :class="checkedList.length > 0 ? '' : 'ban'">分享职位</button>
				<button :hover-class="checkedList.length > 0 ? 'btnHover' : ''" @click="copyTrans" :class="checkedList.length > 0 ? '' : 'ban'">复制详单</button>
				<button :hover-class="checkedList.length > 0 && checkedList.length <= 3 ? 'btnHover' : ''" @click="sharePoster" :class="checkedList.length > 0 && checkedList.length <= 3 ? '' : 'ban'">分享海报</button>
			</div>
		</div>
		<!-- </div> -->
		<canvas type="2d" style="position: absolute; left: -2000px; width: 425px; height: 350px; background: #fff" id="canvasId"></canvas>
		<u-popup v-model="posterShow" mode="bottom" :closeable="true" uZindex="9999" width="694rpx" height="80vh" border-radius="12" :mask-close-able="true">
			<div class="g_text_c g_pt_24 g_pb_24">
				<image class="posterImg g_pb_24" :src="posterImg" :show-menu-by-longpress="true" mode="aspectFit|aspectFill|widthFix" lazy-load="false"></image>
				<g-button btnText="保存到相册" type="primary" class="g_mt_32" @clickBtn="saveToalbum"></g-button>
			</div>
		</u-popup>
	</view>
</template>

<script>
// import that.G from "./utils/commonSub.js";

export default {
	components: {},
	onReady() {
		this.G.setNavStyle();
	},
	onShareAppMessage: function () {
		// `1231`
		// var path = commonUtil.getCurrentPageUrlWithArgs();
		// if (app.globalData.isLogin && app.globalData.agencyStatus - 0 != 0) {
		//   //当前用户是代理人
		//   path += (path.indexOf("?") >= 0 ? "&" : "?") + "agencyUserId=" + app.globalData.loginUserInfo.id;
		// }
		if (this.checkedList.length == 0) {
			throw Error;
		} else {
			return {
				promise: new Promise((resolve, reject) => {
					var arr = [];
					this.checkedList.forEach((item) => {
						arr.push(item.id);
					});
					this.getCanvas(this.shareJobBaseImg, "setJob").then((res) => {
						console.log(res);
						uni.hideLoading();
						resolve({
							title: "你想找的厂都有，立即查看",
							imageUrl: res.tempFilePath,
							path: `/root/home/shareList?scene=i=${arr.join("_")},u=${this.userInfo.agencyId}_${this.userInfo.id}`,
							// path: '/pages/shareList/index'
						});
						// return
					});
				}),
			};
		}
	},
	data() {
		return {
			cdnBaseImg: this.G.store().cdnBaseImg,
			globalData: getApp().globalData,
			selectedCity: "全国",
			whichOneShow: "",
			agencyId: uni.getStorageSync("apply-agencyId"),
			userInfo: uni.getStorageSync("apply-userinfo"),
			appInfo: uni.getStorageSync("miniApp-info"),

			loading: true,
			speed: -1,
			getFilterData: {
				sex: "-1",
				ageRangeStr: "",
				jobCategoryLabelIds: "",
				jobRequestLabelIds: "",
				jobSpecialLabelObjects: [],
				jobCategoryLabelObjects: [],
			},
			tabInfo: {
				list: [
					{
						name: "关注",
						num: 0,
						tip: 0,
						classify: 2,
					},
					{
						name: "我的",
						num: 0,
						tip: 2,
						classify: 99,
					},
				],
				active: 0,
			},
			// 排序的配置
			sortList: {
				list: [
					{
						name: "时间",
						key: 0,
						showName: "按时间",
					},
					{
						name: "工价",
						key: 1,
						showName: "按工价",
					},
					// {
					// 	name: "按佣金",
					// 	key: 3,
					// 	showName: "按佣金",
					// },

					{
						name: "距离",
						key: 2,
						showName: "按距离",
					},
				],
				active: 0,
			},
			query: {
				page: 1,
				size: 20,
				list: [],
				isFinish: -1,
				sortTag: 0,
				ujc: 0, // 0 全部 1收藏
			},
			currentInfo: {},
			isLogin: true,
			keyword: "",
			checkedList: [],
			posterShow: false,
			navInfo: {},
			shareJobBaseImg: "https://matripe-cms.oss-cn-beijing.aliyuncs.com/1shoudan/poster0106.png", // 分享职位基础图片
			sharelImg: "https://matripe-cms.oss-cn-beijing.aliyuncs.com/2023-09-01/7ca85384-9f22-474d-893f-092b61de684d_share.png", // 分享职位基础图片
			currCode: "",
			posterImg: "", // 海报图片
		};
	},
	onLoad(options) {
		console.log("options", options);
		this.navInfo = this.G.getNavInfo();
		uni.removeStorageSync("selectedCity");

		this.getList();
	},
	onUnload() {
		uni.removeStorageSync("selectedCity");
	},
	onShow() {
		this.loadSelectedCityFromCache();
	},
	methods: {
		loadSelectedCityFromCache() {
			// 假设缓存中的键名为 'selectedCity'
			const cachedCity = uni.getStorageSync("selectedCity");
			if (cachedCity && this.selectedCity != cachedCity) {
				this.selectedCity = cachedCity;
				this.getList();
			}
		},
		handleUpdateTab(e) {
			console.log("获取tab数据：", e);
			let that = this;
			that.loading = true;
			that.tabInfo.active = e;
			// 之前的位置排序，现在不需要了
			// if (that.tabInfo.active == 1) {
			// 	that.getLocation().then((res) => {
			// 		that.getList();
			// 	});
			// } else
			that.query.page = 1;
			that.speed = -1;
			if (that.tabInfo.list[that.tabInfo.active].classify == 2) {
				that.query.ujc = 1;
			} else {
				that.query.ujc = 0;
			}
			that.getList();
		},
		getLocation() {
			let that = this;
			return new Promise((resolve, reject) => {
				uni.authorize({
					// 检测是否授权位置信息
					scope: "scope.userLocation",
					success() {
						console.log("用户成功授权位置信息");
						uni.getLocation({
							type: "wgs84",
							success(res) {
								that.currentInfo = {
									latitude: res.latitude,
									longitude: res.longitude,
									timestamp: new Date().getTime(),
								};
								console.log("获取当前经纬度：", that.currentInfo);
								resolve();
							},
							fail(err) {
								console.log(err);
							},
							complete() {
								resolve();
							},
						});
					},
					fail(err) {
						console.log(err);
						console.log("用户拒绝授权位置信息，再次提示用户授权");
						uni.showToast({
							title: "请开启定位权限以显示距职位距离",
							icon: "none",
						});
						resolve();
						// that.showRefuseLocationPermission();
					},
					complete() {
						console.log();
						// resolve();
					},
				});
			});
		},
		sortJob(ind) {
			let that = this;
			this.sortList.active = ind;
			this.query.sortTag = this.sortList.list[ind].key;
			that.query.list = [];
			that.speed = -1;
			that.loading = true;
			this.whichOneShow = "";
			if (this.query.sortTag === 2) {
				// 60 * 60 * 24
				if (that.currentInfo.latitude && new Date().getTime() - that.currentInfo.timestamp < 1000 * 10) {
					console.log("inTime");
					this.getList();
				} else {
					console.log("outTime");
					this.getLocation().then(() => {
						this.getList();
					});
				}
			} else {
				this.getList();
			}
			// uni.showLoading({
			// 	title: "加载中...",
			// });
		},
		getList($type = "init") {
			let that = this,
				params = {};
			params = {
				...that.getFilterData,
				pageNum: that.query.page,
				pageSize: that.query.size,
				agencyId: that.tabInfo.active == 1 ? uni.getStorageSync("apply-agencyId") : "",
				classify: that.tabInfo.list[that.tabInfo.active].classify,
				sortTag: that.query.sortTag,
				keys: that.keyword,
				cityName: that.selectedCity == "全国" ? "" : that.selectedCity,
			};
			if (that.tabInfo.list[that.tabInfo.active].classify == 1) {
				params.jobType = 2;
			}
			if (that.query.sortTag !== 2) {
				params.lat = "";
				params.lng = "";
				// params.sortTag = 0;
			} else {
				params.lat = that.currentInfo.latitude ? that.currentInfo.latitude : "";
				params.lng = that.currentInfo.longitude ? that.currentInfo.longitude : "";
				// params.sortTag = 2;
			}
			that.G.Post(that.api.job_list, params, (res) => {
				uni.hideLoading();
				console.log("一才职位列表：", res);
				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);
				}
				res.recordList.forEach((item, index1) => {
					if (item.logo.indexOf("http:") > -1) {
						item.logo = item.logo.indexOf("http:") > -1 ? item.logo.replace("http:", "https:") : item.logo;
						console.log(item);
					}
					try {
						console.log(item1);
						that.checkedList.forEach((item1, index1) => {
							if (item1.id == item.id) {
								item.checked = true;
								throw Error;
							} else {
								item.checked = false;
							}
						});
					} catch (error) {}
				});
				if ($type == "init") {
					that.query.list = [];
					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),
							salaryClassifyValue: item.salaryClassify != 7 ? that.G.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue) : "月薪",
							logo: item.agencyLogo,
							time: that.G.setDeadLine(item.updateTime, "jiaofu"),
							fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
							gender: that.G.getGenderByMinAge(item),
							leafCateId: item.id,
							// serverPrice: that.tabInfo.list[that.tabInfo.active].tip == 2 ? that.G.setReturnFee(item.returnFee, item.returnFeeType) : that.G.setReturnFee(item.agencyReturnFee, item.agencyReturnFeeType),
							serverPrice: that.G.setReturnFee(item.agencyReturnFee, item.agencyReturnFeeType),
							recruitmentSwitch: item.recruitment == 1 ? true : false,
							recruitmentImage: item.recruitment,
							active: that.tabInfo.active,
							isToday: item.today == 0 ? false : true,
							tip: that.tabInfo.list[that.tabInfo.active].tip,
						};
					});
				} 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),
								salaryClassifyValue: item.salaryClassify != 7 ? that.G.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue) : "月薪",

								logo: item.agencyLogo,
								time: that.G.setDeadLine(item.updateTime, "jiaofu"),
								fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
								gender: that.G.getGenderByMinAge(item),
								leafCateId: item.id,
								// serverPrice: that.tabInfo.list[that.tabInfo.active].tip == 2 ? that.G.setReturnFee(item.returnFee, item.returnFeeType) : that.G.setReturnFee(item.agencyReturnFee, item.agencyReturnFeeType),
								serverPrice: that.G.setReturnFee(item.agencyReturnFee, item.agencyReturnFeeType),
								recruitmentSwitch: item.recruitment == 1 ? true : false,
								recruitmentImage: item.recruitment,
								active: that.tabInfo.active,
								isToday: item.today == 0 ? false : true,
								tip: that.tabInfo.list[that.tabInfo.active].tip,
							};
						})
					);
				}

				console.log("that.query.list", that.query.list);
			});
		},
		goCity() {
			uni.navigateTo({
				url: "/root/other/city",
			});
		},
		checkLength(e) {
			if (e.length <= 0) {
				this.getList();
			}
		},
		searchJob(e) {
			console.log(e);
			this.query.page = 1;
			this.checkedList = [];
			this.getList();
		},
		reachBottom() {
			let that = this;
			// if (!uni.getStorageSync("apply-token") && that.tabInfo.active == 1) {
			// 	return false;
			// }
			that.query.page++;
			that.getList("concat");
		},
		checkJob(_item) {
			if (_item) {
				let index = this.query.list.findIndex((i) => {
					return i.id == _item.id;
				});
				this.query.list[index].checked = !this.query.list[index].checked;
				this.checkedList = [];
				this.query.list.forEach((item) => {
					if (item.checked == true) {
						this.checkedList.push(item);
					}
				});
				console.log(this.checkedList);
			}
		},

		/**
		 * 复制转发选中职位的通告信息
		 */
		copyTrans() {
			var that = this;
			if (this.checkedList.length > 0) {
				let ids = "";
				ids = this.checkedList.map((item) => item.id).join("_");
				that.G.Get(that.api.get_getJobText, { storeJobIds: ids }, (res) => {
					console.log(res);
					let str = "";
					res.forEach((item, index) => {
						console.log(item);
						if (item.jobInfoWithoutReturnFee) {
							str += item.jobInfoWithoutReturnFee + "\n";
						}
					});
					uni.setClipboardData({
						data: str,
						success(res) {
							uni.showToast({
								title: "通告内容已复制",
								icon: "none",
								duration: 1500,
							});
						},
					});
				});
			}
		},
		/**
		 * 分享海报生成海报图并转发
		 */
		sharePoster() {
			console.log(this.checkedList);
			if (this.checkedList.length == 0 || this.checkedList.length > 3) {
				return;
			}
			uni.showLoading({
				title: "生成中...",
			});

			this.getCode().then((res) => {
				setTimeout(() => {
					this.getCanvas(this.sharelImg, "setShare").then((res) => {
						console.log(res);
						uni.hideLoading();
						this.posterImg = res.tempFilePath;
						this.$forceUpdate();
						this.posterShow = true;
					});
				}, 10);
			});
			// this.setData({
			// });
		},
		getCode() {
			var that = this;
			let _env = uni.getAccountInfoSync().miniProgram.envVersion;
			console.log("_env", _env);
			return new Promise((resolve, reject) => {
				// if (this.checkedList.length == 1) {
				// 	that.G.Get(that.api.get_singlejob_QRcode + `/${that.checkedList[0].id}`, {}, (res) => {
				// 		console.log(res);
				// 		that.currCode = res.qrcode;
				// 		resolve();
				// 	});
				// } else {
				that.G.Get(that.api.get_job_QRcode, { storeJobIds: that.checkedList.map((item) => item.id).join(","), env: _env }, (res) => {
					console.log("get_job_QRcode", res);
					that.currCode = res;
					resolve();
				});
				// }
			});
		},
		getCanvas(sharelImg, type) {
			const that = this;
			console.log(sharelImg);
			return new Promise((resolve) => {
				var mycenter = 0; //文字左右居中显示
				var myheight = 0; //文字高度
				const query = uni.createSelectorQuery();
				query
					.select("#canvasId")
					.fields({ node: true, size: true })
					.exec((res) => {
						console.log(res);
						const canvas = res[0].node;
						const ctx = canvas.getContext("2d");
						new Promise(function (resolve) {
							// 绘制背景图片
							uni.getImageInfo({
								src: sharelImg, // 网络图片
								success(res) {
									console.log(res);
									var width = res.width;
									var height = res.height;
									mycenter = width / 2;
									myheight = height;
									canvas.width = width;
									canvas.height = height;
									const img = canvas.createImage();
									console.log(ctx);
									img.src = res.path;
									img.onload = (info) => {
										console.log(info);
										ctx.drawImage(img, 0, 0, width, height);
										resolve(true);
									};
								},
								fail(err) {
									console.log(err);
								},
							});
						}).then(() => {
							//使用：
							console.log(canvas);
							if (type == "setJob") {
								this.setShareJobImg(ctx, canvas)
									.then(function (canvas1) {
										uni.canvasToTempFilePath({
											canvas: canvas1,
											success(res) {
												console.log(res);
												resolve(res);
											},
											fail(res) {
												uni.hideLoading();
												uni.showToast({
													title: res.errMsg,
													icon: "error",
												});
											},
										});
									})
									.catch((err) => {
										console.log(err);
										uni.hideLoading();
										uni.showToast({
											title: "生成失败,请重试",
										});
									});
							} else if (type == "setShare") {
								this.setShareImg(ctx, canvas, mycenter)
									.then(function (canvas1) {
										uni.canvasToTempFilePath({
											canvas: canvas1,
											success(res) {
												console.log(res);
												resolve(res);
											},
											fail(res) {
												uni.hideLoading();
												uni.showToast({
													title: res.errMsg,
													icon: "error",
												});
											},
										});
									})
									.catch((err) => {
										console.log(err);
										uni.hideLoading();
										uni.showToast({
											title: "生成失败,请重试",
										});
									});
							}
						});
					});
			});
		},
		/**
		 * 分享海报生成图片
		 */
		setShareImg(ctx, canvas, mycenter, funObj) {
			let that = this;
			return new Promise((imgres) => {
				// ctx.arcTo()
				let baseTop, logoLeft, logoSize, titleSize, ageTop, salaryClassifyValueLeft, salaryClassifyValueTop, monthlyPaySize, position, markTop, roundRectHeight, fubiaotiTop, bottomSloganTop, bottomSloganTop1, bottomSloganLeft, bottomSloganLeft1, QRSize, QRLeft, QRTop;
				let baseMiddle = 248 * 2;
				if (that.checkedList.length == 1) {
					baseTop = 2 * 370;
					bottomSloganTop = 2 * 355;
					bottomSloganTop1 = 2 * 700;
					QRSize = 2 * 260;
					QRTop = 770;
				} else {
					baseTop = 2 * 294;
					bottomSloganTop = 2 * 740;
					bottomSloganTop1 = 2 * 790;
					bottomSloganLeft = 64;
					bottomSloganLeft1 = 64;
					QRSize = 2 * 120;
					QRLeft = 900;
					QRTop = 1400;
				}
				fubiaotiTop = 2 * 213;
				logoLeft = 2 * 56;
				logoSize = 2 * 80;
				titleSize = 2 * 30;
				roundRectHeight = 2 * 226;
				ageTop = 2 * 92;
				salaryClassifyValueLeft = 2 * 156;
				salaryClassifyValueTop = 2 * 48;
				monthlyPaySize = 2 * 24;
				markTop = 2 * 115;
				console.log(123);
				console.log("https://daotian.matripe.com.cn" + that.currCode);
				uni.getImageInfo({
					// src: "https://matripe-cms.oss-cn-beijing.aliyuncs.com/1shoudan/qrcode.png", //网络图片,如果不行请换一个
					src: "https://daotian.matripe.com.cn" + that.currCode,
					success(res) {
						try {
							console.log("currCode", res);
							const img = canvas.createImage();
							img.src = res.path;
							img.onload = () => {
								if (that.checkedList.length == 1) {
									that.G.roundRect1(ctx, mycenter - 580 / 2, baseTop + 740, 580, 580, 0, "#fff");
									that.G.roundRect(ctx, img, mycenter - res.width / 2 - 120, baseTop + 770, QRSize, QRSize, 0);
									// that.G.roundRect(ctx, img, mycenter - res.width / 2 - 120, baseTop + 770, QRSize, QRSize, 0);
								} else {
									that.G.roundRect1(ctx, QRLeft - 10, baseTop + QRTop - 10, QRSize + 20, QRSize + 20, 0, "#fff");
									that.G.roundRect(ctx, img, QRLeft, baseTop + QRTop, QRSize, QRSize, 0);
								}
								that.checkedList.forEach((item, index) => {
									let labelLeft = 0;
									console.log("item2", item);
									that.G.roundRect1(ctx, 24 * 2, baseTop - 100 + baseMiddle * index, 1104, roundRectHeight, 32, "#fff");
									item.jobSpecialLabelNameArray.forEach((item1, index1) => {
										if (index1 < 4) {
											that.G.fillTextLineBreak(ctx, item1, 60 * 2 + labelLeft, baseTop + markTop + 30 * 2 + baseMiddle * index, 400 * 2, 20, "#333", monthlyPaySize); // 标签字符
											that.G.roundRect1(ctx, 52 * 2 + labelLeft, baseTop + markTop + baseMiddle * index, ctx.measureText(item1).width + 16 * 2, 40 * 2, 2 * 2, "#00000010"); // 标签背景色
											labelLeft += ctx.measureText(item1).width + 32 * 2;
										}
									});

									that.G.fillTextLineBreak(ctx, item.jobName, logoLeft, baseTop + baseMiddle * index, 800 * 2, 20, "#333", titleSize, "600"); // 岗位标题

									that.G.fillTextLineBreak(ctx, item.salaryClassifyValue, logoLeft, baseTop + salaryClassifyValueTop + baseMiddle * index, 400 * 2, 20, "#ff4400", titleSize - 4, "600"); // 时薪

									// setTimeout(() => {
									that.G.fillTextLineBreak(ctx, item.monthlyPay, logoLeft + ctx.measureText(item.salaryClassifyValue + " ").width, baseTop + salaryClassifyValueTop + baseMiddle * index, 400 * 2, 20, "#ff4400", monthlyPaySize, "400"); // 月工资
									// }, 0);

									that.G.fillTextLineBreak(ctx, item.district, logoLeft, baseTop + ageTop + baseMiddle * index, 500 * 2, 20, "#333", monthlyPaySize); // 省市

									that.G.fillTextLineBreak(ctx, "丨" + item.age, logoLeft + ctx.measureText(item.district).width, baseTop + ageTop + baseMiddle * index, 500 * 2, 20, "#333", monthlyPaySize); // 年龄

									that.G.fillTextLineBreak(ctx, that.userInfo.fullName || that.userInfo.agencyName, mycenter - ctx.measureText(that.userInfo.fullName || that.userInfo.agencyName).width / 2, fubiaotiTop, 400 * 2, 20, "#fff", monthlyPaySize, "600"); // 代理名称

									if (that.checkedList.length == 1) {
										// roundRect1(ctx, mycenter - 600 / 2, baseTop + 750, 600, 560, 32, "#fff");
										// that.G.fillTextLineBreak(ctx, "长按查看职位详情", mycenter - ctx.measureText("长按查看职位详情").width / 2, baseTop + bottomSloganTop, 300 * 2, 20, "#fff", monthlyPaySize); // 底部slogan
										that.G.fillTextLineBreak(ctx, "长按查看职位详情", (canvas.width - ctx.measureText("长按查看职位详情").width) / 2.25, baseTop + bottomSloganTop1, ctx.measureText("长按查看职位详情").width + 100, 20, "#fff", titleSize); // 底部slogan
									} else {
										that.G.fillTextLineBreak(ctx, "长按查看职位详情", bottomSloganLeft, baseTop + bottomSloganTop, 300 * 2, 20, "#fff", monthlyPaySize + 8); // 底部slogan
										that.G.fillTextLineBreak(ctx, "好工作 放心干", bottomSloganLeft1, baseTop + bottomSloganTop1, 500 * 2, 20, "#fff", titleSize); // 底部slogan
									}
									imgres(canvas);
									//生成logo图片
									// uni.getImageInfo({
									// 	src: item.logo, //网络图片,如果不行请换一个
									// 	success(res) {
									// 		// console.log(res);

									// 		const img = canvas.createImage();
									// 		// console.log(ctx);
									// 		img.src = res.path;
									// 		img.onload = () => {
									// 			// setTimeout(() => {
									// 			that.G.roundRect(ctx, img, logoLeft, baseTop + 40 + baseMiddle * index, logoSize, logoSize, 8);
									// 			// }, 500);
									// 			if (index == that.checkedList.length - 1) {
									// 				setTimeout(() => {
									// 					imgres(canvas);
									// 				}, 100);
									// 			}
									// 		};
									// 	},
									// 	fail(err) {
									// 		console.log(err);
									// 	},
									// });
								});
							};
						} catch (error) {
							console.log("errorerrorerrorerror", error);
						}
					},
					fail(err) {
						console.log("err", err);
					},
				});

				// setTimeout(() => {
				// },500);
			});
		},
		/**
		 * 分享职位卡片
		 */
		setShareJobImg(ctx, canvas, funObj) {
			let that = this;
			return new Promise((imgres) => {
				// ctx.arcTo()
				let baseTop, logoLeft, titleSize, ageTop, salaryClassifyValueLeft, salaryClassifyValueTop, monthlyPaySize, roundRectHeight, fubiaotiTop;
				let baseMiddle = 175;
				baseTop = 204;
				logoLeft = 60;
				titleSize = 40;
				roundRectHeight = 156;
				ageTop = 62;
				salaryClassifyValueLeft = 56;
				salaryClassifyValueTop = 10;
				monthlyPaySize = 32;
				console.log(123);
        try {
          	that.checkedList.forEach((item, index) => {
					if (index <= 2) {
						let labelLeft = 0;
						console.log("item1", item);
						that.G.roundRect1(ctx, 32, baseTop - 60 + baseMiddle * index, 776, roundRectHeight, 24, "#fff");
						that.G.fillTextLineBreak(ctx, item.jobName, logoLeft, baseTop + baseMiddle * index, 800, 20, "#333", titleSize, "500"); // 岗位标题
						// 薪资位置更新(保留副本)
						// that.G.fillTextLineBreak(ctx, item.cus_price == "月薪" ? item.monthlyPay : item.salaryClassifyValue, salaryClassifyValueLeft + 500, baseTop - 10 + salaryClassifyValueTop + baseMiddle * index, 400, 20, "#ff4400", titleSize - 4, "600"); // 时薪
						that.G.fillTextLineBreak(ctx, item.cus_price == "月薪" ? item.monthlyPay : item.salaryClassifyValue, canvas.width - ctx.measureText(item.cus_price == "月薪" ? item.monthlyPay : item.salaryClassifyValue).width - 40 , baseTop + ageTop + baseMiddle * index, 400, 20, "#ff4400", titleSize - 4, "600"); // 时薪
						// setTimeout(() => {
						// that.G.fillTextLineBreak(ctx, item.monthlyPay, salaryClassifyValueLeft + ctx.measureText(item.salaryClassifyValue + " ").width, baseTop + salaryClassifyValueTop + baseMiddle * index, 400 , 20, "#ff4400", monthlyPaySize, "400"); // 月工资
						// }, 0);
						that.G.fillTextLineBreak(ctx, item.district, logoLeft, baseTop + ageTop + baseMiddle * index, 500, 20, "#999", monthlyPaySize); // 省市
						that.G.fillTextLineBreak(ctx, "丨" + item.age, logoLeft + ctx.measureText(item.district).width, baseTop + ageTop + baseMiddle * index, 500, 20, "#999", monthlyPaySize); // 年龄
					}
				});
				imgres(canvas);
        } catch (error) {
          console.log('error',error);
        }
				// setTimeout(() => {
				// },500);
			});
		},
		saveToalbum() {
			let that = this;
			uni.saveImageToPhotosAlbum({
				filePath: that.posterImg,
				success(res) {
					console.log(res);
					if (res.errMsg == "saveImageToPhotosAlbum:ok") {
						uni.showToast({
							title: "图片已保存",
							icon: "none",
							duration: 1500,
						});
					}
				},
				fail(res) {
					console.log(res);
					uni.showToast({
						title: "图片保存失败",
						icon: "none",
						duration: 1500,
					});
				},
			});
		},
		goDetail($item) {
			console.log("前往详情页", $item);
			if (this.isLogin) {
				uni.navigateTo({
					url: "/root/detail/work?id=" + $item.id,
				});
			} else {
				uni.navigateTo({
					url: "/root/login/index",
				});
			}
		},
		/**
		 * 筛选相关========================================================
		 */
		deleteSex() {
			console.log("deleteSex");
			this.getFilterData.sex = -1;
			this.getList();
		},
		deleteAge() {
			console.log("deleteAge");
			this.getFilterData.ageRangeStr = "";
			this.getList();
		},

		deleteJobCategoryLabel(id) {
			console.log(id);
			this.getFilterData.jobCategoryLabelObjects = this.getFilterData.jobCategoryLabelObjects.filter((obj) => obj.id != id);

			const idsArray = this.getFilterData.jobCategoryLabelObjects.map((obj) => obj.id);
			// 将数组转换为字符串
			this.getFilterData.jobCategoryLabelIds = idsArray.join(",");
			console.log("deleteJobCategoryLabel", this.getFilterData);

			this.getList();
		},
		deleteJobSpecialLabel(id) {
			this.getFilterData.jobSpecialLabelObjects = JSON.parse(JSON.stringify(this.getFilterData.jobSpecialLabelObjects.filter((obj) => obj.id != id)));
			const idsArray = this.getFilterData.jobSpecialLabelObjects.map((obj) => obj.id);
			// 将数组转换为字符串
			this.getFilterData.jobSpecialLabelIds = idsArray.join(",");
			console.log("deleteJobSpecialLabel", this.getFilterData);
			this.getList();
		},
		clearFilter1() {
			var that = this;
			this.getFilterData.jobCategoryLabelIds = "";
			this.getFilterData.jobSpecialLabelIds = "";
			this.getFilterData.jobCategoryLabelObjects = [];
			this.getFilterData.jobSpecialLabelObjects = [];
			this.getFilterData.sex = -1;
			this.getFilterData.ageRangeStr = "";
			console.log("this.getFilterData", this.getFilterData);
			this.$refs.filterChild.clearFilter();
			this.getList();

			// this.scrollTo = "";
			// setTimeout(() => {
			// 	that.scrollTo = "listBox";
			// 	console.log("aaaaaaaaa");
			// }, 1);
		},
		receiveFromChild(data) {
			console.log(data);
			this.whichOneShow = "";
			this.query.page = 1;
			this.getFilterData = JSON.parse(JSON.stringify(data));
			console.log("getFilterData in receiveFromChild", this.getFilterData);
			this.getList();
			// this.messageFromChild = data.message;
		},
		chooseNl(type) {
			let that = this;

			that.whichOneShow = that.whichOneShow == type ? "" : type;
			// that.scrollTo = "";
			// setTimeout(() => {
			// 	that.scrollTo = "tttop";
			// }, 1);
		},
	},
};
</script>

<style lang="scss" scoped>
.p-root-sharejob {
	// display: flex;
	// flex-direction: column;
	// height: calc(100vh - 20px);
	overflow: auto;
	// .g-components-panel-fixed {
	// 	border-top: 1rpx solid #fff;
	// }
	.m-search {
		position: sticky;
		top: 0;
		// background: #f5f5f5;
		z-index: 999;
	}
	.shareBottom {
		position: fixed;
		bottom: 0px;
		width: 100vw;
		height: 74px;
		padding: 0 14px;
		padding-bottom: 20px;
		background-color: #fff;
		box-sizing: border-box;
		border-top: 1px solid #eee;
		z-index: 9999;
		box-sizing: border-box;
		button {
			width: 80px;
			height: 32px;
			padding: 0;
			font-size: 14px;
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 0;
			font-weight: bold;
			margin-left: 10px;
			border-radius: 99px;
			border: 1px solid v-bind("globalData.themeColor");
			background-color: #fff;
			color: v-bind("globalData.themeColor");
		}
		> div {
			margin-top: -16px;
		}
		.ban {
			border-color: transparent;
			background-color: #ededed;
			color: #999;
		}
		.btnHover {
			background-color: v-bind("globalData.themeColor");
			color: #fff;
		}
	}
}
.posterImg {
	height: 75vh;
	width: calc(75vh * 0.52);
}
.csbf {
	padding: 0px 8px;
	height: 28px;
	background-color: #ededed;
	border-radius: 16px;
	text-align: center;
	font-size: 14px;
	font-weight: 400;
	color: #333333;
	line-height: 28px;
	box-sizing: border-box;
	// margin-top: 6px;
	margin-right: 12px;
}
.sticky {
	position: sticky;
	top: 0px;
	left: 0;
	z-index: 999;
}
.sortMask {
	position: absolute;
	top: 105px;
	left: 0;
	width: 100vw;
	height: 100vh;
	z-index: 999999;
	background-color: rgba(0, 0, 0, 0.8);
}
.filterContainer {
	min-height: 60vh !important;
}
</style>
