//时间格式化
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) { 
  if(date==null||date=='') return " "
  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 statusText(type) {
  var status = '';
  switch (type) {
    case 0:
      status = '未支付';
      break;
    case 1:
      status = '已支付';
      break;
    case 2:
      status = '已取消';
      break;
    case 3:
      status = '已退款';
      break;
    case 4:
      status = '待退款';
      break;
   
    default:
      status = '';  

  }
  return status;

}
function specialStatusText(type) {
	var status = '';
	// 2 已生成待同意 3 已同意待发放(不需收集信息) ,4 不同意发放结束 5已同意待发放(已收集具体信息) 6 发放成功 7取消发放,8 发放失败 9 发放中
  switch (type) {
    case 2:
      status = '已生成待同意';
      break;
    case 3:
      status = '已同意待发放(不需收集信息)';
      break;
    case 4:
      status = '不同意';
      break;
    case 5:
      status = '已同意待发放(已收集具体信息)';
      break;
    case 6:
      status = '发放成功';
			break;
		case 7:
      status = '取消发放';
      break;
		case 8:
				status = '发放失败';
				break;
	  case 9:
					status = '发放中';
					break;		
    default:
      status = '';  

  }
  return status;

}


module.exports = {
  formatTime: formatTime,
  formatNumber: formatNumber,
  formatDate: formatDate,
  sliceFun: sliceFun,
  numToReg: numToReg,
  regD: regD,
  defineIndexOf: defineIndexOf,
  includeItem: includeItem,
  serviceModel:serviceModel,
  sliceStr:sliceStr,
	statusText:statusText,
	specialStatusText:specialStatusText,

}

// 截取文字*号代替