const utils = {
	getweekDay(time) {
		let temp_data = new Date(time)
		if (temp_data.getDay() === 0) return "星期天"
		if (temp_data.getDay() === 1) return "星期一"
		if (temp_data.getDay() === 2) return "星期二"
		if (temp_data.getDay() === 3) return "星期三"
		if (temp_data.getDay() === 4) return "星期四"
		if (temp_data.getDay() === 5) return "星期五"
		if (temp_data.getDay() === 6) return "星期六"
	},
	getweekDayZhou(time) {
		let temp_data = new Date(time)
		if (temp_data.getDay() === 0) return "周日"
		if (temp_data.getDay() === 1) return "周一"
		if (temp_data.getDay() === 2) return "周二"
		if (temp_data.getDay() === 3) return "周三"
		if (temp_data.getDay() === 4) return "周四"
		if (temp_data.getDay() === 5) return "周五"
		if (temp_data.getDay() === 6) return "周六"
	},
	dateFormat(time) {
		let date = new Date(time);
		let year = date.getFullYear();
		// 在日期格式中,月份是从0开始的,因此要加0,使用三元表达式在小于10的前面加0,以达到格式统一  如 09:11:05
		let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
		let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
		let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
		let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
		let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
		// 拼接
		
		return year + "-" + month + "-" + day + " " + hours + ":" + minutes;
	},
	dateFormatHoursMinutes(time) {
		let date = new Date(time);
		let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
		let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
		let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
		// 拼接
		
		return hours + ":" + minutes;
	},
	dateFormatYear(time) {
		let date = new Date(time);
		let year = date.getFullYear();
		// 在日期格式中,月份是从0开始的,因此要加0,使用三元表达式在小于10的前面加0,以达到格式统一  如 09:11:05
		let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
		let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();

		// 拼接
		
		return year + "-" + month + "-" + day;
	},
	dateFormatYear2(time) {
		let date = new Date(time);
		let year = date.getFullYear() % 100;
		// 在日期格式中,月份是从0开始的,因此要加0,使用三元表达式在小于10的前面加0,以达到格式统一  如 09:11:05
		let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
		let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
	
		// 拼接
		
		return year + "/" + month + "/" + day;
	},
	getTimeByISO(time) {
		let temp_data = new Date(time).toJSON()
		let bj_time = new Date(+new Date(temp_data) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(
			/\.[\d]{3}Z/, '')
		return bj_time
	},
	getWebView(header, top, height) {
		let wv = plus.webview.create("", "square-webview", {
			additionalHttpHeaders: {
				header: header,
			},
			plusrequire: "none", //禁止远程网页使用plus的API,有些使用mui制作的网页可能会监听plus.key,造成关闭页面混乱,可以通过这种方式禁止
		 'uni-app': 'none', //不加载uni-app渲染层框架,避免样式冲突
			top: top,
			height: height,
		})
		wv.overrideUrlLoading({
			mode: "reject"
		}, (e) => {
			console.log('-------拦截请求', e.url)
			if (e.url.indexOf("?zq") !== -1) {
				let tempData = {
					url: e.url,
				}
				uni.navigateTo({
					url: `/pages/notitle_h5/notitle_h5?info=${encodeURIComponent(JSON.stringify(tempData))}`
				})
			} else if (e.url.indexOf("login") !== -1) {
				uni.navigateTo({
					url: `/pages/login_account/login_account`
				})
			} else if (e.url.indexOf("?ydn_back") !== -1) {
				uni.navigateBack({

				})
			} else {
				if (e.url === 'https://app.ydniu.com/' || e.url === 'https://app.ydniu.com') {
					uni.navigateBack({

					})
				}
			}
		})

		return wv
	},
	getPassUrl() {
		return 'https://app.ydniu.com/sports,https://app.ydniu.com/jczq/index'
	},
	getCurrentState(state, time) {
		var result = "未";
		switch (state) {
			case 4:
			case 10:
			case 12:
				result = "完";
				break;
			case 2:
				result = "中场";
				break;
			case 5:
				result = "中断";
				break;
			case 6:
				result = "取消";
				break;
			case 13:
				result = "延期";
				break;
			case 14:
				result = "腰斩";
				break;
			case 15:
				result = "待定";
				break;
	
			default:
				if (state == 3) {
					result = (time / (1000 * 60) + 45) + "'";
					if ((time / (1000 * 60)) > 45) {
						result = 90 + "+";
					}
				} else if (state == 1) {
					result = time / (1000 * 60) + "'";
					if (time / (1000 * 60) > 45) {
						result = 45 + "+";
					} else if (time / (1000 * 60) == 0) {
						result = 1 + "'";
					}
				} else {
					result = time / (1000 * 60) + "'";
				}
				break;
		}
		return result
	},
	diffCurrentDay(time) {
		// 将时间字符串转换为 Date 对象
		var targetDate = new Date(time);
		
		// 获取当前时间
		const currentDate = new Date();
		
		// 计算当前时间与目标时间之间的差距(以毫秒为单位)
		const timeDifference = currentDate.getTime() - targetDate.getTime();
		
		// 计算差距的天数
		const daysDifference = Math.abs(Math.floor(timeDifference / (1000 * 3600 * 24)));
		
		return daysDifference
	
	}
}

export default utils;