//时间格式化
var formatTime = function(date) {
	var date = getDate(date)
	var year = date.getFullYear()
	var month = date.getMonth() + 1
	var day = date.getDate()
	var hour = date.getHours()
	var minute = date.getMinutes()
	var second = date.getSeconds()

	return [year, month, day].map(formatNumber).join('-')
}

var formatNumber = function(n) {
	n = n.toString()
	return n[1] ? n : '0' + n
}

// + ' ' + [hour, minute, second].map(formatNumber).join(':')
//年月日时分
var formatDate = function(date) {
	var date = getDate(date)
	var year = date.getFullYear()
	var month = date.getMonth() + 1
	var day = date.getDate()
	var hour = date.getHours()
	var minute = date.getMinutes()
	var second = date.getSeconds()

	return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':')
}



//时分格式化
var formatDateSF = function(date) {
	var date = getDate(date)
	var year = date.getFullYear()
	var month = date.getMonth() + 1
	var day = date.getDate()
	var hour = date.getHours()
	var minute = date.getMinutes()
	var second = date.getSeconds()

	return [hour, minute].map(formatNumber).join(':')
}

var numToReg = function(val) {
	return val.replace(getRegExp('[0-9]', 'g'), '*')
}


//截取返回时间到分钟
var sliceFun = function(val) {
	return val.slice(0, 5)
}


//正则-逗号
var regD = function(val) {
	return val.replace(getRegExp('[,]', 'g'), ' ')
}



var interceptStart = function(text) {
	var str = text.substr(1, 3).replace(str, "**");
	return str

}



function defineIndexOf(str, val) {
	return str.indexOf(val);
}

function includeItem(arr, week, val) {
	// let arrItem=arr.filter(item=>{return item.week==week});
	// let isInclude=arrItem.some(item=>{return item.time==val});
	// return isInclude;
	var length = arr.length;
	var timeList = [];
	for (var i = 0; i < length; i++) {
		if (arr[i].week == week) {
			timeList.push(arr[i]);
		}
	}
	var len2 = timeList.length;
	var isInclude = false;
	for (var j = 0; j < len2; j++) {
		if (timeList[j].time == val) {
			isInclude = true;
			break;
		}
	}
	return isInclude;

}

function serviceModel(type) {
	var modelText = '';
	switch (type) {
		case '1':
			modelText = '钟点工';
			break;
		case '2':
			modelText = '白班保姆';
			break;
		case '3':
			modelText = '住家保姆';
			break;
		case '4':
			modelText = '月嫂';
			break;
		case '5':
			modelText = '代班保姆-钟点工';
			break;
		case '6':
			modelText = '代班保姆-保姆';
			break;
		default:
			modelText = '';

	}
	return modelText;

}

function sliceStr(str, start, end) {
	var result = str.substring(start, end);
	result = result.replace(getRegExp('-', 'g'), '.');
	return result;
}

function formatOverTime(time) {
	var minute = '00';
	var second = '00';
	if (time > 0) {
		minute = (Math.floor(time / 60) < 10 ? ('0' + Math.floor(time / 60)) : Math.floor(time / 60));
		second = Number(time % 60).toFixed(0) < 10 ? ('0' + Number(time % 60).toFixed(0)) : Number(time % 60).toFixed(
			0);
	}

	var result = "00:" + minute + ":" + second;

	return result;

}

function getNotServiceTimes(total, serviced) {
	var result = total;
	if (serviced) {
		result = total - serviced;
	}
	return result;
}

function formatDistance(val) {
	var result = val;
	result = Number(val).toFixed(0);
	return result;
}

function servciceName(index) {
	var modelText = '';
	switch (index) {
		case 0:
			modelText = '一';
			break;
		case 1:
			modelText = '二';
			break;
		case 2:
			modelText = '三';
			break;
		case 3:
			modelText = '四';
			break;
		case 4:
			modelText = '五';
			break;
		case 5:
			modelText = '六';
			break;
		case 6:
			modelText = '七';
			break;
		case 7:
			modelText = '八';
			break;
		case 8:
			modelText = '九';
			break;
		case 9:
			modelText = '十';
			break;
		case 10:
			modelText = '十一';
			break;
		case 11:
			modelText = '十二';
			break;
		case 12:
			modelText = '十三';
			break;
		case 13:
			modelText = '十四';
			break;
		case 14:
			modelText = '十五';
			break;
		case 15:
			modelText = '十六';
			break;
		case 16:
			modelText = '十七';
			break;
		case 17:
			modelText = '十八';
			break;
		case 18:
			modelText = '十九';
			break;
		case 19:
			modelText = '二十';
			break;


		default:
			modelText = '';
	}
	return modelText;
}
module.exports = {
	formatTime: formatTime,
	formatNumber: formatNumber,
	formatDate: formatDate,
	sliceFun: sliceFun,
	numToReg: numToReg,
	regD: regD,
	defineIndexOf: defineIndexOf,
	includeItem: includeItem,
	serviceModel: serviceModel,
	sliceStr: sliceStr,
	formatOverTime: formatOverTime,
	getNotServiceTimes: getNotServiceTimes,
	formatDistance: formatDistance,
	servciceName: servciceName
}

// 截取文字*号代替