var dateFormat = function (data, type, row, meta) {
value = data != undefined ? data : "";
if (value) {
if (typeof value == 'object' && value) {
value = new Date(value.time).Format("yyyy-MM-dd");
} else {
value = value.substring(0, 4) + "-" + value.substring(4, 6) + "-"
+ value.substring(6, 8);
}
}
return value;
};
var dateTimeFormat = function (data, type, row, meta) {
value = data != undefined ? data : "";
if (value || value != '') {
if (typeof value == 'object' && value) {
value = new Date(value.time).Format("yyyy-MM-dd hh:mm:ss");
} else {
var old = value;
value = old.substring(0, 4) + "-" + old.substring(4, 6) + "-"
+ old.substring(6, 8) + " ";
value += old.substring(8, 10) + ":" + old.substring(10, 12) + ":"
+ old.substring(12, 14);
}
}
return value;
};
var JeFormat = function (data, type, row, meta) {
value = data != undefined ? data : "";
if ((value && value != '') || value == '0') {
value = value.toFixed(2);
}
return value;
};
var JeFormatDj = function (data, type, row, meta) {
var id = meta.settings.aoColumns[meta.col]["data"];
data = row[id];
if ((data && data != '') || data == '0') {
data = data.toFixed(4);
}
return data;
};
var remainTimeColorFormat = function (data, type, row, meta) {
var newHtml = "";
if (data != null && data != '') {
// 比较大小
var newDate = data;
var colorHtml = "";
if (newDate < 0) {
colorHtml = "#aba9a9";// 已失效
} else if (newDate <= 31 && newDate >= 0) {
colorHtml = "#ffe752";// 近一个月
} else if (newDate <= 91 && newDate > 31) {
colorHtml = "#ffbe00";// 近三个月
} else if (newDate <= 181 && newDate > 91) {
colorHtml = "#537cf1";// 近六个月
} else {
colorHtml = "#000000";
}
newHtml = "" + data + "";
} else {
newHtml = "" + data + "";
}
return newHtml;
};
var gridFnFormat = function (value, record, columnObj, grid, colNo, rowNo) {
var id = columnObj.id ? columnObj.id : columnObj;
if (!gridFormat[id] || gridFormat[id].trim() == '') {
return value;
}
var _format = eval('(' + gridFormat[id] + ')');
if (_format && _format[value]) {
if (_format[value]) {
return _format[value];
} else {
return value;
}
} else
return value;
};
var checkJeFormat = function (data) {
if (data == "" || data == undefined) {
return "";
} else if (data.substring(0, 1) == "¥") {
return data.substring(1);
} else {
return data;
}
};
var addJeFormat = function (data) {
if (data == "0") {
return "¥0.00";
} else if (data == "" || data == undefined) {
return "";
} else {
return "¥" + data.toFixed(2);
}
};
var checkNaN = function (data) {
if (data == "0") {
return "¥0.00";
} else if (data == "" || data == undefined) {
return "";
} else {
return "/" + data;
}
};
/**
* data:要格式化的数量 kpxm:wzml_mzkpxm
*/
var slFormat = function (data, kpxm) {
if (data == "0") {
if ("03" == kpxm) {// 中草药0.00
return "0.00";
} else {
return "0";
}
} else if (data == "" || data == undefined) {
return "";
} else {
if ("03" == kpxm) {// 中草药0.00
return data.toFixed(2);
} else {
return parseInt(data);
}
}
}
/*
* 替换字符串里的全部字符 str 原始字符串 matchStr 需要被替换的字符串 replaceStr 替换进去的字符串 g表示匹配全部
*/
function replaceStr(str, matchStr, replaceStr) {
var reg = new RegExp(matchStr, "g");
return str.replace(reg, replaceStr);
}
/**
* Date时间日期格式化 yyyy-mm-dd
*
* @param date
* @returns {string}
*/
function fmtDate(date) {
var y = 1900 + date.getYear();
var m = "0" + (date.getMonth() + 1);
var d = "0" + date.getDate();
return y + "-" + m.substring(m.length - 2, m.length) + "-"
+ d.substring(d.length - 2, d.length);
}
/*
* 时间格式转化
* */
function timeFormat(date) {
if (!date || typeof (date) === "string") {
this.error("参数异常,请检查...");
}
var y = date.getFullYear(); //年
var m = date.getMonth() + 1; //月
var d = date.getDate(); //日
if (m < 10) {
m = "0" + m;
}
if (d < 10) {
d = "0" + d;
}
return y + "-" + m + "-" + d;
}
function formatDate (date) {
var myYear = date.getFullYear();
var myMonth = date.getMonth() + 1;
var myDate = date.getDate();
if(myMonth < 10) {
myMonth = '0' + myMonth;
}
if(myDate < 10) {
myDate = '0' + myDate;
}
return myYear + '-' + myMonth + '-' + myDate;
}
/**
* 本周第一天
*
* @returns {string}
*/
function showWeekFirstDay() {
var date = new Date()
var weekday = date.getDay() || 7; //获取星期几,getDay()返回值是 0(周日) 到 6(周六) 之间的一个整数。0||7为7,即weekday的值为1-7
date.setDate(date.getDate() - weekday + 1);//往前算(weekday-1)天,年份、月份会自动变化
return timeFormat(date);
// var now = new Date();
// var now_year = now.getFullYear();
// var now_month = now.getMonth();
// var now_date = now.getDate();
// var now_day = now.getDay();
// var weekStart = new Date(now_year, now_month, now_date - now_day +1);
// return formatDate(weekStart);
}
/*
* 本周最后一天
* */
function showWeekLastDay() {
var date = new Date()
var weekday = date.getDay() || 7; //获取星期几,getDay()返回值是 0(周日) 到 6(周六) 之间的一个整数。0||7为7,即weekday的值为1-7
date.setDate(date.getDate() - weekday + 7)
return timeFormat(date);
// var now = new Date();
// var now_year = now.getFullYear();
// var now_month = now.getMonth();
// var now_date = now.getDate();
// var now_day = now.getDay();
// var weekEnd = new Date(now_year, now_month, now_date + (7 - now_day));
// return formatDate(weekEnd);
}
/**
* 本周最后天
*
* @returns {string}
*/
/*
function showWeekLastDay() {
var date = new Date();
var WeekFirstDay = new Date(date - (date.getDay() - 1) * 86400000);
var WeekLastDay = new Date((WeekFirstDay / 1000 + 6 * 86400) * 1000);
M = Number(WeekLastDay.getMonth()) + 1;
if (M < 10) {
M = "0" + M;
}
var D = WeekLastDay.getDate();
if (D < 10) {
D = "0" + D;
}
return WeekLastDay.getFullYear() + "-" + M + "-" + D;
}
*/
/**
* 本月第一天
* @param datePara 传入日期eg:20191011 根据传入参数获取当前月的第一天
* @returns {string}
*/
function showMonthFirstDay(datePara) {
var date;
if (datePara) {
date = new Date(datePara);
} else {
date = new Date();
}
var MonthFirstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var M = Number(MonthFirstDay.getMonth()) + 1;
if (M < 10) {
M = "0" + M;
}
var D = MonthFirstDay.getDate();
if (D < 10) {
D = "0" + D;
}
return MonthFirstDay.getFullYear() + "-" + M + "-" + D;
}
/**
* 本月最后一天
* @param datePara 传入日期eg:20191011 根据传入参数获取当前月的最后一天
* @returns {string}
*/
function showMonthLastDay(datePara) {
var date;
if (datePara) {
date = new Date(datePara);
} else {
date = new Date();
}
var MonthNextFirstDay = new Date(date.getFullYear(), date.getMonth() + 1, 1);
var MonthLastDay = new Date(MonthNextFirstDay - 86400000);
var M = Number(MonthLastDay.getMonth()) + 1;
if (M < 10) {
M = "0" + M;
}
var D = MonthLastDay.getDate();
if (D < 10) {
D = "0" + D;
}
return MonthLastDay.getFullYear() + "-" + M + "-" + D;
}
/**
* 本年第一天
* @returns {string}
*/
function showYearFirstDay() {
var date = new Date();
return date.getFullYear() + "-01-01";
}
/**
* 本年最后一天
* @returns {string}
*/
function showYearLastDay() {
var date = new Date();
return date.getFullYear() + "-12-31";
}
function renderSingle(data, type, row, meta) {
if (data) {
var $th = $('#table_id_example').find("thead").find("th").eq(meta.col);// 获取当前列的th
var width = parseInt($th.data("width"));
var newHtml = "
";
return newHtml;
} else {
return "-";
}
}
function dateFormat2(value) {
if (value) {
if (typeof value == 'object' && value) {
value = new Date(value.time).Format("yyyy-MM-dd");
} else {
value = value.substring(0, 4) + "-" + value.substring(4, 6) + "-"
+ value.substring(6, 8);
}
}
return value;
}
function dateTimeFormat2(data) {
if (data != null && data != '') {
if (typeof data == 'object' && data) {
data = new Date(data.time).Format("yyyy-MM-dd hh:mm:ss");
} else {
var old = data;
data = old.substring(0, 4) + "-" + old.substring(4, 6) + "-"
+ old.substring(6, 8) + " ";
data += old.substring(8, 10) + ":" + old.substring(10, 12) + ":"
+ old.substring(12, 14);
}
} else {
data = "-";
}
return data;
}
function getcurrentDate() {
var date = new Date();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentDate = date.getFullYear() + '' + month + '' + strDate + '';
return currentDate;
}
function getcurrentDateTime() {
var date = new Date();
var month = date.getMonth() + 1;
var strDate = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
if (hour >= 0 && hour <= 9) {
hour = "0" + hour;
}
if (minute >= 0 && minute <= 9) {
minute = "0" + minute;
}
if (second >= 0 && second <= 9) {
second = "0" + second;
}
var currentDateTime = date.getFullYear() + '' + month + '' + strDate + ''
+ hour + '' + minute + '' + second + '';
return currentDateTime;
}
var LayuiDateFormat = function (row) {
var value;
if (typeof row == "object") {
value = row[this.field];
} else {
value = row;
}
if (value) {
if (typeof value == 'object' && value) {
value = new Date(value.time).Format("yyyy-MM-dd");
} else {
value = value.substring(0, 4) + "-" + value.substring(4, 6) + "-"
+ value.substring(6, 8);
}
return value;
} else {
return '';
}
};
var LayuiJeFormat = function (row, align) {
var value;
if (typeof row == "object") {
value = row[this.field];
} else {
value = row;
}
value = value == undefined ? 0 : value == null ? 0 : value;
if ((value && value != '') || value == '0') {
value = value.toFixed(2);
}
// 位置
if (align) {
return value;
} else {
return "" + value + "
";
}
};
var LayuiJeFormatDj = function (row, align) {
var value;
if (typeof row == "object") {
value = row[this.field];
} else {
value = row;
}
value = value == undefined ? 0 : value == null ? 0 : value;
if ((value && value != '') || value == '0') {
value = value.toFixed(3);
}
// 位置
if (align) {
return value;
} else {
return "" + value + "
";
}
};
var LayuiJeFormatDj4 = function (row, align) {
var value;
if (typeof row == "object") {
value = row[this.field];
} else {
value = row;
}
value = value == undefined ? 0 : value == null ? 0 : value;
if ((value && value != '') || value == '0') {
value = value.toFixed(4);
}
// 位置
if (align) {
return value;
} else {
return "" + value + "
";
}
};
// 时间格式翻译(带颜色)
var LayuidateTimeColorFormat = function (row) {
var data;
if (typeof row == "object") {
data = row[this.field];
} else {
data = row;
}
if(!data){
return '-';
}
var newHtml = "";
data = replaceStr(data, "-", "");
if (data != null && data != '') {
data = LayuiDateFormat(data);
// 比较大小
var time1 = Date.parse(new Date(data));
var time2 = Date.parse(new Date(new Date()));
var newDate = parseInt((time1 - time2) / 1000 / 3600 / 24);
var colorHtml = "";
if (newDate < 0) {
colorHtml = "#aba9a9";// 已失效
} else if (newDate <= 30 && newDate > 0) {
colorHtml = "#fb0519";// 近一个月
} else if (newDate <= 90 && newDate > 30) {
colorHtml = "#ffbe00";// 近三个月
} else if (newDate <= 120 && newDate > 90) {
colorHtml = "#537cf1";// 近六个月
} else if (newDate > 30) {
colorHtml = "#000000";
}
newHtml = "" + data + "";
} else {
newHtml = "-";
}
return newHtml;
};
// otc分类
var LayuiOTCFormat = function (row) {
var data = row[this.field];
if (data == '1') {
return '否';
} else {
return '是';
}
};
// 是否麻黄碱
var LayuiSfmhjFormat = function (row) {
var data = row[this.field];
if (data == '1') {
return '是';
} else {
return '否';
}
};
// 时间格式翻译
var LayuiDateTimeFormat = function (row) {
var data = row[this.field];
if (data != null && data != '') {
if (typeof data == 'object' && data) {
data = new Date(data.time).Format("yyyy-MM-dd hh:mm:ss");
} else {
var old = data;
data = old.substring(0, 4) + "-" + old.substring(4, 6) + "-"
+ old.substring(6, 8) + " ";
data += old.substring(8, 10) + ":" + old.substring(10, 12) + ":"
+ old.substring(12, 14);
}
} else {
data = "-";
}
return data;
};
var LayuiJeFormatNoTable = function (value) {
value = value == undefined ? 0 : value == null ? 0 : value;
if ((value && value != '') || value == '0') {
value = value.toFixed(2);
}
return value;
};
/*
* 根据身份号码获取年龄
*/
function GetAge(identityCard) {
var len = (identityCard + "").length;
if (len == 0) {
return 0;
} else {
if ((len != 15) && (len != 18))// 身份证号码只能为15位或18位其它不合法
{
return 0;
}
}
var strBirthday = "";
if (len == 18)// 处理18位的身份证号码从号码中得到生日和性别代码
{
strBirthday = identityCard.substr(6, 4) + "/"
+ identityCard.substr(10, 2) + "/" + identityCard.substr(12, 2);
}
if (len == 15) {
strBirthday = "19" + identityCard.substr(6, 2) + "/"
+ identityCard.substr(8, 2) + "/" + identityCard.substr(10, 2);
}
// 时间字符串里,必须是“/”
var birthDate = new Date(strBirthday);
var nowDateTime = new Date();
var age = nowDateTime.getFullYear() - birthDate.getFullYear();
// 再考虑月、天的因素;.getMonth()获取的是从0开始的,这里进行比较,不需要加1
if (nowDateTime.getMonth() < birthDate.getMonth()
|| (nowDateTime.getMonth() == birthDate.getMonth() && nowDateTime
.getDate() < birthDate.getDate())) {
age--;
}
return age
}
// 获取当前日期
function getNowDate() {
var nowDate = new Date();
var year = nowDate.getFullYear();
var month = nowDate.getMonth() + 1;
var day = nowDate.getDate();
if (month <= 9) {
month = "0" + month;
}
if (day <= 9) {
day = "0" + day;
}
var date = year + "-" + month + "-" + day;
return date;
}
var FormatNL = function (row) {
var value = ''
if (typeof row == "object") {
value = row[this.field];
} else {
value = row;
}
if (value == '' || value == null) {
return value;
} else {
var Y1 = value.substring(0, 4);
var Y = new Date().getFullYear();
return Y - Y1 + 1;
}
};
var gridFnFormatZt = function (data) {
var value = gridFormat[this.field];
var rowdata = data[this.field];
if (value || value != '') {
if (rowdata && rowdata != '' && rowdata != undefined) {
var _format = eval('(' + gridFormat[this.field] + ')');
if (_format && _format[rowdata]) {
rowdata = _format[rowdata];
}
} else {
rowdata = "-";
}
}
var hmtl = rowdata;
return hmtl;
};
//获取上个月
function getUpMonth() {
var tarr = getNowDate().split('-');
var year = tarr[0]; //获取当前日期的年
var month = tarr[1]; //获取当前日期的月
var year2 = year;
var month2 = parseInt(month) - 1;
if (month2 == 0) {
year2 = parseInt(year2) - 1;
month2 = 12;
}
if(month2<10){
month2 = "0"+month2;
}
var t2 = year2 + '-' + month2;
return t2;
}