<template>
	<div class="p-root-bind-search g_w_all g_bg_f_5 g_kuaishou" style="min-height: 100%">
		<!-- #ifdef APP-PLUS || H5 -->
		<u-navbar back-icon-color="#333333" back-icon-size="40" title="发展代理" title-size="36" title-color="#111111" :title-bold="false">
			<!-- <div class="g_pr_16" slot='right' @click="handleOpenSharePop">
				<i class="iconfont icon-zhuanfa1 g_c_3" style="font-size: 36rpx;"></i>
			</div> -->
		</u-navbar>
		<!-- #endif -->
		<div class="g_flex_row_center g_fs_20 g_c_3 g_fw_600 g_mb_16 g_pt_24">邀请代理/供应商关注我的发单号</div>
		<div class="" v-if="active == 0">
			<div class="">
				<div class="" v-for="(item, index) in recommendList" :key="index">
					<g-panel-card-info
						:info="{
							avatar: item.logo,
							title: item.agencyName,
							num: '职位数：' + item.jobNum + ' 粉丝数：' + item.downNum,
							titleFS: 18,
							titleFW: 400,
							numFS: 14,
							agencyCode: item.inviteCode,
						}"
						:radius="6"
						isShowMore="1"
						rightType="button"
					/>
				</div>
			</div>
		</div>
		<div v-if="active == 1">
			<mainPanel :showBg="false" :active="active" @exportCode="getCode" @setImg="setShareImg" />
		</div>

		<u-popup v-model="sharePop.isShow" mode="bottom" border-radius="16">
			<div class="g_fs_14 g_flex_row_center g_pt_20 g_pb_20" style="color: #323233">立即分享给好友</div>
			<div class="g_flex_row_center">
				<div v-for="(item, index) in sharePop.type" :key="index" style="width: 25%" class="g_flex_row_center" @click="handleOpenApp(item, index)">
					<div class="">
						<div class="g_flex_row_center">
							<image :src="localBaseImg + 'share/' + item.icon + '.svg'" style="width: 48px; height: 48px"></image>
						</div>
						<div class="g_pt_8 g_pb_16 g_fs_12 g_flex_row_center" style="color: #646566">{{ item.name }}</div>
					</div>
				</div>
			</div>
			<div class="g_h_8 g_bg_f_5"></div>
			<div class="g_h_48 g_flex_c g_fs_16" style="color: #646566" @click="sharePop.isShow = false">取消</div>
		</u-popup>
	</div>
</template>

<script>
import mainPanel from "../../components/myMain.vue";
export default {
	components: {
		mainPanel,
	},
	data() {
		return {
			localBaseImg: this.G.store().localBaseImg,
			agencyInfo: uni.getStorageSync("agencyInfo"),
			userInfo: uni.getStorageSync("apply-userinfo"),
			active: 0,
			placeholder: "",
			wxCode: "",
			keyword: "",
			agencyName: "报名助手",
			recommendList: [],
			shareImg: "",
			sharePop: {
				isShow: false,
				type: [
					{
						icon: "wechat",
						name: "微信好友",
						tip: "wechat",
					},
					{
						icon: "friends",
						name: "朋友圈",
						tip: "friends",
					},
					{
						icon: "tiktok",
						name: "抖音好友",
						tip: "douyin",
					},
					{
						icon: "kwai",
						name: "快手好友",
						tip: "kwai",
					},
				],
			},
		};
	},
	onReady() {
		this.G.setNavStyle();
	},

	onShareAppMessage1() {
		let that = this;
		let params = {
			id: uni.getStorageSync("apply-agencyId"),
			type: that.active + 1,
			isShowMore: false,
			isShowJob: false,
			shareForm: "friend",
		};
		console.log("代理id：", that.recommendList);
		return this.G.shareFun("/root/person/inviteFollowMe?scene=" + `id=${that.agencyInfo.id}_${that.userInfo.id}`, this.shareImg, that.agencyInfo.fullName + "邀请您关注他的发单号，快来关注吧！");
	},
	onLoad(options) {
		console.log(options);
		this.active = options.active;
		if (!uni.getStorageSync("poster_img")) {
			uni.showLoading({
				title: "生成中...",
			});
		}
		if (this.active === 0) {
			this.placeholder = "请输入发单号账号/手机号";
			uni.setNavigationBarTitle({
				title: "寻找发单号",
			});
		} else {
			this.placeholder = "请输入粉丝ID账号";
			uni.setNavigationBarTitle({
				title: "发展代理",
			});
		}
		uni.onAfterPageUnload(() => {
			console.log("onAfterPageUnload");
			setTimeout(() => {
				uni.removeStorageSync("poster_img");
			}, 3000);
		});
	},
	onShow() {
		this.getDetail();
	},
	methods: {
		setShareImg(e) {
			console.log(e);
			this.shareImg = e;
		},
		getDetail() {
			let that = this;
			that.G.Get(
				that.api.bind_enterpriseDetail + "/" + uni.getStorageSync("apply-agencyId"),
				{
					agencyId: uni.getStorageSync("apply-agencyId"),
					type: 1,
				},
				(res) => {
					console.log("recommendList", res);
					that.recommendList = [res];
					console.log("--", that.recommendList);
				}
			);
		},
		getCode(e) {
			console.log("获取返回数据：", e);
			this.wxCode = e.code;
			this.agencyName = e.agencyName;
			uni.hideLoading();
		},
		goMain() {
			let that = this;
			uni.navigateTo({
				url: "/root/bind/applyForm?code=" + that.keyword + "&form=1",
			});
		},
		handleCopyText() {
			this.G.copyText(this.wxCode);
		},
		// 打卡分享弹窗
		handleOpenSharePop() {
			let that = this;
			that.sharePop.isShow = true;
		},
		// 打卡app
		handleOpenApp($item, $index) {
			let that = this;
			that.G.handleConfirm({
				content: "功能开发中",
				success: (res) => {
					if (res.confirm) {
						that.sharePop.isShow = false;
					}
				},
			});
		},
	},
};
</script>

<style></style>
