var formatDateYYYYMMDDHHMM = function (time) {
  var date = getDate(time);
  var m = date.getMonth() + 1;
  if(m < 10) {
    m = "0" + m;
  }
  var d = date.getDate();
  if(d < 10) {
    d = "0" + d;
  }
  var h = date.getHours();
  if(h < 10) {
    h = "0" + h;
  }
  var mm = date.getMinutes();
  if(mm < 10) {
    mm = "0" + mm;
  }
  return date.getFullYear() + '-' + m + '-' + d + ' ' + h + ':' + mm;
}
var formatDateYYYYMMDD = function (time) {
  var date = getDate(time);
  var m = date.getMonth() + 1;
  if(m < 10) {
    m = "0" + m;
  }
  var d = date.getDate();
  if(d < 10) {
    d = "0" + d;
  }
  return date.getFullYear() + '-' + m + '-' + d;
}
var formatDateYYYYMMDD2 = function (time) {
  var date = getDate(time);
  var m = date.getMonth() + 1;
  if(m < 10) {
    m = "0" + m;
  }
  var d = date.getDate();
  if(d < 10) {
    d = "0" + d;
  }
  return date.getFullYear() + '/' + m + '/' + d;
}
var formatDateMMSS = function (time) {
  return (getDate(time).getHours() > 9 ? getDate(time).getHours() : '0' + getDate(time).getHours()) + ':' + (getDate(time).getMinutes() > 9 ? getDate(time).getMinutes() : '0' + getDate(time).getMinutes());
}

var showClockResult = function (confirmStatus, confirmReason) {
  temp = "";
  if (confirmStatus == 0) {
    temp = "未出勤";
  } else if (confirmStatus == 1) {
    temp = "出勤半天";
  } else if (confirmStatus == 2) {
    temp = "出勤一天";
  }
  if (confirmReason == 0) {
    temp = temp + " 休息";
  } else if (confirmReason == 1) {
    temp = temp + " 请假";
  }
  return temp;
}

var showClockResult2 = function (reason) {
  temp = "未出勤 ";
  if (reason == 0) {
    temp += "休息";
  } else if (reason == 1) {
    temp += "请假";
  }
  return temp;
}


var showWorkState = function(followNewState, appraiserState) {
  var res = "";
  if (appraiserState === 0) {
          res = "未鉴定";
        } else if (appraiserState == 1) {
          res = "待鉴定";
        } else if (appraiserState == 2) {
          res = "已鉴定";
        }
  
  var temp = "";
  switch(followNewState) {
      case 10 :
          temp = "已预约";
          break;
      case 20 :
          temp = "待面试";
          break ;
      case 30 :
          temp = "待入职";
          break ;
      case 40 :
          temp = "在职中";
          break ;
      case 50 :
          temp = "已离职";
          break ;
      case 60 :
          temp = "关闭期望";
          break ;
      default :
          temp = res;
  }
  return temp;
}

showSourceName = function (intervieweeSource) {
  var result = '';
  switch (intervieweeSource) {
      case 0 :
          result = '58';
          break;
      case 5 :
          result = '赶集';
          break;
      case 6 :
          result = '打勾网预约';
          break;
      case 1 :
          result = '推广军推荐';
          break;
      case 2 :
          result = '御林军推荐';
          break;
      case 3 :
          result = '会员推荐';
          break;
      case 4 :
          result = '其它';
          break;
      default:
          break;
  }
  return result;
}

initHopePositionType = function(type) {
  var res = '';
  if(isNotEmptyCheck(type)) {
    switch (type) {
        case 1 :
            res = '全职';
            break;
        case 2 :
            res = '兼职';
            break;
        case 3 :
            res = '小时工';
            break;
    }
  }
  return res;
}

/**
 * 如果是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);
}

function showNotNullStr(value) {
  return value == null ? '' : value;
}

function showNotNullNum(value) {
  return value == null || value == '' ? 0 : value;
}

function showStoreAddress(township, distance) {
  
  result = '';
  if (!isEmptyCheck(township) && !isEmptyCheck(distance)) {
    if (distance >= 1000) {
      distance = distance / 1000;
      return township + '·' + parseInt(distance) + '千米';
    } else {
      return township + '·' + distance + '米';
    }
  } else if (!isEmptyCheck(township) && isEmptyCheck(distance)) {
    result = township;
  } else if (isEmptyCheck(township) && !isEmptyCheck(distance)) {
    if (distance >= 1000) {
      distance = distance / 1000;
      result = parseInt(distance) + '千米';
    } else {
      result = distance + '米';
    }
    
    
  }
  return result;
}


function initDormType(_type) {
  var temp = "";
  switch (_type) {
    case 0:
      temp = "有宿舍";
      break;
    case 1:
      temp = "男有宿舍";
      break;
    case 2:
      temp = "女有宿舍";
      break;
    case 3:
      temp = "无宿舍";
      break;
  }
  return temp;
}

function timeago(timestamp) {
  var mistiming = Math.round((getDate().getTime() - timestamp) / 1000);
  
  var arrr = ['年', '个月', '天', '小时', '分钟', '秒'];
  var arrn = [31536000, 2592000, 86400, 3600, 60, 1];
  var str = "";
  for (var i = 0; i < 6; ++i) {
    var inm = Math.floor(mistiming / arrn[i]);
    if(inm > 0) {
      str = inm + arrr[i] + '前';
      break;
    } else if (inm < 0) {
      str = '1秒前';
      break;
    }
  }
  if(str == "") {
    str = '1秒前';
  }
  return str;
}


function timeafter(timestamp) {
  var mistiming = Math.round((timestamp - getDate().getTime()) / 1000);
  
  var arrr = ['年', '个月', '天', '小时', '分钟', '秒'];
  var arrn = [31536000, 2592000, 86400, 3600, 60, 1];
  var str = "";
  for (var i = 0; i < 6; ++i) {
    var inm = Math.floor(mistiming / arrn[i]);
    if(inm > 0) {
      str = inm + arrr[i] + '后';
      break;
    } else if (inm < 0) {
      str = '1秒后';
      break;
    }
  }
  if(str == "") {
    str = '1秒后';
  }
  return str;
}

function timeago4str(date) {
  var reg = getRegExp("-", "g");
  return timeago(getDate(date.replace(reg, "/")).getTime());
}

function showNum (_money, num) {
  if (_money == null || _money == '' || typeof _money == 'undefined') {
    return 0;
  } else {
    if (parseInt(_money) - _money != 0) {
      if (num == 1) {
        return parseInt(_money * 10) / 10.0;
      } else if (num == 2) {
        return parseInt(_money * 100) / 100.0;
      } else {
        return parseInt(_money);
      }

    } else {
      return parseInt(_money);
    }
  }
}

/**
 * 获取几天前、几小时前等格式(剩余|超时)
 */
function timeagoLater(timestamp) {

  if(timestamp == '' || timestamp == null || timestamp == undefined) {
    return '';
  }
  var str = "";
  var arrr = ['年', '个月', '天', '小时', '分钟', '秒'];
  var arrn = [31536000, 2592000, 86400, 3600, 60, 1];
  if(getDate().getTime() - timestamp > 0) {
    var mistiming = Math.round((getDate().getTime() - timestamp) / 1000);

    for (var i = 0; i < 6; ++i) {
      var inm = Math.floor(mistiming / arrn[i]);
      if(inm > 0) {
        // str = '超时' + (inm + arrr[i]);
        // str = '已处理' + (inm + arrr[i]);
        str = (inm + arrr[i]) + '前';
        break;
      } else if (inm < 0) {
        str = '剩余' + (-inm + arrr[5 - i]);
        //str = '1秒前';
        break;
      }
    }
    if(str == "") {
      // str = '超时1秒';
      // str = '已处理1秒';
      str = '1秒前';
    }
  } else {
    var mistiming = Math.round((timestamp - getDate().getTime()) / 1000);

    for (var i = 0; i < 6; ++i) {
      var inm = Math.floor(mistiming / arrn[i]);
      if(inm > 0) {
        str = '剩余' + (inm + arrr[i]);
        break;
      } else if (inm < 0) {
        // str = '超时1秒';
        // str = '已处理1秒';
        str = '1秒前';
        break;
      }
    }
    if(str == "") {
      // str = '超时1秒';
      // str = '已处理1秒';
      str = '1秒前';
    }
  }

  return str;
}
/**
 * 格式化距离
 */
function getDistanceNum(distance) {
  if(distance == null || distance === '' || distance == 'null' || typeof(distance)=="undefined") {
    return '';
  }
  if(distance < 1000) {
    return distance + 'm';
  } else if(distance == 99999999) {
    return '';
  } else {
    var num = distance / 1000;
    return num.toFixed(2) + 'km'
  }
}

/**
 * endwith
 */
function spliceStr(str) {
  return str.split('_')[1]
}
module.exports.spliceStr = spliceStr;
module.exports.timeagoLater = timeagoLater;
module.exports.timeago = timeago;
module.exports.timeago4str = timeago4str;
module.exports.formatDateYYYYMMDDHHMM = formatDateYYYYMMDDHHMM;
module.exports.formatDateYYYYMMDD = formatDateYYYYMMDD;
module.exports.formatDateYYYYMMDD2 = formatDateYYYYMMDD2;
module.exports.formatDateMMSS = formatDateMMSS;
module.exports.showClockResult = showClockResult;
module.exports.showClockResult2 = showClockResult2;
module.exports.showWorkState = showWorkState;
module.exports.showSourceName = showSourceName;
module.exports.initHopePositionType = initHopePositionType;
module.exports.isEmptyCheck = isEmptyCheck;
module.exports.isNotEmptyCheck = isNotEmptyCheck;
module.exports.showStoreAddress = showStoreAddress;
module.exports.showNotNullStr = showNotNullStr;
module.exports.showNotNullNum = showNotNullNum;
module.exports.initDormType = initDormType;
module.exports.showNum = showNum;
module.exports.getDistanceNum = getDistanceNum;