722 lines
26 KiB
JavaScript
722 lines
26 KiB
JavaScript
//要获取的参数名称
|
||
function getQueryString(name) {
|
||
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
|
||
var r = window.location.search.substr(1).match(reg);
|
||
if (r != null) {
|
||
return r[2];
|
||
}
|
||
return null
|
||
}
|
||
//===========================字符串辅助================================
|
||
|
||
//生成唯一的GUID
|
||
function GetGuid() {
|
||
var s4 = function () {
|
||
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
||
};
|
||
return s4() + s4() + s4() + "-" + s4();
|
||
}
|
||
|
||
//========= common公用方法,只暴露需要的方法,不影响全局变量========
|
||
(function (win) {
|
||
var CRM_Comon, document, defaults;
|
||
document = win.document;
|
||
defaults = {
|
||
//添加属性
|
||
};
|
||
CRM_Comon = function (option) {
|
||
return new CRM_Comon.prototype.init(option);
|
||
};
|
||
CRM_Comon.prototype.init = function (option) {
|
||
this.options = $.extend(true, {}, defaults, option);
|
||
return this;
|
||
};
|
||
//===================这里添加具体方法===============
|
||
|
||
//==设置光标离开开始验证
|
||
CRM_Comon.prototype.FocusoutCheck = function () {
|
||
$.validator.setDefaults({
|
||
//光标移出时
|
||
onfocusout: function (element) {
|
||
this.element(element);
|
||
},
|
||
//光标移入时
|
||
onfocusin: function (element, event) {
|
||
//找到显示错误提示的标签并移除,针对jquery.validate.unobtrusive
|
||
var errorElement = $(element).next('span.field-validation-error');
|
||
if (errorElement) {
|
||
errorElement.children().remove();
|
||
}
|
||
},
|
||
onkeyup: function (element, event) {
|
||
}
|
||
});
|
||
};
|
||
//==ModelState自定义的错误显示在前端
|
||
CRM_Comon.prototype.showErrors = function (Validate) {
|
||
if (typeof Validate !== "undefined" && Validate.length > 0) {
|
||
$.each(Validate, function (index, failure) {
|
||
var timeValue, formElements, nextTd, spans;
|
||
formElements = $("#" + failure.PropertyName);
|
||
nextTd = formElements.parent().next();
|
||
timeValue = failure.PropertyName.toLowerCase().indexOf('time');
|
||
if (nextTd.length > 0) {
|
||
spans = nextTd.children(".validationMessage");
|
||
}
|
||
else {
|
||
spans = formElements.siblings(".validationMessage");
|
||
}
|
||
if (spans.length === 0) {
|
||
///如果未存在 span,则新建
|
||
var span = $('<span></span>', {
|
||
'class': 'validationMessage',
|
||
text: failure.Message
|
||
});
|
||
if (nextTd.length > 0) {
|
||
nextTd.append(span);
|
||
}
|
||
else {
|
||
span.insertAfter(formElements);
|
||
}
|
||
if (timeValue > -1) {
|
||
formElements.bind('focus', function () {
|
||
span.text('').hide();
|
||
$(this).removeClass("input-error");
|
||
}).addClass("input-error");
|
||
}
|
||
else {
|
||
formElements.bind('keyup', function () {
|
||
span.text('').hide();
|
||
$(this).removeClass("input-error");
|
||
}).addClass("input-error");
|
||
}
|
||
} else {
|
||
spans.each(function (i, span) {
|
||
var $span = $(span);
|
||
$span.show().text(failure.Message);
|
||
if (timeValue > -1) {
|
||
formElements.bind('focus', function () {
|
||
$span.text('').hide();
|
||
}).addClass("input-error");
|
||
}
|
||
else {
|
||
formElements.bind('keyup', function () {
|
||
$span.text('').hide();
|
||
}).addClass("input-error");
|
||
}
|
||
});
|
||
}
|
||
|
||
});
|
||
|
||
}
|
||
};
|
||
//--------------获取时间
|
||
CRM_Comon.prototype.GetDate = function (options) {
|
||
var defaults = {
|
||
};
|
||
function DateDetaile(setDate) {
|
||
var date, year, month, day, hours, minutes, seconds, week, timestamp, detaile;
|
||
date = setDate || new Date();
|
||
year = date.getFullYear();
|
||
month = date.getMonth() + 1;
|
||
day = date.getDate();
|
||
hours = date.getHours();
|
||
minutes = date.getMinutes();
|
||
seconds = date.getSeconds();
|
||
week = date.getDay();
|
||
timestamp = date.valueOf();
|
||
month = (month < 10 && "0" + month) || month;
|
||
day = (day < 10 && "0" + day) || day;
|
||
hours = (hours < 10 && "0" + hours) || hours;
|
||
minutes = (minutes < 10 && "0" + minutes) || minutes;
|
||
seconds = (seconds < 10 && "0" + seconds) || seconds;
|
||
detaile = {
|
||
_date: date,
|
||
_year: year,
|
||
_month: month,
|
||
_day: day,
|
||
_hours: hours,
|
||
_minutes: minutes,
|
||
_seconds: seconds,
|
||
_week: week,
|
||
_timestamp: timestamp
|
||
}
|
||
return detaile;
|
||
}
|
||
//日期的最小或最大时间
|
||
function MaxOrMinDate(date, options) {
|
||
var Localdefault, localeDate, optionDefault;
|
||
Localdefault = {
|
||
MaxDate: false,
|
||
MinDate: false
|
||
};
|
||
optionDefault = $.extend(true, {}, Localdefault, options);
|
||
localeDate = (optionDefault.MinDate && date + " 00:00:00") || (optionDefault.MaxDate && date + " 23:59:59") || date;
|
||
return localeDate;
|
||
}
|
||
//----
|
||
var getdate = DateDetaile();
|
||
function GetDate(options) {
|
||
this.options = $.extend(true, {}, defaults, options);
|
||
}
|
||
//本月第一天
|
||
GetDate.prototype.getFistDate = function (options) {
|
||
var firstdate = getdate._year + '-' + getdate._month + "-" + "01";
|
||
var returnDate = MaxOrMinDate(firstdate, options);
|
||
return returnDate;
|
||
}
|
||
//本月最后一天
|
||
GetDate.prototype.getLastDate = function (options) {
|
||
var day = new Date(getdate._year, getdate._month, 0);
|
||
var lastdate = getdate._year + '-' + getdate._month + '-' + day.getDate();
|
||
var returnDate = MaxOrMinDate(lastdate, options);
|
||
return returnDate;
|
||
}
|
||
//当前日期
|
||
GetDate.prototype.getLocalDate = function (options) {
|
||
var localeDate, returnDate;
|
||
localeDate = getdate._year + '-' + getdate._month + "-" + getdate._day;
|
||
returnDate = MaxOrMinDate(localeDate, options);
|
||
return returnDate;
|
||
}
|
||
//当前时间
|
||
GetDate.prototype.getLocalTime = function () {
|
||
var localeTime = getdate._year + '-' + getdate._month + "-" + getdate._day + " " + getdate._hours + ":" + getdate._minutes + ":" + getdate._seconds;
|
||
return localeTime;
|
||
}
|
||
//当前时间+ - 天数
|
||
GetDate.prototype.AddDays = function (days, options) {
|
||
var _days, countstamp, newDate, newDateDetaile, localeDate, returnDate;
|
||
_days = Number(days) || 0;
|
||
countstamp = getdate._timestamp + (_days * 24 * 60 * 60 * 1000);
|
||
newDate = new Date(countstamp);
|
||
var newDateDetaile = DateDetaile(newDate);
|
||
localeDate = newDateDetaile._year + '-' + newDateDetaile._month + "-" + newDateDetaile._day;
|
||
returnDate = MaxOrMinDate(localeDate, options);
|
||
return returnDate;
|
||
}
|
||
//当前周星期(1~n)
|
||
GetDate.prototype.getDateOfWeek = function (week, options) {
|
||
var _setweek, countstamp, newDate, returnDate, _getweek;
|
||
_setweek = (week < 1 && 1) || (week > 7 && 7) || week;
|
||
_getweek = getdate._week || 7;
|
||
countstamp = getdate._timestamp + ((_setweek - _getweek) * 24 * 60 * 60 * 1000);
|
||
newDate = new Date(countstamp);
|
||
var newDateDetaile = DateDetaile(newDate);
|
||
returnDate = newDateDetaile._year + '-' + newDateDetaile._month + "-" + newDateDetaile._day;
|
||
returnDate = MaxOrMinDate(returnDate, options);
|
||
return returnDate;
|
||
}
|
||
return new GetDate(options);
|
||
};
|
||
|
||
//--------------显示详情
|
||
CRM_Comon.prototype.PopUpBox = function (options) {
|
||
var PopUpBox, PublicFn, defaults;
|
||
defaults = {
|
||
isMarked: true,//是否需要遮罩
|
||
marked_opt: 0.3,//遮罩的透明度
|
||
speed: 500,
|
||
width: "400px",
|
||
height: "300px",
|
||
scrollbar: false
|
||
};
|
||
PopUpBox = function (option) {
|
||
this.options = $.extend(true, {}, defaults, option);
|
||
};
|
||
|
||
PublicFn = {
|
||
PopUpBox_init: function () {
|
||
var self = this;
|
||
$('<div id="popup_bg"><div id="popup_content"></div><div class="popup_close">[close]</div></div>').appendTo('body');
|
||
$('<div class="pop_mark"></div>').appendTo('body');
|
||
$('#popup_bg').css({
|
||
position: "absolute",
|
||
padding: "20px 3px 3px 3px",
|
||
zIndex: 999,
|
||
display: "none",
|
||
background: "#fff",
|
||
overflow: "hidden",
|
||
border: "1px solid #CACACA"
|
||
}
|
||
);
|
||
|
||
$('.popup_close').css({
|
||
position: "absolute",
|
||
top: "2px",
|
||
right: "2px",
|
||
cursor: "pointer",
|
||
zIndex: 1000,
|
||
color: "#000"
|
||
}).bind("click", function (e) {
|
||
e.preventDefault();
|
||
self.TurnToHide.apply(self);
|
||
});
|
||
$('.pop_mark').css({
|
||
position: "absolute",
|
||
top: 0,
|
||
backgroundColor: "#777",
|
||
zIndex: 998,
|
||
left: 0,
|
||
display: " none"
|
||
}
|
||
).bind("click", function (e) {
|
||
e.preventDefault();
|
||
self.TurnToHide.apply(self);
|
||
});
|
||
},
|
||
TurnToHide: function () {
|
||
$('.pop_mark').stop(false, true).fadeOut(300);
|
||
$('#popup_bg').stop(false, true).fadeOut(300, function () {
|
||
$('#popup_content').empty();
|
||
});
|
||
},
|
||
marked: function (marked_opt) {
|
||
return $('.pop_mark').css({
|
||
height: document.documentElement.scrollHeight,
|
||
width: document.documentElement.scrollWidth
|
||
}).stop(false, true).show()
|
||
.animate({ opacity: marked_opt }, 0)
|
||
}
|
||
};
|
||
|
||
//(function () {
|
||
// if (!$("#popup_bg")) {
|
||
// PublicFn.PopUpBox_init();
|
||
// }
|
||
//})();
|
||
PopUpBox.prototype.ViewCenter = function (getValue) {
|
||
var $box, top, left, maxbox, $content;
|
||
if (this.options.isMarked) {
|
||
PublicFn.marked(this.options.marked_opt);
|
||
}
|
||
$box = $('#popup_bg');
|
||
$content = $('#popup_content');
|
||
$content.css({
|
||
width: this.options.width,
|
||
height: this.options.height,
|
||
border: "solid 1px #AAA9AE",
|
||
padding: "5px",
|
||
background: "#F8F8F8",
|
||
overflow: "auto"
|
||
});
|
||
maxbox = {
|
||
width: $content.outerWidth(),
|
||
height: $content.outerHeight()
|
||
};
|
||
maxbox.height = maxbox.height > $(window).height() - 80 ? $(window).height() - 80 : maxbox.height;
|
||
maxbox.width = maxbox.width * (maxbox.height / $content.outerHeight());
|
||
top = ($(window).height() - maxbox.height - 30) / 2 + $(document).scrollTop();
|
||
left = ($(window).width() - maxbox.width - 20) / 2 + $(document).scrollLeft();
|
||
$box.css({
|
||
width: maxbox.width,
|
||
height: maxbox.height,
|
||
top: top,
|
||
left: left
|
||
}).stop(false, true).fadeIn(this.options.speed);
|
||
var $p = $('<p></p>');
|
||
$p.css({
|
||
margin: 0,
|
||
padding: 0,
|
||
lineHeight: '22px'
|
||
}).appendTo($content).html(getValue)
|
||
};
|
||
(function () {
|
||
if ($("#popup_bg").length < 1) {
|
||
PublicFn.PopUpBox_init();
|
||
}
|
||
})();
|
||
return new PopUpBox(options);
|
||
}
|
||
|
||
/*------------------------------------*/
|
||
CRM_Comon.prototype.init.prototype = CRM_Comon.prototype;
|
||
win.CRM_Comon = CRM_Comon;
|
||
})(window);
|
||
|
||
//
|
||
function OpenCustomerByResId(resId) {
|
||
var windowUrl = "/Csvr/CustomerInfo/CustomerDetail?resid=" + resId;
|
||
window.parent.ChildAddTab("客户详细", windowUrl, "icon-memeber");
|
||
};
|
||
|
||
|
||
Date.prototype.Format = function (fmt) { //author: meizz
|
||
var o = {
|
||
"M+": this.getMonth() + 1, //月份
|
||
"d+": this.getDate(), //日
|
||
"h+": this.getHours(), //小时
|
||
"m+": this.getMinutes(), //分
|
||
"s+": this.getSeconds(), //秒
|
||
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
|
||
"S": this.getMilliseconds() //毫秒
|
||
};
|
||
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.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;
|
||
}
|
||
/**
|
||
* 日期范围工具类
|
||
*/
|
||
var dateRangeUtil = (function () {
|
||
/***
|
||
* 获得当前时间
|
||
*/
|
||
this.getCurrentDate = function () {
|
||
return new Date();
|
||
};
|
||
|
||
/***
|
||
* 获得本周起止时间
|
||
*/
|
||
this.getCurrentWeek = function () {
|
||
//起止日期数组
|
||
var startStop = new Array();
|
||
//获取当前时间
|
||
var currentDate = this.getCurrentDate();
|
||
//返回date是一周中的某一天
|
||
var week = currentDate.getDay();
|
||
//返回date是一个月中的某一天
|
||
var month = currentDate.getDate();
|
||
|
||
//一天的毫秒数
|
||
var millisecond = 1000 * 60 * 60 * 24;
|
||
//减去的天数
|
||
var minusDay = week != 0 ? week - 1 : 6;
|
||
//alert(minusDay);
|
||
//本周 周一
|
||
var monday = new Date(currentDate.getTime() - (minusDay * millisecond));
|
||
//本周 周日
|
||
var sunday = new Date(monday.getTime() + (6 * millisecond));
|
||
//添加本周时间
|
||
startStop.push(monday); //本周起始时间
|
||
//添加本周最后一天时间
|
||
startStop.push(sunday); //本周终止时间
|
||
//返回
|
||
return startStop;
|
||
};
|
||
|
||
/***
|
||
* 获得本月的起止时间
|
||
*/
|
||
this.getCurrentMonth = function () {
|
||
//起止日期数组
|
||
var startStop = new Array();
|
||
//获取当前时间
|
||
var currentDate = this.getCurrentDate();
|
||
//获得当前月份0-11
|
||
var currentMonth = currentDate.getMonth();
|
||
//获得当前年份4位年
|
||
var currentYear = currentDate.getFullYear();
|
||
//求出本月第一天
|
||
var firstDay = new Date(currentYear, currentMonth, 1);
|
||
|
||
|
||
//当为12月的时候年份需要加1
|
||
//月份需要更新为0 也就是下一年的第一个月
|
||
if (currentMonth == 11) {
|
||
currentYear++;
|
||
currentMonth = 0; //就为
|
||
} else {
|
||
//否则只是月份增加,以便求的下一月的第一天
|
||
currentMonth++;
|
||
}
|
||
|
||
|
||
//一天的毫秒数
|
||
var millisecond = 1000 * 60 * 60 * 24;
|
||
//下月的第一天
|
||
var nextMonthDayOne = new Date(currentYear, currentMonth, 1);
|
||
//求出上月的最后一天
|
||
var lastDay = new Date(nextMonthDayOne.getTime() - millisecond);
|
||
|
||
//添加至数组中返回
|
||
startStop.push(firstDay);
|
||
startStop.push(lastDay);
|
||
//返回
|
||
return startStop;
|
||
};
|
||
|
||
/**
|
||
* 得到本季度开始的月份
|
||
* @param month 需要计算的月份
|
||
***/
|
||
this.getQuarterSeasonStartMonth = function (month) {
|
||
var quarterMonthStart = 0;
|
||
var spring = 0; //春
|
||
var summer = 3; //夏
|
||
var fall = 6; //秋
|
||
var winter = 9; //冬
|
||
//月份从0-11
|
||
if (month < 3) {
|
||
return spring;
|
||
}
|
||
|
||
if (month < 6) {
|
||
return summer;
|
||
}
|
||
|
||
if (month < 9) {
|
||
return fall;
|
||
}
|
||
|
||
return winter;
|
||
};
|
||
|
||
/**
|
||
* 获得该月的天数
|
||
* @param year年份
|
||
* @param month月份
|
||
* */
|
||
this.getMonthDays = function (year, month) {
|
||
//本月第一天 1-31
|
||
var relativeDate = new Date(year, month, 1);
|
||
//获得当前月份0-11
|
||
var relativeMonth = relativeDate.getMonth();
|
||
//获得当前年份4位年
|
||
var relativeYear = relativeDate.getFullYear();
|
||
|
||
//当为12月的时候年份需要加1
|
||
//月份需要更新为0 也就是下一年的第一个月
|
||
if (relativeMonth == 11) {
|
||
relativeYear++;
|
||
relativeMonth = 0;
|
||
} else {
|
||
//否则只是月份增加,以便求的下一月的第一天
|
||
relativeMonth++;
|
||
}
|
||
//一天的毫秒数
|
||
var millisecond = 1000 * 60 * 60 * 24;
|
||
//下月的第一天
|
||
var nextMonthDayOne = new Date(relativeYear, relativeMonth, 1);
|
||
//返回得到上月的最后一天,也就是本月总天数
|
||
return new Date(nextMonthDayOne.getTime() - millisecond).getDate();
|
||
};
|
||
|
||
/**
|
||
* 获得本季度的起止日期
|
||
*/
|
||
this.getCurrentSeason = function () {
|
||
//起止日期数组
|
||
var startStop = new Array();
|
||
//获取当前时间
|
||
var currentDate = this.getCurrentDate();
|
||
//获得当前月份0-11
|
||
var currentMonth = currentDate.getMonth();
|
||
//获得当前年份4位年
|
||
var currentYear = currentDate.getFullYear();
|
||
//获得本季度开始月份
|
||
var quarterSeasonStartMonth = this.getQuarterSeasonStartMonth(currentMonth);
|
||
//获得本季度结束月份
|
||
var quarterSeasonEndMonth = quarterSeasonStartMonth + 2;
|
||
|
||
//获得本季度开始的日期
|
||
var quarterSeasonStartDate = new Date(currentYear, quarterSeasonStartMonth, 1);
|
||
//获得本季度结束的日期
|
||
var quarterSeasonEndDate = new Date(currentYear, quarterSeasonEndMonth, this.getMonthDays(currentYear, quarterSeasonEndMonth));
|
||
//加入数组返回
|
||
startStop.push(quarterSeasonStartDate);
|
||
startStop.push(quarterSeasonEndDate);
|
||
//返回
|
||
return startStop;
|
||
};
|
||
|
||
/***
|
||
* 得到本年的起止日期
|
||
*
|
||
*/
|
||
this.getCurrentYear = function () {
|
||
//起止日期数组
|
||
var startStop = new Array();
|
||
//获取当前时间
|
||
var currentDate = this.getCurrentDate();
|
||
//获得当前年份4位年
|
||
var currentYear = currentDate.getFullYear();
|
||
|
||
//本年第一天
|
||
var currentYearFirstDate = new Date(currentYear, 0, 1);
|
||
//本年最后一天
|
||
var currentYearLastDate = new Date(currentYear, 11, 31);
|
||
//添加至数组
|
||
startStop.push(currentYearFirstDate);
|
||
startStop.push(currentYearLastDate);
|
||
//返回
|
||
return startStop;
|
||
};
|
||
|
||
/**
|
||
* 返回上一个月的第一天Date类型
|
||
* @param year 年
|
||
* @param month 月
|
||
**/
|
||
this.getPriorMonthFirstDay = function (year, month) {
|
||
//年份为0代表,是本年的第一月,所以不能减
|
||
if (month == 0) {
|
||
month = 11; //月份为上年的最后月份
|
||
year--; //年份减1
|
||
return new Date(year, month, 1);
|
||
}
|
||
//否则,只减去月份
|
||
month--;
|
||
return new Date(year, month, 1);;
|
||
};
|
||
|
||
/**
|
||
* 获得上一月的起止日期
|
||
* ***/
|
||
this.getPreviousMonth = function () {
|
||
//起止日期数组
|
||
var startStop = new Array();
|
||
//获取当前时间
|
||
var currentDate = this.getCurrentDate();
|
||
//获得当前月份0-11
|
||
var currentMonth = currentDate.getMonth();
|
||
//获得当前年份4位年
|
||
var currentYear = currentDate.getFullYear();
|
||
//获得上一个月的第一天
|
||
var priorMonthFirstDay = this.getPriorMonthFirstDay(currentYear, currentMonth);
|
||
//获得上一月的最后一天
|
||
var priorMonthLastDay = new Date(priorMonthFirstDay.getFullYear(), priorMonthFirstDay.getMonth(), this.getMonthDays(priorMonthFirstDay.getFullYear(), priorMonthFirstDay.getMonth()));
|
||
//添加至数组
|
||
startStop.push(priorMonthFirstDay);
|
||
startStop.push(priorMonthLastDay);
|
||
//返回
|
||
return startStop;
|
||
};
|
||
|
||
this.getPreviousDay = function() {
|
||
//起止日期数组
|
||
var startStop = new Array();
|
||
//获取当前时间
|
||
var currentDate = this.getCurrentDate();
|
||
//一天的毫秒数
|
||
var millisecond = 1000 * 60 * 60 * 24;
|
||
var priorDayFirstDay = new Date(currentDate.getTime() - millisecond);
|
||
startStop.push(priorDayFirstDay);
|
||
startStop.push(currentDate);
|
||
return startStop;
|
||
};
|
||
|
||
/**
|
||
* 获得上一周的起止日期
|
||
* **/
|
||
this.getPreviousWeek = function () {
|
||
//起止日期数组
|
||
var startStop = new Array();
|
||
//获取当前时间
|
||
var currentDate = this.getCurrentDate();
|
||
//返回date是一周中的某一天
|
||
var week = currentDate.getDay();
|
||
//返回date是一个月中的某一天
|
||
var month = currentDate.getDate();
|
||
//一天的毫秒数
|
||
var millisecond = 1000 * 60 * 60 * 24;
|
||
//减去的天数
|
||
var minusDay = week != 0 ? week - 1 : 6;
|
||
//获得当前周的第一天
|
||
var currentWeekDayOne = new Date(currentDate.getTime() - (millisecond * minusDay));
|
||
//上周最后一天即本周开始的前一天
|
||
var priorWeekLastDay = new Date(currentWeekDayOne.getTime() - millisecond);
|
||
//上周的第一天
|
||
var priorWeekFirstDay = new Date(priorWeekLastDay.getTime() - (millisecond * 6));
|
||
|
||
//添加至数组
|
||
startStop.push(priorWeekFirstDay);
|
||
startStop.push(priorWeekLastDay);
|
||
|
||
return startStop;
|
||
};
|
||
|
||
/**
|
||
* 得到上季度的起始日期
|
||
* year 这个年应该是运算后得到的当前本季度的年份
|
||
* month 这个应该是运算后得到的当前季度的开始月份
|
||
* */
|
||
this.getPriorSeasonFirstDay = function (year, month) {
|
||
var quarterMonthStart = 0;
|
||
var spring = 0; //春
|
||
var summer = 3; //夏
|
||
var fall = 6; //秋
|
||
var winter = 9; //冬
|
||
//月份从0-11
|
||
switch (month) {//季度的其实月份
|
||
case spring:
|
||
//如果是第一季度则应该到去年的冬季
|
||
year--;
|
||
month = winter;
|
||
break;
|
||
case summer:
|
||
month = spring;
|
||
break;
|
||
case fall:
|
||
month = summer;
|
||
break;
|
||
case winter:
|
||
month = fall;
|
||
break;
|
||
|
||
};
|
||
|
||
return new Date(year, month, 1);
|
||
};
|
||
|
||
/**
|
||
* 得到上季度的起止日期
|
||
* **/
|
||
this.getPreviousSeason = function () {
|
||
//起止日期数组
|
||
var startStop = new Array();
|
||
//获取当前时间
|
||
var currentDate = this.getCurrentDate();
|
||
//获得当前月份0-11
|
||
var currentMonth = currentDate.getMonth();
|
||
//获得当前年份4位年
|
||
var currentYear = currentDate.getFullYear();
|
||
//上季度的第一天
|
||
var priorSeasonFirstDay = this.getPriorSeasonFirstDay(currentYear, currentMonth);
|
||
//上季度的最后一天
|
||
var priorSeasonLastDay = new Date(priorSeasonFirstDay.getFullYear(), priorSeasonFirstDay.getMonth() + 2, this.getMonthDays(priorSeasonFirstDay.getFullYear(), priorSeasonFirstDay.getMonth() + 2));
|
||
//添加至数组
|
||
startStop.push(priorSeasonFirstDay);
|
||
startStop.push(priorSeasonLastDay);
|
||
return startStop;
|
||
};
|
||
|
||
/**
|
||
* 得到去年的起止日期
|
||
* **/
|
||
this.getPreviousYear = function () {
|
||
//起止日期数组
|
||
var startStop = new Array();
|
||
//获取当前时间
|
||
var currentDate = this.getCurrentDate();
|
||
//获得当前年份4位年
|
||
var currentYear = currentDate.getFullYear();
|
||
currentYear--;
|
||
var priorYearFirstDay = new Date(currentYear, 0, 1);
|
||
var priorYearLastDay = new Date(currentYear, 11, 1);
|
||
//添加至数组
|
||
startStop.push(priorYearFirstDay);
|
||
startStop.push(priorYearLastDay);
|
||
return startStop;
|
||
};
|
||
|
||
return this;
|
||
})();
|
||
|
||
|
||
String.prototype.format = function () {
|
||
if (arguments.length == 0) return this;
|
||
let param = arguments[0];
|
||
let s = this;
|
||
if (typeof (param) == 'object') {
|
||
for (var key in param) s = s.replace(new RegExp("\\{" + key + "\\}", "g"), param[key]);
|
||
return s;
|
||
} else {
|
||
for (var i = 0; i < arguments.length; i++) s = s.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]);
|
||
return s;
|
||
}
|
||
}
|