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

2573 lines
100 KiB

//组织相关的变量
var ORG_VARIABLE = {
UUID_TO_CHILD_NAME:{
'top_corp_uuid':'corp_name',
'corp_uuid':'county_name',
'county_uuid':'dept_name',
'dept_uuid':'sale_line_name',
'sale_line_uuid':'sale_line_name'
},
CODE_TO_UUID:{
'01':'top_corp_uuid'
,'02':'corp_uuid'
,'03':'county_uuid'
,'07':'dept_uuid'
,'08':'sale_line_uuid'
},
UUID_TO_CODE:{
'top_corp_uuid':'01'
,'corp_uuid':'02'
,'county_uuid':'03'
,'dept_uuid':'07'
,'sale_line_uuid':'08'
},
CODE_TO_CHILD_CODE:{
'01':'02'
,'02':'03'
,'03':'07'
,'07':'08'
,'08':'08'
}
};
$.extend($.fn.datagrid.methods, {
autoMergeCells: function (jq, fields) {
return jq.each(function () {
var target = $(this);
if (!fields) {
fields = target.datagrid("getColumnFields",true);
}
var rows = target.datagrid("getRows");
var i = 0,
j = 0,
temp = {};
for (i; i < rows.length; i++) {
var row = rows[i];
j = 0;
for (j; j < fields.length; j++) {
var field = fields[j];
var tf = temp[field];
if (!tf) {
tf = temp[field] = {};
tf[row[field]] = [i];
} else {
var tfv = tf[row[field]];
if (tfv) {
tfv.push(i);
} else {
tfv = tf[row[field]] = [i];
}
}
}
}
$.each(temp, function (field, colunm) {
$.each(colunm, function () {
var group = this;
if (group.length > 1) {
var before,
after,
megerIndex = group[0];
for (var i = 0; i < group.length; i++) {
before = group[i];
after = group[i + 1];
if (after && (after - before) == 1) {
continue;
}
var rowspan = before - megerIndex + 1;
if (rowspan > 1) {
target.datagrid('mergeCells', {
index: megerIndex,
field: field,
rowspan: rowspan
});
}
if (after && (after - before) != 1) {
megerIndex = after;
}
}
}
});
});
});
}
});
//yubstart report module
function loading(){
$("<div class=\"datagrid-mask\" style=\"display:block\"></div>").appendTo('body');
var msg = $("<div class=\"datagrid-mask-msg\" style=\"display:block;left:50%\"></div>").html('正在装载,请稍候。。。').appendTo('body');
msg.css("marginLeft", -msg.outerWidth() / 2);
}
function loaded(){
$('body').children("div.datagrid-mask-msg").remove();
$('body').children("div.datagrid-mask").remove();
}
function getReportData(_containerid){
return $('#'+_containerid).data('report_data');
}
function orderReport(_containerid,_orderbyfield){
loading();
var jparam = $("#"+_containerid).data("report_data");
var _id = $("#"+_containerid).data("report_data").id;
var jForm = $('#form_'+_id);
var bigData = $.json2str($("#"+_containerid).data("report_data").queryParams);
bigData = Base64.encode(bigData);
jForm.find("input[name='data']").val(bigData);//赋值给iframe中表单的文本框中
jForm.find("input[name='orderbyfield']").val(Base64.encode(_orderbyfield));
//var jAttach = $('#attach_reort_export');
//jAttach.find("input[name='orderbyfield']").val(Base64.encode(_orderbyfield));
jForm.submit();//提交数据
}
$.extend({
/**
* [getFilterOrgField 根据历史查询还是根据当前查询]
* @param {[type]} src_org_uuid [原始组织UUID]
* @return {[type]} []
*/
getFilterOrgField:function(src_org_uuid){
var orgMapping = {
"dept_uuid":"cust_dept_uuid",
"sale_line_uuid":"cust_sale_line_uuid"
};
if(orgMapping.hasOwnProperty && orgMapping.hasOwnProperty(src_org_uuid)){
return orgMapping[src_org_uuid];
}
if((src_org_uuid in orgMapping)){
return orgMapping[src_org_uuid];
}
return src_org_uuid;
},
show_corp_level:function(jparam){
var org_field = jparam._org_field?jparam._org_field:'';
var corp_level = jparam._corp_level?jparam._corp_level:'';
var object_dim = {};
var dimList = [];
var dimorder = "";
var dimcode = "";
if(org_field.length>0&&corp_level.length>0){
if (org_field == 'corp_uuid'){
if (corp_level == 'corp_name'){
dimList = [{
fieldname: '单位',
fieldcode: 'corp_name',
fieldtype: 'dim',
sum: true,
width:210,
align:'left'
}];
dimcode = 'corp_name';
dimorder = 'corp_order';
} else if (corp_level == 'county_name'){
dimList = [{
fieldname: '区县公司',
fieldcode: 'county_name',
fieldtype: 'dim',
sum: true,
width:210,
align:'left'
}];
dimcode = 'county_name';
dimorder = 'county_order';
} else if (corp_level == 'dept_name'){
dimList = [{
fieldname: '区县公司',
fieldcode: 'county_name',
fieldtype: 'dim',
sum: true,
width:210,
align:'left'
}, {
fieldname: '市场部',
fieldcode: 'dept_name',
fieldtype: 'dim',
sum: true,
width:230,
align:'left'
}];
dimcode = 'county_name,dept_name';
dimorder = 'county_order,dept_order';
} else if (corp_level == 'sale_line_name'){
dimList = [{
fieldname: '区县公司',
fieldcode: 'county_name',
fieldtype: 'dim',
sum: true,
width:210,
align:'left'
}, {
fieldname: '市场部',
fieldcode: 'dept_name',
fieldtype: 'dim',
sum: true,
width:230,
align:'left'
}, {
fieldname: '营销线',
fieldcode: 'sale_line_name',
fieldtype: 'dim',
sum: true,
width:230,
align:'left'
}];
dimcode = 'county_name,dept_name,sale_line_name';
dimorder = 'county_order,dept_order,sale_line_order';
}
} else if (org_field == "county_uuid") {
if (corp_level == 'corp_name') {
dimList = [{
fieldname: '单位',
fieldcode: 'corp_name',
fieldtype: 'dim',
sum: true,
width: 210,
align: 'left'
}];
dimcode = 'corp_name';
dimorder = 'corp_order';
} else if (corp_level == 'county_name') {
dimList = [{
fieldname: '区县公司',
fieldcode: 'county_name',
fieldtype: 'dim',
sum: true,
width: 210,
align: 'left'
}];
dimcode = 'county_name';
dimorder = 'county_order';
} else if (corp_level == 'dept_name') {
dimList = [{
fieldname: '市场部',
fieldcode: 'dept_name',
fieldtype: 'dim',
sum: true,
width: 130,
align: 'left'
}];
dimcode = 'dept_name';
dimorder = 'dept_order';
} else if (corp_level == 'sale_line_name') {
dimList = [{
fieldname: '市场部',
fieldcode: 'dept_name',
fieldtype: 'dim',
sum: true,
width: 130,
align: 'left'
}, {
fieldname: '营销线',
fieldcode: 'sale_line_name',
fieldtype: 'dim',
sum: true,
width: 230,
align: 'left'
}];
dimcode = 'county_name,dept_name,sale_line_name';
dimorder = 'county_order,dept_order,sale_line_order';
}
} else if (org_field == "dept_uuid") {
if (corp_level == 'corp_name') {
dimList = [{
fieldname: '单位',
fieldcode: 'corp_name',
fieldtype: 'dim',
sum: true,
width: 210,
align: 'left'
}];
dimcode = 'corp_name';
dimorder = 'corp_order';
} else if (corp_level == 'county_name') {
dimList = [{
fieldname: '区县公司',
fieldcode: 'county_name',
fieldtype: 'dim',
sum: true,
width: 210,
align: 'left'
}];
dimcode = 'county_name';
dimorder = 'county_order';
} else if (corp_level == 'dept_name') {
dimList = [{
fieldname: '市场部',
fieldcode: 'dept_name',
fieldtype: 'dim',
sum: true,
width: 130,
align: 'left'
}];
dimcode = 'dept_name';
dimorder = 'dept_order';
} else if (corp_level == 'sale_line_name') {
dimList = [{
fieldname: '营销线',
fieldcode: 'sale_line_name',
fieldtype: 'dim',
sum: true,
width: 230,
align: 'left'
}];
dimcode = 'sale_line_name';
dimorder = 'sale_line_order';
}
} else if (org_field == "sale_line_uuid"){
if (corp_level == 'corp_name') {
dimList = [{
fieldname: '单位',
fieldcode: 'corp_name',
fieldtype: 'dim',
sum: true,
width: 210,
align: 'left'
}];
dimcode = 'corp_name';
dimorder = 'corp_order';
} else if (corp_level == 'county_name') {
dimList = [{
fieldname: '区县公司',
fieldcode: 'county_name',
fieldtype: 'dim',
sum: true,
width: 210,
align: 'left'
}];
dimcode = 'county_name';
dimorder = 'county_order';
} else if (corp_level == 'dept_name') {
dimList = [{
fieldname: '市场部',
fieldcode: 'dept_name',
fieldtype: 'dim',
sum: true,
width: 130,
align: 'left'
}];
dimcode = 'dept_name';
dimorder = 'dept_order';
} else if (corp_level == 'sale_line_name') {
dimList = [{
fieldname: '营销线',
fieldcode: 'sale_line_name',
fieldtype: 'dim',
sum: true,
width: 230,
align: 'left'
}];
dimcode = 'sale_line_name';
dimorder = 'sale_line_order';
}
}
}
object_dim["dimList"] = dimList;
object_dim["dimcode"] = dimcode;
object_dim["dimorder"] = dimorder;
return object_dim;
},
openDebug:function(_containerid){
if(_containerid == undefined){
_containerid = 'report_gird';
}
var bigData = $.json2str($("#"+_containerid).data("report_data").queryParams);
bigData = Base64.encode(bigData);
$.postOpen('wdk?action=pf.report&method=forwardDebug2',{data:bigData});
},
postOpen:function(URL, PARAMS) {
var temp_form = document.createElement("form");
temp_form.id = "debug_form";
temp_form.action = URL;
temp_form.target = "_blank";
temp_form.method = "post";
temp_form.style.display = "none";
for (var x in PARAMS) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
temp_form.appendChild(opt);
}
document.body.appendChild(temp_form);
temp_form.submit();
},
/**
* [generateContextmenu 创建右键菜单]
* @param {[type]} jparams [菜单]
* @return {[type]} []
*/
generateContextmenu:function(jparams){
var contextmenu = [];
if(typeof _buttons != 'undefined'){
if(_buttons && jparams && jQuery.isArray(_buttons) && jQuery.isArray(jparams)){
for(var i=0;i<jparams.length;i++){
var menu = jparams[i];
var afterMenu = {};
var isAuthed = false;
for(var j=0;j<_buttons.length;i++){
if(_buttons[j].id == menu.id){
isAuthed = true;
afterMenu.name = _buttons[j].name;
afterMenu.id = menu.id;
afterMenu.callback = menu.callback;
afterMenu.icon = menu.icon;
break;
}
}
if(isAuthed){
contextmenu.push(afterMenu);
}
}
}
}
window.RPT_CONTEXT_MENU = contextmenu;
},
/**
* [metricDesc 指标说明显示组件]
* @return {[type]} [description]
*/
metricDesc:function(jparam){
var _id = jparam.id?jparam.id:$.getUUID();
var _data = jparam.data?jparam.data:[];
var divobj = $('.metric_desc');
if(divobj && divobj.length>0){
}else{
divobj = $('<div class="metric_desc"></div>').appendTo('body');
}
var scriptobj = $('#script_frame');
if(scriptobj && scriptobj.length>0){
}else{
scriptobj = $('<link id="script_frame" rel="stylesheet" type="text/css" href="'+$('base').attr('href')+'/platform/report/css/frame.css">').appendTo('head');
}
$('#'+_id).mouseover(function(){
var tablestr = [];
tablestr.push('<table width="420px">');
tablestr.push('<tr class="trbottom" height="19"><th nowrap>指标名称</th><th nowrap>指标说明</th></tr>');
for(var i=0;i<_data.length;i++){
tablestr.push('<tr height="19" bgcolor="#E8E8E8"><td>'+_data[i].title+'</td><td>'+_data[i].desc+'</td></tr>');
}
tablestr.push('</table>');
$('.metric_desc').html(tablestr.join(''));
var topv = $(this).offset().top+$(this).height()+10;
var rightv = $(this).offset().right;
divobj.css('display','block');
divobj.css('top',topv);
divobj.css('right',rightv);
}).mouseleave(function(){
divobj.css('display','none');
});
},
/**
* [salerSelect 销售员选择]
* @param {[type]} jparam [输入参数]
* @return {[type]} []
*/
salerSelect:function(jparam){
var _id = jparam.id?jparam.id:$.getUUID();
var _initvalue = jparam.initvalue?jparam.initvalue:'';//'0101,0201'
var _inittext = jparam.inittext?jparam.inittext:'';//'0101,0201'
var _callBack = jparam.callback?jparam.callback:function(){};
var _ismulti = jparam.ismulselect==undefined?'':jparam.ismulselect;
var _onBeforeOpen = jparam.onBeforeOpen?jparam.onBeforeOpen:function(param){return param};
//人员所属组织标识串
$.inputpop({
id:_id,
height:450,
width:750,
required:false,
editable:false,
url:'products/imp/pub/mds/persontree.jsp',
initvalue:_initvalue, //code
inittext:_inittext, //name
initid:'', //uuid
transfer:'1',
queryParams:{
manage_unit_uuid: $.getSessionUser().manageunituuid, //管理单元标识
person_uuid:$.getSessionUser().personuuid, //操作人员标识
persontype:'02', //人员类型
orgattr:'03', //组织属性
orguuids:'', //人员所属组织标识串
isctrlperm:'', //是否控制权限
ismulselect:_ismulti, //是否多选
asyn:'1' //是否异步加载
},
onBeforeOpen:_onBeforeOpen,
missingMessage:'',
tipPosition:'bottom',
callback:_callBack
});
},
org_fieldMap:{
'01':'top_corp_uuid'
,'02':'corp_uuid'
,'03':'county_uuid'
,'07':'dept_uuid'
,'08':'sale_line_uuid'
},
/**
* [orgSelect 组织选择]
* @return {[type]} [description]
*/
orgSelect:function(jparam){
var _id = jparam.id?jparam.id:$.getUUID();
var _initvalue = jparam.initvalue?jparam.initvalue:'';
var _inittext = jparam.inittext?jparam.inittext:'';
var _initid = jparam.initid?jparam.initid:'';
var _callBack = jparam.callback?jparam.callback:function(){};
var _ismulti = jparam.ismulselect==undefined?'1':jparam.ismulselect;//默认多选
var _onBeforeOpen = jparam.onBeforeOpen?jparam.onBeforeOpen:function(param){return param};
var _onLoadSuccess = jparam.onLoadSuccess?jparam.onLoadSuccess:function(data){};
var _orgLevel = jparam.orgLevel?jparam.orgLevel:'';//过滤组织级别,支持个
if(_initvalue){
_onLoadSuccess.call(jparam,undefined);
renderOrgTree();
}else{
$.cuajax({
url: 'wdk?action=wdk.pub&method=call_service&ajaxparam=' + new Date().getTime(),
method: "post",
timeout: WDK_Timeout,
data: {
_SRVNAME: 'service.md.org',
_SRVMETHOD: 'queryTopOrg',
_DATA: $.json2str({
op_account_uuid: $.getSessionUser().account_id,
manage_unit_uuid: $.getSessionUser().manageunituuid,
isctrlperm: '1', //控制权限
org_attr: '03' //组织属性-销售组织,根据实际情况修改
}),
_DATAFILTER: 1 //启用数据权限
},
success: function(result) {
$.wait_close();
var jres = $.str2json(result);
var root_org;
if (jres.code == '1') {
if (jres.resultset && jres.resultset.length > 0) { //操作成功
root_org = jres.resultset[0]; //取返回结果的第一条数据
root_org.org_field = $.org_fieldMap[root_org.org_level_scode];
_onLoadSuccess.call(jparam,root_org);
}
}
//设置区域初始值
if (root_org) {
_initvalue = root_org.org_code;
_inittext = root_org.org_name;
_initid = root_org.org_uuid;
renderOrgTree(root_org);
}
},
error: function(result) {
$.wait_close();
alert('网络错误!result=' + result);
}
});
}
function renderOrgTree(root_org){
var orglevel = '';
if(root_org){
orglevel = root_org.org_level_scode;
}
$.inputpop({
id:_id,
height:450,
width:750,
required:false,
editable:false,
url:'platform/report/ctrl/departtree.jsp',
initvalue:_initvalue, //code
inittext:_inittext, //name
initid:_initid, //uuid
transfer:'1',
queryParams:{
manage_unit_uuid: $.getSessionUser().manageunituuid, //管理单元标识
person_uuid:$.getSessionUser().personuuid, //操作人员标识
org_uuid:'', //上级组织标识
orglevel:orglevel, //组织级别
orgattr:'03', //组织属性:必须指定为营销组织
isctrlperm:'', //是否控制权限
ismulselect:_ismulti, //是否多选
filterorglevel:_orgLevel, //过滤的组织级别
asyn:'0', //是否异步加载
cascadecheck:'1', //是否级联勾选
returnorglevel:'' //返回的组织级别
},
onBeforeOpen:_onBeforeOpen,
missingMessage:'',
tipPosition:'bottom',
idField:'org_uuid',
textField:'org_name',
valueField:'org_code',
callback:_callBack
});
//数据暂存
if(root_org){
$("#"+_id).data("orgSelect", root_org);
}
}
},
/**
* [orgSelect_getValue 获取组织选择控件默认值]
* @param {[type]} _id [description]
* @return {[type]} [description]
*/
orgSelect_getDefaultValue:function(_id,callbackFun){
var data=undefined;
if(_id){
data = $("#"+_id).data("orgSelect");
}
if(data){
var jo = {};
jo.org_uuid = data.org_uuid;
jo.org_name = data.org_name;
jo.org_field = $.org_fieldMap[data.org_level_scode];
return jo;
}else{
if(callbackFun){
$.cuajax({
url: 'wdk?action=wdk.pub&method=call_service&ajaxparam=' + new Date().getTime(),
method: "post",
timeout: WDK_Timeout,
data: {
_SRVNAME: 'service.md.org',
_SRVMETHOD: 'queryTopOrg',
_DATA: $.json2str({
op_account_uuid: $.getSessionUser().account_id,
manage_unit_uuid: $.getSessionUser().manageunituuid,
isctrlperm: '1', //控制权限
org_attr: '03' //组织属性-销售组织,根据实际情况修改
}),
_DATAFILTER: 1 //启用数据权限
},
success: function(result) {
var jres = $.str2json(result);
var root_org;
if (jres.code == '1') {
if (jres.resultset && jres.resultset.length > 0) { //操作成功
root_org = jres.resultset[0]; //取返回结果的第一条数据
root_org.org_field = $.org_fieldMap[root_org.org_level_scode];
callbackFun(root_org);
}
}
},
error: function(result) {
$.wait_close();
alert('网络错误!result=' + result);
}
});
}else{
return undefined;
}
}
},
/**
* [productSelect 卷烟选择]
* @param {[type]} jparam [输入参数]
* @return {[type]} []
*/
productSelect:function(jparam){
var _id = jparam.id?jparam.id:$.getUUID();
var _initvalue = jparam.initvalue?jparam.initvalue:'';//'0101,0201'
var _inittext = jparam.inittext?jparam.inittext:'';//'0101,0201'
var _callBack = jparam.callback?jparam.callback:function(){};
var _ismulti = jparam.ismulselect==undefined?'':jparam.ismulselect;
var _onBeforeOpen = jparam.onBeforeOpen?jparam.onBeforeOpen:function(param){return param};
var _top = $.getRoot();
var _attr_expr = {
his_active:'1'
,other:{
factory:{
is_active:'-1'
}
,brand:{
is_active:'-1'
}
}
};//默认需要
if($.isPlainObject(jparam.attr_expr) && !$.isEmptyObject(jparam.attr_expr)){
_attr_expr = jparam.attr_expr;
}
var popupParam = {
id:_id,
required:false,
editable:false,
initvalue:_initvalue, //code
inittext:_inittext, //name
initid:_initvalue, //uuid
transfer:'1',
onBeforeOpen:_onBeforeOpen,
missingMessage:'',
tipPosition:'bottom',
//idField:'org_uuid',
//textField:'org_name',
//valueField:'org_code',
callback:_callBack
};
if(_ismulti && _ismulti == '1'){
//多选,需要
popupParam.height = 550;
popupParam.width = 900;
popupParam.url = 'products/imp/pub/mds/cigarselect.jsp';
popupParam.queryParams = {
manage_unit_uuid:$.getSessionUser().manageunituuid, //管理单元标识
person_uuid:$.getSessionUser().personuuid, //操作人员标识
account_id:$.getSessionUser().account_id,
querymode:'1'
//area_uuid:'', //顶级区域标识
//showlevel:'', //显示级别
//isctrlperm:'1', //是否控制权限
//ismulselect:'1', //是否多选
};
$.inputpop(popupParam);
}else{
//单选的话,就初始化卷烟数据吧
popupParam.height = 450;
popupParam.width = 750;
popupParam.url = 'platform/report/ctrl/producttree.jsp';
popupParam.queryParams = {
manage_unit_uuid: $.getSessionUser().manageunituuid, //管理单元标识
person_uuid:$.getSessionUser().personuuid, //操作人员标识
factory_uuid:'', //厂家标识
brand_uuid:'', //品牌标识
ismulselect:_ismulti, //是否多选
attr_expr:_attr_expr
};
$.inputpop(popupParam);
initProductData();
}
function initProductData(){
if(_top.PRODUCT_CTRL_DATA_HIS && _top.PRODUCT_CTRL_DATA_HIS.length > 0){
}else{
$.cuajax({
url:'wdk?action=wdk.pub&method=call_service&ajaxparam='+new Date().getTime(),
data:{
_SRVNAME:'service.md.product',
_SRVMETHOD:'queryProductTreeAttr',
_DATA:$.json2str({
op_acc:$.getSessionUser().account_id,
manage_unit_uuid:$.getSessionUser().manageunituuid,
factory_uuid:'',
brand_uuid:'',
attr_expr:_attr_expr
}),
_RSTYPE:'tree',
_RSPARAM:$.json2str({
idFields:'node_type,id',
parentFields:'parent_type,pid',
asyn:'0',
idField:'id',
textField:'name',
parentField:'pid',
iconField:'',
attrs:'node_type,code',
asyn_urlField:'pid',
asyn_dataField:'' //如果是异步,则从url中取出的参数替换_DATA参数的名
}),
_RSFIELD:'resultset'
},
success:function(data){
_top.PRODUCT_CTRL_DATA_HIS = $.str2json(data);
}
});
}
}
},
/**
* [brandSelect 品牌选择]
* @param {[type]} jparam [输入参数]
* @return {[type]} []
*/
brandSelect:function(jparam){
var _id = jparam.id?jparam.id:$.getUUID();
var _initvalue = jparam.initvalue?jparam.initvalue:'';//'0101,0201'
var _inittext = jparam.inittext?jparam.inittext:'';//'0101,0201'
var _callBack = jparam.callback?jparam.callback:function(){};
var _ismulti = jparam.ismulselect==undefined?'':jparam.ismulselect;
var _onBeforeOpen = jparam.onBeforeOpen?jparam.onBeforeOpen:function(param){return param};
$.inputpop({
id:_id,
height:450,
width:750,
required:false,
editable:false,
url:'products/imp/pub/mds/brandtree.jsp',
initvalue:_initvalue, //code
inittext:_inittext, //name
initid:_initvalue, //uuid
transfer:'1',
queryParams:{
manage_unit_uuid:$.getSessionUser().manageunituuid, //管理单元标识
person_uuid:$.getSessionUser().personuuid, //操作人员标识
factory_uuid:'', //厂家标识
ismulselect:_ismulti //是否多选
},
onBeforeOpen:_onBeforeOpen,
missingMessage:'',
tipPosition:'bottom',
//idField:'org_uuid',
//textField:'org_name',
//valueField:'org_code',
callback:_callBack
});
},
/**
* [factorySelect 厂家选择]
* @param {[type]} jparam [输入参数]
* @return {[type]} []
*/
factorySelect:function(jparam){
var _id = jparam.id?jparam.id:$.getUUID();
var _initvalue = jparam.initvalue?jparam.initvalue:'';//'0101,0201'
var _inittext = jparam.inittext?jparam.inittext:'';//'0101,0201'
var _callBack = jparam.callback?jparam.callback:function(){};
var _ismulti = jparam.ismulselect==undefined?'':jparam.ismulselect;
var _onBeforeOpen = jparam.onBeforeOpen?jparam.onBeforeOpen:function(param){return param};
$.inputpop({
id:_id,
height:450,
width:750,
required:false,
editable:false,
url:'products/imp/pub/mds/factorytree.jsp',
initvalue:_initvalue, //code
inittext:_inittext, //name
initid:_initvalue, //uuid
transfer:'1',
queryParams:{
manage_unit_uuid:$.getSessionUser().manageunituuid, //管理单元标识
person_uuid:$.getSessionUser().personuuid, //操作人员标识
ismulselect:_ismulti //是否多选
},
onBeforeOpen:_onBeforeOpen,
missingMessage:'',
tipPosition:'bottom',
//idField:'org_uuid',
//textField:'org_name',
//valueField:'org_code',
callback:_callBack
});
},
/**
* [bizStorSelect 仓库选择]
* @return {[type]} [description]
*/
bizStorSelect:function(jparam){
var _id = jparam.id?jparam.id:$.getUUID();
var _initvalue = jparam.initvalue?jparam.initvalue:'';//'0101,0201'
var _inittext = jparam.inittext?jparam.inittext:'';//'0101,0201'
var _callBack = jparam.callback?jparam.callback:function(){};
var _ismulti = jparam.ismulselect==undefined?'':jparam.ismulselect;
var _onBeforeOpen = jparam.onBeforeOpen?jparam.onBeforeOpen:function(param){return param};
$.inputpop({
id:_id,
height:450,
width:750,
required:false,
editable:false,
url:'products/imp/pub/mds/bizstorselect.jsp',
initvalue:_initvalue,//'001000017,001000018', //code
inittext:_inittext,//'001000017,001000018', //name
initid:_initvalue,//'001000017,001000018', //uuid
transfer:'1',
queryParams:{
manage_unit_uuid:$.getSessionUser().manageunituuid, //管理单元标识
person_uuid:$.getSessionUser().personuuid, //操作人员标识
onlydvlstor:'', //只显示配送库
onlypurchstor:'', //只显示采购库
real_stor_uuid:'', //实物库标识
isctrlperm:'', //是否控制权限
ismulselect:_ismulti //是否多选
},
onBeforeOpen:_onBeforeOpen,
missingMessage:'',
tipPosition:'bottom',
callback:_callBack
});
},
saleTypeGroupMapping:{
"01":"普通批发",
"02":"特殊销售",
"03":"商商调拨"
},
/**
* [saleTypeSelect 销售类型选择]
* @param {[type]} jparam [输入参数]
* @return {[type]} []
*/
saleTypeSelect:function(jparam){
var _id = jparam.id?jparam.id:$.getUUID();
var _condition = jparam.condition?jparam.condition:" parent_scode IN ('01','02')";
var _initvalue = jparam.initvalue?jparam.initvalue:'';//'0101,0201'
var _callBack = jparam.callback?jparam.callback:function(){};
var panel;
$.combobox({ //订单类型sale_type
id : _id,
url : 'wdk?action=wdk.pub&method=call_service&ajaxparam='+ new Date().getTime(),
queryParams : {
_SRVNAME : 'service.wdk.pub',
_SRVMETHOD : 'wql_query',
_DATA : $.json2str({
modulecode : 'S_TC_ORDER_SALETYPE',
jparam : {
condition : _condition
}
}),
_RSFIELD : 'result'
},
initvalue:_initvalue, // 0101 -
required : false,
editable : false,
multiple : true,
disabled:false,
height : 25,
idField : 'sysdic_code',
textField : 'sysdic_name',
groupField:'parent_scode',
groupFormatter: function(group){
panel = $(this).combo('panel');
return '<div style="font-size:14px;">'+$.saleTypeGroupMapping[group] + '</div>';
},
onLoadSuccess:function(data){
if(panel){
panel.find(".combobox-item").css("padding-left","20px");
}
},
onSelect:_callBack
});
},
ready_count:0,
/**
* [onReadyListener 监听查询条件加载完毕]
* @return {[type]} []
*/
onReadyListener:function(dimFunc,metricFunc,callback){
var dimension = dimFunc();
var metric = metricFunc();//$('input[name="metric"]');
if(metric && metric.length>0 && dimension && dimension.length>0){
this.ready_count = 0;
callback();
}else{
this.ready_count ++ ;
if(this.ready_count<20){
setTimeout(function(){$.onReadyListener(dimFunc,metricFunc,callback)},100);
}else{
console.log('超时!');
}
}
},
combo_dimension:function(jparam){
$.combobox({
id:jparam.id
//,url:'wdk?action=pf.report&method=grid_dimension&ajaxparam='+new Date().getTime()
//,queryParams:{}
,data:jparam.data
,idField:'id'
,textField:'text'
,height:25
,isinitselect:true
,initvalue:jparam.initvalue
});
},
dimension_getValue:function(id){
//构建维护dimension
var list = [];
var data = $('#'+id).combobox('getData');
if(data && data.length>0){
var key = $.combobox_getValue({id:id});
//list.push({fieldname:'单位',fieldcode:'county_name'});
for(var i=0;i<data.length;i++){
if(data[i].id == key){
var extra = data[i].extra;
extra.fieldtype = 'dim';//强制设置为维度列
list = list.concat(extra);
break;
}
}
}
return list;
},
/**
* [checkbox_metric 指标选择器]
* @param {[type]} jparam [组件输入参数]
* @return {[type]} []
*/
checkbox_metric:function(jparam){
var _id = jparam.id?jparam.id:'';
var _formid = jparam.formid;
var _initvalue = jparam.initvalue?jparam.initvalue:'';
var _multi = jparam.multi==undefined?true:jparam.multi;
var _data = jparam.data?jparam.data:[];
var _jparam = $.extend({}, jparam,{});
if(_multi === true){
$.metricCheckbox(_jparam);
}else{
$.metricRadio(_jparam);
}
//最复杂的指标
/*{
id: 'ZBQJB',
text: '占本区间比',
extra:{
width:100
,align:'right'
,refmetric:{
code:'PL_XL',
alias:'PL_XL_TOTAL',
dim:'corp_name',
expression:'func.per(PL_XL{0},PL_XL_TOTAL{0})'
}
}*/
},
/**
* [metric_getValue 获取指标值]
* @param {[type]} id [指标组件id]
* @return {[type]} [返回指标数组]
*/
metric_getValue:function(id){
var metrics = [];
$('input[name="'+id+'"]').each(function(){
if($(this).is(":checked")){
var _extra = $(this).attr('extra')?$(this).attr('extra'):'{}';
var jo = $.extend({}, $.str2json(_extra));
jo.fieldcode = $(this).val();
jo.fieldname = $(this).parent().next().text();
jo.fieldtype = 'metric';
metrics.push(jo);
}
});
return metrics;
},
metricRadio:function(param){
//属性
var _id = param.id?param.id:'';
var _formid=param.formid;
if(!_formid){
_formid="body";
}else{
_formid="#"+_formid;
}
var obj=$(_formid).find('#'+_id);
var _initvalue = param.initvalue?param.initvalue:'';
var _url = param.url?param.url:'';
var _queryParams = param.queryParams?param.queryParams:{};
var _disabled = param.disabled?param.disabled:obj.is(":disabled");;
var _defaultFirst = param.defaultFirst?param.defaultFirst:false;
var _spacing = param.spacing?param.spacing:10;
var _data = param.data?param.data:[];
//事件
var _onChange = param.onChange?$.event_getHandler(param.onChange):function(){};
var _onLoadSuccess = param.onLoadSuccess?$.event_getHandler(param.onLoadSuccess):function(){};
if($(_formid).find("#radio_"+_id).length>0){
$(_formid).find("#radio_"+_id).remove();
}
var _container = $('<div id="radio_'+_id+'" class="radiobox"></div>');
if(_url.length >0){
$.cuajax({
url:_url,
//async:false,
data:_queryParams,
success:function(data){
_data=$.str2json(data);
reader(_data);
}
});
}else{
reader(_data);
}
function reader(_data){
for(var i = 0 ;i<_data.length;i++){
var da = _data[i];
var _extra = da.extra?da.extra:{};
var _extra2 = $.json2str(_extra).replace(new RegExp('"','gm'),'\'');
var inp = $('<input type="radio" id="'+_id+'_'+i+'" name="'+_id+'" extra="'+_extra2+'" value="'+da.id+'"><label for="'+_id+'_'+i+'" style="margin-right:'+ _spacing +'px">'+da.text+'</label>');
if(_disabled){
inp.attr('disabled',true);
}
inp.data('data',da);
if(_defaultFirst && i== 0){
inp.attr('checked','checked');
}
_container.append(inp);
}
_container.find('input[id*='+_id+'][value="'+_initvalue+'"]').attr('checked','checked');
_container.on('loadSuccess',function(){
_onLoadSuccess.call(this);
});
obj.after(_container);
obj.remove();
_container.find("input").on('ifChanged', function(event){
if($(this).is(":checked")){
_onChange.call(this,$(this).data("data"));
}
});
_container.find("input").iCheck({
labelHover : false,
cursor : true,
checkboxClass : 'icheckbox_minimal-blue icheckbox',
radioClass : 'iradio_minimal-blue icheckbox',
increaseArea : '20%'
});
_container.trigger("loadSuccess");
}
},
metricCheckbox:function(param){
//属性
var _id = param.id?param.id:'';
var _formid=param.formid;
if(!_formid){
_formid="body";
}else{
_formid="#"+_formid;
}
var _initvalue = param.initvalue?param.initvalue:'';
var _url = param.url?param.url:'';
var _queryParams = param.queryParams?param.queryParams:{};
var _disabled = param.disabled?param.disabled:false;
var _data = param.data?param.data:[];
var _spacing = param.spacing?param.spacing:10;
//事件
var _onSelect = param.onSelect?$.event_getHandler(param.onSelect):function(){};
var _onUnSelect = param.onUnSelect?$.event_getHandler(param.onUnSelect):function(){};
if($(_formid).find("#checkbox_"+_id).length>0){
$(_formid).find("#checkbox_"+_id).remove();
}
var _container = $('<div id="checkbox_'+_id+'" class="checkbox"></div>');
if(_url.length >0){
$.cuajax({
url:_url,
data:_queryParams,
success:function(data){
_data=$.str2json(data);
reader(_data);
}
});
}else{
reader(_data);
}
function reader(_data){
for(var i = 0 ;i<_data.length;i++){
var da = _data[i];
if(i==_data.length-1){
_spacing=0;
}
var _extra = da.extra?da.extra:{};
var _extra2 = $.json2str(_extra).replace(new RegExp('"','gm'),'\'');
var inp = $('<input type="checkbox" id="'+_id+'_'+i+'" name="'+_id+'" extra="'+_extra2+'" value="'+da.id+'"><label for="'+_id+'_'+i+'" style="margin-right:'+ _spacing +'px">'+da.text+'</label>');
if(_disabled){
inp.attr('disabled',true);
}
inp.data('data',da);
_container.append(inp);
}
if(_initvalue.length >0){
var values = _initvalue.split(",");
for(var i = 0;i<values.length;i++){
_container.find('[name="'+_id+'"][value="'+values[i]+'"]').attr('checked','checked');
}
}
$('#'+_id).after(_container);
$('#'+_id).remove();
_container.find("input").on('ifChanged', function(event){
if($(this).is(":checked")){
_onSelect.call(this,$(this).data("data"));
}else{
_onUnSelect.call(this,$(this).data("data"));
}
$(this).trigger("change");
});
_container.find("input").iCheck({
labelHover : false,
cursor : true,
checkboxClass : 'icheckbox_minimal-blue icheckbox',
radioClass : 'iradio_minimal-blue icheckbox',
increaseArea : '20%'
});
}
},
/**
* [combo_metric_unit 指标计量单位]
* @param {[type]} jparam [组件输入参数]
* @return {[type]} []
*/
combo_metric_unit:function(jparam){
var _id = jparam.id?jparam.id:'';
var _onLoadSuccess = jparam.onLoadSuccess?$.event_getHandler(jparam.onLoadSuccess):function(data){}; //当远程数据加载成功时触发
$.combobox({
id:_id//'measurement_unit'
,url:'wdk?action=pf.report&method=measurement_unit&ajaxparam='+new Date().getTime()
,queryParams:{}
,idField:'id'
,textField:'text'
,height:25
,panelHeight:130
,isinitselect:true
,initvalue:'U03'//默认为箱
,onLoadSuccess:_onLoadSuccess
});
},
/**
* [radio_corp_level 单位过滤级别组件]
* @param {[type]} jparam [组件输入参数]
* @return {[type]} []
*/
radio_corp_level:function(jparam){
var _id = jparam.id?jparam.id:'';
var _formid = jparam.formid;
var _onChange = jparam.onChange?$.event_getHandler(jparam.onChange):function(data){};
var _initvalue = jparam.initvalue?jparam.initvalue:'';
var _orgLevel = jparam.orgLevel?jparam.orgLevel:'';//过滤组织级别,支持个
var _data = [{
id: 'corp_name',//最大维护字段
text: '地区',
org_level:'02'
}, {
id: 'county_name',//最大维护字段
text: '县级',
org_level:'03'
}, {
id: 'dept_name',//最大维护字段
text: '市场部',
org_level:'07'
}, {
id: 'sale_line_name',//最大维护字段
text: '营销线',
org_level:'08'
}];
var used = _data;
if(_orgLevel){
var newDate = [];
for(var i=0;i<_data.length;i++){
if(_orgLevel.indexOf(_data[i].org_level)>-1){
newDate.push(_data[i]);
}
}
used = newDate;
}else{
used = [{
id: 'corp_name',//最大维护字段
text: '地区',
org_level:'02'
}, {
id: 'county_name',//最大维护字段
text: '县级',
org_level:'03'
}];
}
$.radio({
formid: _formid,//'search_form',
id: _id,//'corp_level',
defaultFirst:true,
onChange:_onChange,
spacing:-1,
initvalue:_initvalue,
data: used
});
},
date_fomart:function(date){
return date.format('yyyy-MM-dd');
},
month_fomart:function(date){
return date.format('yyyy-MM');
},
getCurrentYearFirst:function(nowdate){
nowdate.setMonth(0);
return nowdate;
},
getLastMonthDate:function(nowdate){
var currentMonth = nowdate.getMonth();
nowdate.setMonth(nowdate.getMonth()-1);
var thisMonth = nowdate.getMonth();
var cnt = 0;
while (thisMonth == currentMonth){
nowdate.setDate(nowdate.getDate()-1);
thisMonth = nowdate.getMonth();
cnt++;
if(cnt>10){
break;
}
}
return nowdate;
},
getLastYearDate:function(nowdate){
nowdate.setFullYear(nowdate.getFullYear()-1);
return nowdate;
},
getCurrentMonthFirst:function(date){
date.setDate(1);
return date;
},
getCurrentMonthLast:function(date){
var currentMonth=date.getMonth();
var nextMonth=++currentMonth;
var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
var oneDay=1000*60*60*24;
return new Date(nextMonthFirstDay-oneDay);
},
getLastMonthFirst:function(date){//获取上个月1号的日期
date.setDate(1);
date.setMonth(date.getMonth()-1);
return date;
},
getYesterday:function(date){//昨天
date.setDate(date.getDate()-1);
return date;
},
/**
* [export 导出xlswordpdf等文件]
* @param {[type]} _data [导出需要的报文体]
* @param {[type]} file_type [文件类型xlspdfdoc]
* @return {[type]} []
*/
rp_export:function(_data,file_type){
var _id = 'reort_export';
var _containerid = '';//报表ID
if($.rp_export.caller){
var args = $.rp_export.caller.arguments;
if(args.length>0){
_containerid = args[0];
}
}
//本次请求的链路ID
var _traceid = $.getUUID();
_data = $.extend({
_SERVICE_NAME:'metric_system'//默认让指标系统处理数据
}, _data,{
_TRACEID:_traceid
});
var su = $.getSessionUser();
if(su){
_data._BIZ_ACCOUNT_UUID = su.account_id;
_data._BIZ_MANAGE_UUID = su.manageunituuid;
}
var _title = _data.title||$('title').text();
var bigData = $.json2str(_data);
if(!file_type){
file_type = '';//防止文件类型为:undefined
}
var isload = false;//默认第一次未装载
if($('#'+_id).length == 0){
var rptframeDiv = $('<div id="rptfilediv"></div>').appendTo('body');
$('<iframe id="'+_id+'" name="'+_id+'" src="'+$.base()+'/platform/report/core/report_blank.jsp" frameborder="0" scrolling="no" name="report" style="width: 0px;height: 0px;border:0;" ></iframe>').appendTo(rptframeDiv);
var url = 'wdk?action=pf.report&method=grid_export_file&ajaxparam='+new Date().getTime();
var formstr = "<form id='attach_"+_id+"' target='"+_id+"' action='"+url+"' method='post'>" +
"<input type='hidden' name='data' id='data' value=''/> " +
"<input type='hidden' name='type' id='type' value=''/> " +
"<input type='hidden' name='title' id='title' value=''/> " +
"<input type='hidden' name='orderbyfield' id='orderbyfield' value=''/> " +
"</form> ";
var jForm = $(formstr).css('display','none');
jForm.appendTo(rptframeDiv);
//第一次加载iframe时
window.initReport = function(){
if(isload==false){
frameLoadSuccess(true);
}
isload = true;
}
}else{
frameLoadSuccess(false);
}
//导出文件时,
function frameLoadSuccess(init){
var jForm = $('#attach_'+_id);
if(jForm && jForm.length > 0){
jForm.find("input[name='type']").val(file_type);
bigData = Base64.encode(bigData);//做提交
jForm.find("input[name='data']").val(bigData);
_title = Base64.encode(_title);
jForm.find("input[name='title']").val(_title);
if(_containerid){
if($("#"+_containerid).data("report_data")){
var _fid = $("#"+_containerid).data("report_data").id;
var rpForm = $('#form_'+_fid);
if(rpForm.length > 0){
jForm.find("input[name='orderbyfield']").val(rpForm.find("input[name='orderbyfield']").val());
}
}
}
jForm.submit();//提交数据
}
}
//1.5秒后关闭等待框
setTimeout(function(){loaded()},1500);
},
/**
* [reportyub 报表组件分页和不分页采用不同的实现方案]
* @param {[type]} jparam [请求需要的报文体]
* @return {[type]} []
*/
report:function(jparam){
window.RPT_CONTAINER_FLAG = true;//报表容器的标识
var isload = false;
var _id = jparam.id?jparam.id:$.getID();
var _pagination = (true==jparam.pagination)?jparam.pagination:false; //是否显示分页工具栏
var _containerid = jparam.containerid?jparam.containerid:_DEFAULT_containerid; //容器的ID
var _queryParams = jparam.queryParams?jparam.queryParams:{}; //url请求附带参数
var _isinit = jparam.isinit==undefined?true:jparam.isinit; //是否初始化
var _pageSize = jparam.pageSize?jparam.pageSize:200;
var _pageList = jparam.pageList?jparam.pageList:[200,500,1000];
var _pageNumber = jparam.pageNumber?jparam.pageNumber:1;
var _view = jparam.view?jparam.view:'default';//采用哪个方式,默认方式是后台画table;front代表前端绘制table
var _onLoadSuccess = jparam.onLoadSuccess?$.event_getHandler(jparam.onLoadSuccess):function(data){};
var _onClickRow = jparam.onClickRow?$.event_getHandler(jparam.onClickRow):function(rowIndex, rowData){};
if(_pagination == true && false){
//分页时,采用改良过的easyui-datagird(Report)组件
$.biGrid(jparam);
}else{
// _pagination = true;
//不分页时,采用自己封装的基于jsp-taglib的table方式
var _traceid = $.getUUID(); //本次请求的唯一标识
var _data = $.extend({
_SERVICE_NAME:'metric_system'//默认让指标系统处理数据
}, _queryParams,{
_TRACEID:_traceid
});
var su = $.getSessionUser();
if(su){
_data._BIZ_ACCOUNT_UUID = su.account_id;
_data._BIZ_MANAGE_UUID = su.manageunituuid;
}
//如果是初始化,那就不需要数据(数据服务为空)
if(_isinit){
_data["_SERVICE_NAME"] = '';
}
//暂时把用户的信息丢到容器上去,子页面渲染完毕后,再获取
jparam.queryParams = _data;
if(_view == 'default'){
$("#"+_containerid).data("report_data", jparam);
//分不页的情况下,采用自定义的改造过的table展现
if($('#'+_id).length == 0){
var url = 'wdk?action=pf.report&method=renderReportHtml&ajaxparam='+new Date().getTime();
var form ="<form id='form_"+_id+"' target='"+_id+"' action='"+url+"' id='form1' method='post'>" +
"<input type='hidden' name='data' id='data' value=''/> " +
"<input type='hidden' name='rows' id='rows' value=''/> " +
"<input type='hidden' name='page' id='page' value=''/> " +
"<input type='hidden' name='url' id='url' value='"+url+"'/> " +
"<input type='hidden' name='orderbyfield' id='orderbyfield' value=''/> " +
"<input type='hidden' name='container_id' id='container_id' value='"+_containerid+"'/> " +
"</form>";
var htmlstr = '<iframe src="'+$.base()+'/platform/report/core/report_blank.jsp" name="'+_id+'" id="'+_id+'" frameborder="0" scrolling="no" name="report" style="width: 100%;height: 100%;border:0;background-color: #fff;overflow: hidden;" ></iframe>';
if(_pagination == true){
htmlstr = '<div style="height: 100%;position: relative;"><div style="position: absolute;top: 0;left: 0;right: 0;bottom: 35px;"><iframe name="'+_id+'" id="'+_id+'" src="'+$.base()+'/platform/report/core/report_blank.jsp" frameborder="0" scrolling="no" style="width: 100%;height: 100%;border:0;background-color: #fff;overflow: hidden;"></iframe></div><div id="report_pagination" style="position: absolute;bottom: 0;left: 0;right: 0;height: 30px;"></div> </div>';
}
//$('#'+_containerid).append('<iframe id="'+_id+'" frameborder="0" scrolling="no" name="report" style="width: 100%;height: 100%;border:0;background-color: #fff;overflow: hidden;" ></iframe>');
$('#'+_containerid).append(htmlstr);
var jForm = $(form).css('display','none');
jForm.appendTo('#'+_containerid);
//第一次加载iframe时
window.initReport = function(){
if(isload==false){
frameLoadSuccess(true);
}
isload = true;
}
}else{
//第二次以后加载iframe
frameLoadSuccess(false);
}
}else{
//前端方式绘制
$.cuajax({
url:'wdk?action=pf.report&method=report_chart_data&ajaxparam='+new Date().getTime(),
method:"post",
timeout:WDK_Timeout,
data:{
data:$.json2str(_data)
},
success:function(result) {
var jres = $.str2json(result);
if($('#'+_id).length>0){
renderTable(jres);
}
_onLoadSuccess(jres);
loaded();
},
error:function(result){
loaded();
}
});
}
function frameLoadSuccess(init){
if(_pagination == true){
//分页时构建分页组件
$('#report_pagination').pagination({
total:0,//TODO
pageList:_pageList,
pageSize:_pageSize,
pageNumber:_pageNumber,
onSelectPage:function(pageNumber, pageSize){
$(this).pagination('loading');
loading();
$(this).pagination('refresh',{
pageNumber:pageNumber,
pageSize:pageSize
});
var jForm = $('#form_'+_id);
var bigData = $.json2str($("#"+_containerid).data("report_data").queryParams);
bigData = Base64.encode(bigData);
jForm.find("input[name='data']").val(bigData);//赋值给iframe中表单的文本框中
jForm.find("input[name='rows']").val(pageSize);
jForm.find("input[name='page']").val(pageNumber);
jForm.submit();//提交数据
$(this).pagination('loaded');
},
onRefresh:function(pageNumber, pageSize){
}
});
}
var bigData = Base64.encode($.json2str(_data));
var jForm = $('#form_'+_id);
jForm.find("input[name='orderbyfield']").val('');//每次点击查询,都清空内部的排序字段
jForm.find("input[name='data']").val(bigData);//赋值给iframe中表单的文本框中
if(_pagination == true){
jForm.find("input[name='rows']").val(_pageSize);
jForm.find("input[name='page']").val(_pageNumber);
}
jForm.submit();//提交数据
}
}
/**
* [renderTable 渲染表格]
* @param {[type]} data [业务和数据]
* @return {[type]} []
*/
function renderTable(data){
var containerStr = [];
containerStr.push('<table class="datagrid-btable" cellspacing="0" cellpadding="0" border="0" style="width:100%;">');
containerStr.push('<tbody id="report_content">');
var htmlStr = [];
if(data){
if(data.header){
htmlStr.push('<tr class="datagrid-header">');
for(var i=0;i<data.header.length;i++){
htmlStr.push('<td>'+data.header[i].text+'</td>');
}
htmlStr.push('</tr>');
}
if(data.data){
var htmlContent = data.data.map(function (d) {
var str = [];
str = data.header.map(function(d2){
var name = d2['id'];
var value = d[name];
if(value == undefined){
value = '';
}
return '<td>'+value+'</td>';
});
return "<tr>"+str.join('')+"</tr>";
});
htmlStr.push(htmlContent.join(''));
}
}
var allrow = htmlStr.join('');
containerStr.push(allrow);
containerStr.push('</tbody></table>');
$('#'+_id).html(containerStr.join(''));
$('#report_content').on("click", "tr:not(:first-child)", function() {
var index = $(this).parent().find("tr").index($(this)); //行号
if(index>0){
var rowData = {};
rowData.header = data.header;
var oneData = [];
oneData.push(data.data[index-1]);
rowData.data = oneData;
if(_onClickRow){
_onClickRow(index-1,rowData);
}
}
});
}
},
//大数据展现用gird
biGrid:function(jparam){
loaded();
var _id = jparam.id?jparam.id:$.getID();
var _containerid = jparam.containerid?jparam.containerid:_DEFAULT_containerid; //容器的ID
var _title = jparam.title?jparam.title:'';
var _iconCls = jparam.iconCls?jparam.iconCls:'icon-edit';
var _width = jparam.width?jparam.width:'auto'; //宽度
var _height = jparam.height?jparam.height:'auto';
var _nowrap = (false==jparam.nowrap)?jparam.nowrap:true; //是否不折行
var _striped = (false==jparam.striped)?jparam.striped:true; //奇偶行不同颜色 //高度 //标题前的图标,可不设置 //标题,可不设置
var _fitColumns= jparam.fitColumns?jparam.fitColumns:false; //是否启用列自适应宽度,默认启用
var _border = (true==jparam.border)?jparam.border:false; //是否显示边框
var _collapsible = (true==jparam.collapsible)?jparam.collapsible:false; //是否可折叠的
var _fit = (false==jparam.fit)?jparam.fit:true; //自动大小
var _url = jparam.url?jparam.url:'wdk?action=pf.report&method=grid_query&ajaxparam='+new Date().getTime(); //grid数据获取url
var _queryParams = jparam.queryParams?jparam.queryParams:{}; //url请求附带参数
var _pagination = (true==jparam.pagination)?jparam.pagination:false; //是否显示分页工具栏
var _rownumbers = (false==jparam.rownumbers)?jparam.rownumbers:true; //是否显示行号
var _pageSize = jparam.pageSize?jparam.pageSize:10; //默认每页记录数
var _pageList = jparam.pageList?jparam.pageList:[10,20,30,40,50]; //每页记录数列表
var _toolbar = jparam.toolbar?jparam.toolbar:null; //关联的工具栏ID
var _footer = jparam.footer?jparam.footer:[]; //页脚统计行设置
var _keyHandler = jparam.keyHandler?jparam.keyHandler:null; //整个grid的handler
var _mergeField = '';
var _formatter = jparam.formatter?jparam.formatter:{};
var _sortField = '';
if('string'==typeof(_sortField)){
_sortField = _sortField.split(',');
} //格式化函数
//各类事件
var _onLoadSuccess = jparam.onLoadSuccess?$.event_getHandler(jparam.onLoadSuccess):function(data){};
var _onLoadError = jparam.onLoadError?$.event_getHandler(jparam.onLoadError):function(){};
var _onBeforeLoad = jparam.onBeforeLoad?$.event_getHandler(jparam.onBeforeLoad):function(param){};
var _onClickRow = jparam.onClickRow?$.event_getHandler(jparam.onClickRow):function(rowIndex, rowData){};
var _onCheck = jparam.onCheck?$.event_getHandler(jparam.onCheck):function(rowIndex, rowData){};
var _onUncheck = jparam.onUncheck?$.event_getHandler(jparam.onUncheck):function(rowIndex, rowData){};
var _onDblClickRow = jparam.onDblClickRow?$.event_getHandler(jparam.onDblClickRow):function(rowIndex,rowData){return true;};
var _onClickCell = jparam.onClickCell?$.event_getHandler(jparam.onClickCell):function(rowIndex, rowData,field,value){};
var _onDblClickCell = jparam.onDblClickCell?$.event_getHandler(jparam.onDblClickCell):function(rowIndex, rowData,field,value){};
var _onSortColumn = jparam.onSortColumn?$.event_getHandler(jparam.onSortColumn):function(sort, order){};
var _onResizeColumn = jparam.onResizeColumn?$.event_getHandler(jparam.onResizeColumn):function(field, width){};
var _onSelect = jparam.onSelect?$.event_getHandler(jparam.onSelect):function(rowIndex, rowData){};
var _onUnselect = jparam.onUnselect?$.event_getHandler(jparam.onUnselect):function(rowIndex, rowData){};
var _onSelectAll = jparam.onSelectAll?$.event_getHandler(jparam.onSelectAll):function(rows){};
var _onUnselectAll = jparam.onUnselectAll?$.event_getHandler(jparam.onUnselectAll):function(rows){};
var _onCheckAll = jparam.onCheckAll?$.event_getHandler(jparam.onCheckAll):function(rows){};
var _onUncheckAll = jparam.onUncheckAll?$.event_getHandler(jparam.onUncheckAll):function(rows){};
var _onBeforeEdit = jparam.onBeforeEdit?$.event_getHandler(jparam.onBeforeEdit):function(rowIndex, rowData){};
var _onAfterEdit = jparam.onAfterEdit?$.event_getHandler(jparam.onAfterEdit):function(rowIndex, rowData, changes){};
var _onCancelEdit = jparam.onCancelEdit?$.event_getHandler(jparam.onCancelEdit):function(rowIndex, rowData){};
var _onHeaderContextMenu = jparam.onHeaderContextMenu?$.event_getHandler(jparam.onHeaderContextMenu):function(){};
var _onRowContextMenu = jparam.onRowContextMenu?$.event_getHandler(jparam.onRowContextMenu):function(){};
var _caption_multystartcol = 0; //复合表头起始列
var _caption_level = 0; //复核表头层级
var _traceid = $.getUUID(); //本次请求的唯一标识
var _mergeColumns = [];
if(_queryParams._FIXEDCOLUMNS){
for(var i=0;i<_queryParams._FIXEDCOLUMNS.length-1;i++){
var columncode = _queryParams._FIXEDCOLUMNS[i].fieldcode;
if(!_queryParams._TRANSPOSE || _queryParams._TRANSPOSE.indexOf(columncode)==-1){
_mergeColumns.push(columncode);
}
}
}
var _data = $.extend({
_SERVICE_NAME:'metric_system'//默认让指标系统处理数据
}, _queryParams,{
_TRACEID:_traceid
});
var _isinit = jparam.isinit==undefined?true:jparam.isinit; //是否初始化
//如果是初始化,那就不需要数据(数据服务为空)
if(_isinit){
_data["_SERVICE_NAME"] = '';
}
$('#'+_id).datagrid('loading');
$.cuajax({
url:'wdk?action=pf.report&method=grid_dyna_head&ajaxparam='+new Date().getTime(),
method:"post",
timeout:WDK_Timeout,
data:{
data:$.json2str(_data)
},
success:function(result) {
var jparam = eval('('+result+')');
if('-1'==jparam.code){
}else if('0'==jparam.code){
$.getRoot().$.messager.alert('信息提示',jparam.desc,'warning');
}else{
try{
_initGrid(jparam.fields);
}catch(e){
// alert('报表定义加载错误:'+e.message);
$.getRoot().$.messager.alert('信息提示','报表定义加载错误:'+e.message,'error');
}
}
},
error:function(result){
// alert('网络错误!result='+result);
$.getRoot().$.messager.alert('信息提示','网络错误:'+result,'error');
}
});
function _initGridHead(fields){
//计算总层高
//计算合并行的属性
var isok = false;
for(var i=0;i<fields.length;i++){
var field = fields[i];
if('1'==field.ismerge){
_mergeField += field.fieldcode+',';
}
if(!field.parentid||""==field.parentid||"0"==field.parentid){
}else{
if(0==_caption_multystartcol){
_caption_multystartcol = i;
}
}
captionGetLevel(fields,field,1);
}
if(''!=_mergeField){
_mergeField = _mergeField.substring(0,_mergeField.length-1);
}
// alert("总层高==="+_caption_level+" _caption_multystartcol="+_caption_multystartcol);
//计算每个表头的colspan和rowspan以构建多级表头
for(var i=0;i<fields.length;i++){
var field = fields[i];
if(!field.parentid||""==field.parentid||""==field.parentid.trim()||"0"==field.parentid){
captionIterator(fields,field,0);
}
}
/**/
}
//获取caption表头总层高
function captionGetLevel(fields,pfield,level){
if(_caption_level < level){
_caption_level = level;
}
for(var i=0;i<fields.length;i++){
var _field = fields[i];
if(_field.parentid&&(_field.parentid == pfield.fieldcode)){
captionGetLevel(fields,_field,level+1);
}
}
};
//对表头内容进行循环,计算rowspan和colspan
function captionIterator(fields,pfield,level){
var childs = [];
for(var i=0;i<fields.length;i++){
var cp = fields[i];
if(cp.parentid == pfield.fieldcode){
childs.push(cp);
}
}
for(var i=0;i<childs.length;i++){
var cp = childs[i];
captionIterator(fields,cp,level+1);
}
var colspan = 0;
for(var i=0;i<childs.length;i++){
var cp = childs[i];
colspan += cp.colspan;
}
pfield.level = level;
pfield.childlength = childs.length;
if(childs.length>0){
pfield.rowspan = 1;
pfield.colspan = colspan;
}else{
// alert(pfield.fieldname+"= _caption_level="+_caption_level+" level="+level);
pfield.rowspan = _caption_level-level;
pfield.colspan = 1;
}
};
/**
* 生成默认的grid html
*/
function _GridHTMLDefault(fields){
//1、生成默认html
var arr = [];
_initGridHead(fields);
var frozenCol = 0; //需要冻结的列数
if(fields){
for(var i=0;i<fields.length;i++){
var jfield = fields[i];
if(("1"==jfield.isfrozen||"是"==jfield.isfrozen)&&!jfield.parentid){
frozenCol++;
}
}
}
//冻结列最大不能超过多级表头起始列
if(_caption_level>1&&frozenCol>_caption_multystartcol-1){
frozenCol = _caption_multystartcol-1;
}
//生成带colspan和rowspan的html
arr.push('<table id="'+_id+'" cellspacing="0" cellpadding="0">');
arr.push(' <thead data-options="frozen:true">');
for(var i=0;i<_caption_level;i++){
arr.push(' <tr>');
//if(_checkbox&&0==i){
// arr.push(' <th rowspan="'+_caption_level+'" colspan="1" data-options="field:\'ck\',checkbox:true"></th>');
//}
for(var j=0;j<frozenCol;j++){
var jfield = fields[j];
if(jfield.level == i){
//arr.push(' <th rowspan="'+jfield.rowspan+'" colspan="'+jfield.colspan+'" '+(jfield.colspan==1?'data-options="field:\''+jfield.fieldcode+'\',width:'+jfield.width+',align:\''+jfield.align+'\' '+(jfield.dataformat?',formatter:'+_getFormat(jfield.dataformat):(_formatter[jfield.fieldcode]?',formatter:'+_formatter[jfield.fieldcode]:''))+' '+("1"==jfield.datatype?",sorter:_sort_number":"")+' '+(_sortField.contains(jfield.fieldcode)?",sortable:true,":"")+' '+(("1"==jfield.ishidden||"是"==jfield.ishidden)?",hidden:true":"")+'"':"")+'>'+jfield.fieldname+'</th>');
arr.push(' <th rowspan="'+jfield.rowspan+'" colspan="'+jfield.colspan+'" '+(jfield.colspan==1?'data-options="'+(true==jfield.iseditor?'styler:grid_colsytle_editor,':'')+' halign:\'center\', field:\''+jfield.fieldcode+'\',width:'+jfield.width+',align:\''+jfield.align+'\' '+(_formatter[jfield.fieldcode]?',formatter:'+_formatter[jfield.fieldcode]:(jfield.dataformat?',formatter:'+_getFormat(jfield.dataformat):''))+' '+("1"==jfield.datatype?",sorter:_sort_number":"")+' '+(_sortField.contains(jfield.fieldcode)?",sortable:true":("1"==jfield.issort?",sortable:true":""))+' '+(("1"==jfield.ishidden||"是"==jfield.ishidden)?",hidden:true":"")+'"':"")+'>'+jfield.fieldname+'</th>');
}
}
}
arr.push(' </tr>');
arr.push(' </thead>');
arr.push(' <thead>');
for(var i=0;i<_caption_level;i++){
arr.push(' <tr>');
for(var j=frozenCol;j<fields.length;j++){
var jfield = fields[j];
// alert("j="+j+" jfield.level="+jfield.level+" i="+i)
if(jfield.level == i){
var isColun = jfield.colspan==1 && jfield.childlength==0;
//arr.push(' <th rowspan="'+jfield.rowspan+'" colspan="'+jfield.colspan+'" '+(jfield.colspan==1?'data-options="field:\''+jfield.fieldcode+'\',width:'+jfield.width+',align:\''+jfield.align+'\' '+(jfield.dataformat?',formatter:'+_getFormat(jfield.dataformat):(_formatter[jfield.fieldcode]?',formatter:'+_formatter[jfield.fieldcode]:''))+' '+("1"==jfield.datatype?",sorter:_sort_number":"")+' '+(_sortField.contains(jfield.fieldcode)?",sortable:true":"")+' '+(("1"==jfield.ishidden||"是"==jfield.ishidden)?",hidden:true":"")+'"':"")+'>'+jfield.fieldname+'</th>');
arr.push(' <th rowspan="'+jfield.rowspan+'" colspan="'+jfield.colspan+'" '+(isColun?'data-options="'+(true==jfield.iseditor?'styler:grid_colsytle_editor,':'')+' halign:\'center\', field:\''+jfield.fieldcode+'\',width:'+jfield.width+',align:\''+jfield.align+'\' '+(_formatter[jfield.fieldcode]?',formatter:'+_formatter[jfield.fieldcode]:(jfield.dataformat?',formatter:'+_getFormat(jfield.dataformat):''))+' '+("1"==jfield.datatype?",sorter:_sort_number":"")+' '+(_sortField.contains(jfield.fieldcode)?",sortable:true":("1"==jfield.issort?",sortable:true":""))+' '+(("1"==jfield.ishidden||"是"==jfield.ishidden)?",hidden:true":"")+'"':"")+'>'+jfield.fieldname+'</th>');
}
}
}
arr.push(' </tr>');
arr.push(' </thead>');
arr.push('</table>');
return arr.join('');
}
//初始化grid
function _initGrid(jparams){
var gridHTML = _GridHTMLDefault(jparams);
$("#"+_containerid).html(gridHTML);
//加载grid数据
if(_footer.length>0){
_queryParams.footer = $.json2str(_footer);
}
_queryParams.mergefield = _mergeField;
_queryParams=$.formatParam(_queryParams);
var gridParam = {
gridid:_id,
containerid:_containerid,
title:_title,
iconCls:_iconCls, //图标
width: _width,
height: _height,
nowrap: _nowrap,
striped:_striped,
/*fitColumns:_fitColumns,*/
border:_border,
checkOnSelect:false,
selectOnCheck:false,
collapsible:_collapsible, //是否可折叠的
fit:_fit, //自动大小
url:_url,
initdata:{},
toolbar:'#'+_toolbar,
queryParams:{
data:$.json2str(_data)
},
remoteSort:false,
canMerge:true,
copyrows:[], //被复制的行
enableedit:false,
keyHandler:_keyHandler,
footer:_footer,
showFooter:_footer.length>0?true:false,
singleSelect:true, //是否单选,始终false,始终可以多选,通过ctrl来控制
pagination:_pagination, //分页控件
rownumbers:_rownumbers, //行号
/*view:groupview,
groupField:'company,brand',// 分组字段,可以多级
sumFormatter:function(groupname,rows){
var obj = {};//groupFormatter
$.extend(obj,rows[0]);
//obj.brand = '小计';
return obj;
},*/
onLoadSuccess:function(data){
//var dc = $.data($('#'+_id).get(0),"report").dc;
//删除当前表单的鼠标悬浮事件
//dc.body1.add(dc.body2).unbind('mouseover');
if(_mergeColumns.length>0){
//$.grid_merge(_id,_mergeColumns.join(','));
$('#'+_gridid).datagrid("autoMergeCells", _mergeColumns);
}
_onLoadSuccess(data);
}
};
if(_pagination == true){
gridParam.pageSize = _pageSize; //分页每页记录数
gridParam.pageList = _pageList;
}
$('#'+_id).datagrid(gridParam);
//设置分页控件
if(_pagination){
var p = $('#'+_id).datagrid('getPager');
$(p).pagination({
pageSize: _pageSize,//每页显示的记录条数,默认为10
pageList: _pageList,//可以设置每页记录条数的列表
beforePageText: '第',//页数文本框前显示的汉字
afterPageText: '页 共 {pages} 页',
displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录'
});
}
}
}
/**
* 冻结行onLoadSuccess中加入以下代码
* $(this).datagrid('freezeRow',0).datagrid('freezeRow',1);
*/
/**
*
*/
});
$.extend({
getDateByWeek:function(year,week,weekStart,days){
weekStart = (weekStart || $.fn.weekcalendar.defaults.firstDay) - 0;
if (isNaN(weekStart) || weekStart > 6) {
weekStart = 0;
}
days = days||0;
var firstDay = new Date(year, 0, 1);
//第一周的天数
var firstWeekDays = 7 - firstDay.getDay() + weekStart;
if (firstWeekDays > 7) {
firstWeekDays -= 7;
}
firstDay.setDate(firstDay.getDate()+days+firstWeekDays+(week-2)*7);
return firstDay;
},
getLastWeek:function(_week,weekStart){
if(_week){
var week = {};
var date_start = new Date();
date_start.setTime(_week.date_start.getTime());
var date_end = new Date();
date_end.setTime(_week.date_end.getTime());
date_start.setDate(date_start.getDate()-7);//7天前;
week.year = date_start.getFullYear();
week.week = date_start.getWeekOfYear(weekStart);
week.date_start = date_start;
date_end.setDate(date_end.getDate()-7);
week.date_end = date_end;
var m1 = date_start.getMonth()+1;
var m2 = date_end.getMonth()+1;
if(m2 < m1){
week.month = m2;
}else{
week.month = m1;
}
return week;
}else{
return _week;
}
}
});
$.extend(Date.prototype, {
// 计算当前日期在本年度的周数
getWeekOfYear: function(weekStart) { // weekStart:每周开始于周几:周日:0,周一:1,周二:2 ...,默认为周日
weekStart = (weekStart || $.fn.weekcalendar.defaults.firstDay) - 0;
if (isNaN(weekStart) || weekStart > 6) {
weekStart = 0;
}
var year = this.getFullYear();
var firstDay = new Date(year, 0, 1);
var firstWeekDays = 7 - firstDay.getDay() + weekStart;
if (firstWeekDays > 7) {
firstWeekDays -= 7;
}
var dayOfYear = (((new Date(year, this.getMonth(), this.getDate())) - firstDay) / (24 * 3600 * 1000)) + 1;
return Math.ceil((dayOfYear - firstWeekDays) / 7) + 1;
},
// 计算当前日期在本月份的周数
getWeekOfMonth: function(weekStart) {
weekStart = (weekStart || $.fn.weekcalendar.defaults.firstDay) - 0;
if (isNaN(weekStart) || weekStart > 6)
weekStart = 0;
var dayOfWeek = this.getDay();
var day = this.getDate();
return Math.ceil((day - dayOfWeek - 1) / 7) + ((dayOfWeek >= weekStart) ? 1 : 0);
},
// 计算是某年的第几天
getWhichDay : function() {
//一天的秒数
var day_MillSeconds = 24 * 3600 * 1000, firstDay = new Date(this.getFullYear(), 0, 1); //新年第一天 //新年第一天
var dayOfYear = (this - firstDay) / day_MillSeconds + 1;
return Math.ceil(dayOfYear);
}
});
(function($){
function _449(_44a){
var opts=$.data(_44a,"calendar").options;
var t=$(_44a);
opts.fit?$.extend(opts,t._fit()):t._fit(false);
var _44b=t.find(".calendar-header");
t._outerWidth(opts.width);
t._outerHeight(opts.height);
t.find(".calendar-body")._outerHeight(t.height()-_44b._outerHeight());
};
function init(_44c){
$(_44c).addClass("calendar").html("<div class=\"calendar-header\">"+"<div class=\"calendar-prevmonth\"></div>"+"<div class=\"calendar-nextmonth\"></div>"+"<div class=\"calendar-prevyear\"></div>"+"<div class=\"calendar-nextyear\"></div>"+"<div class=\"calendar-title\">"+"<span>Aprial 2010</span>"+"</div>"+"</div>"+"<div class=\"calendar-body\">"+"<div class=\"calendar-menu\">"+"<div class=\"calendar-menu-year-inner\">"+"<span class=\"calendar-menu-prev\"></span>"+"<span><input class=\"calendar-menu-year\" type=\"text\"></input></span>"+"<span class=\"calendar-menu-next\"></span>"+"</div>"+"<div class=\"calendar-menu-month-inner\">"+"</div>"+"</div>"+"</div>");
$(_44c).find(".calendar-title span").hover(function(){
$(this).addClass("calendar-menu-hover");
},function(){
$(this).removeClass("calendar-menu-hover");
}).click(function(){
var menu=$(_44c).find(".calendar-menu");
if(menu.is(":visible")){
menu.hide();
}else{
_453(_44c);
}
});
$(".calendar-prevmonth,.calendar-nextmonth,.calendar-prevyear,.calendar-nextyear",_44c).hover(function(){
$(this).addClass("calendar-nav-hover");
},function(){
$(this).removeClass("calendar-nav-hover");
});
$(_44c).find(".calendar-nextmonth").click(function(){
_44d(_44c,1);
});
$(_44c).find(".calendar-prevmonth").click(function(){
_44d(_44c,-1);
});
$(_44c).find(".calendar-nextyear").click(function(){
_450(_44c,1);
});
$(_44c).find(".calendar-prevyear").click(function(){
_450(_44c,-1);
});
$(_44c).bind("_resize",function(){
var opts=$.data(_44c,"calendar").options;
if(opts.fit==true){
_449(_44c);
}
return false;
});
};
function _44d(_44e,_44f){
var opts=$.data(_44e,"calendar").options;
opts.month+=_44f;
if(opts.month>12){
opts.year++;
opts.month=1;
}else{
if(opts.month<1){
opts.year--;
opts.month=12;
}
}
show(_44e);
var menu=$(_44e).find(".calendar-menu-month-inner");
menu.find("td.calendar-selected").removeClass("calendar-selected");
menu.find("td:eq("+(opts.month-1)+")").addClass("calendar-selected");
};
function _450(_451,_452){
var opts=$.data(_451,"calendar").options;
opts.year+=_452;
show(_451);
var menu=$(_451).find(".calendar-menu-year");
menu.val(opts.year);
};
function _453(_454){
var opts=$.data(_454,"calendar").options;
$(_454).find(".calendar-menu").show();
if($(_454).find(".calendar-menu-month-inner").is(":empty")){
$(_454).find(".calendar-menu-month-inner").empty();
var t=$("<table></table>").appendTo($(_454).find(".calendar-menu-month-inner"));
var idx=0;
for(var i=0;i<3;i++){
var tr=$("<tr></tr>").appendTo(t);
for(var j=0;j<4;j++){
$("<td class=\"calendar-menu-month\"></td>").html(opts.months[idx++]).attr("abbr",idx).appendTo(tr);
}
}
$(_454).find(".calendar-menu-prev,.calendar-menu-next").hover(function(){
$(this).addClass("calendar-menu-hover");
},function(){
$(this).removeClass("calendar-menu-hover");
});
$(_454).find(".calendar-menu-next").click(function(){
var y=$(_454).find(".calendar-menu-year");
if(!isNaN(y.val())){
y.val(parseInt(y.val())+1);
}
});
$(_454).find(".calendar-menu-prev").click(function(){
var y=$(_454).find(".calendar-menu-year");
if(!isNaN(y.val())){
y.val(parseInt(y.val()-1));
}
});
$(_454).find(".calendar-menu-year").keypress(function(e){
if(e.keyCode==13){
_455();
}
});
$(_454).find(".calendar-menu-month").hover(function(){
$(this).addClass("calendar-menu-hover");
},function(){
$(this).removeClass("calendar-menu-hover");
}).click(function(){
var menu=$(_454).find(".calendar-menu");
menu.find(".calendar-selected").removeClass("calendar-selected");
$(this).addClass("calendar-selected");
_455();
});
}
function _455(){
var menu=$(_454).find(".calendar-menu");
var year=menu.find(".calendar-menu-year").val();
var _456=menu.find(".calendar-selected").attr("abbr");
if(!isNaN(year)){
opts.year=parseInt(year);
opts.month=parseInt(_456);
show(_454);
}
menu.hide();
};
var body=$(_454).find(".calendar-body");
var sele=$(_454).find(".calendar-menu");
var _457=sele.find(".calendar-menu-year-inner");
var _458=sele.find(".calendar-menu-month-inner");
_457.find("input").val(opts.year).focus();
_458.find("td.calendar-selected").removeClass("calendar-selected");
_458.find("td:eq("+(opts.month-1)+")").addClass("calendar-selected");
sele._outerWidth(body._outerWidth());
sele._outerHeight(body._outerHeight());
_458._outerHeight(sele.height()-_457._outerHeight());
};
function _459(_45a,year,_45b){
var opts=$.data(_45a,"calendar").options;
var _45c=[];
var _45d=new Date(year,_45b,0).getDate();
for(var i=1;i<=_45d;i++){
_45c.push([year,_45b,i]);
}
var _45e=[],week=[];
var _45f=-1;
while(_45c.length>0){
var date=_45c.shift();
week.push(date);
var day=new Date(date[0],date[1]-1,date[2]).getDay();
if(_45f==day){
day=0;
}else{
if(day==(opts.firstDay==0?7:opts.firstDay)-1){
_45e.push(week);
week=[];
}
}
_45f=day;
}
if(week.length){
_45e.push(week);
}
var _460=_45e[0];
if(_460.length<7){
while(_460.length<7){
var _461=_460[0];
var date=new Date(_461[0],_461[1]-1,_461[2]-1);
_460.unshift([date.getFullYear(),date.getMonth()+1,date.getDate()]);
}
}else{
var _461=_460[0];
var week=[];
for(var i=1;i<=7;i++){
var date=new Date(_461[0],_461[1]-1,_461[2]-i);
week.unshift([date.getFullYear(),date.getMonth()+1,date.getDate()]);
}
_45e.unshift(week);
}
var _462=_45e[_45e.length-1];
while(_462.length<7){
var _463=_462[_462.length-1];
var date=new Date(_463[0],_463[1]-1,_463[2]+1);
_462.push([date.getFullYear(),date.getMonth()+1,date.getDate()]);
}
if(_45e.length<6){
var _463=_462[_462.length-1];
var week=[];
for(var i=1;i<=7;i++){
var date=new Date(_463[0],_463[1]-1,_463[2]+i);
week.push([date.getFullYear(),date.getMonth()+1,date.getDate()]);
}
_45e.push(week);
}
return _45e;
};
function show(target){
var opts = $.data(target, 'calendar').options;
$(target).find('.calendar-title span').html(opts.months[opts.month-1] + ' ' + opts.year);
var body = $(target).find('div.calendar-body');
body.find('>table').remove();
var t = $('<table cellspacing="0" cellpadding="0" border="0"><thead></thead><tbody></tbody></table>').prependTo(body);
var tr = $('<tr></tr>').appendTo(t.find('thead'));
tr.append('<th>'+opts.weeks[0]+'</th>');
var afterWeeks = [];
for(var i=1;i<opts.weeks.length;i++){
afterWeeks.push(opts.weeks[i]);
}
for(var i=opts.firstDay; i<afterWeeks.length; i++){
tr.append('<th>'+afterWeeks[i]+'</th>');
}
for(var i=0; i<opts.firstDay; i++){
tr.append('<th>'+afterWeeks[i]+'</th>');
}
var weeks = _459(target, opts.year, opts.month);
for(var i=0; i<weeks.length; i++){
var week = weeks[i];
var tr = $('<tr></tr>').appendTo(t.find('tbody'));
var weekDay = week[0];
if (!(opts.year == weekDay[0] && opts.month == weekDay[1])){
weekDay=week[6];
}
var weekValue = new Date(weekDay[0], parseInt(weekDay[1])-1, weekDay[2]).getWeekOfYear(opts.firstDay);
tr.append('<td class="calendar-week" name="'+weekValue+'">'+weekValue+'</td>')
for(var j=0; j<week.length; j++){
var day = week[j];
$('<td class="calendar-day calendar-other-month"></td>').attr('abbr',day[0]+','+day[1]+','+day[2]).html(day[2]).appendTo(tr);
}
}
t.find('td[abbr^="'+opts.year+','+opts.month+'"]').removeClass('calendar-other-month');
var now = new Date();
var today = now.getFullYear()+','+(now.getMonth()+1)+','+now.getDate();
t.find('td[abbr="'+today+'"]').addClass('calendar-today');
if (opts.week){
t.find('.calendar-week-selected').removeClass('calendar-week-selected');
t.find('td[name="'+opts.week+'"]').parent().addClass('calendar-week-selected');
}
// calulate the saturday and sunday index
var saIndex = 6 - opts.firstDay;
var suIndex = saIndex + 1;
if (saIndex >= 7) saIndex -= 7;
if (suIndex >= 7) suIndex -= 7;
saIndex = saIndex+1;
suIndex = suIndex+1;
t.find('tr').find('td:eq('+saIndex+')').addClass('calendar-saturday');
t.find('tr').find('td:eq('+suIndex+')').addClass('calendar-sunday');
t.find('tbody tr').hover(
function(){$(this).addClass('calendar-hover');},
function(){$(this).removeClass('calendar-hover');}
).click(function(){
t.find('.calendar-selected').removeClass('calendar-selected');
$(this).addClass('calendar-selected');
var parts = $(this).find('.calendar-week').text();
var part1 = $(this).find('.calendar-day:first').attr('abbr').split(',');
var part2 = $(this).find('.calendar-day:last').attr('abbr').split(',');
opts.current = new Date(part1[0], parseInt(part1[1])-1, part1[2]);
opts.onSelect.call(target, {year:parseInt(opts.year),week:parseInt(parts)});
});
};
$.fn.weekcalendar=function(_46b,_46c){
if(typeof _46b=="string"){
return $.fn.weekcalendar.methods[_46b](this,_46c);
}
_46b=_46b||{};
return this.each(function(){
var _46d=$.data(this,"calendar");
if(_46d){
$.extend(_46d.options,_46b);
}else{
_46d=$.data(this,"calendar",{options:$.extend({},$.fn.weekcalendar.defaults,$.fn.calendar.parseOptions(this),_46b)});
init(this);
}
if(_46d.options.border==false){
$(this).addClass("calendar-noborder");
}
_449(this);
show(this);
$(this).find("div.calendar-menu").hide();
});
};
$.fn.weekcalendar.methods={options:function(jq){
return $.data(jq[0],"calendar").options;
},resize:function(jq){
return jq.each(function(){
_449(this);
});
},moveTo:function(jq,date){
return jq.each(function(){
$(this).weekcalendar({year:date.year,month:date.month,week:date.week});
});
}};
$.fn.weekcalendar.defaults = {
width:200,
height:180,
fit:false,
border:true,
firstDay:0,
weeks:['周','日','一','二','三','四','五','六'],
months:['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
year:new Date().getFullYear(),
month:new Date().getMonth()+1,
current:(function(){
var d = new Date();
return new Date(d.getFullYear(), d.getMonth()+1, d.getDate());
})(),
onSelect: function(date){}
};
})(jQuery);
$.parser.plugins.push("weekcalendar");//注册组件
(function($){
/**
* create date box
*/
function createBox(target){
var state = $.data(target, 'weekbox');
var opts = state.options;
opts.editable = false;
$(target).addClass('datebox-f').combo($.extend({}, opts, {
onShowPanel:function(){
setCalendarSize();
opts.onShowPanel.call(target);
}
}));
$(target).combo('textbox').parent().addClass('datebox');
/**
* if the calendar isn't created, create it.
*/
if (!state.weekcalendar){
createCalendar();
}
function createCalendar(){
var panel = $(target).combo('panel');
state.weekcalendar = $('<div></div>').appendTo(panel).wrap('<div class="datebox-calendar-inner"></div>');
var _firstDay = $.fn.weekcalendar.defaults.firstDay;
if(opts.firstDay != undefined){
_firstDay = opts.firstDay;
}
state.weekcalendar.weekcalendar({
fit:true,
border:false,
firstDay:_firstDay,
onSelect:function(date){
setValue(target, date);
$(target).combo('hidePanel');
opts.onSelect.call(target, date);
}
});
setValue(target, opts.value);
var button = $('<div class="datebox-button"></div>').appendTo(panel);
var current_btn = $('<a href="javascript:void(0)" class="datebox-current"></a>').html(opts.currentText).appendTo(button);
var close_btn = $('<a href="javascript:void(0)" class="datebox-close"></a>').html(opts.closeText).appendTo(button);
var clear_btn = $('<a href="javascript:void(0)"></a>').html('清除').appendTo(button);
var state2 = $.data(state.weekcalendar[0], 'calendar');
current_btn.click(function(){
var now = new Date();
var value = {
year:now.getFullYear()
,month:now.getMonth()+1
,week:now.getWeekOfYear(state2.options.firstDay)
};
state.weekcalendar.weekcalendar(value);
setValue(target, value);
$(target).combo('hidePanel');
opts.onSelect.call(target,value);
});
close_btn.click(function(){
$(target).combo('hidePanel');
});
clear_btn.click(function(){
setValue(target, '');
$(target).combo('hidePanel');
});
}
function setCalendarSize(){
if (opts.panelHeight != 'auto'){
var panel = $(target).combo('panel');
var ci = panel.children('div.datebox-calendar-inner');
var height = panel.height();
panel.children().not(ci).each(function(){
height -= $(this).outerHeight();
});
ci._outerHeight(height);
}
state.weekcalendar.weekcalendar('resize');
}
}
/**
* called when user inputs some value in text box
*/
function doQuery(target, q){
setValue(target, q);
}
/**
* called when user press enter key
*/
function doEnter(target){
var state = $.data(target, 'weekbox');
var opts = state.options;
var c = state.calendar;
var value = opts.formatter(c.weekcalendar('options').current);
setValue(target, value);
$(target).combo('hidePanel');
}
function setValue(target, value){
var state = $.data(target, 'weekbox');
var opts = state.options;
if(value){
var state2 = $.data(state.weekcalendar[0], 'calendar');
var date_start = $.getDateByWeek(value.year,value.week,state2.options.firstDay,0);
var mon1 = date_start.getMonth()+1;
var date_end = $.getDateByWeek(value.year,value.week,state2.options.firstDay,6);
var mon2 = date_end.getMonth()+1;
if(mon2<mon1){
value.month = mon2;
}else{
value.month = mon1;
}
value.date_start = date_start;
value.date_end = date_end;
var desc = value.year+'年第'+value.week+'周('+(date_start.getMonth()+1)+'.'+(date_start.getDate())+'-'+(date_end.getMonth()+1)+'.'+(date_end.getDate())+')';
$(target).combo('setValue', value.year+''+value.week).combo('setText', desc);
state.selectvalue = value;
state.weekcalendar.weekcalendar('moveTo', value);
}else{
$(target).combo('setValue','').combo('setText', '');
}
}
$.fn.weekbox = function(options, param){
if (typeof options == 'string'){
var method = $.fn.weekbox.methods[options];
if (method){
return method(this, param);
} else {
return this.combo(options, param);
}
}
options = options || {};
var setHeight = options.height;
if(!setHeight){
options.height = 25;
}
return this.each(function(){
var state = $.data(this, 'weekbox');
if (state){
$.extend(state.options, options);
} else {
$.data(this, 'weekbox', {
options: $.extend({}, $.fn.weekbox.defaults, $.fn.weekbox.parseOptions(this), options)
});
}
createBox(this);
});
};
$.fn.weekbox.methods = {
options: function(jq){
var copts = jq.combo('options');
return $.extend($.data(jq[0], 'weekbox').options, {
originalValue: copts.originalValue,
disabled: copts.disabled,
readonly: copts.readonly
});
},
weekcalendar: function(jq){ // get the calendar object
return $.data(jq[0], 'weekbox').weekcalendar;
},
setValue: function(jq, value){
return jq.each(function(){
setValue(this, value);
});
},
getValue:function(jq){
var state = $.data(jq[0], 'weekbox');
return state.selectvalue;
},
reset: function(jq){
return jq.each(function(){
var opts = $(this).datebox('options');
$(this).weekbox('setValue', opts.originalValue);
});
}
};
$.fn.weekbox.parseOptions = function(target){
var t = $(target);
return $.extend({}, $.fn.combo.parseOptions(target), {
});
};
$.fn.weekbox.defaults = $.extend({}, $.fn.combo.defaults, {
panelWidth:200,
panelHeight:'auto',
keyHandler: {
up:function(){},
down:function(){},
enter:function(){doEnter(this);},
query:function(q){doQuery(this, q);}
},
currentText:'本周',
closeText:'关闭',
okText:'确定',
formatter:function(date){
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return m+'/'+d+'/'+y;
},
onSelect:function(date){}
});
})(jQuery);
$.parser.plugins.push("weekbox");//注册组件
$.fn.datebox.methods.getValue = function(jq){
var state = $.data(jq[0], 'datebox');
var opts = state.options;
var c = state.calendar;
if(c){
var value = opts.formatter(c.calendar('options').current);
return value;
}else{
var combo = $.data(jq[0], 'combo').combo;
return combo.find('input.combo-value:first').val();
}
}
$(function(){
});
document.write('<style type="text/css">.datagrid-body{background-color:#FFF;}.dategroup>span{padding:0px;} .rp-search{float: left;height: 100%;margin-right: 100px;} .rp-buttons{position: absolute;top:0;bottom:0;right:0;min-width: 100px;padding:10px;display:table;height:100%;} .rp-buttons>div{display: table-row;} .calendar-week{ color: #2F2FDE; border-right: 1px solid #eee; padding: 0px 1px; cursor: pointer; } .calendar-day{ border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; } .calendar-week-selected { background-color: #e6e6e6; }</style>');