<template>
	<view class="p-person-inedx g_w_all g_bg_f_5 g_kuaishou" :style="{ minHeight: `calc(100vh - ${tabbarHeight}px)` }">
		<view class="g_h_10"></view>
		<!-- 基本信息 -->
		<view style="" class="">
			<g-panel-card-info
				:info="{
					avatar: userInfo.avatar ? userInfo.avatar : svgBaseImg + 'defaultAva.svg',
					title: userInfo.name,
					num: userInfo.tel,
					isHaveOrder: false,
				}"
				@clickCard="goPage('/root/person/info')"
			/>
		</view>
		<view class="g_mt_10" v-if="isJm"
				  style="background-color: #fff;border-radius: 8px;overflow: hidden;width: calc(100% - 20px);margin: 10px auto;"
		>
			<div class="g_flex_row_between" @click="goPage('/root/bind/fensi')">
				<div class="g_flex_none g_flex_column_center" style="padding-left: 10px;height: 56px;">
					<i class="iconfont g_fs_24 g_mr_5 icon-index" style="color: #333;"></i>
				</div>
				<div class="g_flex_1 g_flex_row_between" style="border-bottom: 0.5px solid #eee;">
					<div class="g_flex_none g_flex_column_center" style="color: #000;font-size: 17px;">
						下游代理
					</div>
					<div class="g_flex_1 g_flex_column_center" style="padding-right: 10px;">
						<div class="g_flex_row_end">
							<div class="g_flexx_1 g_flex_column_center" style="color: #999;font-size: 17px;height: 56px;" v-if="downCount">
								{{ downCount }}家
							</div>
							<div class="g_flex_none g_flex_column_center" style="height: 56px;">
								<i class="iconfont icon-gengduo11" style="color: #ccc;"></i>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="g_flex_row_between" @click="goPage('/root/bind/search?active=1')">
				<div class="g_flex_none g_flex_column_center" style="padding-left: 10px;height: 56px;">
					<i class="iconfont g_fs_24 g_mr_5 icon-addteam" style="color: #333;"></i>
				</div>
				<div class="g_flex_1 g_flex_row_between">
					<div class="g_flex_none g_flex_column_center" style="color: #000;font-size: 17px;">
						发展代理
					</div>
					<div class="g_flex_1 g_flex_column_center" style="padding-right: 10px;">
						<div class="g_flex_row_end">
							<div class="g_flexx_1 g_flex_column_center" style="color: #999;font-size: 17px;height: 56px;">
								 邀请更多代理关注我
							</div>
							<div class="g_flex_none g_flex_column_center" style="height: 56px;">
								<i class="iconfont icon-gengduo11" style="color: #ccc;"></i>
							</div>
						</div>
					</div>
				</div>
			</div>
		</view>
		<view class="g_mt_10" v-if="isJm">
			<g-panel-poster-card :list="poastList" cardType="img" titleNav="/root/person/posterShare" subhead="更多" :speed="1" :marginBottom="16" :num="4" cusTitle="分享海报" @clickImg="clickImg" @clickItem="titleNavigator" />
		</view>
		<view class="g_mt_10 g_position_rela u-skeleton" v-if="applystatys == 1">
			<g-panel-form-item
				:list="[
					{
						icon: 'block',
						label: '申请成为代理',
						result: '已提交',
						path: '/root/bind/applyForm?code=' + agencyCode + '&foa=1',
						pRow: 0,
						rpl:0,
						fpl:0,
						itype: 'icon',
						pColumn:16,
					},
				]"
				@clickItem="goPaga('/root/bind/applyForm?code=' + agencyCode + '&foa=1')"
			/>
		</view>
		<view class="g_mt_10" v-if="userInfo.agencyId">
			<g-panel-card-num :list="billDataList" titleNav="/root/person/applyIndex" :border="true" :speed="1" :marginBottom="16" cusType="num" :height="26" :num="5" cusTitle="报名工单(我报的)" @clickItem="goOrder" />
		</view>
		<view class="g_mt_10" v-if="!userInfo.agencyId && isLogin">
			<g-panel-form-item
				:list="[
					{
						icon: 'folder-add',
						label: '申请关注',
						result: '',
						path: '',
						tip: 'set',
						pRow: 0,
						rpl:0,
						fpl:0, 
						pColumn:16,
					},
				]"
				@clickItem="handleOpenForm"
			/>
		</view>
		<view class="g_mt_10" style="margin-top: 24px;">
			<g-panel-form-item
				:list="[
					{
						icon: 'edit-square',
						label: '反馈与建议',
						result: '',
						path: '/root/person/feedback',
						tip: 'set',
						pRow: 0,
						rpl:0,
						fpl:0,
						pColumn:16,
					},
				]"
				@clickItem="goPage('/root/person/feedback')"
			/>
		</view>

		<view class="g_mt_10">
			<g-panel-form-item
				:list="[
					{
						icon: 'setting',
						label: '设置',
						result: '',
						path: '/root/person/set',
						tip: 'set',
						pRow: 0,
						rpl:0,
						fpl:0,
						pColumn:16,
					},
				]"
				@clickItem="goPage('/root/person/set')"
			/>
		</view>
		<view class="g_mt_10" v-if="isAdmin && isfdb">
			<g-panel-form-item
				:list="[
					{
						icon: 'laptop',
						label: '演示模式',
						result: demoModeEnabled ? '已开启' : '',
						path: '/root/person/config',
						tip: 'set',
						pRow: 0,
						rpl:0,
						fpl:0,
						pColumn:16,
					},
				]"
				@clickItem="goPage('/root/person/config')"
			/>
		</view>
		<view class="g_mt_24 g_position_rela u-skeleton" v-if="userInfo.admin || isTeamleader">
			<view class="g_radius_50 g_text_c" style="position: absolute; right: 16px; top: 5px; color: #fff; background-color: #ff4400; font-size: 12px; min-width: 16px" v-if="applyNum > 0">
				{{ applyNum }}
			</view>
			<g-panel-form-item
				:list="[
					{
						icon: 'team',
						label: '我的团队',
						result: agencyInfo.fullName || agencyInfo.agencyName || '设置企业信息',
						path: '/root/person/teamManage',
						pRow: 0,
						rpl:0,
						fpl:0,
						itype: 'icon',
						pColumn:16,
					},
				]"
				@clickItem="goPage('/root/merchantManagement/teamManage')"
			/>
		</view>
		<view class="g_bg_f g_h_56 g_ml_12 g_mr_12 g_mt_24 g_radius_8 g_flex_row_center flex_center g_position_rela" 
				  @click="goPage('/root/merchantManagement/merchantManagement')" hover-class="thover" 
					v-if="isAdmin"
		>
			<view class="iconfont icon-shangjiahoutai g_mr_6 g_mt_2"></view>
			<view class="g_fw_600 g_fs_17">商家管理后台</view>
			<view v-if="hasNewResume > 0" class="g_ml_4" style="font-size: 12px; color: #ffffff; background-color: #fa3534; display: inline-flex; justify-content: center; align-items: center; line-height: 24rpx; padding: 4rpx 8rpx; border-radius: 100rpx; z-index: 9">
				{{ hasNewResume }}
			</view>
			<!-- <u-badge v-if="hasNewResume > 0" :offset="[20, 200]" :count="hasNewResume"></u-badge> -->
		</view>

		<view class="g_h_100"></view>
		<u-popup v-model="posterShow" mode="center" :closeable="true" uZindex="9999" width="90%" height="87%" border-radius="12" :mask-close-able="true" @close="currentImg = ''">
			<div v-if="currentImg" class="g_pt_36 g_pb_12 g_text_c g_position_abso" style="height: calc(100% - 66px); width: 100%; box-sizing: border-box; left: 0%; top: 0px; z-index: 999">
				<view class="fakerClose g_w_36 g_h_36" style="position: absolute; top: 0; right: 0; z-index: 999" @click="posterShow = false"></view>
				<image class="g_position_abso" style="height: 92%; left: 50%; top: 36px; transform: translateX(-50%)" :show-menu-by-longpress="true" :src="currentImg" mode="aspectFit" lazy-load binderror="" bindload=""> </image>
			</div>
			<!-- v-else  -->
			<div class="g_w_all g_flex_row_center g_pt_36 g_pb_12" style="height: calc(100% - 56px); box-sizing: border-box">
				<div class="g_position_rela" style="height: 100%; aspect-ratio: 9 / 16">
					<img :src="fakeImg" class="g_h_all g_w_all" alt="" />
					<div class="g_position_abso g_bg_f g_radius_6 g_flex_row_between flex_center" style="width: 94%; height: 18%; padding: 0 4%; transform: translateX(-50%); left: 50%; bottom: 3%; box-sizing: border-box">
						<div class="g_flex_row_start flex_center g_flex_1 g_h_all">
							<!-- <img style="width: 17%; height: 40%" :src="miniAppInfo.logo || 'https://matripe.oss-cn-beijing.aliyuncs.com/default.png'" alt="" /> -->
							<div class="g_ml_4 g_c_6">
								<div class="g_fw_600" :style="{ fontSize: '100%' }">
									{{ miniAppInfo.fullName || miniAppInfo.agencyName }}
								</div>
								<div :style="{ fontSize: '60%' }">
									{{ miniAppInfo.slogan || "为劳动者创造价值" }}
								</div>
							</div>
						</div>
						<img style="width: 22%; height: 60%" :src="miniAppInfo.qrCode" alt="" />
					</div>
				</div>
			</div>
			<div class="g_flex_row_center">
				<rh-button :btnText="fakeImg ? '生成中...' : '保存图片'" :loading="fakeImg ? true : false" @clickBtn="saveImg" type="primary" size="160" class="" />
				<!-- <rh-button  btnText="保存图片" @clickBtn="saveImg" type="primary" size="160" class="" /> -->
				<!-- <rh-button  btnText="分享图片" size="small" class="" /> -->
			</div>
		</u-popup>
		<canvas type="2d" style="position: absolute; left: -2000px; width: 425px; height: 350px; background: #fff" id="canvasId" ref="canvasId"></canvas>
	</view>
	<!-- <g-tabbar class="tabbar" :isShow="tabbarShow"></g-tabbar> -->
</template>

<script>
export default {
	onShareAppMessage() {
		let that = this;
		let path;
		path = `/pages/person/index`;
		let appInfo = uni.getStorageSync("miniApp-info");
		return {
			title: appInfo.slogan || "为劳动者创造价值",
			imageUrl: appInfo.sharePoster,
			path,
		};
	},
	onShareTimeline() {
		let that = this;
		let appInfo = uni.getStorageSync("miniApp-info");
		return {
			title: appInfo.slogan || "为劳动者创造价值",
			imageUrl: appInfo.logo,
		};
	},
	onReady() {},
	data() {
		return {
			isfdb:uni.getAccountInfoSync().miniProgram.appId == 'wxfab5320942daaafa',
			downCount: 0,
			poastList: [],
			appdatas:{},
			agencyCode:'',
			applystatys:null,
			isJm:uni.getStorageSync("apply-userinfo") && uni.getStorageSync("apply-userinfo").agencyId && uni.getStorageSync("apply-userinfo").agencyId == '114827',
			demoModeEnabled: uni.getStorageSync("DEMO_MODE_ENABLED") || false,
			themeColor: getApp().globalData.themeColor,
			themeBackgroundColor: getApp().globalData.themeBackgroundColor,
			applyNum: 0,
			agencyInfo: {}, // 登陆者的代理信息
			isTeamleader: uni.getStorageSync("is_teamleader"), // 部门管理员判断
			tabbarShow: true,
			fakeImg: "", // 站位虚拟分享图
			posterShow: false, // 海报分享弹窗
			currentImg: "", // 海报分享临时图片
			tabbarHeight: uni.getStorageSync("TABBAR_HEIGHT"),
			hasNewResume: 0,
			isAdmin: uni.getStorageSync("IS_MINIAPP_ADMIN"),
			hasPermission: uni.getStorageSync("HAS_PERMISSION") == 1 ? true : false, // 登陆者是否有权限查看
			miniAppInfo: uni.getStorageSync("miniApp-info"),
			pageSpeed: -1,
			isLogin: null,
			localBaseImg: this.G.store().localBaseImg,
			cdnBaseImg: this.G.store().cdnBaseImg,
			svgBaseImg: this.G.store().svgBaseImg,
			speed: -1,
			navInfo: {},
			userInfo: {
				all: {},
				avatar: "",
				name: "微信用户",
				tel: "全心全意为老乡服务",
				num: [
					{
						name: "",
						num: "",
					},
				],
				agencyName: "",
				teamType: 0,
			},
			map: { num10: "0", num20: "0", num25: "0", num30: "0", num40: "0", num999: "0", user999: "0", user40: "0", user48: "0", user50: "0", agencyData: {} },

			billDataList: [
				{
					name: "审核中",
					num: 0,
					type: 1,
					path: "/root/person/applyIndex?status=1",
				},
				{
					name: "待接待",
					num: 0,
					type: 2,
					path: "/root/person/applyIndex?status=2",
				},
				{
					name: "待面试",
					num: 0,
					type: 3,
					path: "/root/person/applyIndex?status=3",
				},
				{
					name: "待入职",
					num: 0,
					type: 4,
					path: "/root/person/applyIndex?status=4",
				},
				{
					name: "在职中",
					num: 0,
					type: 5,
					path: "/root/person/applyIndex?status=5",
				},
			],
		};
	},
	onLoad() {
		let that = this;
		that.navInfo = that.G.getNavInfo();
		if (uni.getStorageSync("apply-token")) {
			that.G.checkToken();
		}
	},
	onShow() {
		let that = this;
		that.demoModeEnabled = uni.getStorageSync("DEMO_MODE_ENABLED") || false;
		if (uni.getStorageSync("apply-token")) {
			that.G.checkToken().then(() => {
				that.agencyInfo = uni.getStorageSync("agencyInfo");
				that.setUserInfo();
				that.getResumeInfo();
				that.getData();
				that.getinfoByLogin();
				that.getPoastList();
				that.G.Post(
				that.api.bind_list,
					{
						pageNum: 1,
						pageSize: 1,
						keys: '',
						platform: "pc",
						type: 2,
						formdata: true,
					},
					(downRes) => {
						that.downCount = downRes.recordCount;
					}
				);
			});
		} else {
			that.pageSpeed = 1;
			that.isLogin = false;
			that.userInfo.avatar = that.G.store().svgBaseImg + "defaultAva.svg";
			that.userInfo.name = "微信用户";
			that.userInfo.tel = that.miniAppInfo.slogan || "为劳动者创造价值";
			// that.userInfo.tel = "钱多 活少 离家近";
			that.userInfo.agencyName = "";
			that.userInfo.teamType = 0;
			that.speed = 0;
		}
	},
	methods: {
		getPoastList() {
			let that = this;
			that.G.Post(`/poster/getList`, { pageNum: 1, pageSize: 50, classify: 1 }, (res) => {
				console.log("resresresresres", res);
				that.poastList = res
					.filter((item, index) => {
						if (index <= 3) {
							return item;
						}
					})
					.map((item) => {
						return {
							url: item.img,
						};
					});
				that.showPoast = true;
				console.log("that.poastList", that.poastList);
			});
		},
		clickImg(_item) {
			if (uni.getStorageSync("user_qrcode")) {
				this.miniAppInfo.qrCode = uni.getStorageSync("user_qrcode");
			}
			this.getPoster(_item.url);
		},
		titleNavigator(e) {
			uni.navigateTo({
				url: e.item.path,
			});
		},
		getPoster(e) {
			const that = this;
			this.fakeImg = e;
			that.posterShow = true;
			// uni.showLoading({
			// 	title: "生成中...",
			// 	mask: true,
			// });
			try {
				// #ifdef  APP-PLUS
				that.getAppCanvas(e);

				// .then((res) => {});
				// #endif
				// #ifdef  MP-WEIXIN
				that.getWXCanvas(e).then((res) => {
					console.log("res", res);
					that.currentImg = res.tempFilePath;
					setTimeout(() => {
						this.fakeImg = "";
					}, 200);
					uni.hideLoading();
				});
				// #endif
			} catch (error) {
				uni.showToast({
					title: "生成失败，请重试",
					icon: "none",
				});
				uni.hideLoading();
				that.posterShow = false;
				console.log("error", error);
			}
		},
		// App端绘制
		getAppCanvas(sharelImg, type) {
			let that = this,
				ctx = uni.createCanvasContext("text");
			console.log("this.miniAppInfo.qrCodethis.miniAppInfo.qrCodethis.miniAppInfo.qrCode", this.miniAppInfo.qrCode);
			new Promise(function (resolve) {
				// 绘制背景图片
				uni.downloadFile({
					url: sharelImg,
					success: function (bgRes) {
						uni.getImageInfo({
							src: bgRes.tempFilePath, // 网络图片
							success(res) {
								let mycenter = res.width;
								let _height = res.height;
								that.canvasWidth = res.width;
								that.canvasHeight = res.height;
								ctx.drawImage(bgRes.tempFilePath, 0, 0, mycenter, _height);
								console.log("bgResbgResbgResbgResbgRes", bgRes);

								// ctx.drawImage(bgRes.tempFilePath, 0, 0, mycenter, _height);
								uni.downloadFile({
									url: that.miniAppInfo.qrCode,
									success: function (QRres) {
										console.log("QRresQRresQRresQRresQRres", QRres);
										let baseTop, QRSize, baseLeft, titleFontSize, contentFontSize;
										baseTop = _height - 412;
										// baseTop = 1470;
										QRSize = 144;
										baseLeft = 80;
										titleFontSize = 54;
										contentFontSize = 36;
										that.G.roundRect1(ctx, 30, baseTop, mycenter - 60, 360, 48, "#fff");
										that.G.fillTextLineBreak(ctx, that.miniAppInfo.fullName || that.miniAppInfo.agencyName, baseLeft + 20, baseTop + 162, 300, 64, "#000", titleFontSize, "500"); // 代理名字
										let slogan = that.miniAppInfo.slogan || "为劳动者创造价值";
										that.G.fillTextLineBreak(ctx, slogan, baseLeft + 20, baseTop + 168 + titleFontSize, 600, 48, "#666", contentFontSize, "500"); // slogan
										that.G.roundRect(ctx, QRres.tempFilePath, mycenter - 320, baseTop + 60, 240, 240, 0);
										ctx.restore();
										ctx.draw(false, () => {
											setTimeout(function () {
												that.endAppCanvas(ctx, mycenter, _height);
											}, 50);
										});
									},
								});
								// uni.downloadFile({
								// 	url: info.logo,
								// 	success: function (bgRes) {
								// 		that.G.roundRect(ctx, bgRes.tempFilePath, 915, 218, 272, 272, 136); // logo
								// 	},
								// });
							},
							fail(err) {},
						});
					},
				});
			}).then(() => {});
		},
		endAppCanvas(ctx, _width, _height) {
			let that = this;
			uni.canvasToTempFilePath({
				x: 0,
				y: 0,
				width: _width,
				height: _height,
				canvasId: "text",
				success: function (pathRres) {
					const savedFilePath = pathRres.tempFilePath; //相对路径
					const path = plus.io.convertLocalFileSystemURL(savedFilePath); //绝对路径
					console.log("path", path);
					that
						.getBase64FromFile(path)
						.then((res) => {
							console.log("resresres", res);
							that.currentImg = res;
							that.appfile = savedFilePath;
							setTimeout(() => {
								that.fakeImg = "";
							}, 200);
							uni.hideLoading();
						})
						.catch((err) => {
							console.log("err", err);
						});
					// const fileReader = new plus.io.FileReader();
					// fileReader.readAsDataURL(path);
					// fileReader.onloadend = (res) => {
					// 	console.log("resresresresres", res);
					// 	that.currentImg = path;
					// 	that.appfile = savedFilePath;
					// 	setTimeout(() => {
					// 		that.fakeImg = "";
					// 	}, 200);
					// 	uni.hideLoading();
					// };
				},
			});
		},
		getBase64FromFile(path) {
			return new Promise((resolve, reject) => {
				plus.io.resolveLocalFileSystemURL(
					path,
					(entry) => {
						console.log("entry", entry);
						entry.file((file) => {
							let reader = new plus.io.FileReader();
							reader.onloadend = function (e) {
								console.log("eeeeee", e);
								// 结果为 "data:image/png;base64,xxx..." 格式
								resolve(e.target.result);
							};
							reader.onerror = function (e) {
								reject("读取失败：" + e.message);
							};
							// 关键：使用 readAsDataURL 生成 Base64
							reader.readAsDataURL(file);
						}, reject);
					},
					reject,
				);
			});
		},
		// 微信端绘制
		getWXCanvas(sharelImg, type) {
			const that = this;

			return new Promise((resolve) => {
				var mycenter = 0; //文字左右居中显示
				var myheight = 0; //文字高度
				const query = uni.createSelectorQuery().in(this);
				query
					.select("#canvasId")
					.fields({
						node: true,
						size: true,
					})
					.exec((res) => {
						console.log("uni 获取节点信息：", res);
						console.log("sharelImg", sharelImg);
						const canvas = res[0].node;
						const ctx = canvas.getContext("2d");
						new Promise(function (res) {
							// 绘制背景图片
							uni.getImageInfo({
								src: sharelImg, // 网络图片
								success(res) {
									console.log("res111", res);
									canvas.width = res.width;
									canvas.height = res.height;
									mycenter = canvas.width / 2;
									myheight = canvas.height;
									const img = canvas.createImage();
									img.src = res.path;
									console.log("img111", img);
									img.onload = (info) => {
										ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
										console.log("info111", info);
										that
											.setShareJobImg(ctx, canvas, mycenter)
											.then(function (canvas1) {
												console.log("canvas1", canvas1);
												uni.canvasToTempFilePath({
													canvas: canvas1,
													success(res) {
														console.log("res222", res);
														resolve(res);
													},
													fail(res) {
														uni.hideLoading();
														uni.showToast({
															title: res.errMsg,
															icon: "error",
														});
													},
												});
											})
											.catch((err) => {
												console.log(err);
												uni.hideLoading();
												uni.showToast({
													title: "生成失败,请重试",
												});
											});
									};
								},
								fail(err) {},
							});
						});
						// .then(() => {
						// 	console.log("inthen");
						// 	//使用：
						// });
					});
			});
		},
		// 设置分享布局
		setShareJobImg(ctx, canvas, mycenter, funObj) {
			let that = this;
			let labelLeft = 0;
			// ctx.arcTo()
			let baseTop, QRSize, baseLeft, titleFontSize, contentFontSize;
			baseTop = canvas.height - 412;
			// baseTop = 1470;
			QRSize = 144;
			baseLeft = 80;
			titleFontSize = 54;
			contentFontSize = 36;
			that.G.roundRect1(ctx, mycenter - (canvas.width - 60) / 2, baseTop, canvas.width - 60, 360, 48, "#fff");
			that.G.fillTextLineBreak(ctx, that.miniAppInfo.fullName || that.miniAppInfo.agencyName, baseLeft + 20, baseTop + 162, 300, 64, "#000", titleFontSize, "500"); // 代理名字
			let slogan = that.miniAppInfo.slogan || "为劳动者创造价值";
			that.G.fillTextLineBreak(ctx, slogan, baseLeft + 20, baseTop + 168 + titleFontSize, 600, 48, "#666", contentFontSize, "500"); // slogan
			// miniAppInfo
			return new Promise((imgres) => {
				let p1 = new Promise((resolve) => {
					uni.getImageInfo({
						// src: "https://bocai-cms.oss-cn-beijing.aliyuncs.com/web-resource/dailibaoming/poster/renhaiQRCode.png",
						src: that.miniAppInfo.qrCode,
						success(res) {
							console.log("res333", res);
							const img = canvas.createImage();
							img.src = res.path;
							img.onload = () => {
								console.log("ctx", ctx);
								console.log("canvas", canvas);
								console.log("that.miniAppInfo.logo", that.miniAppInfo.logo);
								// that.G.roundRect1(ctx, mycenter - 580 / 2, baseTop + 740, 580, 580, 0, "#fff");
								that.G.roundRect(ctx, img, canvas.width - 320, baseTop + 60, 240, 240, 0);
								resolve();
							};
						},
						fail(err) {
							console.log(err);
						},
					});
				});
				let p2 = new Promise((resolve) => {
					uni.downloadFile({
						url: that.miniAppInfo.logo || "https://matripe.oss-cn-beijing.aliyuncs.com/default.png",
						success(res) {
							const img = canvas.createImage();
							img.src = res.tempFilePath;
							img.onload = () => {
								that.G.roundRect(ctx, img, 20, 20, 180, 180, 90);
								resolve();
							};
						},
						fail(err) {
							console.log(err);
							resolve();
						},
					});
				});
				Promise.all([p1, p2]).then(() => {
					// setTimeout(() => {
					imgres(canvas);
					// }, 300);
				});
			});
		},
		saveImg() {
			let that = this;
			// console.log("saveImg", that.currentImg);
			if (that.fakeImg) return false;
			uni.saveImageToPhotosAlbum({
				// #ifdef  APP-PLUS
				filePath: that.appfile,
				// #endif
				// #ifdef  MP-WEIXIN
				filePath: that.currentImg,
				// #endif
				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,
					});
				},
			});
		},
		getinfoByLogin(){
			let that = this;
			that.G.Get(that.api.get_infoByLogin + '/' + uni.getStorageSync("AGENCY_ID"), {}, (res) => {
				console.log("getinfoByLogin", res);
				if(res){
					that.applystatys = res.recordStatus;
					that.agencyCode = res.agencyCode;
					that.appdatas = res;
				}else{
					that.applystatys = '';
					that.agencyCode = '';
				}
			});
		},
		getResumeInfo() {
			let that = this;
			that.G.Get(`/yishoudan/order/helper/check/neworder`, {}, (resorder) => {
				that.G.Get(that.api.order_getNewApplyNumNotViewed, {}, (resapply) => {
					that.hasNewResume = resorder + resapply;
					that.applyNum = resapply;
					// console.log("that.hasNewResume", that.hasNewResume);
					that.$forceUpdate();
				});
			});
		},
		setUserInfo() {
			let that = this;
			that.speed = 1;
			let userInfo = uni.getStorageSync("apply-userinfo");
			that.userInfo = { ...userInfo };
			that.isLogin = true;
			that.userInfo.agencyName = userInfo.agencyName;
			that.userInfo.user = userInfo.user;
			that.userInfo.avatar = uni.getStorageSync("apply-userinfo").imgSrc;
			that.userInfo.name = userInfo.userName || userInfo.aliasName;
			that.userInfo.tel = userInfo.tel;
			that.userInfo.agencyName = userInfo.agencyName;
			that.userInfo.teamType = userInfo.teamType;
			console.log("that.userInfo", that.userInfo);
		},
		goPaga($path){
			let that = this;
			console.log("goPaga $path", $path);
			uni.setStorageSync("applyfoemdata", JSON.stringify(that.appdatas));
			uni.navigateTo({
				url: $path,
			});
		},
		goPage($path) {
			this.G.isLogin();
			if (this.G.isLogin()) {
				uni.navigateTo({
					url: $path,
				});
			}
		},
		handleClickNum(e) {
			// console.log("我的服务：", e);
			this.G.isLogin();
			if (this.G.isLogin()) {
				uni.navigateTo({
					url: e.item.path,
				});
			}
		},
		goOrder(e) {
			// console.log("e", e);
			uni.setStorageSync("applyType", e.item.type ? e.item.type : 0);
			uni.switchTab({
				url: "/pages/order/index",
				success: (res) => {},
				fail: (res) => {},
				complete: (res) => {},
			});
		},
		getData() {
			let that = this;
			this.G.Get(
				this.api.person_dataValue + "?classify=1",
				{
					classify: 1,
				},
				(res) => {
					// console.log("res", res);
					if (res) {
						that.map = res;
						that.billDataList = [
							{
								name: "审核中",
								num: that.map.classify1num.num10 || 0,
								type: 1,
								path: "/root/person/applyIndex?status=1",
							},
							{
								name: "待接待",
								num: that.map.classify1num.num20 || 0,
								type: 2,
								path: "/root/person/applyIndex?status=2",
							},
							{
								name: "待面试",
								num: that.map.classify1num.num25 || 0,
								type: 3,
								path: "/root/person/applyIndex?status=3",
							},
							{
								name: "待入职",
								num: that.map.classify1num.num30 || 0,
								type: 4,
								path: "/root/person/applyIndex?status=4",
							},
							{
								name: "在职中",
								num: that.map.classify1num.num40 || 0,
								type: 5,
								path: "/root/person/applyIndex?status=5",
							},
						];
					}
				},
			);
		},
		getPoster(e) {
			const that = this;
			this.fakeImg = e;
			that.posterShow = true;
			// uni.showLoading({
			// 	title: "生成中...",
			// 	mask: true,
			// });
			that.getWXCanvas(e).then((res) => {
				// console.log("res", res);
				that.currentImg = res.tempFilePath;
				setTimeout(() => {
					this.fakeImg = "";
				}, 100);
				uni.hideLoading();
			});
		},
		// 微信端绘制
		getWXCanvas(sharelImg, type) {
			const that = this;
			return new Promise((resolve) => {
				var mycenter = 0; //文字左右居中显示
				var myheight = 0; //文字高度
				const query = uni.createSelectorQuery().in(this);
				query
					.select("#canvasId")
					.fields({
						node: true,
						size: true,
					})
					.exec((res) => {
						// console.log("uni 获取节点信息：", res);
						// console.log("sharelImg", sharelImg);
						const canvas = res[0].node;
						const ctx = canvas.getContext("2d");
						new Promise(function (resolve) {
							// 绘制背景图片
							uni.getImageInfo({
								src: sharelImg, // 网络图片
								success(res) {
									// console.log("res111", res);
									canvas.width = res.width;
									canvas.height = res.height;
									mycenter = canvas.width / 2;
									myheight = canvas.height;
									const img = canvas.createImage();
									img.src = res.path;
									// console.log("img111", img);
									img.onload = (info) => {
										ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
										// console.log("info111", info);
										resolve(true);
									};
								},
								fail(err) {},
							});
						}).then(() => {
							// console.log("inthen");
							//使用：
							that
								.setShareJobImg(ctx, canvas, mycenter)
								.then(function (canvas1) {
									// console.log("canvas1", canvas1);
									uni.canvasToTempFilePath({
										canvas: canvas1,
										success(res) {
											// console.log("res222", res);
											resolve(res);
										},
										fail(res) {
											uni.hideLoading();
											uni.showToast({
												title: res.errMsg,
												icon: "error",
											});
										},
									});
								})
								.catch((err) => {
									// console.log(err);
									uni.hideLoading();
									uni.showToast({
										title: "生成失败,请重试",
									});
								});
						});
					});
			});
		},
		// 设置分享布局 
		setShareJobImg(ctx, canvas, mycenter, funObj) {
			let that = this;
			let labelLeft = 0;
			// ctx.arcTo()
			let baseTop, QRSize, baseLeft, titleFontSize, contentFontSize;
			baseTop = canvas.height - 412;
			// baseTop = 1470;
			QRSize = 144;
			baseLeft = 80;
			titleFontSize = 54;
			contentFontSize = 36;
			that.G.roundRect1(ctx, mycenter - (canvas.width - 60) / 2, baseTop, canvas.width - 60, 360, 48, "#fff");
			that.G.fillTextLineBreak(ctx, that.miniAppInfo.fullName || that.miniAppInfo.agencyName, baseLeft + 20, baseTop + 162, 300, 64, "#000", titleFontSize, "500"); // 代理名字
			let slogan = that.miniAppInfo.slogan || "为劳动者创造价值";
			that.G.fillTextLineBreak(ctx, slogan, baseLeft + 20, baseTop + 168 + titleFontSize, 600, 48, "#666", contentFontSize, "500"); // slogan
			// miniAppInfo
			return new Promise((imgres) => {
				let p1 = new Promise((resolve) => {
					uni.getImageInfo({
						// src: "https://bocai-cms.oss-cn-beijing.aliyuncs.com/web-resource/dailibaoming/poster/renhaiQRCode.png",
						src: that.miniAppInfo.qrCode,
						success(res) {
							// console.log("res333", res);
							const img = canvas.createImage();
							img.src = res.path;
							img.onload = () => {
								// console.log("ctx", ctx);
								// console.log("canvas", canvas);
								// console.log("that.miniAppInfo.logo", that.miniAppInfo.logo);
								// that.G.roundRect1(ctx, mycenter - 580 / 2, baseTop + 740, 580, 580, 0, "#fff");
								that.G.roundRect(ctx, img, canvas.width - 320, baseTop + 60, 240, 240, 0);
								resolve();
							};
						},
						fail(err) {
							// console.log(err);
						},
					});
				});
				let p2 = new Promise((resolve) => {
					uni.downloadFile({
						url: that.miniAppInfo.logo || "https://matripe.oss-cn-beijing.aliyuncs.com/default.png",
						success(res) {
							const img = canvas.createImage();
							img.src = res.tempFilePath;
							img.onload = () => {
								that.G.roundRect(ctx, img, 20, 20, 180, 180, 90);
								resolve();
							};
						},
						fail(err) {
							// console.log(err);
							resolve();
						},
					});
				});
				Promise.all([p1, p2]).then(() => {
					// setTimeout(() => {
					imgres(canvas);
					// }, 300);
				});
			});
		},
		saveImg() {
			let that = this;
			// console.log("saveImg");
			if (that.fakeImg) return false;
			uni.saveImageToPhotosAlbum({
				filePath: that.currentImg,
				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,
					});
				},
			});
		},
		clickImg(_item) {
			if (uni.getStorageSync("user_qrcode")) {
				this.miniAppInfo.qrCode = uni.getStorageSync("user_qrcode");
			}
			this.getPoster(_item.url);
		},
		handleOpenForm(){
			let that = this;
			uni.showModal({
				cancelText: '取消',
				confirmColor: getApp().globalData.themeColor,
				confirmText: '申请加入',
				content: '需要加入' + getApp().globalData.title + '后，才能查看职位佣金',
				title: '',
				success: (result) => {},
				fail: (res) => {},
				complete: (res) => {},
			})
		}
	},
};
</script>

<style lang="scss">
page {
	background-color: #ededed;
}
.p-person-inedx {
	// min-height: 100vh;
	background-repeat: no-repeat;
	background-size: 100% 100%;
	.m-money {
		width: calc(100vw - 20px);
		margin: 10px auto 0;
		height: 84px;
		background-repeat: no-repeat;
		background-size: 100% 100%;
		overflow: hidden;
		border-radius: 6px;
		.con {
			left: 0;
			top: 50%;
			width: 100%;
			height: 200%;
			transform: translateY(-50%);
		}
	}
}
</style>
