标签:
var jq;
var tab;
var tabsIndex;
/**
* 常用说明
* @param row
* @returns {String}
*/
function formatItem(row) {
var s = ‘<span class="text-span">‘ + row.text + ‘</span>‘;
if (row.type == "private") {
s += ‘<span class="remove-span"><a href="javascript:;" onclick="deleteOpinion(‘ + row.id + ‘);" class="remove">X</a></span>‘;
}
return s;
}
/**
* 删除常用说明
* @param id
*/
function deleteOpinion(id) {
if (id != "") {
$.post(‘opinion/delete.action‘, {
id: id
},
function(result) {
if (result.success) {
$(‘#comments‘).combobox(‘clear‘).combobox(‘reload‘);
$.messager.show({
title: ‘成功‘,
msg: "操作成功!"
});
} else {
$.messager.show({
title: ‘错误‘,
msg: result.title
});
}
},
‘json‘);
}
}
/**
* 增加常用说明
*/
function saveOpinion() {
var text = $("#suggestion").val();
if (text != "") {
$.post(‘opinion/save.action‘, {
text: text,
type: "private"
},
function(result) {
if (result.success) {
$(‘#comments‘).combobox(‘reload‘);
$.messager.show({
title: ‘成功‘,
msg: "操作成功!"
});
} else {
$.messager.show({
title: ‘错误‘,
msg: result.title
});
}
},
‘json‘);
}
}
function exportExcels(id) {
var params = $(‘#‘ + id).datagrid(‘options‘).queryParams;
var url = $(‘#‘ + id).datagrid(‘options‘).url;
var sortName = $(‘#‘ + id).datagrid(‘options‘).sortName;
var sortOrder = $(‘#‘ + id).datagrid(‘options‘).sortOrder;
params["order"] = sortOrder;
params["sort"] = sortName;
params["operate"] = "export";
var columnJsonf = $(‘#‘ + id).datagrid("options").frozenColumns;
var columnJson = $(‘#‘ + id).datagrid("options").columns;
var form = $(‘<form></form>‘);
// 设置属性
form.attr(‘action‘, url);
form.attr(‘method‘, ‘post‘);
form.attr(‘target‘, ‘_self‘);
// 创建Input
var input = $(‘<input type="hidden" name="columnJson" />‘);
var inputRow = $(‘<input type="hidden" name="rows" value="10" />‘);
var inputPage = $(‘<input type="hidden" name="page" value="1" />‘);
form.append(inputRow);
form.append(inputPage);
var jsonArray = new Array();
var arrayOn = new Array();
for (var i = 0; i < columnJsonf.length; i++) {
for (var j = 0; j < columnJsonf[i].length; j++) {
var col = columnJsonf[i][j];
col.rowspan = columnJson.length;
arrayOn.push(col);
}
}
for (var i = 0; i < columnJson.length; i++) {
if (i == 0) {
for (var j = 0; j < columnJson[i].length; j++) {
var colj = columnJson[i][j];
arrayOn.push(colj);
}
jsonArray.push(arrayOn);
} else {
jsonArray.push(columnJson[i]);
}
}
// alert(JSON.stringify(jsonArray));
input.attr(‘value‘, JSON.stringify(jsonArray));
// 附加到Form
form.append(input);
form.appendTo("body");
form.css(‘display‘, ‘none‘);
// 提交表单
form.form(‘submit‘, {
url: url,
onSubmit: function(param) {
$.each(params,
function(name, value) {
param[name] = value;
});
}
});
form.remove();
}
/**
* @author
* 过滤table导出
* @param id table Id
*/
function exportExcelToFilter(id){
var filterRules = $(‘#‘+id).datagrid(‘options‘).filterRules;
var params = $(‘#‘+id).datagrid(‘options‘).queryParams;
var url = $(‘#‘+id).datagrid(‘options‘).url;
for (var i = 0; i < filterRules.length; i++) {
var obj = filterRules[i];
if (obj.field == ‘applicationDate‘) {
if (obj.op == ‘greater‘) {
params.rdGt = obj.value;
} else if (obj.op == ‘less‘) {
params.rdLt = obj.value;
} else if (obj.op == ‘equal‘) {
params.rdGt = obj.value;
params.rdLt = obj.value;
}
}else{
params[obj.field] = obj.value;
}
}
var sortName = $(‘#‘+id).datagrid(‘options‘).sortName;
var sortOrder = $(‘#‘+id).datagrid(‘options‘).sortOrder;
params["order"]=sortOrder;
params["sort"]=sortName;
params["operate"]="export";
var columnJsonf = $(‘#‘+id).datagrid("options").frozenColumns;
var columnJson = $(‘#‘+id).datagrid("options").columns;
var form = $(‘<form></form>‘);
// 设置属性
form.attr(‘action‘, url);
form.attr(‘method‘, ‘post‘);
// form的target属性决定form在哪个页面提交
// _self -> 当前页面 _blank -> 新页面
form.attr(‘target‘, ‘_self‘);
// 创建Input
var input = $(‘<input type="hidden" name="columnJson" />‘);
var inputRow = $(‘<input type="hidden" name="rows" value="10" />‘);
var inputPage = $(‘<input type="hidden" name="page" value="1" />‘);
form.append(inputRow);
form.append(inputPage);
var jsonArray=new Array();
var arrayOn=new Array();
for (var i=0;i<columnJsonf.length;i++)
{
for (var j=0;j<columnJsonf[i].length;j++)
{
var col=columnJsonf[i][j];
col.rowspan=columnJson.length;
arrayOn.push(col);
}
}
for (var i=0;i<columnJson.length;i++)
{
if(i==0){
for (var j=0;j<columnJson[i].length;j++)
{
var colj=columnJson[i][j];
arrayOn.push(colj);
}
jsonArray.push(arrayOn);
}else{
jsonArray.push(columnJson[i]);
}
}
// alert(JSON.stringify(jsonArray));
input.attr(‘value‘, JSON.stringify(jsonArray));
// 附加到Form
form.append(input);
form.appendTo("body");
form.css(‘display‘, ‘none‘);
// 提交表单
form.form(‘submit‘, {
url:url,
onSubmit: function(param){
$.each(params, function(name, value) {
param[name]=value;
});
}
});
form.remove();
}
function exportExcelToCollect(id,url,taId){
var taToJson=tableToJson(taId);
var columnJsonf = $("#"+id).datagrid("options").frozenColumns;
var columnJson = $("#"+id).datagrid("options").columns;
var form = $(‘<form></form>‘);
// 设置属性
form.attr(‘action‘, url);
form.attr(‘method‘, ‘post‘);
// form的target属性决定form在哪个页面提交
// _self -> 当前页面 _blank -> 新页面
form.attr(‘target‘, ‘_self‘);
// 创建Input
var input = $(‘<input type="hidden" name="columnJson" />‘);
var jsonArray=new Array();
var arrayOn=new Array();
for (var i=0;i<columnJsonf.length;i++)
{
for (var j=0;j<columnJsonf[i].length;j++)
{
var col=columnJsonf[i][j];
col.rowspan=columnJson.length;
arrayOn.push(col);
}
}
for (var i=0;i<columnJson.length;i++)
{
if(i==0){
for (var j=0;j<columnJson[i].length;j++)
{
var colj=columnJson[i][j];
arrayOn.push(colj);
}
jsonArray.push(arrayOn);
}else{
jsonArray.push(columnJson[i]);
}
}
// alert(JSON.stringify(jsonArray));
input.attr(‘value‘,"["+ taToJson+","+JSON.stringify(jsonArray)+"]");
// 附加到Form
form.append(input);
form.appendTo("body");
form.css(‘display‘, ‘none‘);
// 提交表单
form.submit();
form.remove();
}
//导出数据
/*
* id datagrid id
* url Action 路径
*/
function exportExcelTreeGrids(id) {
var params = $(‘#‘ + id).treegrid(‘options‘).queryParams;
var url = $(‘#‘ + id).treegrid(‘options‘).url;
var sortName = $(‘#‘ + id).treegrid(‘options‘).sortName;
var sortOrder = $(‘#‘ + id).treegrid(‘options‘).sortOrder;
params["order"] = sortOrder;
params["sort"] = sortName;
params["operate"] = "export";
var columnJsonf = $(‘#‘ + id).treegrid("options").frozenColumns;
var columnJson = $(‘#‘ + id).treegrid("options").columns;
var form = $(‘<form></form>‘);
// 设置属性
form.attr(‘action‘, url);
form.attr(‘method‘, ‘post‘);
form.attr(‘target‘, ‘_self‘);
// 创建Input
var input = $(‘<input type="hidden" name="columnJson" />‘);
var inputRow = $(‘<input type="hidden" name="rows" value="10" />‘);
var inputPage = $(‘<input type="hidden" name="page" value="1" />‘);
form.append(inputRow);
form.append(inputPage);
var jsonArray = new Array();
var arrayOn = new Array();
for (var i = 0; i < columnJsonf.length; i++) {
for (var j = 0; j < columnJsonf[i].length; j++) {
var col = columnJsonf[i][j];
col.rowspan = columnJson.length;
arrayOn.push(col);
}
}
for (var i = 0; i < columnJson.length; i++) {
if (i == 0) {
for (var j = 0; j < columnJson[i].length; j++) {
var colj = columnJson[i][j];
arrayOn.push(colj);
}
jsonArray.push(arrayOn);
} else {
jsonArray.push(columnJson[i]);
}
}
// alert(JSON.stringify(jsonArray));
input.attr(‘value‘, JSON.stringify(jsonArray));
// 附加到Form
form.append(input);
form.appendTo("body");
form.css(‘display‘, ‘none‘);
// 提交表单
form.form(‘submit‘, {
url: url,
onSubmit: function(param) {
$.each(params,
function(name, value) {
param[name] = value;
});
}
});
form.remove();
}
/**
* @author
* 过滤table导出
* @param id table Id
*/
function exportExcelTreeGridFilter(id) {
var filterRules = $(‘#‘ + id).treegrid(‘options‘).filterRules;
var params = $(‘#‘ + id).treegrid(‘options‘).queryParams;
var url = $(‘#‘ + id).treegrid(‘options‘).url;
for (var i = 0; i < filterRules.length; i++) {
var obj = filterRules[i];
if (obj.field == ‘applicationDate‘) {
if (obj.op == ‘greater‘) {
params.rdGt = obj.value;
} else if (obj.op == ‘less‘) {
params.rdLt = obj.value;
} else if (obj.op == ‘equal‘) {
params.rdGt = obj.value;
params.rdLt = obj.value;
}
} else {
params[obj.field] = obj.value;
}
}
var sortName = $(‘#‘ + id).treegrid(‘options‘).sortName;
var sortOrder = $(‘#‘ + id).treegrid(‘options‘).sortOrder;
params["order"] = sortOrder;
params["sort"] = sortName;
params["operate"] = "export";
var columnJsonf = $(‘#‘ + id).treegrid("options").frozenColumns;
var columnJson = $(‘#‘ + id).treegrid("options").columns;
var form = $(‘<form></form>‘);
// 设置属性
form.attr(‘action‘, url);
form.attr(‘method‘, ‘post‘);
// form的target属性决定form在哪个页面提交
// _self -> 当前页面 _blank -> 新页面
form.attr(‘target‘, ‘_self‘);
// 创建Input
var input = $(‘<input type="hidden" name="columnJson" />‘);
var inputRow = $(‘<input type="hidden" name="rows" value="10" />‘);
var inputPage = $(‘<input type="hidden" name="page" value="1" />‘);
form.append(inputRow);
form.append(inputPage);
var jsonArray = new Array();
var arrayOn = new Array();
for (var i = 0; i < columnJsonf.length; i++) {
for (var j = 0; j < columnJsonf[i].length; j++) {
var col = columnJsonf[i][j];
col.rowspan = columnJson.length;
arrayOn.push(col);
}
}
for (var i = 0; i < columnJson.length; i++) {
if (i == 0) {
for (var j = 0; j < columnJson[i].length; j++) {
var colj = columnJson[i][j];
arrayOn.push(colj);
}
jsonArray.push(arrayOn);
} else {
jsonArray.push(columnJson[i]);
}
}
// alert(JSON.stringify(jsonArray));
input.attr(‘value‘, JSON.stringify(jsonArray));
// 附加到Form
form.append(input);
form.appendTo("body");
form.css(‘display‘, ‘none‘);
// 提交表单
form.form(‘submit‘, {
url: url,
onSubmit: function(param) {
$.each(params,
function(name, value) {
param[name] = value;
});
}
});
form.remove();
}
//数字千分位高速转换
function edienum(value, row, index){
var num = value;
num = (num || 0).toString(), result = ‘‘;
while (num.length > 3) {
result = ‘,‘ + num.slice(-3) + result;
num = num.slice(0, num.length - 3);
}
if (num) { result = num + result; }
return result;
}
/**
* 获得相差天数
* @author
* @param strDateStart
* @param strDateEnd
* @returns
*/
function getDays(strDateStart,strDateEnd){
var strSeparator = "-"; //日期分隔符
var oDate1;
var oDate2;
var iDays;
oDate1= strDateStart.split(strSeparator);
oDate2= strDateEnd.split(strSeparator);
var strDateS = new Date(oDate1[0], oDate1[1]-1, oDate1[2]);
var strDateE = new Date(oDate2[0], oDate2[1]-1, oDate2[2]);
iDays = parseInt((strDateS - strDateE ) / 1000 / 60 / 60 /24);//把相差的毫秒数转换为天数
return iDays ;
}
/*
* 跳转tabls
*/
$(function(){
jq = top.jQuery;
tab = jq("#mainTabs").tabs(‘getSelected‘);
tabsIndex = jq("#mainTabs").tabs(‘getTabIndex‘,tab);
});
function tabsSelectAndClose(s,c){
jq("#mainTabs").tabs(‘select‘,parseInt(s));
jq("#mainTabs").tabs(‘close‘,parseInt(c));
}
function back(){
tabsSelectAndClose($("#tabsIndex").val(),tabsIndex);
}
function backUpdate(){
tabsSelectAndCloseToUpdate($("#tabsIndex").val(),tabsIndex);
}
function tabsSelectAndCloseToUpdate(s,c){
jq("#mainTabs").tabs(‘select‘,parseInt(s));
var tabb = jq("#mainTabs").tabs(‘getTab‘,parseInt(s));
jq("#mainTabs").tabs(‘update‘, {
tab: tabb,
options: {
content:$("iframe",tabb) // 新内容的URL
}
});
jq("#mainTabs").tabs(‘close‘,parseInt(c));
}
/*
* 跳转tabls
*/
function JumpPage(type,title,src){
var jq = top.jQuery;
var content = "<iframe id=‘mainFrame‘ frameborder=‘no‘ width=‘100%‘ height=‘100%‘ src=‘"+src+"‘></iframe>";
if(type==0){
if (jq("#mainTabs").tabs(‘exists‘, title)){
jq("#mainTabs").tabs(‘select‘, title);
} else {
jq("#mainTabs").tabs(‘add‘,{
title:title,
content:content,
bodyCls: ‘cos-overflow-hidden‘,
closable:true
});
}
}else{
jq("#mainTabs").tabs(‘close‘,title);
jq("#mainTabs").tabs(‘add‘,{
title:title,
content:content,
bodyCls: ‘cos-overflow-hidden‘,
closable:true
});
}
}
function linkStyle(value,row,index) {
if(value!="合计"){
return "<span class=‘a‘>" + value + "</span>";
}else{
return value;
}
}
function nonzeroWarning(value,row,index){
if (value > 0){
return "<span class=‘warning‘>" + value + "</span>";
} else {
return value;
}
}
function nonzeroWarningFixed(value,row,index){
if (value > 0){
return "<span class=‘warning‘>" + value.toFixed(2) + "</span>";
} else {
value=0;
return value.toFixed(2);
}
}
/**
* table封装json
* @param id
* @returns {String}
*/
function tableToJson(id){
var styleArray=["height","rowspan","width","align","colspan"];
var tab=document.getElementById(id);
var rows=tab.rows;
var txt = "[";
for(var i=0;i<rows.length;i++)
{
var r = "[";
for(var j=0;j<rows[i].cells.length;j++)
{
var c="{";
for (var k = 0; k < styleArray.length; k++) {
c+="\""+styleArray[k]+"\":\""+$(rows[i].cells[j]).attr(styleArray[k])+"\",";
}
c+="\"title\":"+"\"" + rows[i].cells[j].innerHTML+"\"";
c+="},";
r += c;
}
r = r.substring(0, r.length - 1);
r += "],";
txt += r;
}
txt = txt.substring(0, txt.length - 1);
txt += "]";
return txt;
}
function getFormatterDate(value){
var time = new Date();
if(value){
if((value+"").indexOf("-")>0){
value=/\d{4}-\d{1,2}-\d{1,2}/g.exec(value);
return value;
}
time = new Date(value);
}
var year=time.getFullYear();
var month = time.getMonth() + 1;
var day = time.getDate();
if(month<10){
month="0"+month;
}
if(day<10){
day="0"+day;
}
return year+"-"+month+"-"+day;
}
/**
* 格式化日期
* @param value
* @param row
* @param index
* @returns
*/
function valueFormatterDate(value,row,index){
var time = new Date();
if(value){
if((value+"").indexOf("-")>0){
value=/\d{4}-\d{1,2}-\d{1,2}/g.exec(value);
return value;
}
time = new Date(value);
}
var year=time.getFullYear();
var month = time.getMonth() + 1;
var day = time.getDate();
if(month<10){
month="0"+month;
}
if(day<10){
day="0"+day;
}
return year+"-"+month+"-"+day;
}
//将日期输入框变为年月的函数方法
function setYearMonth(id){
var month=0;
$(‘#‘+id).datebox({
onShowPanel: function () {//显示日趋选择对象后再触发弹出月份层的事件,初始化时没有生成月份层
span.trigger(‘click‘); //触发click事件弹出月份层
if (!tds) setTimeout(function () {//延时触发获取月份对象,因为上面的事件触发和对象生成有时间间隔
tds = p.find(‘div.calendar-menu-month-inner td‘);
tds.click(function (e) {
e.stopPropagation(); //禁止冒泡执行easyui给月份绑定的事件
var year = /\d{4}/.exec(span.html())[0]//得到年份
, month = parseInt($(this).attr(‘abbr‘), 10); //月份
$(‘#‘+id).datebox(‘hidePanel‘)//隐藏日期对象
.datebox(‘setValue‘, year + ‘-‘ + (month < 10 ? ‘0‘ : ‘‘) + month); //设置日期的值
});
}, 0);
},
parser: function (s) {//配置parser,返回选择的日期
if (!s) return new Date();
var arr = s.split(‘-‘);
month=parseInt(arr[1], 10);
//monthStr=month==13?month-1:month;
var newDate=new Date(parseInt(arr[0], 10)+"/"+(month < 10 ? ‘0‘ : ‘‘)+month+"/01");
return newDate;
},
formatter: function (d) {
var f=d.getFullYear() + ‘-‘ + (d.getMonth() < 10 ? ‘0‘ : ‘‘) + (d.getMonth() + 1);
return f;
}//配置formatter,只返回年月
});
var p = $(‘#‘+id).datebox(‘panel‘), //日期选择对象
tds = false, //日期选择对象中月份
span = p.find(‘span.calendar-text‘); //显示月份层的触发控件
}
var MaskUtil = (function(){
var $mask,$maskMsg;
var defMsg = ‘正在处理,请稍待。。。‘;
function init(){
if(!$mask){
$mask = $("<div class=\"datagrid-mask mymask\"></div>").appendTo("body");
}
if(!$maskMsg){
$maskMsg = $("<div class=\"datagrid-mask-msg mymask\">"+defMsg+"</div>")
.appendTo("body").css({‘font-size‘:‘12px‘});
}
$mask.css({width:"100%",height:$(document).height()});
var scrollTop = $(document.body).scrollTop();
$maskMsg.css({
left:( $(document.body).outerWidth(true) - 190 ) / 2
,top:( ($(window).height() - 45) / 2 ) + scrollTop
});
}
return {
mask:function(msg){
init();
$mask.show();
$maskMsg.html(msg||defMsg).show();
}
,unmask:function(){
$mask.hide();
$maskMsg.hide();
}
}
}());
function valueToFixed(value,row,index){
if(value==null||value==""){
value=0;
}
return toDecimal2(value);
}
/**
* 精确小数俩位
* @param value
* @param row
* @param index
* @returns
*/
function toDecimal2(x) {
var f = parseFloat(x);
if (isNaN(f)) {
return false;
}
var f = Math.round(x*100)/100;
var s = f.toString();
var rs = s.indexOf(‘.‘);
if (rs < 0) {
rs = s.length;
s += ‘.‘;
}
while (s.length <= rs + 2) {
s += ‘0‘;
}
return s;
}
/**
* 折叠标题
*/
(function($){
var buttonDir = {north:‘down‘,south:‘up‘,east:‘left‘,west:‘right‘};
$.extend($.fn.layout.paneldefaults,{
onBeforeCollapse:function(){
var popts = $(this).panel(‘options‘);
var dir = popts.region;
var btnDir = buttonDir[dir];
if(!btnDir) return false;
setTimeout(function(){
var pDiv = $(‘.layout-button-‘+btnDir).closest(‘.layout-expand‘).css({
textAlign:‘center‘,lineHeight:‘18px‘,fontWeight:‘bold‘
});
if(popts.title){
var vtitle = popts.title;
if(dir == "east" || dir == "west"){
var vTitle = popts.title.split(‘‘).join(‘<br/>‘);
pDiv.find(‘.panel-body‘).html(vTitle);
}else{
$(‘.layout-button-‘+btnDir).closest(‘.layout-expand‘).find(‘.panel-title‘)
.css({textAlign:‘left‘})
.html(vTitle)
}
}
},100);
}
});
})(jQuery);
标签:
原文地址:http://www.cnblogs.com/ckaifeng/p/5131024.html