<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(${navInfo.windowHeight}px)` }" :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-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"></g-tabs>
						</view>
						<!-- <view v-if="isMember && hasPermission" class="g_mr_8" @click="goShare"> 批量分享 </view> -->

						<view class="g_flex_row_end flex_center g_flex_1">
							<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_f' : 'g_border_f'" class="g_fs_16 g_fw_600 g_mt_16 g_bg_f" :style="sortList.active == index ? {color: globalData.themeColor, borderColor: globalData.themeColor, border: '1px solid ' + globalData.themeColor} : {}" 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" containerHeight="60vh" top="110px" :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 class="specialTag" wx:if="{{selectJobList.length > 0}}">
                  <block wx:for="{{selectJobList}}" wx:key="index">
                    <div class="por" catchtap="deleteMark" data-item="{{item}}">
                      {{item.name}}
                      <div class="clear_icon iconfont icon-qingchu"></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-yi-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 :style="{color: globalData.themeColor}">{{ 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>
				<rh-button btnText="保存到相册" type="primary" class="g_mt_32" @clickBtn="saveToalbum"></rh-button>
			</div>
		</u-popup>
	</view>
</template>

<script>
import _G from "./utils/commonSub.js";
import mfilter from "../../pages/home/child/filter";

export default {
	components: {
		mfilter,
	},
	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);
						wx.hideLoading();
						resolve({
							title: "你想找的厂都有，立即查看??",
							imageUrl: res.tempFilePath,
							path: `/root/detail/shareList?scene=i=${arr.join("_")},u=${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: "全部",
						classify: 0,
					},
					{
						name: "推荐",
						classify: 1,
					},
					{
						name: "收藏",
						classify: 2,
					},
					// {
					// 	name: "附近",
					// 	num: 0,
					// 	tip: 2,
					// 	classify: 2,
					// },
				],
				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://bocai-cms.oss-cn-beijing.aliyuncs.com/web-resource/1shoudan/poster0106.png", // 分享职位基础图片
			sharelImg: "https://bocai-cms.oss-cn-beijing.aliyuncs.com/web-resource/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 = wx.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,
				keys: that.keyword,
				ujc: that.query.ujc,
				sortTag: that.query.sortTag,
				recruitment: 1,
				classify: 1,
				workTypeStr: "",
				jobClassify: "",
				cityName: that.selectedCity == "全国" ? "" : that.selectedCity,
				brandIds: "",
				checkStore: true
			};
			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.yi_job_list, params, (res) => {
				uni.hideLoading();
				console.log("一才职位列表：", res);
				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);
				}
				res.pageBean.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.pageBean.recordList.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),
							recruitmentValue: item.recruitment == 1 ? true : false,
							fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
						};
					});
				} else {
					that.query.list = that.query.list.concat(
						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) : "月薪",
								salaryClassifyValue: item.salaryClassify != 7 ? that.G.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue) : "月薪",
								// jobDesp: item.jobDesp.replaceAll("*****", "").split("————————")[0],
								gender: that.G.getGenderByMinAge(item),
								recruitmentValue: item.recruitment == 1 ? true : false,
								fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
							};
						}),
					);
				}
			});
		},
		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() {
			let that = this;
			if (this.checkedList.length > 0) {
				let str = "";
				that.G.Get(that.api.yi_job_select_field, { id: that.checkedList.map((item) => item.id).join(","), field: "jobInfoWithoutReturnFee" }, (res) => {
					str = res.map((item) => item.jobInfoWithoutReturnFee).join("\n");
					wx.setClipboardData({
						data: str,
						success(res) {
							wx.showToast({
								title: "通告内容已复制",
								icon: "none",
								duration: 1500,
							});
							// wx.getClipboardData({
							// 	success(res) {
							// 		console.log(res.data); // data

							// 	},
							// });
						},
					});
					// console.log("resresresresresres", res);
				});

				return;
				this.checkedList.forEach((item, index) => {
					console.log(item);
					let subStr;
					if (item.jobInfoWithoutReturnFee) {
						subStr = item.jobInfoWithoutReturnFee;
					}
					str += subStr;
				});
				wx.setClipboardData({
					data: str,
					success(res) {
						wx.getClipboardData({
							success(res) {
								console.log(res.data); // data
								wx.showToast({
									title: "通告内容已复制",
									icon: "none",
									duration: 1500,
								});
							},
						});
					},
				});
			}
		},
		/**
		 * 分享海报生成海报图并转发
		 */
		sharePoster() {
			console.log(this.checkedList);
			if (this.checkedList.length == 0 || this.checkedList.length > 3) {
				return;
			}
			wx.showLoading({
				title: "生成中...",
			});

			this.getCode().then((res) => {
				setTimeout(() => {
					this.getCanvas(this.sharelImg, "setShare").then((res) => {
						console.log(res);
						wx.hideLoading();
						this.posterImg = res.tempFilePath;
						this.$forceUpdate();
						this.posterShow = true;
					});
				}, 10);
			});
			// this.setData({
			// });
		},
		getCode() {
			var that = this;
			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(",") }, (res) => {
					console.log(res);
					that.currCode = res.qrcode;
					resolve();
				});
				// }
			});
		},
		getCanvas(sharelImg, type) {
			const that = this;
			console.log(sharelImg);
			return new Promise((resolve) => {
				var mycenter = 0; //文字左右居中显示
				var myheight = 0; //文字高度
				const query = wx.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) {
							// 绘制背景图片
							wx.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(() => {
							const fillTextLineBreak = (ctx, text, x, y, lw, lh, color = "#333", font = "32", weight = "500") => {
								var i = 0;
								var n = 0;
								var r = -1;
								var initHeight = 0;
								ctx.font = weight + " " + font + "px Arial"; //字体大小
								console.log("text", text);
								ctx.fillStyle = color; //字体颜色
								while (i < text.length) {
									while (ctx.measureText(text.substring(n, i)).width < lw && i < text.length) {
										i++;
									}
									r++;
									ctx.fillText(text.substring(n, i), x, y + lh * r);
									n = i;
								}
								initHeight = lh * r;
								// wx.setStorageSync("initHeight", initHeight);
							};
							const roundRect = (ctx, img, bg_x, bg_y, bg_w, bg_h, bg_r) => {
								// 开始绘制
								ctx.save();
								ctx.beginPath();
								ctx.arc(bg_x + bg_r, bg_y + bg_r, bg_r, Math.PI, Math.PI * 1.5);
								ctx.arc(bg_x + bg_w - bg_r, bg_y + bg_r, bg_r, Math.PI * 1.5, Math.PI * 2);
								ctx.arc(bg_x + bg_w - bg_r, bg_y + bg_h - bg_r, bg_r, 0, Math.PI * 0.5);
								ctx.arc(bg_x + bg_r, bg_y + bg_h - bg_r, bg_r, Math.PI * 0.5, Math.PI);
								ctx.clip();
								ctx.drawImage(img, bg_x, bg_y, bg_w, bg_h);
								// 恢复之前保存的绘图上下文
								ctx.restore();
							};
							const roundRect_yuan = (ctx, x, y, size) => {
								// 开始绘制
								ctx.save(); // 保存
								ctx.beginPath(); // 开始绘制
								// ctx.arc(100, 75, 50, 0, 2 * Math.PI)
								ctx.arc(size / 2 + x, size / 2 + y, size / 2, 0, Math.PI * 2, false);
								ctx.clip();
								// 恢复之前保存的绘图上下文
								ctx.restore();
							};
							function roundRect1(ctx, x, y, w, h, r, color) {
								//绘制圆角矩形(无填充色))
								ctx.save();
								ctx.fillStyle = color;
								ctx.strokeStyle = color;
								ctx.lineJoin = "round"; //交点设置成圆角
								ctx.lineWidth = r;
								ctx.strokeRect(x + r / 2, y + r / 2, w - r, h - r);
								ctx.fillRect(x + r, y + r, w - r * 2, h - r * 2);
								ctx.stroke();
								ctx.closePath();
							}
							//使用：
							console.log(canvas);
							if (type == "setJob") {
								this.setShareJobImg(ctx, canvas, { roundRect1, roundRect_yuan, roundRect, fillTextLineBreak })
									.then(function (canvas1) {
										wx.canvasToTempFilePath({
											canvas: canvas1,
											success(res) {
												console.log(res);
												resolve(res);
											},
											fail(res) {
												wx.hideLoading();
												wx.showToast({
													title: res.errMsg,
													icon: "error",
												});
											},
										});
									})
									.catch((err) => {
										console.log(err);
										wx.hideLoading();
										wx.showToast({
											title: "生成失败,请重试",
										});
									});
							} else if (type == "setShare") {
								this.setShareImg(ctx, canvas, mycenter, { roundRect1, roundRect_yuan, roundRect, fillTextLineBreak })
									.then(function (canvas1) {
										wx.canvasToTempFilePath({
											canvas: canvas1,
											success(res) {
												console.log(res);
												resolve(res);
											},
											fail(res) {
												wx.hideLoading();
												wx.showToast({
													title: res.errMsg,
													icon: "error",
												});
											},
										});
									})
									.catch((err) => {
										console.log(err);
										wx.hideLoading();
										wx.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 * 110;
					QRLeft = 880;
					QRTop = 1380;
				}
				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);
				wx.getImageInfo({
					// src: "https://bocai-cms.oss-cn-beijing.aliyuncs.com/web-resource/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) {
									_G.roundRect1(ctx, mycenter - 580 / 2, baseTop + 740, 580, 580, 0, "#fff");
									// roundRect1(ctx, mycenter - 600 / 2, baseTop + 750, 600, 560, 0, "#fff");
									_G.roundRect(ctx, img, mycenter - res.width / 2 - 120, baseTop + 770, QRSize, QRSize, 0);
									// _G.roundRect(ctx, img, mycenter - res.width / 2 - 120, baseTop + 770, QRSize, QRSize, 0);
								} else {
									// _G.roundRect1(ctx, QRLeft - 10, baseTop + QRTop - 10, QRSize + 20, QRSize + 20, 0, "#fff");
									_G.roundRect(ctx, img, QRLeft, baseTop + QRTop, QRSize + 40, QRSize + 40, 0);
								}
								that.checkedList.forEach((item, index) => {
									let labelLeft = 0;
									console.log("item2", item);
									_G.roundRect1(ctx, 24 * 2, baseTop - 100 + baseMiddle * index, 1104, roundRectHeight, 32, "#fff");
									item.jobSpecialLabelNameArray.forEach((item1, index1) => {
										if (index1 < 4) {
											_G.fillTextLineBreak(ctx, item1, 60 * 2 + labelLeft, baseTop + markTop + 30 * 2 + baseMiddle * index, 400 * 2, 20, "#333", monthlyPaySize); // 标签字符
											_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;
										}
									});

									_G.fillTextLineBreak(ctx, item.jobName.length > 16 ? item.jobName.slice(0, 16) + "..." : item.jobName, logoLeft, baseTop + baseMiddle * index, 500 * 2, 20, "#333", titleSize, "600"); // 岗位标题
									// _G.fillTextLineBreak(ctx, item.jobName, logoLeft, baseTop + baseMiddle * index, 500 * 2, 20, "#333", titleSize, "600"); // 岗位标题

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

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

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

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

									_G.fillTextLineBreak(ctx, that.appInfo.fullName || that.appInfo.agencyName, mycenter - ctx.measureText(that.appInfo.fullName || that.appInfo.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");
										// _G.fillTextLineBreak(ctx, "长按查看职位详情", mycenter - ctx.measureText("长按查看职位详情").width / 2, baseTop + bottomSloganTop, 300 * 2, 20, "#fff", monthlyPaySize); // 底部slogan
										_G.fillTextLineBreak(ctx, "长按查看职位详情", mycenter - ctx.measureText("长按查看职位详情").width / 1.45, baseTop + bottomSloganTop1, 500 * 2, 20, "#fff", titleSize); // 底部slogan
									} else {
										_G.fillTextLineBreak(ctx, "长按查看职位详情", bottomSloganLeft, baseTop + bottomSloganTop, 300 * 2, 20, "#fff", monthlyPaySize + 8); // 底部slogan
										_G.fillTextLineBreak(ctx, "好工作 放心干", bottomSloganLeft1, baseTop + bottomSloganTop1, 500 * 2, 20, "#fff", titleSize); // 底部slogan
									}
									imgres(canvas);
									//生成logo图片
									// wx.getImageInfo({
									// 	src: item.logo, //网络图片,如果不行请换一个
									// 	success(res) {
									// 		// console.log(res);

									// 		const img = canvas.createImage();
									// 		// console.log(ctx);
									// 		img.src = res.path;
									// 		img.onload = () => {
									// 			// setTimeout(() => {
									// 			_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;
			uni.showLoading({
				title: "生成中...",
			});
			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);
							_G.roundRect1(ctx, 32, baseTop - 60 + baseMiddle * index, 776, roundRectHeight, 24, "#fff");
							_G.fillTextLineBreak(ctx, item.jobName.length > 15 ? item.jobName.slice(0, 15) + "..." : item.jobName, logoLeft, baseTop + baseMiddle * index, 800, 20, "#333", titleSize, "500"); // 岗位标题
							// _G.fillTextLineBreak(ctx, item.jobName, logoLeft, baseTop + baseMiddle * index, 800, 20, "#333", titleSize, "500"); // 岗位标题
							// 薪资位置更新(保留副本)
							// _G.fillTextLineBreak(ctx, item.cus_price == "月薪" ? item.monthlyPay : item.salaryClassifyValue, salaryClassifyValueLeft + 500, baseTop - 10 + salaryClassifyValueTop + baseMiddle * index, 400, 20, "#ff4400", titleSize - 4, "600"); // 时薪
							_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(() => {
							// _G.fillTextLineBreak(ctx, item.monthlyPay, salaryClassifyValueLeft + ctx.measureText(item.salaryClassifyValue + " ").width, baseTop + salaryClassifyValueTop + baseMiddle * index, 400 , 20, "#ff4400", monthlyPaySize, "400"); // 月工资
							// }, 0);
							_G.fillTextLineBreak(ctx, item.district, logoLeft, baseTop + ageTop + baseMiddle * index, 500, 20, "#999", monthlyPaySize); // 省市
							_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/job?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>
