You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.1 KiB
JavaScript

//JQuery扩展
(function ($) {
//form转json
$.fn.serializeFormJSON = function () {
var o = {};
var a = this.serializeArray();
$.each(a, function () {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
//时间控件年月日
$.fn.zdate = function () {
$(this).datetimepicker({
language: 'zh-CN',
format: "yyyy-mm-dd",
autoclose: true,
todayBtn: true,
minView: "month"
});
}
//时间控件年与日时分
$.fn.ztime = function () {
$(this).datetimepicker({
language: 'zh-CN',
format: "yyyy-mm-dd hh:ii",
autoclose: true,
todayBtn: true
});
}
})(jQuery);
function getFormData($form) {
var unindexed_array = $form.serializeArray();
var indexed_array = {};
$.map(unindexed_array, function (n, i) {
indexed_array[n['name']] = n['value'];
});
return indexed_array;
}
//填充form
function SetData(form,data) {
$.each(form, function (index, item) {
var itag = item.tagName;
var itype = $(item).attr('type');
if ((itag == 'INPUT' && (itype == 'text' || itype == 'number' || itype == 'hidden')) || itag == 'TEXTAREA' || itag=='SELECT') {
for (var d in data) {
if ($(item).attr('name') == d) {
if (itag!= 'SELECT') {
$(item).val(data[d]);
} else {
$(item).val(data[d]).trigger('change');
}
}
}
}
})
}
///获取QuertString
function getQueryString(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
//生成select
function SetSelectData(s, data) {
$.each(data, function (index, item) {
var t = item.text;
var v = item.value;
$(s).append("<option value=" + v + ">" + t + "</option>");
})
}
function SetSelect(s, name, condition) {
$(s).find("option").remove();
var url = '/MvcShipping/MsOpSeaeTD/GetSelDataWithName';
var param = { name: name, condition: condition };
$.ajax({
url: url,
type: 'POST',
async: false,
dataType: 'json',
data: param,
timeout: 10000,
cache: false,
success: function (t) {
var data = eval(t).data;
SetSelectData(s, data);
}
})
}
//bootstrap 明细form row转json对象
function BSRowToJsonArray(form) {
var jd = [];
var rows = $(form).children();
$.each(rows, function (index, row) {
var cols = $(row).children();
var jrow = [];
var json = {};
$.each(cols, function (i, col) {
var fields = $(col).children();
$.each(fields, function (n, field) {
var itag = field.tagName;
var itype = $(field).attr('type');
if ((itag == 'INPUT' && (itype == 'text' || itype == 'number' || itype == 'hidden')) || itag == 'TEXTAREA' || itag == 'SELECT') {
var iname = $(field).attr('name');
var ivalue = $(field).val();
json[iname] = ivalue;
}
})
})
jd.push(json);
})
return jd;
}
function getFormatDate() {
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
+ " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
return currentDate;
}