<template>
	<view class="p-root-bind-applyForm g_w_all g_h_all g_bg_f_5 g_kuaishou">
		<view class="g_h_10"></view>
		<g-panel-card-info
			:info="{
				avatar: info.logo,
				title: info.agencyName,
				num: '已发布职位' + info.jobNum,
			}"
			:isShowMore="0"
		/>
		<view class="g_mt_10 g_bg_f g_p_16 g_ml_10 g_mr_10 g_radius_8">
			<view class="g_fs_16 g_c_6">发送关注申请</view>
			<view class="g_mt_10 g_bg_f_7 g_pl_16 g_pr_16 g_radius_8 g_pt_14 g_pb_14">
				<u-input v-model="remark" type="textarea" class="g_bg_f_7 g_fs_16" style="font-size: 16px" placeholder-style="font-size:16px" />
			</view>
		</view>
		<view class="g_flex_row_center g_mt_32">
			<view class="g_w_184 g_h_40 g_flex_c g_radius_20 g_c_f g_fs_16" :class="info.recordStatus == 1 || info.recordStatus == 2 ? 'g_bg_e g_c_9' : 'g_bg_main'" :style="info.recordStatus == 1 || info.recordStatus == 2 ? 'pointer-events: none;' : ''" hover-class="thover" @click="handleSubmit">
				{{ info.recordStatus == 1 ? "申请中" : info.recordStatus == 2 ? "已关注" : "发送" }}
			</view>
		</view>
	</view>
</template>

<script>
export default {
	onReady() {
		this.G.setNavStyle();
	},
	onShareAppMessage() {
		return this.G.shareFun();
	},
	data() {
		return {
			wxCode: "",
			info: {
				logo: "",
				agencyName: "",
				jobNum: 0,
				agencyId: 0,
			},
			remark: "",
			form: 1,
			customButton: {
				width: "184px",
				height: "40px",
				borderRadius: "20px",
				backgroundColor: "#00B666",
				color: "#fff",
				fontSize: "16px",
			},

			btnSpeed: -1, // -1 默认 0 按下 1请求中 2请求后
		};
	},
	onLoad(options) {
		console.log("申请关注页面：", options);

		if (options.scene) {
			var sceneStr = decodeURIComponent(options.scene);
			var sceneJson = this.G.sceneToJson(sceneStr);
			this.wxCode = sceneJson.inviteCode;
		} else {
			this.wxCode = options.code;
			this.form = options.form;
		}
	},
	onShow() {
		this.init();
	},
	methods: {
		init() {
			let that = this;
			that.G.Get(
				that.api.bind_getSubscribeDetail,
				{
					inviteCode: that.wxCode,
				},
				(res) => {
					console.log("企业基本信息：", res);
					that.info = res;
					// that.info.recordStatus = 2;
				}
			);
		},
		handleSubmit() {
			let that = this;
			if (that.info.recordStatus == 1 || that.info.recordStatus == 2) {
				return false;
			}

			// 按下
			that.btnSpeed = 0;
			// 请求中
			that.btnSpeed = 1;
			uni.showLoading({
				title: "正在发送",
			});
			setTimeout(() => {
				uni.hideLoading();
				that.G.Get(
					that.api.bind_subscribeSubmit + "/" + that.info.agencyId,
					{
						agencyId: that.info.agencyId,
						source: that.form,
						remark: that.remark,
					},
					(res) => {
						// 请求后
						that.btnSpeed = 2;
						uni.showToast({
							title: "提交成功",
						});
						setTimeout(() => {
							uni.navigateBack();
						}, 1500);
					}
				);
			}, 500);
		},
		goPage($path) {
			uni.navigateTo({
				url: $path,
			});
		},
	},
};
</script>

<style lang="scss">
.custom-button {
	width: 184px;
	height: 40px;
	border-radius: 20px;
	background-color: #00b666;
	color: #fff;
	font-size: 16px;
}
</style>
