//转换响应数据中的日期
ChangeDateFormat: function (new Date()) {var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return date.getFullYear() + "-" + month + "-" + currentDate;
},
//格式化日期对象为yyyy-MM-dd格式
formatTime: function (new Date()) {var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
return [year, month, day].map(function (n) { n = n.toString(); return n[1] ? n : '0' + n }).join('-');
},
//JS 封装前后台交互
var Temp{
//封装ajax请求[给予常规默认值,并判断调用可行性]
query: function (options) {//url,para,callbackvar defaultPara = {
type: "POST",
showLoading: true,
async: true
};
var opt = $.extend(defaultPara, options);
$.ajax({
url: opt.url,
data: opt.data,
type: opt.type,
async: opt.async,
beforeSend: function (xhr) {
if (opt.showLoading) {
var index = layer.load(0, {
shade: [0.01, '#000']
});
};
},
success: function (res) {
layer.closeAll('loading');
if (res.errcode == 0) {
if (typeof opt.callback == "function") {
opt.callback(res);
} else if (opt.callback != undefined) {
throw new Error(opt.callback + "不是一个函数");
};
} else if (res.errcode == 3) {
if (typeof opt.callback3 == "function") {
opt.callback3(res);
} else if (opt.callback3 != undefined) {
throw new Error(opt.callback3 + "不是一个函数");
};
} else {
var idx = layer.alert(res.errmsg, {
icon: 2,
skin: 'layer-ext-moon'
}, function () {
layer.close(idx);
if (typeof opt.callback2 == "function") {
opt.callback2();
} else if (opt.callback2 != undefined) {
throw new Error(opt.callback2 + "不是一个函数");
};
});
};
},
dataType: "json"
});
},’
//调用后台数据并返回方法
getInitData: function (options, callback) {
this.query({
url: "/Area/Controller/Action",
data: options,
callback: callback
});
},
}
//直接调用封装的方法
Temp.getInitData({
"storeid": CWBookOrder.currStoreID
}, function (res) {
console.log(res)
});