/**
*/
var PublicUtil = {
//提示框类型
alertType: {
warnType: 0,
okType: 1
},
//alert提示框
alertWindow: function (alertType, title, msg, okBtnText, okFunction) {
var randowSuffix = JCPublicUtil.DateFormat(new Date(), "YYYYMMddhhmmss");
var dialogId = "dialogWindow_" + randowSuffix;
var dialogOverlayId = "dialogOverlay_" + randowSuffix;
var stringBuilder = this.StringBuilder();
switch (alertType) {
case this.alertType.okType:
stringBuilder.Append('<div class="dialogWindow" id="' + dialogId + '" style="display:none;">');
break;
case this.alertType.warnType:
stringBuilder.Append('<div class="dialogWindow warnDialog" id="' + dialogId + '" style="display:none;">');
break;
}
stringBuilder.Append('<div class="dialogHeader">');
stringBuilder.Append(' <span class="dialogTitle">' + title + '</span>');
stringBuilder.Append(' <a href="javascript:void(0);" class="dialogClose"></a>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div class="dialogBody">');
stringBuilder.Append(' <table cellspacing="0px" border="0px" cellpadding="0px">');
stringBuilder.Append(' <tr>');
stringBuilder.Append(' <td><span class="dialogIcon"></span></td>');
stringBuilder.Append(' <td>');
stringBuilder.Append(' <span class="dialogMsg">' + msg + '</span>');
stringBuilder.Append(' </td>');
stringBuilder.Append(' </tr>');
stringBuilder.Append(' </table>');
stringBuilder.Append(' <div class="dialogFooter">');
stringBuilder.Append(' <input type="button" class="dialogOK newOk_Btn" value="' + okBtnText + '" />');
stringBuilder.Append(' </div>');
stringBuilder.Append(' <div style="clear:both;"></div>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div style="clear:both;"></div>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div class="dialog-overlay" id="' + dialogOverlayId + '" style="display:none;"><iframe frameborder="0" style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);"></iframe></div>');
if ($("#" + dialogId).length > 0) {
$("#" + dialogId).remove();
$("#" + dialogOverlayId).remove();
}
$("body").append(stringBuilder.ToString());
var zIndex = 999;
//设置层次关系
var currentCount = $(".dialogWindow").length + 1;
zIndex += currentCount;
$("body").css("overflow", "hidden");
var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
$("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
$("#" + dialogOverlayId).css({
'left': 0, 'top': 0,
'width': $(document).width(),
'height': $(document).height(),
'z-index': zIndex,
'position': 'absolute'
})
$("#" + dialogId + " .dialogClose").click(function () {
$("#" + dialogId).remove();
$("#" + dialogOverlayId).remove();
$("body").css("overflow", "auto");
$(window).unbind("resize.dialogwindow");
})
$("#" + dialogId + " .dialogOK").click(function () {
if (okFunction != null && okFunction != undefined) {
okFunction();
}
if ($("#" + dialogId).length > 0) {
$("#" + dialogId + " .dialogClose").click();
}
});
$(window).bind("resize.dialogwindow", function () {
var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
$("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
$("#" + dialogOverlayId).css({
'width': $(document).width()
})
})
$("#" + dialogOverlayId).show();
$("#" + dialogId).show();
},
/*内容可以自定义的弹出框 返回框对象
*title 标题
*content 弹出框中的内容
*okBtnText 确定按钮的文字 为空时则不显示该按钮
*okFunction 确定按钮的事件 无事件就为null
*cancelBtnText 取消按钮的文字 为空时则不显示该按钮
*cancelFunc 取消按钮的事件 无事件就为null
*/
dialogWindow: function (title, content, okBtnText, okFunction, cancelBtnText, cancelFunc) {
var randowSuffix = JCPublicUtil.DateFormat(new Date(), "YYYYMMddhhmmss");
var dialogId = "dialogWindow_" + randowSuffix;
var dialogOverlayId = "dialogOverlay_" + randowSuffix;
var stringBuilder = this.StringBuilder();
stringBuilder.Append('<div class="dialogWindow" id="' + dialogId + '" style="display:none;">');
stringBuilder.Append('<div class="dialogHeader">');
stringBuilder.Append(' <span class="dialogTitle">' + title + '</span>');
stringBuilder.Append(' <a href="javascript:void(0);" class="dialogClose"></a>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div class="dialogBody">');
stringBuilder.Append(' <table cellspacing="0px" border="0px" cellpadding="0px">');
stringBuilder.Append(' <tr>');
stringBuilder.Append(' <td>');
stringBuilder.Append(content);
stringBuilder.Append(' </td>');
stringBuilder.Append(' </tr>');
stringBuilder.Append(' </table>');
stringBuilder.Append(' <div class="dialogFooter">');
if (okBtnText != "") {
stringBuilder.Append(' <input type="button" class="dialogOK newOk_Btn" value="' + okBtnText + '" />');
}
if (cancelBtnText != "") {
stringBuilder.Append(' <input type="button" class="dialogCancel newCancel_Btn" value="' + cancelBtnText + '" />');
}
stringBuilder.Append(' </div>');
stringBuilder.Append(' <div style="clear:both;"></div>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div style="clear:both;"></div>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div class="dialog-overlay" id="' + dialogOverlayId + '"><iframe frameborder="0" style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);"></iframe></div>');
if ($("#" + dialogId).length > 0) {
$("#" + dialogId).remove();
$("#" + dialogOverlayId).remove();
}
$("body").append(stringBuilder.ToString());
var zIndex = 999;
//设置层次关系
var currentCount = $(".dialogWindow").length + 1;
zIndex += currentCount;
$("body").css("overflow", "hidden");
var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
$("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
$("#" + dialogOverlayId).css({
'left': 0, 'top': 0,
'width': $(document).width(),
'height': $(document).height(),
'z-index': zIndex,
'position': 'absolute'
})
$("#" + dialogId + " .dialogClose").click(function () {
$("#" + dialogId).remove();
$("#" + dialogOverlayId).remove();
$("body").css("overflow", "auto");
$(window).unbind("resize.dialogwindow");
})
$("#" + dialogId + " .dialogOK").click(function () {
if (okFunction != null && okFunction != undefined) {
if(okFunction($("#" + dialogId))==false){
return;
}
}
if ($("#" + dialogId).length > 0) {
$("#" + dialogId + " .dialogClose").click();
}
});
$("#" + dialogId + " .dialogCancel").click(function () {
$("#" + dialogId + " .dialogClose").click();
if (cancelFunc != null && cancelFunc != undefined) {
cancelFunc();
}
});
$(window).bind("resize.dialogwindow", function () {
var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
$("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
$("#" + dialogOverlayId).css({
'width': $(document).width()
})
})
//拖动
var mouse={x:0,y:0};
$("#" + dialogId + " .dialogHeader").mousedown(function (event) {
var e = window.event || event;
var offset = $("#" + dialogId).offset();
mouse.x = e.clientX - offset.left;
mouse.y = e.clientY - offset.top;
$(document).bind('mousemove', moveDialog).bind("mouseup",function(){$(document).unbind('mousemove', moveDialog);});
});
function moveDialog(event) {
var e = window.event || event;
var top = e.clientY - mouse.y;
var left = e.clientX - mouse.x;
$("#" + dialogId).css({"top": top, "left": left});
};
$("#" + dialogId).show();
return $("#" + dialogId);
},
//确定提示框
confirmWindow: function (alertType, title, msg, okBtnText, okFunction, cancelBtnText, cancelFunc) {
var randowSuffix = JCPublicUtil.DateFormat(new Date(), "YYYYMMddhhmmss");
var dialogId = "dialogWindow_" + randowSuffix;
var dialogOverlayId = "dialogOverlay_" + randowSuffix;
var stringBuilder = this.StringBuilder();
switch (alertType) {
case this.alertType.okType:
stringBuilder.Append('<div class="dialogWindow" id="' + dialogId + '" style="display:none;">');
break;
case this.alertType.warnType:
stringBuilder.Append('<div class="dialogWindow warnDialog" id="' + dialogId + '" style="display:none;">');
break;
}
stringBuilder.Append('<div class="dialogHeader">');
stringBuilder.Append(' <span class="dialogTitle">' + title + '</span>');
stringBuilder.Append(' <a href="javascript:void(0);" class="dialogClose"></a>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div class="dialogBody">');
stringBuilder.Append(' <table cellspacing="0px" border="0px" cellpadding="0px">');
stringBuilder.Append(' <tr>');
stringBuilder.Append(' <td><span class="dialogIcon"></span></td>');
stringBuilder.Append(' <td>');
stringBuilder.Append(' <span class="dialogMsg">' + msg + '</span>');
stringBuilder.Append(' </td>');
stringBuilder.Append(' </tr>');
stringBuilder.Append(' </table>');
stringBuilder.Append(' <div class="dialogFooter">');
stringBuilder.Append(' <input type="button" class="dialogOK newOk_Btn" value="' + okBtnText + '" />');
stringBuilder.Append(' <input type="button" class="dialogCancel newCancel_Btn" value="' + cancelBtnText + '" />');
stringBuilder.Append(' </div>');
stringBuilder.Append(' <div style="clear:both;"></div>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div style="clear:both;"></div>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div class="dialog-overlay" id="' + dialogOverlayId + '" style="display:block;"><iframe frameborder="0" style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0); opacity:0;"></iframe></div>');
if ($("#" + dialogId).length > 0) {
$("#" + dialogId).remove();
$("#" + dialogOverlayId).remove();
}
$("body").append(stringBuilder.ToString());
var zIndex = 999;
//设置层次关系
var currentCount = $(".dialogWindow").length + 1;
zIndex += currentCount;
$("body").css("overflow", "hidden");
var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
$("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
$("#" + dialogOverlayId).css({
'left': 0, 'top': 0,
'width': $(document).width(),
'height': $(document).height(),
'z-index': zIndex,
'position': 'absolute'
})
$("#" + dialogId + " .dialogClose").click(function () {
$("#" + dialogId).remove();
$("#" + dialogOverlayId).remove();
$("body").css("overflow", "auto");
$(window).unbind("resize.dialogwindow");
})
$("#" + dialogId + " .dialogOK").click(function () {
if (okFunction != null && okFunction != undefined) {
if(okFunction($("#" + dialogId))==false){
return;
}
}
if ($("#" + dialogId).length > 0) {
$("#" + dialogId + " .dialogClose").click();
}
});
$("#" + dialogId + " .dialogCancel").click(function () {
$("#" + dialogId + " .dialogClose").click();
if (cancelFunc != null && cancelFunc != undefined) {
cancelFunc();
}
});
$(window).bind("resize.dialogwindow", function () {
var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
$("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
$("#" + dialogOverlayId).css({
'width': $(document).width()
})
})
$("#" + dialogOverlayId).show();
$("#" + dialogId).show();
},
//字符串对象
StringBuilder: function () {
//实体对象
var StringBuilderObj = function (args) {
this._buffers = [];
this._length = 0;
this._splitChar = args.length > 0 ? args[args.length - 1] : '';
if (args.length > 0) {
for (var i = 0, iLen = args.length - 1; i < iLen; i++) {
this.Append(args[i]);
}
}
}
//append方法
StringBuilderObj.prototype.Append = function (str) {
this._length += str.length;
this._buffers[this._buffers.length] = str;
}
//向对象中添加字符串
//参数:一个字符串值
StringBuilderObj.prototype.Add = StringBuilderObj.prototype.append;
//向对象附加格式化的字符串
//参数:参数一是预格式化的字符串,如:'{0} {1} {2}'
//格式参数可以是数组,或对应长度的arguments,
StringBuilderObj.prototype.AppendFormat = function () {
if (arguments.length > 1) {
var TString = arguments[0];
if (arguments[1] instanceof Array) {
for (var i = 0, iLen = arguments[1].length; i < iLen; i++) {
var jIndex = i;
var re = eval("/\\{" + jIndex + "\\}/g;");
TString = TString.replace(re, arguments[1][i]);
}
}
else {
for (var i = 1, iLen = arguments.length; i < iLen; i++) {
var jIndex = i - 1;
var re = eval("/\\{" + jIndex + "\\}/g;");
TString = TString.replace(re, arguments[i]);
}
}
this.Append(TString);
}
else if (arguments.length == 1) {
this.Append(arguments[0]);
}
}
//字符串长度(相当于ToString()后输出的字符串长度
StringBuilderObj.prototype.Length = function () {
if (this._splitChar.length > 0 && (!this.IsEmpty())) {
return this._length + (this._splitChar.length * (this._buffers.length - 1));
}
else {
return this._length;
}
}
//字符串是否为空
StringBuilderObj.prototype.IsEmpty = function () {
return this._buffers.length <= 0;
}
//清空
StringBuilderObj.prototype.Clear = function () {
this._buffers = [];
this._length = 0;
}
//输出
//参数:可以指定一个字符串(或单个字符),作为字符串拼接的分隔符
StringBuilderObj.prototype.ToString = function () {
if (arguments.length == 1) {
return this._buffers.join(arguments[1]);
}
else {
return this._buffers.join(this._splitChar);
}
}
return new StringBuilderObj(arguments);
},
//时间格式转换
DateFormat: function (dateObj, format) {
try {
/*
* eg:format="YYYY-MM-dd hh:mm:ss";
*/
var o = {
"Y+": dateObj.getFullYear(),
"M+": dateObj.getMonth() + 1, //month
"d+": dateObj.getDate(), //day
"h+": dateObj.getHours(), //hour
"m+": dateObj.getMinutes(), //minute
"s+": dateObj.getSeconds(), //second
"q+": Math.floor((dateObj.getMonth() + 3) / 3), //quarter
"S": dateObj.getMilliseconds() //millisecond
}
if (/(Y+)/.test(format)) {
format = format.replace(RegExp.$1, (dateObj.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
} catch (e) {
return "";
}
},
//初始化几个模块的事件绑定。
initModuleFunc: function () {
$(function () {
//绑定高级搜索的事件
if ($("#SearchDiv").length > 0) {
$("#SearchDiv").click(function (e) { e.stopPropagation(); });
//高级搜索按钮的事件
$("#topDivBtn").click(function (e) {
if ($("#topDiv").hasClass("TopSearchSelected")) {
$("#topDiv").removeClass().addClass("TopSearch");
$("#SearchDiv").hide();
}
else {
$("#topDiv").removeClass().addClass("TopSearchSelected");
$("#SearchDiv").show();
}
$(document).bind("click", function () {
if ($("#topDiv").hasClass("TopSearchSelected")) {
$("#topDiv").removeClass().addClass("TopSearch");
$("#SearchDiv").hide();
}
$(document).unbind("click");
})
e.stopPropagation();
});
//取消高级搜索
$("#cancelBtn").click(function () { $("#topDivBtn").click(); });
}
//绑定列表行的颜色和鼠标移动上去的事件----------------------------------------
if ($(".cyListContent").length > 0) {
$(".ListItem").hover(function () { $(this).addClass("selectUL") }, function () { $(this).removeClass("selectUL"); })
//给列表行的奇数行添加背景颜色
$(".cyListContent>ul>li:odd").css("background", "#f2f2f2");
}
//全选----------------------------------------------
var cbList = document.getElementsByName("cb");
var all = document.getElementById("checkAll");
if (all != null) {
all.onclick = function () {
for (var i = 0; i < cbList.length; i++) {
cbList[i].checked = all.checked;
}
};
}
//导航选择------------------------------------------------------
if ($(".daohang").length > 0) {
$(".daohang>ul>li").click(function () {
$(this).parent().find("li").removeClass();
$(this).addClass("selectedLi");
});
}
//流程定制-------------------------------------------------------
$(".listContent").each(function(){
$(this).find("table tr.listtr:even").addClass("evenTr");
$(this).find("table tr.listtr:odd").addClass("oddTr");
$(this).find("table tr.listtr").mouseover(function () {
$(this).addClass("selectedTR");
}).mouseout(function () {
$(this).removeClass("selectedTR");
});
})
});
},
/*某个字符串中是否包含另一个字符串或者包含另一个字符串以特殊字符分割的字符串,注意英文为英文单词
* mainStr 为主字符串
* strContained 被包含的字符串
* splitMark 被包含字符串的分隔符,如果没有分隔符可以为空字符串
* 返回实体对象{"isContain":true,"msg":""},true为都包含否则不全部包含或者全部不包含
* */
containsStr:function(mainStr,strContained,splitMark){
var isContain=true;
var msg="";
var strArray=new Array();
if(strContained==""){
return {"isContain":false,"msg":"0"};
}
if(splitMark!=""){
strArray=strContained.split(splitMark);
}else{
strArray.push(strContained);
}
for(var i=0;i<strArray.length;i++){
//中文
if(/[\u4e00-\u9fa5]+/g.test(strArray[i])){
if(mainStr.indexOf(strArray[i])==-1){
isContain=false;
msg+=strArray[i]+"\r\n";
}
}else{
//英文单词
var regex=new RegExp("\\b"+strArray[i]+"\\b","g");
if(!regex.test(mainStr)){
isContain=false;
msg+=strArray[i]+"\r\n";
}
}
}
return {"isContain":isContain,"msg":msg};
},
//流程表单模板实体类
FlowFormTemplate: {
prefixStr: "flowPropMap['",
suffixStr: "']",
fiexNum: 2,
initFunc: function () {
//绑定新增列表事件
$(".addTableRow").not("[disabled]").click(function () {
JCPublicUtil.FlowFormTemplate._addRow($(this));
});
//删除列表
$(".delTableRow").not("[disabled]").click(function (e) {
JCPublicUtil.FlowFormTemplate._delRow($(this)[0]);
e.stopPropagation();
return false;
});
//绑定输入框事件
$("input[data-calculate-to-variable]").keyup(function () {
JCPublicUtil.FlowFormTemplate.calculateOperate($(this)[0]);
});
//样式绑定
$(".dynamic-form-table-body,.dynamic-form-table-body table").css({ "border-collapse": "collapse", "border": "solid 1px #cccccc" }).attr({ "cellpadding": "0", "cellspacing": "0" });
$(".dynamic-form-table-body td,.dynamic-form-table-body th").css({ "border": "solid 1px #cccccc" });
$(".delTableRow").html('<img src="' + JCPublicUtil.Location.getRootPath() + '/images/funcation_ico/delete.png" style="border:0px;"/>');
$(".addTableRow").html('<img src="' + JCPublicUtil.Location.getRootPath() + '/images/funcation_ico/add.gif" style="border:0px;"/>');
$("table[tableType='JCTABLE']").find("thead tr").css({ "background-color": "#cccccc" });
//控制列表的新增和删除按钮是否显示
$("table[tableType='JCTABLE']").each(function () {
var isShowAddBtn = $(this).attr("data-showAddBtn") != undefined && $(this).attr("data-showAddBtn") == "true" ? true : false;
var isShowDelBtn = $(this).attr("data-showDelBtn") != undefined && $(this).attr("data-showDelBtn") == "true" ? true : false;
var AddBtns = $(this).find(".addTableRow");
var DelBtns = $(this).find(".delTableRow");
if (!isShowAddBtn) {
AddBtns.hide();
}
if (!isShowDelBtn) {
DelBtns.hide();
}
if (isShowAddBtn && isShowDelBtn) {
$(this).find("tr").each(function () {
$(this).find("td:last").hide();
$(this).find("th:last").hide();
})
}
// var disableAddBtns=$(this).find(".addTableRow:disabled");
// var disableDelBtns=$(this).find(".delTableRow:disabled");
// //存在没作用的新增按钮
// if(disableAddBtns.length>0){
// if(!isShowAddBtn){
// $(this).find(".addTableRow").hide();
// }
// }
//
// //存在没作用删除按钮
// if(disableDelBtns.length>0){
// if(!isShowDelBtn){
// $(this).find(".delTableRow").hide();
// }
// }
//
// //如果两者都存在,就隐藏最后一列
// if(disableAddBtns.length>0&&disableDelBtns.length>0){
// $(this).find("tr").each(function(){
// $(this).find("td:last").hide();
// $(this).find("th:last").hide();
// })
// }
})
},
//新增列表事件
_addRow: function (obj) {
var prefix = this.prefixStr;
var suffix = this.suffixStr;
var tr = obj.closest("tr").clone(true);
var table = obj.closest("table['tabletype'='JCTABLE']");
var currentRowNum = $('input[name="' + prefix + table.attr("name") + '_HiddenField' + suffix + '"]');
var maxRowNum = table.attr("data-maxRowNum");
if (isNaN(Number(maxRowNum))) {
maxRowNum = 20;
}
if (Number(currentRowNum.val()) >= maxRowNum) {
alert("最多只能添加" + maxRowNum + "行!");
return;
}
//给控件名称加上序号
tr.find('[name^="' + prefix + '"]').each(function () {
var name = $(this).attr("name").replace(prefix, "").replace(suffix, "");
name = name + "_" + currentRowNum.val();
$(this).attr("name", prefix + name + suffix);
$(this).val("");
//同时修改操作目标名称
if ($(this).attr("data-calculate-to-variable") != undefined) {
var calculateTo = $(this).attr("data-calculate-to-variable");
//如果他的计算值在同一行内,则修改属性值
if (tr.find('[name="' + prefix + calculateTo + suffix + '"]').length > 0) {
$(this).attr("data-calculate-to-variable", calculateTo + "_" + currentRowNum.val())
}
//添加计算事件
$(this).keyup(function () {
JCPublicUtil.FlowFormTemplate.calculateOperate($(this)[0]);
})
}
});
var isShowDelBtn = table.attr("data-showDelBtn") != undefined && table.attr("data-showDelBtn") == "true" ? true : false;
if (isShowDelBtn) {
//添加删除按钮
tr.children("td:last").html('<a href="javascript:void(0);" class="delTableRow" οnclick="JCPublicUtil.FlowFormTemplate._delRow(this);return false;"><img src="' + JCPublicUtil.Location.getRootPath() + '/images/funcation_ico/delete.png" style="border:0px;"/></a>');
} else {
tr.children("td:last").html("");
}
table.children("tbody").find("tr.JCTABLE_Row:last").after(tr);
currentRowNum.val(table.find(".JCTABLE_Row").length);
},
//删除行 同时重新计算
_delRow: function (delObj) {
var prefix = this.prefixStr;
var suffix = this.suffixStr;
var tr = $(delObj).closest("tr");
var table = $(delObj).closest("table['tabletype'='JCTABLE']");
var dataCalculateToVariable = tr.find("[data-calculate-to-variable]");
dataCalculateToVariable.each(function (index) {
var calculateTo = $(this).attr("data-calculate-to-variable");
//如果他的计算值在同一行内,则不重新计算
if (tr.find('[name="' + prefix + calculateTo + suffix + '"]').length > 0) {
if (index == dataCalculateToVariable.length - 1) {
removeTr(tr);
}
return true;
} else {
$(this).val("");
JCPublicUtil.FlowFormTemplate.calculateOperate($(this)[0]);
if (index == dataCalculateToVariable.length - 1) {
removeTr(tr);
}
}
})
table.find('input[name="' + prefix + table.attr("name") + '_HiddenField' + suffix + '"]').val(table.find(".JCTABLE_Row").length);
//移除行私有方法 trObj jquery对象
function removeTr(trObj) {
var controls = trObj.find('[name^="' + prefix + '"]');
if (controls.length > 0) {
var inputName = controls.eq(0).attr("name").replace(prefix, "").replace(suffix, "");
var index = parseInt(inputName.split("_")[1], 10);
var nextAllTr = trObj.nextAll();
//修改即将删除行后的所有行name值
nextAllTr.each(function (i) {
if ($(this).hasClass("JCTABLE_Row")) {
var currentTr = $(this);
//给控件名称加上序号
$(this).find('[name^="' + prefix + '"]').each(function () {
var name = $(this).attr("name").replace(prefix, "").replace(suffix, "");
name = name.split("_")[0];
name = name + "_" + (index + i);
$(this).attr("name", prefix + name + suffix);
//同时修改操作目标名称
if ($(this).attr("data-calculate-to-variable") != undefined) {
var calculateTo = $(this).attr("data-calculate-to-variable");
//如果他的计算值在同一行内,则修改属性值
if (currentTr.find('[name="' + prefix + calculateTo + suffix + '"]').length > 0) {
calculateTo = calculateTo.split("_")[0];
$(this).attr("data-calculate-to-variable", calculateTo + "_" + (index + i))
}
}
});
}
});
trObj.remove();
}
}
},
//计算事件
//currentObj是dom对象
calculateOperate: function (currentObj) {
var prefix = this.prefixStr;
var suffix = this.suffixStr;
if ($(currentObj).attr("data-calculate-to-variable") != undefined) {
var calculateTo = $(currentObj).attr("data-calculate-to-variable");
var calculateOp = $(currentObj).attr("calculate-op");
var resultStr = "";
switch (calculateOp) {
case "plus":
var sum = 0;
var fixedCount = 0;
$("input[data-calculate-to-variable='" + calculateTo + "']").each(function () {
var valStr = $.trim($(this).val());
if (valStr != "" && !isNaN(Number(valStr))) {
sum += Number(valStr);
if (valStr.indexOf(".") != -1) {
var tempCount = valStr.split(".")[1].length;
if (tempCount > fixedCount) {
fixedCount = tempCount;
}
}
}
})
resultStr = sum.toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
break;
case "minus":
var minusResult = 0;
var fixedCount = 0;
$("input[data-calculate-to-variable='" + calculateTo + "']").each(function (i) {
var valStr = $.trim($(this).val());
if (valStr != "" && !isNaN(Number(valStr))) {
if (i == 0) {
minusResult = Number(valStr);
} else {
minusResult -= Number(valStr);
}
if (valStr.indexOf(".") != -1) {
var tempCount = valStr.split(".")[1].length;
if (tempCount > fixedCount) {
fixedCount = tempCount;
}
}
}
})
resultStr = minusResult.toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
break;
case "multiply":
var product = 0;
$("input[data-calculate-to-variable='" + calculateTo + "']").each(function (i) {
var valStr = $.trim($(this).val());
if (valStr != "" && !isNaN(Number(valStr))) {
if (i == 0) {
product = Number(valStr);
} else {
product *= Number(valStr);
}
}
})
resultStr = product.toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
break;
case "divide":
var divideResult = 0;
$("input[data-calculate-to-variable='" + calculateTo + "']").each(function (i) {
var valStr = $.trim($(this).val());
if (valStr != "" && !isNaN(Number(valStr))) {
if (i == 0) {
divideResult = Number(valStr);
} else if (Number(valStr) != 0) {
divideResult /= Number(valStr);
}
}
})
resultStr = divideResult.toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
break;
case "toUpper":
var toUpperStr = JCPublicUtil.NumberFormat.numberToChinese($(currentObj).val());
if (toUpperStr != "error") {
resultStr = toUpperStr;
}
break;
case "average":
var sum = 0;
var num = 0;
$("input[data-calculate-to-variable='" + calculateTo + "']").each(function () {
var valStr = $.trim($(this).val());
if (valStr != "" && !isNaN(Number(valStr))) {
sum += Number(valStr);
num++;
}
})
if (num != 0) {
resultStr = (sum / num).toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
}
break;
}
var resultInput = $('input[name="' + prefix + calculateTo + suffix + '"]')
resultInput.val(resultStr);
//如果计算结果的输入框也有计算要求则计算
if (resultInput.attr("data-calculate-to-variable") != undefined) {
JCPublicUtil.FlowFormTemplate.calculateOperate(resultInput[0]);
}
}
},
//验证表单
validateForm: function () {
var result = true;
$("input[regexstr]").not("[disabled]").not("[readonly]").each(function () {
var regStr = $(this).attr("regexstr");
if (regStr == "") { return true; }
var regex = new RegExp(regStr);
var valueStr = $(this).val();
//去掉逗号后是数字的,则获取去掉逗号后的值来验证
var tempValue = valueStr.replace(/,/g, "");
if (JCPublicUtil.NumberFormat.testNumber(tempValue) == true) {
valueStr = tempValue;
}
if (!regex.test(valueStr)) {
$(this).attr("style", "border:solid 1px red;");
result = false;
$(this).focus();
} else {
$(this).removeAttr("style");
}
});
return result;
}
},
//数字格式化
NumberFormat: {
//以某个分隔符分开
splitMarkFormat: function (numberStr, fixedNumber, markStr) {
if (isNaN(Number(numberStr))) {
return "";
}
fixedNumber = fixedNumber > 0 && fixedNumber <= 20 ? fixedNumber : 2;
numberStr = parseFloat((numberStr + "").replace(/[^\d\.-]/g, "")).toFixed(fixedNumber) + "";
var l = numberStr.split(".")[0].split("").reverse(),
r = numberStr.split(".")[1];
t = "";
for (i = 0; i < l.length; i++) {
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? markStr : "");
}
return t.split("").reverse().join("") + "." + r;
},
//移除分割符号
removeSplitMark: function (str) {
return str.replace(/[^\d\.-]/g, "");
},
//数字转中文大写
numberToChinese: function (n) {
if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))
return "error";
var unit = "仟佰拾亿仟佰拾万仟佰拾圆角分", str = "";
n += "00";
var p = n.indexOf('.');
if (p >= 0)
n = n.substring(0, p) + n.substr(p + 1, 2);
unit = unit.substr(unit.length - n.length);
for (var i = 0; i < n.length; i++)
str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i);
str = str.replace(/零(仟|佰|拾|角)/g, "零").replace(/(零)+/g, "零").replace(
/零(万|亿|圆)/g, "$1").replace(/(亿)万|(壹拾)/g, "$1$2").replace(
/^圆零?|零分/g, "").replace(/圆$/g, "圆整");
return str;
},
//验证是否是数字或浮点型数字
testNumber: function (numberStr) {
if (/^-?(0|[1-9]\d*)(\.\d+)?$/.test(numberStr)) {
return true;
} else {
return false;
}
},
//保留几位有效数字
toFixed:function(numStr,fixnum){
if (!isNaN(Number(numberStr))) {
if(numStr.indexOf(".")!=-1){
var numStrSplitArray=numStr.split(".");
if(numStrSplitArray[1].length>fixnum){
return numStrSplitArray[0]+"."+numStrSplitArray[1].substr(0,fixnum);
}
}
}
return numStr;
}
},
//地址相关类 http://localhost:8080/JC/
Location: {
getRootPath: function () {
var strFullPath = window.document.location.href;
var strPath = window.document.location.pathname;
var pos = strFullPath.indexOf(strPath);
var prePath = strFullPath.substring(0, pos);
var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
return (prePath + postPath);
}
},
//触摸屏的的相关事件
touchScreen:{
//鼠标滚动界面
mouseScroll:function(){
var x=0,y=0,isDown=false,top=0,left=0;//记录鼠标点击的坐标
$(document).mousedown(function(e){
x=e.clientX;
y=e.clientY;
top=$(document).scrollTop();
left=$(document).scrollLeft();
isDown=true;
}).mousemove(function(e){
if(isDown){
var offsetX=e.clientX-x;
var offsetY=e.clientY-y;
$(document).scrollTop(top+offsetY*-1);
$(document).scrollLeft(left+offsetX*-1);
}
}).mouseup(function(){
isDown=false;
})
//禁止选中文字
$("body").css({"-moz-user-select":"none","-webkit-user-select":"none","user-select":"none"});
$("html").css({"overflow":"hidden"});
//禁止出现滚动条
$("body").attr("scroll","no");
//禁用右键
$(document).bind("contextmenu",function(e){return false;}).bind("selectstart",function(e){return false;});
}
},
Ajax:function(url,method,data,successFunc,errorFunc,timeout,cache,datatype){
$.ajax({
type: method,
url: url,
data: data,
timeout:timeout,
cache:cache,
dataType:datatype,
success: successFunc,
error:errorFunc
});
}
};
//初始化操作
PublicUtil.initModuleFunc();
*/
var PublicUtil = {
//提示框类型
alertType: {
warnType: 0,
okType: 1
},
//alert提示框
alertWindow: function (alertType, title, msg, okBtnText, okFunction) {
var randowSuffix = JCPublicUtil.DateFormat(new Date(), "YYYYMMddhhmmss");
var dialogId = "dialogWindow_" + randowSuffix;
var dialogOverlayId = "dialogOverlay_" + randowSuffix;
var stringBuilder = this.StringBuilder();
switch (alertType) {
case this.alertType.okType:
stringBuilder.Append('<div class="dialogWindow" id="' + dialogId + '" style="display:none;">');
break;
case this.alertType.warnType:
stringBuilder.Append('<div class="dialogWindow warnDialog" id="' + dialogId + '" style="display:none;">');
break;
}
stringBuilder.Append('<div class="dialogHeader">');
stringBuilder.Append(' <span class="dialogTitle">' + title + '</span>');
stringBuilder.Append(' <a href="javascript:void(0);" class="dialogClose"></a>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div class="dialogBody">');
stringBuilder.Append(' <table cellspacing="0px" border="0px" cellpadding="0px">');
stringBuilder.Append(' <tr>');
stringBuilder.Append(' <td><span class="dialogIcon"></span></td>');
stringBuilder.Append(' <td>');
stringBuilder.Append(' <span class="dialogMsg">' + msg + '</span>');
stringBuilder.Append(' </td>');
stringBuilder.Append(' </tr>');
stringBuilder.Append(' </table>');
stringBuilder.Append(' <div class="dialogFooter">');
stringBuilder.Append(' <input type="button" class="dialogOK newOk_Btn" value="' + okBtnText + '" />');
stringBuilder.Append(' </div>');
stringBuilder.Append(' <div style="clear:both;"></div>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div style="clear:both;"></div>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div class="dialog-overlay" id="' + dialogOverlayId + '" style="display:none;"><iframe frameborder="0" style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);"></iframe></div>');
if ($("#" + dialogId).length > 0) {
$("#" + dialogId).remove();
$("#" + dialogOverlayId).remove();
}
$("body").append(stringBuilder.ToString());
var zIndex = 999;
//设置层次关系
var currentCount = $(".dialogWindow").length + 1;
zIndex += currentCount;
$("body").css("overflow", "hidden");
var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
$("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
$("#" + dialogOverlayId).css({
'left': 0, 'top': 0,
'width': $(document).width(),
'height': $(document).height(),
'z-index': zIndex,
'position': 'absolute'
})
$("#" + dialogId + " .dialogClose").click(function () {
$("#" + dialogId).remove();
$("#" + dialogOverlayId).remove();
$("body").css("overflow", "auto");
$(window).unbind("resize.dialogwindow");
})
$("#" + dialogId + " .dialogOK").click(function () {
if (okFunction != null && okFunction != undefined) {
okFunction();
}
if ($("#" + dialogId).length > 0) {
$("#" + dialogId + " .dialogClose").click();
}
});
$(window).bind("resize.dialogwindow", function () {
var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
$("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
$("#" + dialogOverlayId).css({
'width': $(document).width()
})
})
$("#" + dialogOverlayId).show();
$("#" + dialogId).show();
},
/*内容可以自定义的弹出框 返回框对象
*title 标题
*content 弹出框中的内容
*okBtnText 确定按钮的文字 为空时则不显示该按钮
*okFunction 确定按钮的事件 无事件就为null
*cancelBtnText 取消按钮的文字 为空时则不显示该按钮
*cancelFunc 取消按钮的事件 无事件就为null
*/
dialogWindow: function (title, content, okBtnText, okFunction, cancelBtnText, cancelFunc) {
var randowSuffix = JCPublicUtil.DateFormat(new Date(), "YYYYMMddhhmmss");
var dialogId = "dialogWindow_" + randowSuffix;
var dialogOverlayId = "dialogOverlay_" + randowSuffix;
var stringBuilder = this.StringBuilder();
stringBuilder.Append('<div class="dialogWindow" id="' + dialogId + '" style="display:none;">');
stringBuilder.Append('<div class="dialogHeader">');
stringBuilder.Append(' <span class="dialogTitle">' + title + '</span>');
stringBuilder.Append(' <a href="javascript:void(0);" class="dialogClose"></a>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div class="dialogBody">');
stringBuilder.Append(' <table cellspacing="0px" border="0px" cellpadding="0px">');
stringBuilder.Append(' <tr>');
stringBuilder.Append(' <td>');
stringBuilder.Append(content);
stringBuilder.Append(' </td>');
stringBuilder.Append(' </tr>');
stringBuilder.Append(' </table>');
stringBuilder.Append(' <div class="dialogFooter">');
if (okBtnText != "") {
stringBuilder.Append(' <input type="button" class="dialogOK newOk_Btn" value="' + okBtnText + '" />');
}
if (cancelBtnText != "") {
stringBuilder.Append(' <input type="button" class="dialogCancel newCancel_Btn" value="' + cancelBtnText + '" />');
}
stringBuilder.Append(' </div>');
stringBuilder.Append(' <div style="clear:both;"></div>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div style="clear:both;"></div>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div class="dialog-overlay" id="' + dialogOverlayId + '"><iframe frameborder="0" style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);"></iframe></div>');
if ($("#" + dialogId).length > 0) {
$("#" + dialogId).remove();
$("#" + dialogOverlayId).remove();
}
$("body").append(stringBuilder.ToString());
var zIndex = 999;
//设置层次关系
var currentCount = $(".dialogWindow").length + 1;
zIndex += currentCount;
$("body").css("overflow", "hidden");
var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
$("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
$("#" + dialogOverlayId).css({
'left': 0, 'top': 0,
'width': $(document).width(),
'height': $(document).height(),
'z-index': zIndex,
'position': 'absolute'
})
$("#" + dialogId + " .dialogClose").click(function () {
$("#" + dialogId).remove();
$("#" + dialogOverlayId).remove();
$("body").css("overflow", "auto");
$(window).unbind("resize.dialogwindow");
})
$("#" + dialogId + " .dialogOK").click(function () {
if (okFunction != null && okFunction != undefined) {
if(okFunction($("#" + dialogId))==false){
return;
}
}
if ($("#" + dialogId).length > 0) {
$("#" + dialogId + " .dialogClose").click();
}
});
$("#" + dialogId + " .dialogCancel").click(function () {
$("#" + dialogId + " .dialogClose").click();
if (cancelFunc != null && cancelFunc != undefined) {
cancelFunc();
}
});
$(window).bind("resize.dialogwindow", function () {
var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
$("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
$("#" + dialogOverlayId).css({
'width': $(document).width()
})
})
//拖动
var mouse={x:0,y:0};
$("#" + dialogId + " .dialogHeader").mousedown(function (event) {
var e = window.event || event;
var offset = $("#" + dialogId).offset();
mouse.x = e.clientX - offset.left;
mouse.y = e.clientY - offset.top;
$(document).bind('mousemove', moveDialog).bind("mouseup",function(){$(document).unbind('mousemove', moveDialog);});
});
function moveDialog(event) {
var e = window.event || event;
var top = e.clientY - mouse.y;
var left = e.clientX - mouse.x;
$("#" + dialogId).css({"top": top, "left": left});
};
$("#" + dialogId).show();
return $("#" + dialogId);
},
//确定提示框
confirmWindow: function (alertType, title, msg, okBtnText, okFunction, cancelBtnText, cancelFunc) {
var randowSuffix = JCPublicUtil.DateFormat(new Date(), "YYYYMMddhhmmss");
var dialogId = "dialogWindow_" + randowSuffix;
var dialogOverlayId = "dialogOverlay_" + randowSuffix;
var stringBuilder = this.StringBuilder();
switch (alertType) {
case this.alertType.okType:
stringBuilder.Append('<div class="dialogWindow" id="' + dialogId + '" style="display:none;">');
break;
case this.alertType.warnType:
stringBuilder.Append('<div class="dialogWindow warnDialog" id="' + dialogId + '" style="display:none;">');
break;
}
stringBuilder.Append('<div class="dialogHeader">');
stringBuilder.Append(' <span class="dialogTitle">' + title + '</span>');
stringBuilder.Append(' <a href="javascript:void(0);" class="dialogClose"></a>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div class="dialogBody">');
stringBuilder.Append(' <table cellspacing="0px" border="0px" cellpadding="0px">');
stringBuilder.Append(' <tr>');
stringBuilder.Append(' <td><span class="dialogIcon"></span></td>');
stringBuilder.Append(' <td>');
stringBuilder.Append(' <span class="dialogMsg">' + msg + '</span>');
stringBuilder.Append(' </td>');
stringBuilder.Append(' </tr>');
stringBuilder.Append(' </table>');
stringBuilder.Append(' <div class="dialogFooter">');
stringBuilder.Append(' <input type="button" class="dialogOK newOk_Btn" value="' + okBtnText + '" />');
stringBuilder.Append(' <input type="button" class="dialogCancel newCancel_Btn" value="' + cancelBtnText + '" />');
stringBuilder.Append(' </div>');
stringBuilder.Append(' <div style="clear:both;"></div>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div style="clear:both;"></div>');
stringBuilder.Append('</div>');
stringBuilder.Append('<div class="dialog-overlay" id="' + dialogOverlayId + '" style="display:block;"><iframe frameborder="0" style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0); opacity:0;"></iframe></div>');
if ($("#" + dialogId).length > 0) {
$("#" + dialogId).remove();
$("#" + dialogOverlayId).remove();
}
$("body").append(stringBuilder.ToString());
var zIndex = 999;
//设置层次关系
var currentCount = $(".dialogWindow").length + 1;
zIndex += currentCount;
$("body").css("overflow", "hidden");
var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
$("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
$("#" + dialogOverlayId).css({
'left': 0, 'top': 0,
'width': $(document).width(),
'height': $(document).height(),
'z-index': zIndex,
'position': 'absolute'
})
$("#" + dialogId + " .dialogClose").click(function () {
$("#" + dialogId).remove();
$("#" + dialogOverlayId).remove();
$("body").css("overflow", "auto");
$(window).unbind("resize.dialogwindow");
})
$("#" + dialogId + " .dialogOK").click(function () {
if (okFunction != null && okFunction != undefined) {
if(okFunction($("#" + dialogId))==false){
return;
}
}
if ($("#" + dialogId).length > 0) {
$("#" + dialogId + " .dialogClose").click();
}
});
$("#" + dialogId + " .dialogCancel").click(function () {
$("#" + dialogId + " .dialogClose").click();
if (cancelFunc != null && cancelFunc != undefined) {
cancelFunc();
}
});
$(window).bind("resize.dialogwindow", function () {
var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
$("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
$("#" + dialogOverlayId).css({
'width': $(document).width()
})
})
$("#" + dialogOverlayId).show();
$("#" + dialogId).show();
},
//字符串对象
StringBuilder: function () {
//实体对象
var StringBuilderObj = function (args) {
this._buffers = [];
this._length = 0;
this._splitChar = args.length > 0 ? args[args.length - 1] : '';
if (args.length > 0) {
for (var i = 0, iLen = args.length - 1; i < iLen; i++) {
this.Append(args[i]);
}
}
}
//append方法
StringBuilderObj.prototype.Append = function (str) {
this._length += str.length;
this._buffers[this._buffers.length] = str;
}
//向对象中添加字符串
//参数:一个字符串值
StringBuilderObj.prototype.Add = StringBuilderObj.prototype.append;
//向对象附加格式化的字符串
//参数:参数一是预格式化的字符串,如:'{0} {1} {2}'
//格式参数可以是数组,或对应长度的arguments,
StringBuilderObj.prototype.AppendFormat = function () {
if (arguments.length > 1) {
var TString = arguments[0];
if (arguments[1] instanceof Array) {
for (var i = 0, iLen = arguments[1].length; i < iLen; i++) {
var jIndex = i;
var re = eval("/\\{" + jIndex + "\\}/g;");
TString = TString.replace(re, arguments[1][i]);
}
}
else {
for (var i = 1, iLen = arguments.length; i < iLen; i++) {
var jIndex = i - 1;
var re = eval("/\\{" + jIndex + "\\}/g;");
TString = TString.replace(re, arguments[i]);
}
}
this.Append(TString);
}
else if (arguments.length == 1) {
this.Append(arguments[0]);
}
}
//字符串长度(相当于ToString()后输出的字符串长度
StringBuilderObj.prototype.Length = function () {
if (this._splitChar.length > 0 && (!this.IsEmpty())) {
return this._length + (this._splitChar.length * (this._buffers.length - 1));
}
else {
return this._length;
}
}
//字符串是否为空
StringBuilderObj.prototype.IsEmpty = function () {
return this._buffers.length <= 0;
}
//清空
StringBuilderObj.prototype.Clear = function () {
this._buffers = [];
this._length = 0;
}
//输出
//参数:可以指定一个字符串(或单个字符),作为字符串拼接的分隔符
StringBuilderObj.prototype.ToString = function () {
if (arguments.length == 1) {
return this._buffers.join(arguments[1]);
}
else {
return this._buffers.join(this._splitChar);
}
}
return new StringBuilderObj(arguments);
},
//时间格式转换
DateFormat: function (dateObj, format) {
try {
/*
* eg:format="YYYY-MM-dd hh:mm:ss";
*/
var o = {
"Y+": dateObj.getFullYear(),
"M+": dateObj.getMonth() + 1, //month
"d+": dateObj.getDate(), //day
"h+": dateObj.getHours(), //hour
"m+": dateObj.getMinutes(), //minute
"s+": dateObj.getSeconds(), //second
"q+": Math.floor((dateObj.getMonth() + 3) / 3), //quarter
"S": dateObj.getMilliseconds() //millisecond
}
if (/(Y+)/.test(format)) {
format = format.replace(RegExp.$1, (dateObj.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
} catch (e) {
return "";
}
},
//初始化几个模块的事件绑定。
initModuleFunc: function () {
$(function () {
//绑定高级搜索的事件
if ($("#SearchDiv").length > 0) {
$("#SearchDiv").click(function (e) { e.stopPropagation(); });
//高级搜索按钮的事件
$("#topDivBtn").click(function (e) {
if ($("#topDiv").hasClass("TopSearchSelected")) {
$("#topDiv").removeClass().addClass("TopSearch");
$("#SearchDiv").hide();
}
else {
$("#topDiv").removeClass().addClass("TopSearchSelected");
$("#SearchDiv").show();
}
$(document).bind("click", function () {
if ($("#topDiv").hasClass("TopSearchSelected")) {
$("#topDiv").removeClass().addClass("TopSearch");
$("#SearchDiv").hide();
}
$(document).unbind("click");
})
e.stopPropagation();
});
//取消高级搜索
$("#cancelBtn").click(function () { $("#topDivBtn").click(); });
}
//绑定列表行的颜色和鼠标移动上去的事件----------------------------------------
if ($(".cyListContent").length > 0) {
$(".ListItem").hover(function () { $(this).addClass("selectUL") }, function () { $(this).removeClass("selectUL"); })
//给列表行的奇数行添加背景颜色
$(".cyListContent>ul>li:odd").css("background", "#f2f2f2");
}
//全选----------------------------------------------
var cbList = document.getElementsByName("cb");
var all = document.getElementById("checkAll");
if (all != null) {
all.onclick = function () {
for (var i = 0; i < cbList.length; i++) {
cbList[i].checked = all.checked;
}
};
}
//导航选择------------------------------------------------------
if ($(".daohang").length > 0) {
$(".daohang>ul>li").click(function () {
$(this).parent().find("li").removeClass();
$(this).addClass("selectedLi");
});
}
//流程定制-------------------------------------------------------
$(".listContent").each(function(){
$(this).find("table tr.listtr:even").addClass("evenTr");
$(this).find("table tr.listtr:odd").addClass("oddTr");
$(this).find("table tr.listtr").mouseover(function () {
$(this).addClass("selectedTR");
}).mouseout(function () {
$(this).removeClass("selectedTR");
});
})
});
},
/*某个字符串中是否包含另一个字符串或者包含另一个字符串以特殊字符分割的字符串,注意英文为英文单词
* mainStr 为主字符串
* strContained 被包含的字符串
* splitMark 被包含字符串的分隔符,如果没有分隔符可以为空字符串
* 返回实体对象{"isContain":true,"msg":""},true为都包含否则不全部包含或者全部不包含
* */
containsStr:function(mainStr,strContained,splitMark){
var isContain=true;
var msg="";
var strArray=new Array();
if(strContained==""){
return {"isContain":false,"msg":"0"};
}
if(splitMark!=""){
strArray=strContained.split(splitMark);
}else{
strArray.push(strContained);
}
for(var i=0;i<strArray.length;i++){
//中文
if(/[\u4e00-\u9fa5]+/g.test(strArray[i])){
if(mainStr.indexOf(strArray[i])==-1){
isContain=false;
msg+=strArray[i]+"\r\n";
}
}else{
//英文单词
var regex=new RegExp("\\b"+strArray[i]+"\\b","g");
if(!regex.test(mainStr)){
isContain=false;
msg+=strArray[i]+"\r\n";
}
}
}
return {"isContain":isContain,"msg":msg};
},
//流程表单模板实体类
FlowFormTemplate: {
prefixStr: "flowPropMap['",
suffixStr: "']",
fiexNum: 2,
initFunc: function () {
//绑定新增列表事件
$(".addTableRow").not("[disabled]").click(function () {
JCPublicUtil.FlowFormTemplate._addRow($(this));
});
//删除列表
$(".delTableRow").not("[disabled]").click(function (e) {
JCPublicUtil.FlowFormTemplate._delRow($(this)[0]);
e.stopPropagation();
return false;
});
//绑定输入框事件
$("input[data-calculate-to-variable]").keyup(function () {
JCPublicUtil.FlowFormTemplate.calculateOperate($(this)[0]);
});
//样式绑定
$(".dynamic-form-table-body,.dynamic-form-table-body table").css({ "border-collapse": "collapse", "border": "solid 1px #cccccc" }).attr({ "cellpadding": "0", "cellspacing": "0" });
$(".dynamic-form-table-body td,.dynamic-form-table-body th").css({ "border": "solid 1px #cccccc" });
$(".delTableRow").html('<img src="' + JCPublicUtil.Location.getRootPath() + '/images/funcation_ico/delete.png" style="border:0px;"/>');
$(".addTableRow").html('<img src="' + JCPublicUtil.Location.getRootPath() + '/images/funcation_ico/add.gif" style="border:0px;"/>');
$("table[tableType='JCTABLE']").find("thead tr").css({ "background-color": "#cccccc" });
//控制列表的新增和删除按钮是否显示
$("table[tableType='JCTABLE']").each(function () {
var isShowAddBtn = $(this).attr("data-showAddBtn") != undefined && $(this).attr("data-showAddBtn") == "true" ? true : false;
var isShowDelBtn = $(this).attr("data-showDelBtn") != undefined && $(this).attr("data-showDelBtn") == "true" ? true : false;
var AddBtns = $(this).find(".addTableRow");
var DelBtns = $(this).find(".delTableRow");
if (!isShowAddBtn) {
AddBtns.hide();
}
if (!isShowDelBtn) {
DelBtns.hide();
}
if (isShowAddBtn && isShowDelBtn) {
$(this).find("tr").each(function () {
$(this).find("td:last").hide();
$(this).find("th:last").hide();
})
}
// var disableAddBtns=$(this).find(".addTableRow:disabled");
// var disableDelBtns=$(this).find(".delTableRow:disabled");
// //存在没作用的新增按钮
// if(disableAddBtns.length>0){
// if(!isShowAddBtn){
// $(this).find(".addTableRow").hide();
// }
// }
//
// //存在没作用删除按钮
// if(disableDelBtns.length>0){
// if(!isShowDelBtn){
// $(this).find(".delTableRow").hide();
// }
// }
//
// //如果两者都存在,就隐藏最后一列
// if(disableAddBtns.length>0&&disableDelBtns.length>0){
// $(this).find("tr").each(function(){
// $(this).find("td:last").hide();
// $(this).find("th:last").hide();
// })
// }
})
},
//新增列表事件
_addRow: function (obj) {
var prefix = this.prefixStr;
var suffix = this.suffixStr;
var tr = obj.closest("tr").clone(true);
var table = obj.closest("table['tabletype'='JCTABLE']");
var currentRowNum = $('input[name="' + prefix + table.attr("name") + '_HiddenField' + suffix + '"]');
var maxRowNum = table.attr("data-maxRowNum");
if (isNaN(Number(maxRowNum))) {
maxRowNum = 20;
}
if (Number(currentRowNum.val()) >= maxRowNum) {
alert("最多只能添加" + maxRowNum + "行!");
return;
}
//给控件名称加上序号
tr.find('[name^="' + prefix + '"]').each(function () {
var name = $(this).attr("name").replace(prefix, "").replace(suffix, "");
name = name + "_" + currentRowNum.val();
$(this).attr("name", prefix + name + suffix);
$(this).val("");
//同时修改操作目标名称
if ($(this).attr("data-calculate-to-variable") != undefined) {
var calculateTo = $(this).attr("data-calculate-to-variable");
//如果他的计算值在同一行内,则修改属性值
if (tr.find('[name="' + prefix + calculateTo + suffix + '"]').length > 0) {
$(this).attr("data-calculate-to-variable", calculateTo + "_" + currentRowNum.val())
}
//添加计算事件
$(this).keyup(function () {
JCPublicUtil.FlowFormTemplate.calculateOperate($(this)[0]);
})
}
});
var isShowDelBtn = table.attr("data-showDelBtn") != undefined && table.attr("data-showDelBtn") == "true" ? true : false;
if (isShowDelBtn) {
//添加删除按钮
tr.children("td:last").html('<a href="javascript:void(0);" class="delTableRow" οnclick="JCPublicUtil.FlowFormTemplate._delRow(this);return false;"><img src="' + JCPublicUtil.Location.getRootPath() + '/images/funcation_ico/delete.png" style="border:0px;"/></a>');
} else {
tr.children("td:last").html("");
}
table.children("tbody").find("tr.JCTABLE_Row:last").after(tr);
currentRowNum.val(table.find(".JCTABLE_Row").length);
},
//删除行 同时重新计算
_delRow: function (delObj) {
var prefix = this.prefixStr;
var suffix = this.suffixStr;
var tr = $(delObj).closest("tr");
var table = $(delObj).closest("table['tabletype'='JCTABLE']");
var dataCalculateToVariable = tr.find("[data-calculate-to-variable]");
dataCalculateToVariable.each(function (index) {
var calculateTo = $(this).attr("data-calculate-to-variable");
//如果他的计算值在同一行内,则不重新计算
if (tr.find('[name="' + prefix + calculateTo + suffix + '"]').length > 0) {
if (index == dataCalculateToVariable.length - 1) {
removeTr(tr);
}
return true;
} else {
$(this).val("");
JCPublicUtil.FlowFormTemplate.calculateOperate($(this)[0]);
if (index == dataCalculateToVariable.length - 1) {
removeTr(tr);
}
}
})
table.find('input[name="' + prefix + table.attr("name") + '_HiddenField' + suffix + '"]').val(table.find(".JCTABLE_Row").length);
//移除行私有方法 trObj jquery对象
function removeTr(trObj) {
var controls = trObj.find('[name^="' + prefix + '"]');
if (controls.length > 0) {
var inputName = controls.eq(0).attr("name").replace(prefix, "").replace(suffix, "");
var index = parseInt(inputName.split("_")[1], 10);
var nextAllTr = trObj.nextAll();
//修改即将删除行后的所有行name值
nextAllTr.each(function (i) {
if ($(this).hasClass("JCTABLE_Row")) {
var currentTr = $(this);
//给控件名称加上序号
$(this).find('[name^="' + prefix + '"]').each(function () {
var name = $(this).attr("name").replace(prefix, "").replace(suffix, "");
name = name.split("_")[0];
name = name + "_" + (index + i);
$(this).attr("name", prefix + name + suffix);
//同时修改操作目标名称
if ($(this).attr("data-calculate-to-variable") != undefined) {
var calculateTo = $(this).attr("data-calculate-to-variable");
//如果他的计算值在同一行内,则修改属性值
if (currentTr.find('[name="' + prefix + calculateTo + suffix + '"]').length > 0) {
calculateTo = calculateTo.split("_")[0];
$(this).attr("data-calculate-to-variable", calculateTo + "_" + (index + i))
}
}
});
}
});
trObj.remove();
}
}
},
//计算事件
//currentObj是dom对象
calculateOperate: function (currentObj) {
var prefix = this.prefixStr;
var suffix = this.suffixStr;
if ($(currentObj).attr("data-calculate-to-variable") != undefined) {
var calculateTo = $(currentObj).attr("data-calculate-to-variable");
var calculateOp = $(currentObj).attr("calculate-op");
var resultStr = "";
switch (calculateOp) {
case "plus":
var sum = 0;
var fixedCount = 0;
$("input[data-calculate-to-variable='" + calculateTo + "']").each(function () {
var valStr = $.trim($(this).val());
if (valStr != "" && !isNaN(Number(valStr))) {
sum += Number(valStr);
if (valStr.indexOf(".") != -1) {
var tempCount = valStr.split(".")[1].length;
if (tempCount > fixedCount) {
fixedCount = tempCount;
}
}
}
})
resultStr = sum.toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
break;
case "minus":
var minusResult = 0;
var fixedCount = 0;
$("input[data-calculate-to-variable='" + calculateTo + "']").each(function (i) {
var valStr = $.trim($(this).val());
if (valStr != "" && !isNaN(Number(valStr))) {
if (i == 0) {
minusResult = Number(valStr);
} else {
minusResult -= Number(valStr);
}
if (valStr.indexOf(".") != -1) {
var tempCount = valStr.split(".")[1].length;
if (tempCount > fixedCount) {
fixedCount = tempCount;
}
}
}
})
resultStr = minusResult.toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
break;
case "multiply":
var product = 0;
$("input[data-calculate-to-variable='" + calculateTo + "']").each(function (i) {
var valStr = $.trim($(this).val());
if (valStr != "" && !isNaN(Number(valStr))) {
if (i == 0) {
product = Number(valStr);
} else {
product *= Number(valStr);
}
}
})
resultStr = product.toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
break;
case "divide":
var divideResult = 0;
$("input[data-calculate-to-variable='" + calculateTo + "']").each(function (i) {
var valStr = $.trim($(this).val());
if (valStr != "" && !isNaN(Number(valStr))) {
if (i == 0) {
divideResult = Number(valStr);
} else if (Number(valStr) != 0) {
divideResult /= Number(valStr);
}
}
})
resultStr = divideResult.toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
break;
case "toUpper":
var toUpperStr = JCPublicUtil.NumberFormat.numberToChinese($(currentObj).val());
if (toUpperStr != "error") {
resultStr = toUpperStr;
}
break;
case "average":
var sum = 0;
var num = 0;
$("input[data-calculate-to-variable='" + calculateTo + "']").each(function () {
var valStr = $.trim($(this).val());
if (valStr != "" && !isNaN(Number(valStr))) {
sum += Number(valStr);
num++;
}
})
if (num != 0) {
resultStr = (sum / num).toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
}
break;
}
var resultInput = $('input[name="' + prefix + calculateTo + suffix + '"]')
resultInput.val(resultStr);
//如果计算结果的输入框也有计算要求则计算
if (resultInput.attr("data-calculate-to-variable") != undefined) {
JCPublicUtil.FlowFormTemplate.calculateOperate(resultInput[0]);
}
}
},
//验证表单
validateForm: function () {
var result = true;
$("input[regexstr]").not("[disabled]").not("[readonly]").each(function () {
var regStr = $(this).attr("regexstr");
if (regStr == "") { return true; }
var regex = new RegExp(regStr);
var valueStr = $(this).val();
//去掉逗号后是数字的,则获取去掉逗号后的值来验证
var tempValue = valueStr.replace(/,/g, "");
if (JCPublicUtil.NumberFormat.testNumber(tempValue) == true) {
valueStr = tempValue;
}
if (!regex.test(valueStr)) {
$(this).attr("style", "border:solid 1px red;");
result = false;
$(this).focus();
} else {
$(this).removeAttr("style");
}
});
return result;
}
},
//数字格式化
NumberFormat: {
//以某个分隔符分开
splitMarkFormat: function (numberStr, fixedNumber, markStr) {
if (isNaN(Number(numberStr))) {
return "";
}
fixedNumber = fixedNumber > 0 && fixedNumber <= 20 ? fixedNumber : 2;
numberStr = parseFloat((numberStr + "").replace(/[^\d\.-]/g, "")).toFixed(fixedNumber) + "";
var l = numberStr.split(".")[0].split("").reverse(),
r = numberStr.split(".")[1];
t = "";
for (i = 0; i < l.length; i++) {
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? markStr : "");
}
return t.split("").reverse().join("") + "." + r;
},
//移除分割符号
removeSplitMark: function (str) {
return str.replace(/[^\d\.-]/g, "");
},
//数字转中文大写
numberToChinese: function (n) {
if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))
return "error";
var unit = "仟佰拾亿仟佰拾万仟佰拾圆角分", str = "";
n += "00";
var p = n.indexOf('.');
if (p >= 0)
n = n.substring(0, p) + n.substr(p + 1, 2);
unit = unit.substr(unit.length - n.length);
for (var i = 0; i < n.length; i++)
str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i);
str = str.replace(/零(仟|佰|拾|角)/g, "零").replace(/(零)+/g, "零").replace(
/零(万|亿|圆)/g, "$1").replace(/(亿)万|(壹拾)/g, "$1$2").replace(
/^圆零?|零分/g, "").replace(/圆$/g, "圆整");
return str;
},
//验证是否是数字或浮点型数字
testNumber: function (numberStr) {
if (/^-?(0|[1-9]\d*)(\.\d+)?$/.test(numberStr)) {
return true;
} else {
return false;
}
},
//保留几位有效数字
toFixed:function(numStr,fixnum){
if (!isNaN(Number(numberStr))) {
if(numStr.indexOf(".")!=-1){
var numStrSplitArray=numStr.split(".");
if(numStrSplitArray[1].length>fixnum){
return numStrSplitArray[0]+"."+numStrSplitArray[1].substr(0,fixnum);
}
}
}
return numStr;
}
},
//地址相关类 http://localhost:8080/JC/
Location: {
getRootPath: function () {
var strFullPath = window.document.location.href;
var strPath = window.document.location.pathname;
var pos = strFullPath.indexOf(strPath);
var prePath = strFullPath.substring(0, pos);
var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
return (prePath + postPath);
}
},
//触摸屏的的相关事件
touchScreen:{
//鼠标滚动界面
mouseScroll:function(){
var x=0,y=0,isDown=false,top=0,left=0;//记录鼠标点击的坐标
$(document).mousedown(function(e){
x=e.clientX;
y=e.clientY;
top=$(document).scrollTop();
left=$(document).scrollLeft();
isDown=true;
}).mousemove(function(e){
if(isDown){
var offsetX=e.clientX-x;
var offsetY=e.clientY-y;
$(document).scrollTop(top+offsetY*-1);
$(document).scrollLeft(left+offsetX*-1);
}
}).mouseup(function(){
isDown=false;
})
//禁止选中文字
$("body").css({"-moz-user-select":"none","-webkit-user-select":"none","user-select":"none"});
$("html").css({"overflow":"hidden"});
//禁止出现滚动条
$("body").attr("scroll","no");
//禁用右键
$(document).bind("contextmenu",function(e){return false;}).bind("selectstart",function(e){return false;});
}
},
Ajax:function(url,method,data,successFunc,errorFunc,timeout,cache,datatype){
$.ajax({
type: method,
url: url,
data: data,
timeout:timeout,
cache:cache,
dataType:datatype,
success: successFunc,
error:errorFunc
});
}
};
//初始化操作
PublicUtil.initModuleFunc();