// 查看PDF文件
function pdfPreview(url){
	let PDFurl = url[0].url;
	console.log(PDFurl);
	window.native.pdfPreview(PDFurl);
}

// 查看图片
function imagePreviewArray(url){
	console.log(url);
}

// 获取token
function getAccessToken(){
	var AccessToken = window.native.getAccessToken();
	// console.log("Token>>>"+AccessToken);
 //    alert("Token>>>"+AccessToken);
	return AccessToken;
}

// 获取当前年月
function getNowYearMonth(){
	var myDate = new Date();
	var tYear = myDate.getFullYear();
	var tMonth = myDate.getMonth();
	
	var m = tMonth + 1;
	if (m.toString().length == 1) {
	m = "0" + m;
	}
	return tYear +'-'+ m;
	}
	function doHandleYear(tYear) {
	var myDate = new Date();
	var tYear = myDate.getFullYear();
	
	return tYear;
	}
	function doHandleMonth() {
	var myDate = new Date();
	var tMonth = myDate.getMonth();
	
	var m = tMonth + 1;
	if (m.toString().length == 1) {
	m = "0" + m;
	}
	return m;
}

// 获取当前日期指定天数前后日期
function getDate(type) {
	const date = new Date();

	let year = date.getFullYear();
	let month = date.getMonth() + 1;
	let day = date.getDate();

	if (type === 'start') {
		year = year - 10;
	} else if (type === 'end') {
		year = year + 10;
	}
	month = month > 9 ? month : '0' + month;;
	day = day > 9 ? day : '0' + day;

	return `${year}-${month}-${day}`;
}
// 获取直接天数后的日期
function getAfterDate(AddDayCount){
	var dd = new Date();
	dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期  
	var y = dd.getFullYear();
	var m = (dd.getMonth() + 1) < 10 ? "0" + (dd.getMonth() + 1) : (dd.getMonth() + 1); //获取当前月份的日期，不足10补0  
	var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate(); //获取当前几号，不足10补0  
	return y + "-" + m + "-" + d;
}

// 日期格式化
function dateFormat(date) {
	date = new Date(Date.parse(date.replace(/-/g, "/"))); //转换成Data();
	var y = date.getFullYear();
	var m = date.getMonth() + 1;
	m = m < 10 ? '0' + m : m;
	var d = date.getDate();
	d = d < 10 ? ('0' + d) : d;
	return y + '-' + m + '-' + d;
}
module.exports = {
	pdfPreview,
	imagePreviewArray,
	getAccessToken,
	getNowYearMonth,
	getDate,
	dateFormat
}