<template>
	<div class="user">
		<u-cell title="我的简历" isLink @click="toResume"/>
		<u-cell title="投递记录" isLink @click="toDeliverLog"/>
		<u-cell title="收藏记录" isLink @click="toCollectLog"/>
		<u-cell title="人力资源许可证&营业执照" isLink @click="toLicense"/>
		<u-cell title="清空缓存" isLink @click="clean"/>
		<resume-popup
			:visible="visible"
			appId="2021005184646262"
			outBizNo="outBizNo"
			templateId="DEFAULT"
			onClose="onClose"
			onSuccess="onSuccess"
			onFailure="onFailure"
		/>
	</div>
</template>
<script>
import { getResume } from '../../util/loginSetInfo.js'
export default {
	data() {
		return {
			outBizNo: '',
			visible: false,
		};
	},
	onLoad() {
		this.$scope.onClose = this.onClose;
		this.$scope.onSuccess = this.onSuccess;
		this.$scope.onFailure = this.onFailure;
	},
	methods: {
		generateOutBizNo() {
		  const timestamp = new Date().getTime();
		  const random = Math.floor(Math.random() * 10000).toString().padStart(4, '0');
		  return `job_auth_${timestamp}_${random}`;
		},

		handleTap() {
			this.outBizNo = this.generateOutBizNo()
			this.visible = true;
		},
		onFailure({code, message}) {
			console.log(code, message);
			this.visible = true
		},
		onClose() {
			this.visible = false;
		},
		onSuccess(applyId) {
			this.visible = false;
			getResume(applyId,()=> {
				uni.showToast({
					title: '登录成功',
					icon: 'none'
				})
				this.toResume()
			})
		},
		toResume() {
			const token = uni.getStorageSync('jy-recruit-token');
			if (token) {
				uni.navigateTo({
					url: '/pages/user/resume/index'
				})
			} else {
				this.handleTap()
			}
		},
		toLicense() {
			uni.navigateTo({
				url: '/pages/user/license'
			})
		},
		toDeliverLog() {
			const token = uni.getStorageSync('jy-recruit-token');
			if (token) {
				uni.navigateTo({
					url: '/pages/user/deliverLog'
				})
			} else {
				this.handleTap()
			}
		},
		toCollectLog() {
			const token = uni.getStorageSync('jy-recruit-token');
			if (token) {
				uni.navigateTo({
					url: '/pages/user/collectLog'
				})
			} else {
				this.handleTap()
			}
		},
		clean() {
			uni.setStorageSync('jy-recruit-token','')
			uni.showToast({
				title: '清理成功',
				icon: 'none'
			})
		}
	}
};
</script>
<style lang="scss">
	.user{
		.u-cell{
			margin-top: 30rpx;
		}
	}
</style>