<template>
	<view class="p-root-home-success g_kuaishou">
		<view class="g_flex_row_center g_pt_159">
			<rh-image :url="cdnBaseImg + 'applia_success.svg'" size="220" />
		</view>
		<view class="g_pt_23 g_pb_12 g_fs_19 g_c_3 g_fw_600 g_flex_row_center"> 已报名成功 </view>
		<view class="g_pt_12 g_pb_106 g_fs_14 g_flex_row_center" style="color: #8f8f8f"> 您已成功报名该岗位，请等待发单号审核。 </view>
		<view class="g_flex_row_center g_pl_20 g_pr_20">
			<view class="g_flex_1 g_mr_12">
				<rh-button primaryColor='#00b666' btnText="继续报名" type="primary" size="small_auto" @clickBtn="goReturn" />
			</view>
			<view class="g_flex_1">
				<rh-button primaryColor='#00b666' btnText="联系客服" size="small_auto" @clickBtn="sendJobInfo" />
			</view>
		</view>
		<view class="g_flex_row_center">
			<view class="g_c_sub g_mt_16 g_fs_14 g_text_c g_w_all g_fw_700" style="position: fixed; bottom: 56px; width: calc(100vw - 20px); left: 50%; transform: translateX(-50%)" hover-class="thover" @click="goList">查看报名工单</view>
		</view>
	</view>
</template>

<script>
export default {
	onLoad(options) {
		console.log(options);
		if (options.jobId) {
			this.jobId = options.jobId;
			this.getDetail();
		}
	},
	onReady() {
		this.G.setNavStyle();
	},
	onShareAppMessage() {
		return this.G.shareFun();
	},
	data() {
		return {
			jobId: "",
			jobDetail: {},
			goImLoading: false,
			cdnBaseImg: this.G.store().cdnBaseImg,
		};
	},
	methods: {
		goReturn() {
			uni.$emit("resetTownsman", { reset: true });
			uni.navigateBack();
		},
		sendJobInfo() {
			let that = this;
			if (that.goImLoading) {
				return false;
			}

			that.goImLoading = true;
			that.F.wyyxGet(that.api.job_get_cus + "?jobId=" + that.jobId, {}, (cusData) => {
				that.F.wyyxPost(
					that.api.wyyx_create,
					{
						senderAccid: uni.getStorageSync("im-accid"),
						receiverAccid: cusData.accid,
					},
					(res) => {
						console.log("res", res);
						uni.$UIKitStore.uiStore.selectConversation(res.conversationId);
						let list = ["addss", "genderRestrict", "genderAge"];
						let newList = [];
						list.forEach((item) => {
							if (that.jobDetail[item]) {
								newList.push(that.jobDetail[item]);
							}
						});
						that.jobDetail.info = newList.join("丨");
						const customMsg = uni.$UIKitNIM.V2NIMMessageCreator.createCustomMessage(
							"",
							JSON.stringify({
								type: 100000,
								title: that.jobDetail.jobName,
								info: that.jobDetail.info,
								label: that.jobDetail.jobRequestLabelNames.length > 0 ? that.jobDetail.jobRequestLabelNames : [],
								salaryClassifyValue: that.jobDetail.priceStr,
								serviceFee: that.jobDetail.serverPrice,
								monthPay: that.jobDetail.monthPay,
								jobId: that.jobId,
							})
						);
						console.log("customMsg", customMsg);
						uni.$UIKitStore.msgStore.sendMessageActive({
							msg: customMsg,
							conversationId: res.conversationId,
							sendBefore: () => {
								uni.navigateTo({
									url: "/root/NEUIKit/pages/Chat/index",
								});
								that.goImLoading = false;
								// scrollBottom();
							},
						});
						return;
						let sendParams = {
							conversationType: 1,
							senderAccid: uni.getStorageSync("im-accid"),
							receiverAccid: cusData.accid,
							type: 100000,
							jobDetail: {
								title: that.jobDetail.jobName,
								info: that.jobDetail.info,
								label: that.jobDetail.jobRequestLabelNames.length > 0 ? that.jobDetail.jobRequestLabelNames : [],
								salaryClassifyValue: that.jobDetail.priceStr,
								serviceFee: that.jobDetail.serverPrice,
								monthPay: that.jobDetail.monthPay,
								jobId: that.jobId,
							},
						};
						uni.setStorageSync("im_sendParams", JSON.stringify(sendParams));
						uni.navigateTo({
							url: "/root/NEUIKit/pages/Chat/index",
						});
						that.goImLoading = false;
					},
					() => {}
				);
			});
		},
		getDetail() {
			let that = this;
			that.speed = 0;
			return new Promise((resolve) => {
				that.G.Get(that.api.job_detail + "/" + that.jobId, "", (res) => {
					res = { ...res, ...res.record };
					if (!res.hasOwnProperty("storeJobDetail")) {
						res.storeJobDetail = {
							jobDesp: "",
						};
					}
					res.serverPrice = that.G.setReturnFee(res.returnFee, res.returnFeeType);
					let setData = that.G.disposeJobListData(res);
					res.genderRestrict = that.G.getGenderByMinAge(res);
					res.addss = that.G.setJobInfoPositionv3(res.storeAddr);
					res.monthPay = res.minMonthlyPay / 100 + "-" + res.maxMonthlyPay / 100;
					res.priceStr = res.salaryClassify != 7 ? that.G.getSalaryClassifyValueHtml(res.salaryClassify, res.salaryClassifyValue) : that.G.getSalaryClassifyValue(res.salaryClassify, res.minMonthlyPay, res.maxMonthlyPay);
					that.jobDetail = res;
				});
			});
		},
		goList() {
			uni.setStorageSync("apply-tab-active", 1);
			uni.navigateTo({
				url: "/root/person/applyIndex",
			});
		},
	},
};
</script>

<style>
.g_pt_159 {
	padding-top: 159px;
}
.g_pb_106 {
	margin-bottom: 106px;
}
</style>
