const formatTime = (date) => {
	const year = date.getFullYear();
	const month = date.getMonth() + 1;
	const day = date.getDate();
	const hour = date.getHours();
	const minute = date.getMinutes();
	const second = date.getSeconds();

	return [year, month, day].map(formatNumber).join("/") + " " + [hour, minute, second].map(formatNumber).join(":");
};
//开始年份
const yearStart = 1978;
//结束年份
const yearEnd = 2100;

const formatNumber = (n) => {
	n = n.toString();
	return n[1] ? n : "0" + n;
};

module.exports = {
	formatTime: formatTime,
};

function withData(param) {
	return param < 10 ? "0" + param : "" + param;
}
function getLoopArray(start, end) {
	var start = start || 0;
	var end = end || 1;
	var array = [];
	for (var i = start; i <= end; i++) {
		array.push(withData(i));
	}
	return array;
}
function getMonthDay(year, month) {
	var flag = year % 400 == 0 || (year % 4 == 0 && year % 100 != 0),
		array = null;
	console.log(year + "--" + month);
	switch (month) {
		case "01":
		case "03":
		case "05":
		case "07":
		case "08":
		case "10":
		case "12":
		case "1":
		case "3":
		case "5":
		case "7":
		case "8":
			array = getLoopArray(1, 31);
			break;
		case "4":
		case "6":
		case "9":
		case "04":
		case "06":
		case "09":
		case "11":
			array = getLoopArray(1, 30);
			break;
		case "02":
		case "2":
			array = flag ? getLoopArray(1, 29) : getLoopArray(1, 28);
			break;
		default:
			//array = '月份格式不正确，请重新输入！'
			array = getLoopArray(1, 30);
	}
	return array;
}
function getNewDateArry() {
	// 当前时间的处理
	var newDate = new Date();
	var year = withData(newDate.getFullYear()),
		mont = withData(newDate.getMonth() + 1),
		date = withData(newDate.getDate()),
		hour = withData(newDate.getHours()),
		minu = withData(newDate.getMinutes()),
		seco = withData(newDate.getSeconds());

	return [year, mont, date, hour, minu, seco];
}

/**
 * 返回传入时间对应的值
 * 对应的值显示年月日时分秒（时分秒不为00:00:00）
 */
function dateTimePickerNowDate(date, startYear, endYear) {
	// 返回默认显示的数组和联动数组的声明
	var dateTime = [],
		dateTimeArray = [[], [], [], [], [], []];
	var start = startYear || yearStart;
	var end = endYear || yearEnd;
	// 默认开始显示数据
	// var defaultDate = date ? [...date.split(' ')[0].split('-'), ...date.split(' ')[1].split(':')] : getNewDateArry();
	var defaultDate;
	if (date != null && date != "") {
		// if (date.indexOf('T')) {
		//   date = date.replace('T', ' ');//原来L端可能返回的时间格式有带T的格式，处理一下
		// }
		date = formatDateYMDHMS(date); //先格式化一下时间
		defaultDate = [...date.split(" ")[0].split("-"), ...date.split(" ")[1].split(":")];
	} else {
		defaultDate = getNewDateArry();
	}

	// 处理联动列表数据
	/*年月日 时分秒*/
	dateTimeArray[0] = getLoopArray(start, end);
	dateTimeArray[1] = getLoopArray(1, 12);
	dateTimeArray[2] = getMonthDay(defaultDate[0], defaultDate[1]);
	dateTimeArray[3] = getLoopArray(0, 23);
	dateTimeArray[4] = getLoopArray(0, 59);
	dateTimeArray[5] = getLoopArray(0, 59);

	dateTimeArray.forEach((current, index) => {
		dateTime.push(current.indexOf(defaultDate[index]));
	});

	return {
		dateTimeArray: dateTimeArray,
		dateTime: dateTime,
	};
}
/**
 * 返回传入时间对应的值 分钟只显示  00和30
 * 对应的值显示年月日时分秒（时分秒不为00:00:00）
 */
function dateTimePickerNowDate2(date, startYear, endYear) {
	// 返回默认显示的数组和联动数组的声明
	var dateTime = [],
		dateTimeArray = [[], [], [], [], [], []];
	var start = startYear || yearStart;
	var end = endYear || yearEnd;
	// 默认开始显示数据
	// var defaultDate = date ? [...date.split(' ')[0].split('-'), ...date.split(' ')[1].split(':')] : getNewDateArry();
	var defaultDate;
	if (date != null && date != "") {
		// if (date.indexOf('T')) {
		//   date = date.replace('T', ' ');//原来L端可能返回的时间格式有带T的格式，处理一下
		// }
		date = formatDateYMDHMS(date); //先格式化一下时间
		defaultDate = [...date.split(" ")[0].split("-"), ...date.split(" ")[1].split(":")];
	} else {
		defaultDate = getNewDateArry();
	}

	// 处理联动列表数据
	/*年月日 时分秒*/
	dateTimeArray[0] = getLoopArray(start, end);
	dateTimeArray[1] = getLoopArray(1, 12);
	dateTimeArray[2] = getMonthDay(defaultDate[0], defaultDate[1]);
	dateTimeArray[3] = getLoopArray(0, 23);
	dateTimeArray[4] = ["00", "30"];
	dateTimeArray[5] = getLoopArray(0, 59);

	dateTimeArray.forEach((current, index) => {
		dateTime.push(current.indexOf(defaultDate[index]));
	});

	return {
		dateTimeArray: dateTimeArray,
		dateTime: dateTime,
	};
}
/**
 * 返回传入时间对应的值
 * 对应的值显示年月日时分秒（时分秒为00:00:00）
 */
function dateTimePicker(date, startYear, endYear) {
	// 返回默认显示的数组和联动数组的声明
	var dateTime = [],
		dateTimeArray = [[], [], [], [], [], []];
	var start = startYear || yearStart;
	var end = endYear || yearEnd;
	// 默认开始显示数据
	// var defaultDate = date ? [...date.split(' ')[0].split('-'), ...date.split(' ')[1].split(':')] : getNewDateArry();
	var defaultDate;
	if (date != null && date != "") {
		// if (date.indexOf('T')) {
		//   date = date.replace('T', ' ');//原来L端可能返回的时间格式有带T的格式，处理一下
		// }
		date = formatDateYMDHMS(date); //先格式化一下时间
		defaultDate = [...date.split(" ")[0].split("-"), ...date.split(" ")[1].split(":")];
	} else {
		defaultDate = getNewDateArry();
	}

	defaultDate[3] = "00";
	defaultDate[4] = "00";
	defaultDate[5] = "00";

	// 处理联动列表数据
	/*年月日 时分秒*/
	dateTimeArray[0] = getLoopArray(start, end);
	dateTimeArray[1] = getLoopArray(1, 12);
	dateTimeArray[2] = getMonthDay(defaultDate[0], defaultDate[1]);
	dateTimeArray[3] = getLoopArray(0, 23);
	dateTimeArray[4] = getLoopArray(0, 59);
	dateTimeArray[5] = getLoopArray(0, 59);

	dateTimeArray.forEach((current, index) => {
		dateTime.push(current.indexOf(defaultDate[index]));
	});

	return {
		dateTimeArray: dateTimeArray,
		dateTime: dateTime,
	};
}
function dateTimePicker2(date, startYear, endYear) {
	// 返回默认显示的数组和联动数组的声明
	var dateTime = [],
		dateTimeArray = [[], [], [], [], [], []];
	var start = startYear || yearStart;
	var end = endYear || yearEnd;
	// 默认开始显示数据
	// var defaultDate = date ? [...date.split(' ')[0].split('-'), ...date.split(' ')[1].split(':')] : getNewDateArry();
	var defaultDate;
	// debugger;
	if (date != null && date != "") {
		// if (date.indexOf('T')) {
		//   date = date.replace('T', ' ');//原来L端可能返回的时间格式有带T的格式，处理一下
		// }
		date = formatDateYMDHMS(date); //先格式化一下时间
		defaultDate = [...date.split(" ")[0].split("-"), ...date.split(" ")[1].split(":")];
	} else {
		defaultDate = getNewDateArry();
	}

	// defaultDate[3] = '00';
	// defaultDate[4] = '00';
	// defaultDate[5] = '00';

	// 处理联动列表数据
	/*年月日 时分秒*/
	dateTimeArray[0] = getLoopArray(start, end);
	dateTimeArray[1] = getLoopArray(1, 12);
	dateTimeArray[2] = getMonthDay(defaultDate[0], defaultDate[1]);
	dateTimeArray[3] = getLoopArray(0, 23);
	//dateTimeArray[4] = ['00'];
	dateTimeArray[4] = getLoopArray(0, 59);
	dateTimeArray[5] = getLoopArray(0, 59);

	dateTimeArray.forEach((current, index) => {
		dateTime.push(current.indexOf(defaultDate[index]));
	});

	return {
		dateTimeArray: dateTimeArray,
		dateTime: dateTime,
	};
}
function dateTimePickerYMDHM(date, startYear, endYear) {
	// 返回默认显示的数组和联动数组的声明
	var dateTime = [],
		dateTimeArray = [[], [], [], [], []];
	var start = startYear || yearStart;
	var end = endYear || yearEnd;
	// 默认开始显示数据
	var defaultDate;
	if (date != null && date != "") {
		// if (date.indexOf('T')) {
		//   date = date.replace('T', ' ');//原来L端可能返回的时间格式有带T的格式，处理一下
		// }
		date = formatDateYMDHMS(date); //先格式化一下时间
		defaultDate = [...date.split(" ")[0].split("-"), ...date.split(" ")[1].split(":")];
	} else {
		defaultDate = getNewDateArry();
	}

	defaultDate[3] = "00";
	defaultDate[4] = "00";
	defaultDate[5] = "00";
	// var defaultDate = date ? [...date.split(' ')[0].split('-'), ...date.split(' ')[1].split(':')] : getNewDateArry();

	// 处理联动列表数据
	/*年月日 时分秒*/
	dateTimeArray[0] = getLoopArray(start, end);
	dateTimeArray[1] = getLoopArray(1, 12);
	dateTimeArray[2] = getMonthDay(defaultDate[0], defaultDate[1]);
	dateTimeArray[3] = getLoopArray(0, 23);
	dateTimeArray[4] = getLoopArray(0, 59);
	// dateTimeArray[5] = getLoopArray(0, 59);

	dateTimeArray.forEach((current, index) => {
		dateTime.push(current.indexOf(defaultDate[index]));
	});
	return {
		dateTimeArray: dateTimeArray,
		dateTime: dateTime,
	};
}

function dateTimePickerYMDHM2(date, startYear, endYear) {
	//分钟为00和30
	// 返回默认显示的数组和联动数组的声明
	var dateTime = [],
		dateTimeArray = [[], [], [], [], []];
	var start = startYear || yearStart;
	var end = endYear || yearEnd;
	// 默认开始显示数据
	var defaultDate;
	if (date != null && date != "") {
		// if (date.indexOf('T')) {
		//   date = date.replace('T', ' ');//原来L端可能返回的时间格式有带T的格式，处理一下
		// }
		date = formatDateYMDHMS(date); //先格式化一下时间
		defaultDate = [...date.split(" ")[0].split("-"), ...date.split(" ")[1].split(":")];
	} else {
		defaultDate = getNewDateArry();
	}

	defaultDate[3] = "00";
	defaultDate[4] = "00";
	defaultDate[5] = "00";
	// var defaultDate = date ? [...date.split(' ')[0].split('-'), ...date.split(' ')[1].split(':')] : getNewDateArry();

	// 处理联动列表数据
	/*年月日 时分秒*/
	dateTimeArray[0] = getLoopArray(start, end);
	dateTimeArray[1] = getLoopArray(1, 12);
	dateTimeArray[2] = getMonthDay(defaultDate[0], defaultDate[1]);
	dateTimeArray[3] = getLoopArray(0, 23);
	dateTimeArray[4] = ["00", "30"];
	// dateTimeArray[5] = getLoopArray(0, 59);

	dateTimeArray.forEach((current, index) => {
		dateTime.push(current.indexOf(defaultDate[index]));
	});
	return {
		dateTimeArray: dateTimeArray,
		dateTime: dateTime,
	};
}

function dateTimePickerYMD(date, startYear, endYear) {
	// 返回默认显示的数组和联动数组的声明
	var dateTime = [],
		dateTimeArray = [[], [], [], [], []];
	var start = startYear || yearStart;
	var end = endYear || yearEnd;
	// 默认开始显示数据
	var defaultDate;
	if (date != null && date != "") {
		// if (date.indexOf('T')) {
		//   date = date.replace('T', ' ');//原来L端可能返回的时间格式有带T的格式，处理一下
		// }
		date = formatDateYMDHMS(date); //先格式化一下时间
		defaultDate = [...date.split(" ")[0].split("-"), ...date.split(" ")[1].split(":")];
	} else {
		defaultDate = getNewDateArry();
	}
	// var defaultDate = date ? [...date.split(' ')[0].split('-'), ...date.split(' ')[1].split(':')] : getNewDateArry();

	// 处理联动列表数据
	/*年月日 时分秒*/
	dateTimeArray[0] = getLoopArray(start, end);
	dateTimeArray[1] = getLoopArray(1, 12);
	dateTimeArray[2] = getMonthDay(defaultDate[0], defaultDate[1]);
	// dateTimeArray[3] = getLoopArray(0, 23);
	// dateTimeArray[4] = getLoopArray(0, 59);
	// dateTimeArray[5] = getLoopArray(0, 59);

	dateTimeArray.forEach((current, index) => {
		dateTime.push(current.indexOf(defaultDate[index]));
	});

	return {
		dateTimeArray: dateTimeArray,
		dateTime: dateTime,
	};
}

/**
 * 时间格式化  2017-01-01 01:01:01
 * @param val
 * @returns {string}
 */
function formatDateYMDHMS(val) {
	// model -> view，在更新 `<input>` 元素之前格式化值
	if ((val != null || val == "") && typeof val == "string") {
		if (val.indexOf("T")) {
			val = val.replace("T", " "); //原来L端可能返回的时间格式有带T的格式，处理一下
		}
		val = val.replace("-", "/").replace("-", "/");
	}
	var value = new Date(val);
	//console.log(val);
	var fmt = "yyyy-MM-dd HH:mm:ss";
	var o = {
		"M+": value.getMonth() + 1, //月份
		"d+": value.getDate(), //日
		"H+": value.getHours(), //小时
		//"h+": val.getHours()%12 == 0 ? 12 : val.getHours()%12, //小时
		"m+": value.getMinutes(), //分
		"s+": value.getSeconds(), //秒
		//"S": val.getMilliseconds() //毫秒
		//"q+": Math.floor((val.getMonth() + 3) / 3) //季度
	};
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (value.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o) {
		if (new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return fmt;
}

/**
 * 时间格式化  2017-01-01 01:01:01
 * @param val
 * @returns {string}
 */
function formatDateYMDHM(val) {
	// model -> view，在更新 `<input>` 元素之前格式化值
	if (val != null && val != "") {
		if (typeof val == "string") {
			if (val.indexOf("T")) {
				val = val.replace("T", " "); //原来L端可能返回的时间格式有带T的格式，处理一下
			}
			val = val.replace("-", "/").replace("-", "/");
		}
		var value = new Date(val);
		//console.log(val);
		var fmt = "yyyy-MM-dd HH:mm";
		var o = {
			"M+": value.getMonth() + 1, //月份
			"d+": value.getDate(), //日
			"H+": value.getHours(), //小时
			//"h+": val.getHours()%12 == 0 ? 12 : val.getHours()%12, //小时
			"m+": value.getMinutes(), //分
			// "s+": value.getSeconds() //秒
			//"S": val.getMilliseconds() //毫秒
			//"q+": Math.floor((val.getMonth() + 3) / 3) //季度
		};
		if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (value.getFullYear() + "").substr(4 - RegExp.$1.length));
		for (var k in o) {
			if (new RegExp("(" + k + ")").test(fmt)) {
				fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
			}
		}
		return fmt || "";
	} else {
		return "-";
	}
}

// 年月日
function formatDateYMD(val) {
	// model -> view，在更新 `<input>` 元素之前格式化值
	if (val == null || val == "") {
		return null;
	}

	if ((val != null || val == "") && typeof val == "string") {
		if (val.indexOf("T")) {
			val = val.replace("T", " "); //原来L端可能返回的时间格式有带T的格式，处理一下
		}
		val = val.replace("-", "/").replace("-", "/");
	}
	var value = new Date(val);
	//console.log(val);
	var fmt = "yyyy-MM-dd";
	var o = {
		"M+": value.getMonth() + 1, //月份
		"d+": value.getDate(), //日
		// "H+": value.getHours(), //小时
		//"h+": val.getHours()%12 == 0 ? 12 : val.getHours()%12, //小时
		// "m+": value.getMinutes(), //分
		// "s+": value.getSeconds() //秒
		//"S": val.getMilliseconds() //毫秒
		//"q+": Math.floor((val.getMonth() + 3) / 3) //季度
	};
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (value.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o) {
		if (new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return fmt;
}
/**
 * 时间格式化  mm:ss
 * @param val
 * @returns {string}
 */
function formatDateMS(val) {
	if ((val != null || val == "") && typeof val == "string") {
		if (val.indexOf("T")) {
			val = val.replace("T", " "); //原来L端可能返回的时间格式有带T的格式，处理一下
		}
		val = val.replace("-", "/").replace("-", "/");
	}
	var value = new Date(val);
	var fmt = "HH:mm";
	var o = {
		"H+": value.getHours(), //小时
		"m+": value.getMinutes(), //分
	};
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (value.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o) {
		if (new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return fmt;
}
/**
格式化为苹果手机能认的时间格式yyyy/MM/dd HH:mm:ss
*/
function formatDateYMDHMS_TO_APPLE(val) {
	// model -> view，在更新 `<input>` 元素之前格式化值
	if (val != null || val == "") {
		val = val + "";
		if (val.indexOf("T")) {
			val = val.replace("T", " "); //原来L端可能返回的时间格式有带T的格式，处理一下
		}
		val = val.replace("-", "/").replace("-", "/");
	}
	var value = new Date(val);
	//console.log(val);
	var fmt = "yyyy/MM/dd HH:mm:ss";
	var o = {
		"M+": value.getMonth() + 1, //月份
		"d+": value.getDate(), //日
		"H+": value.getHours(), //小时
		//"h+": val.getHours()%12 == 0 ? 12 : val.getHours()%12, //小时
		"m+": value.getMinutes(), //分
		"s+": value.getSeconds(), //秒
		//"S": val.getMilliseconds() //毫秒
		//"q+": Math.floor((val.getMonth() + 3) / 3) //季度
	};
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (value.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o) {
		if (new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return fmt;
}
/**
获取当前时间所在年
*/
function getNowYear() {
	return new Date().getFullYear();
}
/**
获取当前时间所在月
*/
function getNowMonth() {
	return new Date().getMonth() + 1;
}
/**
获取当前时间的年月
*/
function getNowYearMonth() {
	var date = new Date();
	var month = date.getMonth() + 1;
	if (month < 10) {
		month = "0" + month;
	}
	return date.getFullYear() + "-" + month;
}
/**
获取当前时间的年月日
*/
function getNowYearMonthDay() {
	var date = new Date();
	var month = date.getMonth() + 1;
	if (month < 10) {
		month = "0" + month;
	}
	return date.getFullYear() + "-" + month + "-" + date.getDate();
}
/**
获取时间的上午下午格式
*/
function formateTimeAMPM(date) {
	if (date == null || date == "") {
		return "";
	}
	if (typeof date == "string") {
		date = date.replace("-", "/").replace("-", "/");
	}
	var d = new Date(date);
	var hour = d.getHours();
	if (hour <= 12) {
		return "AM " + (hour + 1) + ":" + d.getMinutes();
	} else if (hour > 12) {
		return "PM " + (hour + 1) + ":" + d.getMinutes();
	} else {
		return "";
	}
}

function getTodayYYYYMMDD() {
	var date = new Date();
	return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
}
function formateMonthDay(dateTime) {
	// debugger;
	var dt = dateTime.split("-");
	return dt[1] * 1 + "月" + dt[2] * 1 + "日";
}
// 时间对比
function subTimes(_val1, _val2) {
	var start_date = new Date(_val1.replace(/-/g, "/"));
	var end_date = new Date(_val2.replace(/-/g, "/"));
	var days = end_date.getTime() - start_date.getTime();
	return days / (1000 * 60); //返回分钟数
}
// 时间对比

function subDays(sDate1) {
	//sDate1和sDate2是2017-9-25格式
	sDate1 = formatDateYMD(sDate1);
	var sDate2 = getTodayYYYYMMDD();
	var aDate, oDate1, oDate2, iDays;
	aDate = sDate1.split("-");
	oDate1 = new Date(aDate[1] + "/" + aDate[2] + "/" + aDate[0]); //转换为9-25-2017格式
	aDate = sDate2.split("-");
	oDate2 = new Date(aDate[1] + "/" + aDate[2] + "/" + aDate[0]);
	iDays = parseInt((oDate2 - oDate1) / 1000 / 60 / 60 / 24); //把相差的毫秒数转换为天数
	return iDays;
}

function subDays1(_val1) {
	var start_date = new Date(_val1.replace(/-/g, "/"));

	// console.log(start_date.toLocaleDateString()+"pppp");
	var end_date = new Date();

	// var days = end_date - start_date;
	var days = parseInt((end_date.getTime() - start_date.getTime()) / 1000 / 3600 / 24);
	console.log("start_date:" + start_date);
	console.log("end_date:" + end_date);
	console.log(days);
	var day = parseInt(days);
	console.log(day + "uuuuuu");
	return day;
}
/**
 * 获取今天、明天、后天
 */
function getDataName(dateTemp) {
	var timeStr = "";
	if (isNotEmptyCheck(dateTemp)) {
		var str = formatDateYMD(dateTemp);

		var date = str.split(" ")[0];
		if (getFutureDateYMD(0) == date) {
			timeStr = "（今天）";
		} else if (getFutureDateYMD(1) == date) {
			timeStr = "（明天）";
		} else if (getFutureDateYMD(2) == date) {
			timeStr = "（后天）";
		}
	}
	return timeStr;
}
/**
 * 如果是null '' 'null' 'undefined'
 * @param item
 * @returns
 */
function isEmptyCheck(value) {
	if (value == null || value === "" || value == "null" || typeof value == "undefined") {
		return true;
	}
	return false;
}
/**
 * 如果不是是null '' 'null' 'undefined'
 * @param item
 * @returns
 */
function isNotEmptyCheck(value) {
	return !isEmptyCheck(value);
}
/**
 * 获取未来第几天，
 * 1、传入正数，返回未来几天
 * 2、传入负数，返回过去几天
 */
function getFutureDateYMD(dayNum) {
	// 开始时间
	var date = new Date();
	date.setDate(date.getDate() + dayNum);
	var prevYear = date.getFullYear();
	var prevMonth = date.getMonth() + 1;
	var prevDay = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
	return prevYear + "-" + (prevMonth >= 10 ? prevMonth : "0" + prevMonth) + "-" + prevDay;
}

function getDateYMDHM() {
	// 开始时间
	let date = new Date();
	let prevYear = date.getFullYear();
	let prevMonth = date.getMonth() + 1;
	let prevDay = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
	let hour = date.getHours();
	let minute = date.getMinutes();
	// let second = date.getSeconds();
	return prevYear + "-" + (prevMonth >= 10 ? prevMonth : "0" + prevMonth) + "-" + prevDay + " " + hour + ":" + minute;
}

// function getDateYMDHM() {
//   // 开始时间
//   let date = new Date();
//   let prevYear = date.getFullYear();
//   let prevMonth = date.getMonth() + 1;
//   let prevDay = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
//   let hour = date.getHours();
//   let minute = date.getMinutes();
//   // let second = date.getSeconds();
//   return prevYear + "-" + (prevMonth >= 10 ? prevMonth : ('0' + prevMonth))  + "-" + prevDay + " " + hour + ":" + minute;
// }

function getDateYMD() {
	// 开始时间
	let date = new Date();
	let prevYear = date.getFullYear();
	let prevMonth = date.getMonth() + 1;
	let prevDay = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
	// let second = date.getSeconds();
	return prevYear + "-" + (prevMonth >= 10 ? prevMonth : "0" + prevMonth) + "-" + prevDay;
}

function getHour() {
	// 开始时间
	let date = new Date();
	let hour = date.getHours();
	// let second = date.getSeconds();
	return hour;
}
function timeShow(val) {
	if (isEmptyCheck(val)) {
		return "";
	}

	if (typeof val == "string") {
		val = val + "";
		if (val.indexOf("T")) {
			val = val.replace("T", " "); //原来L端可能返回的时间格式有带T的格式，处理一下
		}
		val = val.replace("-", "/").replace("-", "/");
	}

	var date = new Date();
	var value = new Date(val);

	const year0 = date.getFullYear();
	const month0 = date.getMonth() + 1;
	const day0 = date.getDate();
	const hour0 = date.getHours();
	const minute0 = date.getMinutes();
	// const second = date.getSeconds()

	const year1 = value.getFullYear();
	const month1 = value.getMonth() + 1;
	const day1 = value.getDate();
	const hour1 = value.getHours();
	const minute1 = value.getMinutes();
	// const second = value.getSeconds()

	if (year0 == year1 && month0 == month1 && day0 == day1) {
		return hour1 + ":" + (minute1 >= 10 ? minute1 : "0" + minute1);
	}

	let d = new Date(val).setHours(0, 0, 0, 0);
	let today = new Date().setHours(0, 0, 0, 0);

	if (d - today == -86400000) {
		return "昨天";
	}

	if (year0 == year1) {
		return month1 + "月" + day1 + "日";
	}
	return (year1 + "").slice(2) + "年" + month1 + "月" + day1 + "日";

	return hour;
}

function timeShowXXX(val) {
	if (isEmptyCheck(val)) {
		return "";
	}
	let date = "";
	let differenceTime = new Date().getTime() - new Date(val).getTime();
	var D = Math.floor(differenceTime / (24 * 60 * 60 * 1000));
	var level1 = differenceTime % (24 * 3600 * 1000);
	var H = Math.floor(level1 / (3600 * 1000));
	var level2 = level1 % (3600 * 1000);
	var M = Math.floor(level2 / (60 * 1000));
	var level3 = level2 % (60 * 1000);
	var S = Math.floor(level3 / 1000);
	date = null;
	if (D > 0 && D <= 100) {
		date = D + "天前";
	} else if (D > 0) {
		let date1 = new Date(val);
		var y = date1.getFullYear();
		var m = date1.getMonth() + 1;
		m = m < 10 ? "0" + m : m;
		var d = date1.getDate();
		d = d < 10 ? "0" + d : d;
		var h = date1.getHours();
		h = h < 10 ? "0" + h : h;
		var minute = date1.getMinutes();
		minute = minute < 10 ? "0" + minute : minute;
		var second = date1.getSeconds();
		second = second < 10 ? "0" + second : second;
		date = y + "-" + m + "-" + d + " " + h + ":" + minute;
	} else if (H > 0) {
		date = H + "小时前";
	} else if (M > 0) {
		date = M + "分钟前";
	} else {
		date = S + "秒前";
	}
	return date;
}
/**
 * 处理工单状态
 */
export function userApplyOrderStatusArray() {
	// let orderStatus = [
	//   { id: "10", name: "审核中", value: "10", text: "审核中" },
	//   { id: "20", name: "待面试", value: "20", text: "待面试" },
	//   { id: "30", name: "待入职", value: "30", text: "待入职" },
	//   { id: "40", name: "在职中", value: "40", text: "在职中" },
	//   { id: "50", name: "待离职", value: "50", text: "待离职" },
	//   { id: "60", name: "已完成", value: "60", text: "已完成" },
	// ];
	let orderStatus = [
		{
			id: "10",
			name: "审核中",
			value: "10",
			text: "审核中",
			num: 0,
		},
		{
			id: "20",
			name: "待接待",
			value: "20",
			text: "待接待",
			num: 0,
		},
		{
			id: "21",
			name: "审核未通过",
			value: "21",
			text: "审核未通过",
			num: 0,
		},
		{ id: "25", name: "待面试", value: "25", text: "待面试", num: 0 },
		{ id: "26", name: "未接到", value: "26", text: "未接到", num: 0 },
		{
			id: "30",
			name: "待入职",
			value: "30",
			text: "待入职",
			num: 0,
		},
		{ id: "35", name: "面试未通过", value: "35", text: "面试未通过", num: 0 },
		{ id: "40", name: "在职中", value: "40", text: "在职中", num: 0 },
		{
			id: "45",
			name: "通过未入职",
			value: "45",
			text: "通过未入职",
			num: 0,
		},
		{
			id: "48",
			name: "约离职",
			value: "48",
			text: "约离职",
			num: 0,
		},
		{ id: "50", name: "已离职", value: "50", text: "已完成", num: 0 },
		// { id: "60", name: "已完成", value: "60", text: "已完成", num: 0 }
	];
	return orderStatus;
}
/* 
  截取备注字段
*/
export function splitRemark(info) {
	let index = info.lastIndexOf("备注");
	let remark = info.substr(index + 3);
	console.log(remark);
	return remark;
}

/**
 * 根据工单类型获取名称
 */
export function getUserApplyOrderTypeByType(type) {
	let typeStr = "";
	let array = userApplyOrderStatusArray();
	array.forEach((item) => {
		if (item.type == type) {
			typeStr = item.text;
		}
	});
	return typeStr;
}

/**
 * 根据工单状态ID获取名称
 */
export function getUserApplyOrderStatusById(id) {
	let str = "";
	let array = userApplyOrderStatusArray();
	array.forEach((item) => {
		if (item.id == id) {
			str = item.name;
		}
	});
	return str;
}
module.exports = {
	getFutureDateYMD: getFutureDateYMD,
	isEmptyCheck: isEmptyCheck,
	isNotEmptyCheck: isNotEmptyCheck,
	dateTimePickerNowDate: dateTimePickerNowDate,
	dateTimePickerNowDate2: dateTimePickerNowDate2,
	dateTimePicker: dateTimePicker,
	dateTimePicker2: dateTimePicker2,
	dateTimePickerYMDHM: dateTimePickerYMDHM,
	dateTimePickerYMDHM2: dateTimePickerYMDHM2,
	dateTimePickerYMD: dateTimePickerYMD,
	getMonthDay: getMonthDay,
	formatDateYMDHMS: formatDateYMDHMS,
	formatDateYMDHM: formatDateYMDHM,
	formatDateYMD: formatDateYMD,
	formatDateMS: formatDateMS,
	formatDateYMDHMS_TO_APPLE: formatDateYMDHMS_TO_APPLE,
	getNowYear: getNowYear,
	getNowMonth: getNowMonth,
	getNowYearMonth: getNowYearMonth,
	getNowYearMonthDay: getNowYearMonthDay,
	formateTimeAMPM: formateTimeAMPM,
	getTodayYYYYMMDD: getTodayYYYYMMDD,
	formateMonthDay: formateMonthDay,
	subTimes: subTimes,
	subDays: subDays,
	getDataName: getDataName,
	getDateYMDHM: getDateYMDHM,
	getDateYMD: getDateYMD,
	getHour: getHour,
	timeShowXXX: timeShowXXX,
	getUserApplyOrderStatusById,
	getUserApplyOrderTypeByType,
	splitRemark,
	timeShow,
};
