<template>
	<div class="g_bg_page g_pl_10 g_pr_10">
		<div class="g_h_20"></div>
		<div class="g_mb_10 g_fs_18 g_pl_10">「{{ agencyInfo.inviteUserName || "-" }}」邀请您加入他的团队：</div>
		<div class="r_box g_pt_24 g_text_c g_pl_20 g_pr_20">
			<div class="g_pb_16">
				<img class="g_h_80 g_w_80 g_radius_50" :src="agencyInfo.logo || 'https://matripe-cms.oss-cn-beijing.aliyuncs.com/dailibaoming/APP/default.svg'" alt="" />
				<div class="g_fs_20 g_mt_12 g_mb_12 g_fw_600">
					{{ agencyInfo.agencyName || "-" }}
				</div>
				<div class="g_c_9 g_fs_14">
					{{ agencyInfo.desp || "-" }}
				</div>
			</div>
			<div class="g_flex_row_between g_pb_12 g_pt_12" style="border-top: 1rpx dotted #eee">
				<div v-for="item in numList" class="g_flex_row_center flex_end">
					<div class="g_fs_20 g_fw_600">{{ item.num }}</div>
					<div class="g_fs_14 g_c_9">{{ item.label }}</div>
				</div>
			</div>
		</div>
		<div class="g_mt_30">
			<div class="g_fs_18 g_mb_8 g_pl_12">填写企业简称:</div>
			<div class="r_box g_pl_10">
				<u-input v-model="userInfo.userName" height="88" placeholder="区域+名称，如:上海发财劳务"></u-input>
			</div>
			<div class="g_fs_12 g_c_9 g_mt_6 g_pl_12">设置后系统将自动创建团队并关注该发单号，您作为创建人可在我的页面管理团队。</div>
		</div>

		<div class="g_mt_84">
			<g-button v-if="!applying && agencyInfo.agencyName" btnText="申请加入团队" type="primary" class="" @clickBtn="applyAdd"></g-button>
			<g-button v-else btnText="已申请" type="disabled" class=""></g-button>
		</div>
	</div>
</template>

<script>
export default {
	data() {
		return {
			agencyInfo: {
				agencyName: "",
				fullName: "",
			},
			userInfo: {
				userName: "",
				userId: "",
			},
			numList: [
				{ label: "总职位", num: 0 },
				{ label: "最近更新", num: 0 },
				{ label: "粉丝", num: 0 },
			],
			applying: false,
			inviteUserId: "",
			uid: "",
			ing: false,
		};
	},
	onLoad(options) {
		console.log(options);
		// options.scene = "id=3087_101125";
		if (uni.getStorageSync("scene") || options.scene) {
			console.log("XXXXXXXXXXXX");
			//扫小程序码携带参数
			var sceneStr = uni.getStorageSync("scene") ? decodeURIComponent(uni.getStorageSync("scene")) : decodeURIComponent(options.scene);
			var sceneJson = this.G.sceneToJson(sceneStr);
			console.log("sceneJson===", sceneJson);
			this.inviteUserId = sceneJson.id.split("_")[1];
			this.uid = sceneJson.id.split("_")[0];
			// this.G.checkToken().then((info) => {
				console.log("info11", info);
				if (!info.msg) {
					this.userInfo = uni.getStorageSync("apply-userinfo");
					this.getAgencyById();
					this.checkHasApply();
					uni.removeStorageSync("scene");
				} else {
					// uni.reLaunch({
					// 	url: `/pages/login/index?path='/root1/person/memberApplyAdd'&scene=${options.scene}`,
					// });
					uni.setStorageSync("scene", options.scene);
				}
			// });

			// uni.setStorageSync("AGENCY_USER_ID", this.userId);
		}
	},
	created() {},

	methods: {
		applyAdd() {
			let that = this;

			if (!this.userInfo.userName) {
				uni.showToast({
					title: "请输入你的姓名",
					icon: "none",
				});
				return;
			}
			if (this.ing) {
				return;
			}
			that.ing = true;
			this.G.Post(this.api.bind_subscribeSubmit, { agencyId: that.uid, username: this.userInfo.userName, inviteUserId: this.inviteUserId }, (res) => {
				uni.showToast({
					title: "申请成功",
					icon: "none",
				});
				that.checkHasApply();
				console.log(res);
			});
		},
		getAgencyById() {
			let that = this;
			this.G.Get(this.api.order_getAgencyByIdForApply, { agencyId: that.uid, inviteUserId: this.inviteUserId }, (res) => {
				console.log(res);
				that.agencyInfo = res;
				that.numList = [
					{ label: "总职位", num: res.jobNum },
					{ label: "最近更新", num: res.jobUpdateNum },
					{ label: "粉丝", num: res.downNum },
				];
			});
		},
		checkHasApply() {
			let that = this;
			this.G.Post(this.api.order_checkHasApply, { agencyId: that.uid, userId: this.userInfo.id }, (res) => {
				if (res.length > 0) {
					that.applying = true;
				} else {
					that.applying = false;
				}
				that.ing = false;
				console.log(res);
			});
		},
	},
};
</script>

<style></style>
