<template>
	<view>
		<web-view :src="href"></web-view>
	</view>
</template>

<script>
	import "@/common/time.js"

	// 返回指定日期距今多少天
	const daysComputed = time => {
		let oldTimeFormat = new Date(time)
		let nowDate = new Date()
		if (nowDate.getTime() - oldTimeFormat.getTime() > 0) {
			let times = nowDate.getTime() - oldTimeFormat.getTime()
			let days = parseInt(times / (60 * 60 * 24 * 1000))
			return days
		} else {
			throw ('传入时间不能大于当前日期')
		}
	}

	// console.log(daysComputed('2022-02-26'))

	export default {
		data() {
			return {
				url: "",
				href: ""
			};
		},
		onLoad() {
			// #ifndef APP-NVUE
			const eventChannel = this.getOpenerEventChannel();
			// #endif
			// 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
			eventChannel.on('acceptDataFromOpenerPage', (data) => {
				console.log(data)

				this.url = escape(data.url)
			})


			if (!uni.getStorageSync("oa_login_time")) {
				// 第一次登录
				console.log("第一次登陆")

				let oa_login_time = "2010-01-01"

				uni.setStorageSync("oa_login_time", new Date().format("yyyy-MM-dd"))

				this.href = "http://oa_system.nxjiewei.com:8011/oa_login.html?staff_num=" + uni.getStorageSync('user')
					.staff_num + "&url=" + this.url + "&oa_login_time=" + oa_login_time
			} else {
				// 有登录记录
				console.log("有登录记录")

				let oa_login_time = uni.getStorageSync("oa_login_time")

				if (daysComputed(oa_login_time) > 5) {
					uni.setStorageSync("oa_login_time", new Date().format("yyyy-MM-dd"))
					
					console.log(">5",uni.getStorageSync("oa_login_time"))
					this.href = "http://oa_system.nxjiewei.com:8011/oa_login.html?staff_num=" + uni.getStorageSync('user')
						.staff_num + "&url=" + this.url + "&oa_login_time=" + uni.getStorageSync("oa_login_time")

				} else {
					console.log("<5",oa_login_time)
					
					this.href = "http://oa_system.nxjiewei.com:8011/oa_login.html?staff_num=" + uni.getStorageSync('user')
						.staff_num + "&url=" + this.url + "&oa_login_time=" + oa_login_time
				}



			}
		}
	}
</script>

<style lang="scss">

</style>
