bitable.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  1. if($ == undefined){
  2. $ = jQuery;
  3. }
  4. //创建交叉表
  5. function crtCrossTable(){
  6. var ret = "<table class='d_table'><tr><td class='blank'>"
  7. + "</td><td>"+
  8. "<div id='d_colDims' class='tabhelpr'>将维度拖到此处作为列标签</div>"+"</td></tr><tr><td>"+
  9. "<div id='d_rowDims' class='tabhelpr'>将维度拖到此处<br>作为行标签</div>"+"</td><td>"+
  10. "<div id='d_kpi' class='tabhelpr'>将度量拖到此处<br>查询数据</div>"+"</td></tr></table>";
  11. return ret;
  12. }
  13. /**
  14. 注册行列维度、度量区域的拖拽事件
  15. 对应表格组件的事件
  16. **/
  17. function initDropDiv(id){
  18. var ischg = false;
  19. $("#T" + id + " #d_colDims, #T" + id +" #d_rowDims, #T"+id+" #d_kpi").droppable({
  20. accept:"ul.tableTreeCss .tree-node",
  21. onDragEnter:function(e,source){
  22. var node = $("#datasettree").tree("getNode", source);
  23. var tp = node.attributes.col_type;
  24. //对维度拖拽设置图标
  25. if(tp == 1 && ($(this).attr("id") == "d_colDims" || $(this).attr("id") == "d_rowDims")){
  26. $(source).draggable('proxy').find("span").removeClass("tree-dnd-no");
  27. $(source).draggable('proxy').find("span").addClass("tree-dnd-yes");
  28. if($(this).attr("id") == "d_colDims"){
  29. $("#T"+id+" #d_colDims").css("border", "1px solid #ff0000");
  30. }
  31. if($(this).attr("id") == "d_rowDims"){
  32. $("#T"+id+" #d_rowDims").css("border", "1px solid #ff0000");
  33. }
  34. ischg = true;
  35. }else{
  36. ischg = false;
  37. }
  38. //对度量拖拽设置图标
  39. if(tp == 2 && $(this).attr("id") == "d_kpi"){
  40. $(source).draggable('proxy').find("span").removeClass("tree-dnd-no");
  41. $(source).draggable('proxy').find("span").addClass("tree-dnd-yes");
  42. $("#T"+id+" #d_kpi").css("border", "1px solid #ff0000");
  43. ischg = false;
  44. }
  45. e.cancelBubble=true;
  46. e.stopPropagation(); //阻止事件冒泡
  47. },
  48. onDragLeave:function(e,source){
  49. if($(this).attr("id") == 'd_kpi' && ischg == true){
  50. }else{
  51. $(source).draggable('proxy').find("span").addClass("tree-dnd-no");
  52. $(source).draggable('proxy').find("span").removeClass("tree-dnd-yes");
  53. $("#T"+id+" #" + $(this).attr("id")).css("border", "none");
  54. }
  55. e.cancelBubble=true;
  56. e.stopPropagation(); //阻止事件冒泡
  57. },
  58. onDrop:function(e,source){
  59. var id = $(this).parents(".comp_table").attr("id").replace("T","");
  60. var json = findCompById(Number(id));
  61. e.cancelBubble=true;
  62. e.stopPropagation(); //阻止事件冒泡
  63. //清除边框颜色
  64. $("#T"+id+" #" + $(this).attr("id")).css("border", "none");
  65. //获取TREE
  66. var node = $("#datasettree").tree("getNode", source);
  67. //判断拖入的维度及度量是否和以前维度及度量在同一个表。
  68. if(json.cubeId != undefined){
  69. if(json.cubeId != node.attributes.cubeId){
  70. msginfo("您拖入的"+ (node.attributes.col_type == 2 ? "度量" : "维度") +"与组件已有的内容不在同一个数据表中,拖放失败。");
  71. return;
  72. }
  73. }
  74. //判断拖入的度量是否是(同比、环比),如果是,需要判断当前维度是否有date类型
  75. /** 放入度量计算菜单判断
  76. if(node.attributes.calc_kpi == 1){
  77. if(!isExistDateDim(json, 'table')){
  78. msginfo("您拖入的度量需要表格中先有时间类型的维度(年/季度/月/日)。");
  79. return;
  80. }
  81. }
  82. **/
  83. json.cubeId = node.attributes.cubeId;
  84. json.dsid = node.attributes.dsid;
  85. json.dsetId = node.attributes.dsetId;
  86. if(json.kpiJson == undefined){
  87. json.kpiJson = [];
  88. };
  89. if(json.cols == undefined){
  90. json.cols = [];
  91. }
  92. if(json.rows == undefined){
  93. json.rows = [];
  94. }
  95. //写度量
  96. if(node.attributes.col_type == 2 && $(this).attr("id") == "d_kpi"){
  97. //如果度量存在就忽略
  98. if(!kpiExist(node.attributes.col_id, json.kpiJson)){
  99. json.kpiJson.push({"kpi_id":node.attributes.col_id, "kpi_name" : node.text, "col_name":node.attributes.col_name, "aggre":node.attributes.aggre, "fmt":node.attributes.fmt, "alias":node.attributes.alias,"tname":node.attributes.tname,"unit":node.attributes.unit,"rate":node.attributes.rate,"calc":node.attributes.calc});
  100. }else{
  101. msginfo("度量已经存在。");
  102. return;
  103. }
  104. curTmpInfo.isupdate = true;
  105. tableView(json, Number(id));
  106. }
  107. //写维度
  108. if(node.attributes.col_type == 1){
  109. //写col维度
  110. if($(this).attr("id") == "d_colDims"){
  111. if(dimExist(node.attributes.col_id, json.cols) || dimExist(node.attributes.col_id, json.rows)){
  112. msginfo("维度已经存在。");
  113. return;
  114. }
  115. //如果维度有分组,分组必须相同
  116. var group = node.attributes.grouptype;
  117. if(group != null && findGroup(json.rows, group)){
  118. msginfo("拖放失败,同一分组的维度必须在同一行/列标签。");
  119. return;
  120. }
  121. json.cols.push({"id":node.attributes.col_id, "dimdesc" : node.text, "type":node.attributes.dim_type, "colname":node.attributes.col_name,"alias":node.attributes.alias,"tname":node.attributes.tname,"iscas":node.attributes.iscas, "tableName":node.attributes.tableName, "tableColKey":node.attributes.tableColKey,"tableColName":node.attributes.tableColName, "dimord":node.attributes.dimord, "grouptype":node.attributes.grouptype,"valType":node.attributes.valType,ordcol:node.attributes.ordcol,dateformat:node.attributes.dateformat,"calc":node.attributes.calc});
  122. curTmpInfo.isupdate = true;
  123. tableView(json, Number(id));
  124. }
  125. //写row维度
  126. if($(this).attr("id") == "d_rowDims"){
  127. if(dimExist(node.attributes.col_id, json.rows) || dimExist(node.attributes.col_id, json.cols)){
  128. msginfo("维度已经存在。");
  129. return;
  130. }
  131. //如果维度有分组,分组必须相同
  132. var group = node.attributes.grouptype;
  133. if(group != null && findGroup(json.cols, group)){
  134. msginfo("拖放失败,同一分组的维度必须在同一行/列标签。");
  135. return;
  136. }
  137. json.rows.push({"id":node.attributes.col_id, "dimdesc" : node.text, "type":node.attributes.dim_type, "colname":node.attributes.col_name,"alias":node.attributes.alias,"tname":node.attributes.tname,"iscas":node.attributes.iscas, "tableName":node.attributes.tableName, "tableColKey":node.attributes.tableColKey,"tableColName":node.attributes.tableColName, "dimord":node.attributes.dimord,"grouptype":node.attributes.grouptype,"valType":node.attributes.valType,ordcol:node.attributes.ordcol,dateformat:node.attributes.dateformat,"calc":node.attributes.calc});
  138. curTmpInfo.isupdate = true;
  139. tableView(json, Number(id));
  140. }
  141. }
  142. }
  143. });
  144. //注册固定表头事件
  145. fireTableScroll(id);
  146. }
  147. function fireTableScroll(id){
  148. $("#T"+id+" #d_kpi").scroll(function(){
  149. var top = $(this).scrollTop();
  150. $("#d_rowDims table").css("margin-top", "-"+top+"px");
  151. //$("#T"+id+" #d_rowDims").scrollTop(top);
  152. var left = $(this).scrollLeft();
  153. $("#T"+id+" #d_colDims table").css("margin-left", "-"+left+"px");
  154. });
  155. var comp = findCompById(id);
  156. var rowLvl = comp.rows?comp.rows.length:1;
  157. if(rowLvl == 0){
  158. rowLvl = 1;
  159. }
  160. var w = $("#optarea").width(), h = $(window).height();
  161. h = h - 300;
  162. w = w - (127 * rowLvl);
  163. if(w <0){
  164. w = 200;
  165. }
  166. $("#T"+id+" #d_rowDims").height(h);
  167. $("#T"+id+" #d_colDims").width(w);
  168. $("#T"+id+" #d_kpi").width(w).height(h);
  169. }
  170. //查找维度分组
  171. function findGroup(dims, group, curNode){
  172. var ret = false;
  173. if(!dims || dims == null){
  174. return ret;
  175. }
  176. for(m=0; m<dims.length; m++){
  177. if(curNode && curNode == dims[m]){ //curNode存在表示忽略当前节点
  178. continue;
  179. }
  180. if(dims[m].grouptype == group){
  181. ret = true;
  182. break;
  183. }
  184. }
  185. return ret;
  186. }
  187. /**
  188. 判断是否有时间参数,如果有,必须表格组件中也具有相同的参数
  189. **/
  190. function paramsamedimdate(comp){
  191. var same = true;
  192. var exist = function(input){
  193. var ret = false;
  194. for(var i=0; comp.cols&&i<comp.cols.length; i++){
  195. if(comp.cols[i].type == input){
  196. ret = true;
  197. break;
  198. }
  199. }
  200. for(var i=0; comp.rows&&i<comp.rows.length; i++){
  201. if(comp.rows[i].type == input){
  202. ret = true;
  203. break;
  204. }
  205. }
  206. return ret;
  207. }
  208. var params = pageInfo.params;
  209. for(i=0; params&&i<params.length; i++){
  210. if(params[i].type == "year" || params[i].type == "quarter" || params[i].type == "month" || params[i].type == "day"){
  211. if(!exist(params[i].type)){
  212. same = false;
  213. break;
  214. }
  215. }
  216. }
  217. return same;
  218. }
  219. function kpicompute(tp){
  220. //设置计算类型, 1表示不能同时存在,2表示可以同时存在。
  221. var tpobj = {"zb":1,"sxpm":1, "jxpm": 1, "ydpj":1, "sq":2, "tq":2, "zje":2, "hb":2, "tb":2}
  222. var kpiId = curTmpInfo.ckid;
  223. var compId = curTmpInfo.compId.replace("T", "");
  224. var comp = findCompById(compId);
  225. var kpi = findKpiById(kpiId, comp.kpiJson);
  226. if(tp == "zb"){
  227. kpi.compute = "zb";
  228. }else if(tp == "sxpm"){
  229. kpi.compute = "sxpm";
  230. }else if(tp == "jxpm"){
  231. kpi.compute = "jxpm";
  232. }else{
  233. if(!isExistDateDim(comp, 'table')){
  234. msginfo("当前度量计算需要表格中先有时间类型的维度(年/季度/月/日)。", "error");
  235. return;
  236. }
  237. //如果有参数,并且参数是时间维度,需要判断表格中是否有同样的参数维度,如果没有提示用户添加
  238. if(!paramsamedimdate(comp)){
  239. msginfo("度量计算时,需要表格中具有和参数相同的维度。", "error");
  240. return;
  241. }
  242. //先判断已经存在的,如果是时间偏移计算就追加,或者替换.
  243. var exist = kpi.compute;
  244. if(!exist || exist == ""){
  245. kpi.compute = tp;
  246. }else{
  247. var js = exist.split(",");
  248. if(tpobj[js[0]] == 1){
  249. kpi.compute = tp;
  250. }else{
  251. var cz = false; //不存在才添加
  252. for(j=0; j<js.length; j++){
  253. if(js[j] == tp){
  254. cz = true;
  255. break;
  256. }
  257. }
  258. if(!cz){
  259. kpi.compute = exist+","+tp;
  260. }
  261. }
  262. }
  263. }
  264. tableView(comp, compId);
  265. }
  266. function delExtKpi(ts, kpiId, compute){
  267. var compId = $(ts).parents(".comp_table").attr("id").replace("T", "");
  268. var comp = findCompById(Number(compId));
  269. //设置度量排序的标识
  270. var kpi = findKpiById(kpiId, comp.kpiJson);
  271. var js = kpi.compute.split(",");
  272. if(js.length == 1){
  273. delete kpi.compute;
  274. }else{
  275. //剔除需要删除的计算度量
  276. var ret = "";
  277. for(i=0; i<js.length; i++){
  278. if(js[i] != compute){
  279. ret = ret + js[i] + ",";
  280. }
  281. }
  282. kpi.compute = ret.substring(0, ret.length - 1);
  283. }
  284. tableView(comp, compId);
  285. }
  286. function tableView(table, compId){
  287. if(table.kpiJson == undefined){
  288. return;
  289. } //如果没有度量,维度等内容,返回界面到初始状态
  290. if(table.kpiJson.length == 0 && table.cols.length == 0 && table.rows.length == 0){
  291. $("#T" + compId + " div.ctx").html(crtCrossTable());
  292. initDropDiv(compId);
  293. return;
  294. }
  295. var json = {cols:table.cols,rows:table.rows,kpiJson:table.kpiJson,dsid:table.dsid, dsetId:table.dsetId, "compId":compId, "params":pageInfo.params};
  296. __showLoading();
  297. $.ajax({
  298. type: "POST",
  299. url: "TableView.action",
  300. dataType:"html",
  301. contentType : "application/json",
  302. data: JSON.stringify(json),
  303. success: function(resp){
  304. __hideLoading();
  305. $("#T" + compId + " div.ctx").html(resp);
  306. //重新注册拖放事件(从度量拖入的事件)
  307. initDropDiv(compId);
  308. },
  309. error:function(resp){
  310. __hideLoading();
  311. $.messager.alert('出错了','系统出错,请联系管理员。','error');
  312. }
  313. });
  314. }
  315. //指标预警
  316. function kpiwarning(){
  317. var kpiId = curTmpInfo.ckid;
  318. var compId = curTmpInfo.compId.replace("T", "");
  319. var comp = findCompById(compId);
  320. var kpi = findKpiById(kpiId, comp.kpiJson);
  321. var warn = kpi.warning;
  322. var str = "<div style='margin:10px;'><span class=\"inputtext\">图片样式:</span><select id=\"wctype\" class=\"inputform2\" style=\"width:90px;\"><option value=\"1\" "+(warn&&warn.pictype=="1"?"selected":"")+">交通灯</option><option value=\"2\" "+(warn&&warn.pictype=="2"?"selected":"")+">箭头</option></select> <div class=\"checkbox checkbox-inline\"><input type=\"checkbox\" value=\"y\" id=\"fztp\" name=\"fztp\" "+(warn&&warn.reverse=="y"?"checked":"")+"><label for=\"fztp\">反转图片</label></div><br/>";
  323. str = str + "<span id=\"w1\" class=\""+(warn?warn.pic1:"warning6")+"\"></span> <span class=\"inputtext\">当前值</span> <select id=\"logic1\" name=\"logic1\" class=\"inputform2\" style=\"width:50px;\"><option value=\">=\" "+(warn&&warn.logic1==">="?"selected":"")+">&gt;=</option><option value=\">\" "+(warn&&warn.logic1==">"?"selected":"")+">&gt;</option></select> <input type=\"text\" id=\"val1\" name=\"val1\" idx=\"1\" value=\""+(warn?warn.val1:"")+"\"> <br/><span id=\"w2\" class=\""+(warn?warn.pic2:"warning5")+"\"></span> <span class=\"inputtext\">当前值 &lt; <span id=\"and1\">"+(warn?warn.val1:"X")+"</span> 且 </span> <select id=\"logic2\" name=\"logic2\" class=\"inputform2\" style=\"width:50px;\"><option value=\">=\" "+(warn&&warn.logic2==">="?"selected":"")+">&gt;=</option><option value=\">\" "+(warn&&warn.logic2=="="?"selected":"")+">&gt;</option></select> <input type=\"text\" name=\"val2\" idx=\"2\" id=\"val2\" value=\""+(warn?warn.val2:"")+"\"><br/> <span id=\"w3\" class=\""+(warn?warn.pic3:"warning4")+"\"></span> <span class=\"inputtext\"> 当前值 &lt; <span id=\"and2\">"+(warn?warn.val2:"X")+"</span></span> <br/><div class=\"checkbox checkbox-info\"><input type=\"checkbox\" value=\"y\" id=\"clear\" name=\"clear\" ><label for=\"clear\">清除预警信息</label></div></div>";
  324. $('#pdailog').dialog({
  325. title: '指标预警',
  326. width: 360,
  327. height: 240,
  328. closed: false,
  329. cache: false,
  330. modal: true,
  331. toolbar:null,
  332. content: str,
  333. buttons:[{
  334. text:'确定',
  335. iconCls:'icon-ok',
  336. handler:function(){
  337. var pictype = $("#pdailog #wctype").val();
  338. var reverse = $("#pdailog input[name=\"fztp\"]:checked").val();
  339. if(!reverse){
  340. reverse = "n";
  341. }
  342. var logic1 = $("#pdailog #logic1").val();
  343. var val1 = $("#pdailog #val1").val();
  344. var logic2 = $("#pdailog #logic2").val();
  345. var val2 = $("#pdailog #val2").val();
  346. var pic1 = $("#pdailog #w1").attr("class");
  347. var pic2 = $("#pdailog #w2").attr("class");
  348. var pic3 = $("#pdailog #w3").attr("class");
  349. if(val1 == '' || val2 == ''){
  350. delete kpi.warning;
  351. tableView(comp, compId);
  352. $('#pdailog').dialog('close');
  353. return;
  354. }
  355. kpi.warning = {pictype:pictype,reverse:reverse,logic1:logic1,val1:val1,logic2:logic2,val2:val2,pic1:pic1,pic2:pic2,pic3:pic3}
  356. tableView(comp, compId);
  357. $('#pdailog').dialog('close');
  358. }
  359. },{
  360. text:'取消',
  361. iconCls:"icon-cancel",
  362. handler:function(){
  363. $('#pdailog').dialog('close');
  364. }
  365. }]
  366. });
  367. $("#pdailog #val1,#pdailog #val2").numberbox({width:100,height:28, onChange:function(a, b){
  368. var idx = $(this).attr("idx");
  369. $("#pdailog #and" + idx).text(a);
  370. }
  371. });
  372. /**
  373. $("#pdailog #val2").numberbox("onChange", function(){
  374. $("#pdailog #and2").text($("#pdailog #val2").numberbox("getValue"));
  375. });
  376. **/
  377. $("#pdailog #wctype").change(function(){
  378. if($(this).val() == 1){
  379. $("#pdailog #w1").attr("class", "warning6");
  380. $("#pdailog #w2").attr("class", "warning5");
  381. $("#pdailog #w3").attr("class", "warning4");
  382. }else if($(this).val() == 2){
  383. $("#pdailog #w1").attr("class", "warning3");
  384. $("#pdailog #w2").attr("class", "warning2");
  385. $("#pdailog #w3").attr("class", "warning1");
  386. }
  387. });
  388. //反转图片
  389. $("#pdailog #fztp").change(function(){
  390. if(this.checked){
  391. if($("#pdailog #wctype").val() == 1){
  392. $("#pdailog #w1").attr("class", "warning4");
  393. $("#pdailog #w2").attr("class", "warning5");
  394. $("#pdailog #w3").attr("class", "warning6");
  395. }else if($("#pdailog #wctype").val() == 2){
  396. $("#pdailog #w1").attr("class", "warning1");
  397. $("#pdailog #w2").attr("class", "warning2");
  398. $("#pdailog #w3").attr("class", "warning3");
  399. }
  400. }else{
  401. if($("#pdailog #wctype").val() == 1){
  402. $("#pdailog #w1").attr("class", "warning6");
  403. $("#pdailog #w2").attr("class", "warning5");
  404. $("#pdailog #w3").attr("class", "warning4");
  405. }else if($("#pdailog #wctype").val() == 2){
  406. $("#pdailog #w1").attr("class", "warning3");
  407. $("#pdailog #w2").attr("class", "warning2");
  408. $("#pdailog #w3").attr("class", "warning1");
  409. }
  410. }
  411. });
  412. $("#pdailog #clear").change(function(){
  413. if(this.checked){
  414. $("#pdailog #val1").numberbox("clear");
  415. $("#pdailog #val2").numberbox("clear");
  416. }
  417. });
  418. }
  419. function kpiFilter(tp){
  420. var kpiId = curTmpInfo.ckid;
  421. var compId = curTmpInfo.compId.replace("T", "");
  422. var comp = findCompById(compId);
  423. var kpi = findKpiById(kpiId, comp.kpiJson);
  424. var ft = kpi.filter;
  425. var unitStr = "";
  426. if(kpi.rate == 1000){
  427. unitStr = "千";
  428. }else if(kpi.rate == 10000){
  429. unitStr = "万";
  430. }else if(kpi.rate == 1000000){
  431. unitStr = "百万";
  432. }else if(kpi.rate == 100000000){
  433. unitStr = "亿";
  434. }
  435. var ctx = "<div style='margin:5px; line-height:25px;'><span class=\"inputtext\">"+kpi.kpi_name+":</span> <select id=\"ftype\" class=\"inputform\" style=\"width:100px;\"><option value=\"\"></option><option value=\">\" "+(ft&&ft.filterType==">"?"selected":"")+">大于</option><option value=\"<\" "+(ft&&ft.filterType=="<"?"selected":"")+">小于</option><option value=\"=\" "+(ft&&ft.filterType=="="?"selected":"")+">等于</option><option value=\"between\" "+(ft&&ft.filterType=="between"?"selected":"")+">区间</option></select> <br/> <span class=\"inputtext\"> </span> <input type=\"text\" style=\"\" id=\"startval\" size=\"5\" value=\""+(ft?ft.val1:"")+"\"><span id=\"endvalspan\" style=\"display:"+(ft&&ft.filterType=='between'?"inline":"none")+"\"> - <input class=\"inputform\" type=\"text\" id=\"endval\" size=\"5\" value=\""+(ft?ft.val2:"")+"\"></span>" + unitStr+kpi.unit+"<br/><button id=\"clear\" class=\"btn btn-success btn-xs\">清除筛选</button></div>";
  436. $('#pdailog').dialog({
  437. title: '度量筛选',
  438. width: 350,
  439. height: 220,
  440. closed: false,
  441. cache: false,
  442. modal: true,
  443. toolbar:null,
  444. content: ctx,
  445. buttons:[{
  446. text:'确定',
  447. iconCls:'icon-ok',
  448. handler:function(){
  449. var ft = $("#pdailog #ftype").val();
  450. var sv = $("#pdailog #startval").val();
  451. var ev = $("#pdailog #endval").val();
  452. if(ft == "" || sv == ""){
  453. delete kpi.filter;
  454. }else{
  455. var filter = {"kpi":kpi.kpi_id,"filterType":ft,"val1":Number(sv),"val2":(ev == ""?0:Number(ev))};
  456. kpi.filter = filter;
  457. }
  458. $('#pdailog').dialog('close');
  459. curTmpInfo.isupdate = true;
  460. if(tp == 'table'){
  461. tableView(comp, compId);
  462. }else if(tp == 'chart'){
  463. chartview(comp, compId);
  464. }
  465. }
  466. },{
  467. text:'取消',
  468. iconCls:"icon-cancel",
  469. handler:function(){
  470. $('#pdailog').dialog('close');
  471. }
  472. }]
  473. });
  474. $('#pdailog #startval,#pdailog #endval').numberbox({width:100,height:28});
  475. $("#pdailog #ftype").bind("change", function(){
  476. var o = $(this);
  477. if(o.val() == 'between'){
  478. $("#pdailog #endvalspan").css("display","inline");
  479. }else{
  480. $("#pdailog #endvalspan").css("display","none");
  481. }
  482. });
  483. $("#pdailog #clear").bind("click", function(){
  484. $("#pdailog #ftype").val("");
  485. $("#pdailog #startval").numberbox("clear");
  486. $("#pdailog #endval").numberbox("clear");
  487. });
  488. }
  489. //从表格JSON中删除KPI
  490. function delJsonKpiOrDim(tp){
  491. var id = curTmpInfo.ckid;
  492. var compId = curTmpInfo.compId.replace("T", "");
  493. var comp = findCompById(Number(compId));
  494. var pos = curTmpInfo.pos;
  495. if(tp == 'kpi'){
  496. var kpis = comp.kpiJson;
  497. var idx = -1;
  498. for(var i=0; i<kpis.length; i++){
  499. if(kpis[i].kpi_id == id){
  500. idx = i;
  501. break;
  502. }
  503. }
  504. kpis.splice(idx, 1);
  505. }
  506. if(tp == 'dim'){
  507. var dims = null;
  508. if(pos == 'col'){
  509. dims = comp.cols;
  510. }else{
  511. dims = comp.rows;
  512. }
  513. var idx = -1;
  514. for(var i=0; i<dims.length; i++){
  515. if(dims[i].id == id){
  516. idx = i
  517. break;
  518. }
  519. }
  520. dims.splice(idx, 1);
  521. //如果删除维度后无时间维度,并且度量中含有计算度量,需要清除计算度量内容
  522. if(!isExistDateDim(comp, 'table')){
  523. for(var j=0; comp.kpiJson&&j<comp.kpiJson.length; j++){
  524. delete comp.kpiJson[j].compute;
  525. }
  526. }
  527. //如果有参数,并且参数是时间维度,如果参数时间类型表格中没有,移除计算度量
  528. if(!paramsamedimdate(comp)){
  529. for(var j=0; comp.kpiJson&&j<comp.kpiJson.length; j++){
  530. delete comp.kpiJson[j].compute;
  531. }
  532. }
  533. }
  534. curTmpInfo.isupdate = true;
  535. tableView(comp, compId);
  536. }
  537. function setKpiInfo(ts, id){
  538. var offset = $(ts).offset();
  539. //放入临时对象中,方便下次获取
  540. curTmpInfo.ckid = id;
  541. curTmpInfo.compId = $(ts).parents(".comp_table").attr("id");
  542. var comp = findCompById(Number(curTmpInfo.compId.replace("T", "")));
  543. //设置度量排序的标识
  544. var kpi = findKpiById(id, comp.kpiJson);
  545. if(kpi.sort == 'asc'){
  546. $("#dimoptmenu").menu("setIcon", {target:$("#kpioptmenu").menu("getItem", $("#k_kpi_ord1")).target, iconCls:"icon-ok"});
  547. $("#dimoptmenu").menu("setIcon", {target:$("#kpioptmenu").menu("getItem", $("#k_kpi_ord2")).target, iconCls:"icon-blank"});
  548. $("#dimoptmenu").menu("setIcon", {target:$("#kpioptmenu").menu("getItem", $("#k_kpi_ord3")).target, iconCls:"icon-blank"});
  549. }else if(kpi.sort == 'desc'){
  550. $("#dimoptmenu").menu("setIcon", {target:$("#kpioptmenu").menu("getItem", $("#k_kpi_ord1")).target, iconCls:"icon-blank"});
  551. $("#dimoptmenu").menu("setIcon", {target:$("#kpioptmenu").menu("getItem", $("#k_kpi_ord2")).target, iconCls:"icon-ok"});
  552. $("#dimoptmenu").menu("setIcon", {target:$("#kpioptmenu").menu("getItem", $("#k_kpi_ord3")).target, iconCls:"icon-blank"});
  553. }else{
  554. $("#dimoptmenu").menu("setIcon", {target:$("#kpioptmenu").menu("getItem", $("#k_kpi_ord1")).target, iconCls:"icon-blank"});
  555. $("#dimoptmenu").menu("setIcon", {target:$("#kpioptmenu").menu("getItem", $("#k_kpi_ord2")).target, iconCls:"icon-blank"});
  556. $("#dimoptmenu").menu("setIcon", {target:$("#kpioptmenu").menu("getItem", $("#k_kpi_ord3")).target, iconCls:"icon-ok"});
  557. }
  558. $("#kpioptmenu").menu("show", {left:offset.left, top:offset.top + 20});
  559. }
  560. function setCdimInfo(ts, id, name){
  561. var offset = $(ts).offset();
  562. //放入临时对象中,方便下次获
  563. curTmpInfo.ckid = id;
  564. curTmpInfo.compId = $(ts).parents(".comp_table").attr("id");
  565. curTmpInfo.pos = "col";
  566. curTmpInfo.dimname = name;
  567. //设置聚合菜单
  568. var issum = false;
  569. var comp = findCompById(Number(curTmpInfo.compId.replace("T", "")));
  570. var dims = comp.cols;
  571. for(var i=0; i<dims.length; i++){
  572. if(dims[i].id == id){
  573. if(dims[i].issum == 'y'){
  574. issum = true;
  575. break;
  576. }
  577. }
  578. }
  579. if(issum){
  580. var aggr = $("#dimoptmenu").menu("getItem", $("#m_aggre"));
  581. $("#dimoptmenu").menu("setText", {target:aggr.target, text:"取消聚合"});
  582. }else{
  583. var aggr = $("#dimoptmenu").menu("getItem", $("#m_aggre"));
  584. $("#dimoptmenu").menu("setText", {target:aggr.target, text:"聚合..."});
  585. }
  586. //设置移至行、列的文本
  587. var aggr = $("#dimoptmenu").menu("getItem", $("#m_moveto"));
  588. $("#dimoptmenu").menu("setText", {target:aggr.target, text:"移至行维度"});
  589. $("#dimoptmenu").menu("show", {left:offset.left, top:offset.top + 20});
  590. }
  591. function setRdimInfo(ts, id, name){
  592. var offset = $(ts).offset();
  593. curTmpInfo.ckid = id;
  594. curTmpInfo.compId = $(ts).parents(".comp_table").attr("id");
  595. curTmpInfo.pos = "row";
  596. curTmpInfo.dimname = name;
  597. //设置聚合菜单
  598. var issum = false;
  599. var comp = findCompById(Number(curTmpInfo.compId.replace("T", "")));
  600. var dims = comp.rows;
  601. for(var i=0; i<dims.length; i++){
  602. if(dims[i].id == id){
  603. if(dims[i].issum == 'y'){
  604. issum = true;
  605. break;
  606. }
  607. }
  608. }
  609. if(issum){
  610. var aggr = $("#dimoptmenu").menu("getItem", $("#m_aggre"));
  611. $("#dimoptmenu").menu("setText", {target:aggr.target, text:"取消聚合"});
  612. }else{
  613. var aggr = $("#dimoptmenu").menu("getItem", $("#m_aggre"));
  614. $("#dimoptmenu").menu("setText", {target:aggr.target, text:"聚合..."});
  615. }
  616. //设置移至行、列的文本
  617. var aggr = $("#dimoptmenu").menu("getItem", $("#m_moveto"));
  618. $("#dimoptmenu").menu("setText", {target:aggr.target, text:"移至列维度"});
  619. $("#dimoptmenu").menu("show", {left:offset.left, top:offset.top + 20});
  620. }
  621. function changecolrow(islink){
  622. var compId = curTmpInfo.compId.replace("T", "");
  623. var comp = findCompById(compId);
  624. var tmp = comp.rows;
  625. comp.rows = comp.cols;
  626. comp.cols = tmp;
  627. tableView(comp, compId);
  628. //判断是否联动
  629. if(comp.complink && islink){
  630. //联动图形
  631. var chartComp = findCompById(comp.complink);
  632. if(chartComp != null && isSameDimsInDrill(comp, chartComp)){
  633. exchangexs(chartComp.id, false); //存在相同维度才能联动
  634. }
  635. }
  636. }
  637. function searchDims(val, vls){
  638. var tab = $('#dimfiltertab').tabs('getSelected');
  639. var dimid = curTmpInfo.ckid;
  640. var compId = curTmpInfo.compId.replace("T", "");
  641. var comp = findCompById(compId);
  642. var url = 'paramSearch.action?dsid='+comp.dsid+'&id='+dimid+'&cubeId=' + comp.cubeId;
  643. $.ajax({
  644. type:"POST",
  645. url:url,
  646. data:{keyword:val, vals:vls, t:Math.random()},
  647. dataType:'HTML',
  648. success:function(resp){
  649. $('#dimfiltertab').tabs('update', {
  650. tab: tab,
  651. options: {
  652. content:"<div class=\"dfilter\">"+resp+"</div>"
  653. }
  654. });
  655. }
  656. });
  657. }
  658. function filterDims(){
  659. var dimid = curTmpInfo.ckid;
  660. var compId = curTmpInfo.compId.replace("T", "");
  661. var pos = curTmpInfo.pos;
  662. var name = curTmpInfo.dimname;
  663. //获取组件的JSON对象
  664. var comp = findCompById(compId);
  665. var dims = null;
  666. if(pos == 'col'){
  667. dims = comp.cols;
  668. }else{
  669. dims = comp.rows;
  670. }
  671. var dim_type;
  672. for(var i=0; i<dims.length; i++){
  673. if(dims[i].id == dimid){
  674. dim_type = dims[i].type;
  675. break;
  676. }
  677. }
  678. $('#pdailog').dialog({
  679. title: name + ' - 维度筛选',
  680. width: 300,
  681. height: dim_type=="frd" ? 341 : 310,
  682. closed: false,
  683. cache: false,
  684. modal: true,
  685. content:'<div id="div_dimfilter"><div class="panel-loading">Loading...</div></div>',
  686. buttons:[{
  687. text:'确定',
  688. iconCls:'icon-ok',
  689. handler:function(){
  690. //获取DIM
  691. var dim = null;
  692. for(var i=0; i<dims.length; i++){
  693. if(dims[i].id == dimid){
  694. dim = dims[i];
  695. break;
  696. }
  697. }
  698. //获取选择项
  699. var tab = $('#dimfiltertab').tabs('getSelected');
  700. var index = $('#dimfiltertab').tabs('getTabIndex',tab);
  701. if("day" == dim.type && index == 0){
  702. var st = $("#dimfiltertab #dft2").val();
  703. var ed = $("#dimfiltertab #dft1").val();
  704. //判断是否st < ed
  705. if(Number(st.replace(/-/g, "")) > Number(ed.replace(/-/g, ""))){
  706. msginfo("您选择的开始日期不能大于结束日期。", "error");
  707. return;
  708. }
  709. dim.startdt = st;
  710. dim.enddt = ed;
  711. dim.filtertype = 1;
  712. delete dim.vals;
  713. }else if("month" == dim.type && index == 0){
  714. var st = $("#dimfiltertab #dfm2").val();
  715. var ed = $("#dimfiltertab #dfm1").val();
  716. //判断是否st < ed
  717. if(Number(st) > Number(ed)){
  718. msginfo("您选择的开始月份不能大于结束月份。", "error");
  719. return;
  720. }
  721. dim.startmt = st;
  722. dim.endmt = ed;
  723. dim.filtertype = 1;
  724. delete dim.vals;
  725. }else{
  726. //获取勾选值
  727. var vals = "";
  728. var seles = $("#pdailog input[name='dimval']:checkbox:checked");
  729. seles.each(function(a, b){
  730. if(a >= 10){ //只能最多选10个
  731. return;
  732. }
  733. vals = vals + $(this).val();
  734. if(a == seles.size() - 1 || a == 9){
  735. }else{
  736. vals = vals + ',';
  737. }
  738. });
  739. dim.vals = vals;
  740. dim.filtertype = 2;
  741. delete dim.startmt;
  742. delete dim.endmt;
  743. delete dim.startdt;
  744. delete dim.enddt;
  745. }
  746. curTmpInfo.isupdate = true;
  747. tableView(comp, compId);
  748. $('#pdailog').dialog('close');
  749. }
  750. },{
  751. text:'取消',
  752. iconCls:"icon-cancel",
  753. handler:function(){
  754. $('#pdailog').dialog('close');
  755. }
  756. }]
  757. });
  758. var vals = "";
  759. var dimtp = "";
  760. var filtertype = ""; //用来筛选的方式,1为区间,2为值筛选
  761. var curDim = null;
  762. for(var i=0; i<dims.length; i++){
  763. if(dims[i].id == dimid){
  764. vals = (dims[i].vals?dims[i].vals:"");
  765. dimtp = dims[i].type;
  766. filtertype = dims[i].filtertype == undefined ? "" : dims[i].filtertype;
  767. curDim = dims[i];
  768. break;
  769. }
  770. }
  771. var url = (curTmpInfo.filterUrl ? curTmpInfo.filterUrl :"DimFilter.action")+"?dsid="+comp.dsid+"&cubeId="+comp.cubeId+"&filtertype="+filtertype+"&id="+dimid;
  772. if(dimtp == 'month'){
  773. url = url + "&st="+(curDim.startmt == undefined ? "" : curDim.startmt);
  774. url = url + "&end="+(curDim.endmt == undefined ? "" : curDim.endmt);
  775. }
  776. if(dimtp == 'day'){
  777. url = url + "&st="+(curDim.startdt == undefined ? "" : curDim.startdt);
  778. url = url + "&end="+(curDim.enddt == undefined ? "" : curDim.enddt);
  779. url = url + "&dateformat=" + curDim.dateformat?curDim.dateformat:"";
  780. }
  781. //$('#pdailog').dialog('refresh', url);
  782. $("#pdailog #div_dimfilter").load(url, {vals:vals,t:Math.random()});
  783. }
  784. //添加维度聚合项
  785. function aggreDim(){
  786. var dimid = curTmpInfo.ckid;
  787. var compId = curTmpInfo.compId.replace("T", "");
  788. var pos = curTmpInfo.pos;
  789. var name = curTmpInfo.dimname;
  790. var comp = findCompById(compId);
  791. var dims = null;
  792. if(pos == 'col'){
  793. dims = comp.cols;
  794. }else{
  795. dims = comp.rows;
  796. }
  797. var dim = null;
  798. for(var i=0; i<dims.length; i++){
  799. if(dims[i].id == dimid){
  800. dim = dims[i];
  801. }
  802. }
  803. if(dim.issum == 'y'){
  804. dim.issum = "n";
  805. delete dim.aggre;
  806. curTmpInfo.isupdate = true;
  807. tableView(comp, compId);
  808. return;
  809. }
  810. var ctx = "<div style='line-height:30px; margin:20px 20px 20px 40px;'><span class=\"inputtext\">聚合方式:</span><select id=\"dimaggre\" name=\"dimaggre\" class=\"inputform2\"><option value=\"sum\">求和</option><option value=\"count\">计数</option><option value=\"avg\">平均</option><option value=\"max\">最大</option><option value=\"min\">最小</option><option value=\"var\">方差</option><option value=\"sd\">标准差</option><option value=\"middle\">中位数</option></select></div>";
  811. $('#pdailog').dialog({
  812. title: '维度聚合',
  813. width: 300,
  814. height: 180,
  815. closed: false,
  816. cache: false,
  817. modal: true,
  818. toolbar:null,
  819. content: ctx,
  820. buttons:[{
  821. text:'确定',
  822. iconCls:'icon-ok',
  823. handler:function(){
  824. if(dim.issum == 'y'){
  825. dim.issum = "n";
  826. delete dim.aggre;
  827. }else{
  828. dim.issum = 'y';
  829. dim.aggre = $("#pdailog #dimaggre").val();
  830. }
  831. curTmpInfo.isupdate = true;
  832. tableView(comp, compId);
  833. $('#pdailog').dialog('close');
  834. }
  835. },{
  836. text:'取消',
  837. iconCls:"icon-cancel",
  838. handler:function(){
  839. $('#pdailog').dialog('close');
  840. }
  841. }]
  842. });
  843. }
  844. /**
  845. 判断是否存在date类型的维度,比如day/month/quarter/year
  846. **/
  847. function isExistDateDim(comp, tp){
  848. var ret = false;
  849. if(tp == 'table'){
  850. if(!comp.cols){
  851. return ret;
  852. }
  853. for(var i=0; i<comp.cols.length; i++){
  854. var tp = comp.cols[i].type;
  855. if(tp == 'year' || tp == 'quarter' || tp == 'month' || tp == 'day'){
  856. ret = true;
  857. break;
  858. }
  859. }
  860. if(!comp.rows){
  861. return ret;
  862. }
  863. for(var i=0; i<comp.rows.length; i++){
  864. var tp = comp.rows[i].type;
  865. if(tp == 'year' || tp == 'quarter' || tp == 'month' || tp == 'day'){
  866. ret = true;
  867. break;
  868. }
  869. }
  870. }
  871. if(tp == 'chart'){
  872. if(!comp.chartJson || !comp.chartJson.params){
  873. return ret;
  874. }
  875. for(var i=0; i<comp.chartJson.params.length; i++){
  876. var tp = comp.chartJson.params[i].type;
  877. if(tp == 'year' || tp == 'quarter' || tp == 'month' || tp == 'day'){
  878. ret = true;
  879. break;
  880. }
  881. }
  882. if(!comp.chartJson || !comp.chartJson.xcol){
  883. return ret;
  884. }
  885. var xtype = comp.chartJson.xcol.type;
  886. if(xtype == 'year' || xtype == 'quarter' || xtype == 'month' || xtype == 'day'){
  887. ret = true;
  888. }
  889. }
  890. return ret;
  891. }
  892. function kpiproperty(){
  893. var kpiId = curTmpInfo.ckid;
  894. var compId = curTmpInfo.compId.replace("T", "");
  895. var comp = findCompById(compId);
  896. var kpi = findKpiById(kpiId, comp.kpiJson);
  897. var ctx = "<div style='line-height:30px; margin:5px;'><span class=\"inputtext\">度量名称:</span>"+kpi.kpi_name+"<br><span class=\"inputtext\">度量单位:</span><select id=\"kpiunit\" name=\"kpiunit\" class=\"inputform\"><option value='1'></option><option value='1000'>千</option><option value='10000'>万</option><option value='1000000'>百万</option><option value='100000000'>亿</option></select>"+kpi.unit+"<br><span class=\"inputtext\">格 式 化:</span>"+
  898. "<select id=\"fmt\" name=\"fmt\" class=\"inputform\"><option value=\"\"></option><option value=\"###,##0\">整数</option><option value=\"###,##0.0\">小数(保留1位)</option><option value=\"###,##0.00\">小数(保留2位)</option><option value=\"0.00%\">百分比</option></select></div>";
  899. $('#pdailog').dialog({
  900. title: '度量属性',
  901. width: 400,
  902. height: 230,
  903. closed: false,
  904. cache: false,
  905. modal: true,
  906. toolbar:null,
  907. content: ctx,
  908. buttons:[{
  909. text:'确定',
  910. iconCls:'icon-ok',
  911. handler:function(){
  912. kpi.fmt = $("#pdailog #fmt").val();
  913. kpi.rate = Number($("#pdailog #kpiunit").val());
  914. $('#pdailog').dialog('close');
  915. curTmpInfo.isupdate = true;
  916. tableView(comp, compId);
  917. }
  918. },{
  919. text:'取消',
  920. iconCls:"icon-cancel",
  921. handler:function(){
  922. $('#pdailog').dialog('close');
  923. }
  924. }]
  925. });
  926. //让格式化、聚合方式选中
  927. $("#pdailog #fmt").find("option[value='"+kpi.fmt+"']").attr("selected",true);
  928. $("#pdailog #kpiunit").find("option[value='"+kpi.rate+"']").attr("selected",true);
  929. //$("#pdailog #aggreType").find("option[value='"+kpi.aggre+"']").attr("selected",true);
  930. }
  931. function linkdetail(pms){
  932. var comp = findCompById(1);
  933. $.ajax({
  934. type: "POST",
  935. url: "header.action",
  936. dataType:"JSON",
  937. data: {dsetId:comp.dsetId,dsid:comp.dsid},
  938. success: function(resp){
  939. if($("#dsColumn_div").size() == 0){
  940. $("<div id=\"dsColumn_div\"></div>").appendTo("body");
  941. }
  942. var ctx = "<table id=\"detailTable\"></table>";
  943. $('#dsColumn_div').dialog({
  944. title: '度量提取明细',
  945. width: 660,
  946. height: 400,
  947. closed: false,
  948. cache: false,
  949. modal: true,
  950. toolbar:null,
  951. content: ctx,
  952. toolbar:[{iconCls: 'icon-export',text:"导出",handler: function(){
  953. location.href = 'exportDetail.action';
  954. }}],
  955. onClose:function(){
  956. $('#dsColumn_div').dialog('destroy');
  957. },
  958. buttons:[{
  959. text:'关闭',
  960. iconCls:"icon-ok",
  961. handler:function(){
  962. $('#dsColumn_div').dialog('close');
  963. }
  964. }]
  965. });
  966. var cols = [];
  967. for(i=0; i<resp.length; i++){
  968. cols.push({field:"c"+i,title:resp[i].name,width:'90'});
  969. }
  970. $("#detailTable").datagrid({
  971. fitColumns:true,
  972. pagination:true,
  973. columns:[cols],
  974. singleSelect:true,
  975. pageSize:20,
  976. fit:true,
  977. loader:function(param, func, err){
  978. var json = {pms:pms, dsetId:comp.dsetId,dsid:comp.dsid, page:param.page, rows:param.rows};
  979. $.ajax({
  980. type: "POST",
  981. url: "detail.action",
  982. contentType : "application/json",
  983. dataType:"JSON",
  984. data: JSON.stringify(json),
  985. success: function(resp){
  986. //$("#detailTable").datagrid("loadData", resp);
  987. func(resp);
  988. },
  989. error:function(resp){
  990. $.messager.alert('出错了','系统出错,请联系管理员。','error');
  991. }
  992. });
  993. }
  994. });
  995. },
  996. error:function(resp){
  997. $.messager.alert('出错了','系统出错,请联系管理员。','error');
  998. }
  999. });
  1000. }
  1001. function getDimTop(){
  1002. var dimid = curTmpInfo.ckid;
  1003. var compId = curTmpInfo.compId.replace("T", "");
  1004. var pos = curTmpInfo.pos;
  1005. var name = curTmpInfo.dimname;
  1006. var comp = findCompById(compId);
  1007. var dims = null;
  1008. if(pos == 'col'){
  1009. dims = comp.cols;
  1010. }else{
  1011. dims = comp.rows;
  1012. }
  1013. var dim = null;
  1014. for(var i=0; i<dims.length; i++){
  1015. if(dims[i].id == dimid){
  1016. dim = dims[i];
  1017. }
  1018. }
  1019. var ctx = "<div style=\"margin:20px;\"><span class=\"inputtext\">维度取Top:</span><input type=\"text\" id=\"top\" name=\"top\" size=\"5\" value=\""+(dim.top?dim.top:"")+"\"><br/><span class=\"inputtext\"></span><select id=\"type\" name=\"type\" class=\"inputform2\"><option value=\"number\" "+(dim.topType=="number"?"selected":"")+">数字</option><option value=\"percent\" "+(dim.topType=="percent"?"selected":"")+">百分比</option></select></div>";
  1020. $('#pdailog').dialog({
  1021. title: '维度取Top',
  1022. width: 360,
  1023. height: 170,
  1024. closed: false,
  1025. cache: false,
  1026. modal: true,
  1027. toolbar:null,
  1028. content: ctx,
  1029. buttons:[{
  1030. text:'完成',
  1031. iconCls:"icon-ok",
  1032. handler:function(){
  1033. var top = $("#pdailog #top").numberbox("getValue");
  1034. var type = $("#pdailog #type").val();
  1035. dim.top = top;
  1036. dim.topType = type;
  1037. $('#pdailog').dialog('close');
  1038. tableView(comp, compId);
  1039. }
  1040. },{
  1041. text:'取消',
  1042. iconCls:"icon-cancel",
  1043. handler:function(){
  1044. $('#pdailog').dialog('close');
  1045. }
  1046. }]
  1047. });
  1048. $("#pdailog #top").numberbox({width:180, height:28});
  1049. }
  1050. function kpisort(tp){
  1051. var kpiId = curTmpInfo.ckid;
  1052. var compId = curTmpInfo.compId.replace("T", "");
  1053. var comp = findCompById(compId);
  1054. for(i=0; i<comp.kpiJson.length; i++){
  1055. if(comp.kpiJson[i].kpi_id == kpiId){
  1056. comp.kpiJson[i].sort = tp;
  1057. }else{
  1058. comp.kpiJson[i].sort = '';
  1059. }
  1060. }
  1061. curTmpInfo.isupdate = true;
  1062. tableView(comp, compId);
  1063. }
  1064. function dimsort(tp){
  1065. var dimid = curTmpInfo.ckid;
  1066. var compId = curTmpInfo.compId.replace("T", "");
  1067. var pos = curTmpInfo.pos;
  1068. var name = curTmpInfo.dimname;
  1069. //获取组件的JSON对象
  1070. var comp = findCompById(compId);
  1071. var dims = null;
  1072. if(pos == 'col'){
  1073. dims = comp.cols;
  1074. }else{
  1075. dims = comp.rows;
  1076. }
  1077. for(var i=0; i<dims.length; i++){
  1078. if(dims[i].id == dimid){
  1079. dims[i].dimord = tp;
  1080. break;
  1081. }
  1082. }
  1083. //进行维度排序时,清除度量的排序信息
  1084. for(i=0; i<comp.kpiJson.length; i++){
  1085. comp.kpiJson[i].sort = '';
  1086. }
  1087. curTmpInfo.isupdate = true;
  1088. tableView(comp, compId);
  1089. $("#dimoptmenu").menu("hide")
  1090. }
  1091. //维度交换行列
  1092. function dimexchange(){
  1093. var dimid = curTmpInfo.ckid;
  1094. var compId = curTmpInfo.compId.replace("T", "");
  1095. var pos = curTmpInfo.pos;
  1096. var name = curTmpInfo.dimname;
  1097. //获取组件的JSON对象
  1098. var comp = findCompById(compId);
  1099. if(pos == 'col'){
  1100. //先移除维度
  1101. var idx = 0;
  1102. var tmp = null;
  1103. var dims = comp.cols;
  1104. for(var i=0; i<dims.length; i++){
  1105. if(dims[i].id == dimid){
  1106. idx = i;
  1107. tmp = dims[i];
  1108. break;
  1109. }
  1110. }
  1111. //如果维度有分组,分组必须相同
  1112. var group = tmp.grouptype;
  1113. if(group != null && findGroup(comp.cols, group, tmp)){
  1114. msginfo("移动失败,同一分组的维度必须在同一行/列标签。", "error");
  1115. return;
  1116. }
  1117. comp.cols.splice(idx, 1);
  1118. //再添加维度
  1119. comp.rows.push(tmp);
  1120. }
  1121. if(pos == 'row'){
  1122. //先移除维度
  1123. var idx = 0;
  1124. var tmp = null;
  1125. var dims = comp.rows;
  1126. for(var i=0; i<dims.length; i++){
  1127. if(dims[i].id == dimid){
  1128. idx = i;
  1129. tmp = dims[i];
  1130. break;
  1131. }
  1132. }
  1133. //如果维度有分组,分组必须相同
  1134. var group = tmp.grouptype;
  1135. if(group != null && findGroup(comp.rows, group, tmp)){
  1136. msginfo("移动失败,同一分组的维度必须在同一行/列标签。", "error");
  1137. return;
  1138. }
  1139. comp.rows.splice(idx, 1);
  1140. //再添加维度
  1141. comp.cols.push(tmp);
  1142. }
  1143. curTmpInfo.isupdate = true;
  1144. tableView(comp, compId);
  1145. }
  1146. function dimmove(tp){
  1147. var dimid = curTmpInfo.ckid;
  1148. var compId = curTmpInfo.compId.replace("T", "");
  1149. var pos = curTmpInfo.pos;
  1150. var name = curTmpInfo.dimname;
  1151. //获取组件的JSON对象
  1152. var comp = findCompById(compId);
  1153. var dims = null;
  1154. if(pos == 'col'){
  1155. dims = comp.cols;
  1156. }else{
  1157. dims = comp.rows;
  1158. }
  1159. if(dims.length <= 1){
  1160. msginfo('无效移动。', "error");
  1161. return;
  1162. }
  1163. for(var i=0; i<dims.length; i++){
  1164. if(dims[i].id == dimid){
  1165. if(tp == 'left'){
  1166. if(i <= 0){
  1167. msginfo('无效移动。', "error");
  1168. return;
  1169. }else{
  1170. var tp = dims[i - 1];
  1171. dims[i - 1] = dims[i];
  1172. dims[i] = tp;
  1173. curTmpInfo.isupdate = true;
  1174. tableView(comp, compId);
  1175. $("#dimoptmenu").menu("hide");
  1176. return;
  1177. }
  1178. }else
  1179. if(tp == 'right'){
  1180. if( i >= dims.length - 1){
  1181. msginfo('无效移动。', "error");
  1182. return;
  1183. }else{
  1184. var tp = dims[i + 1];
  1185. dims[i + 1] = dims[i];
  1186. dims[i] = tp;
  1187. curTmpInfo.isupdate = true;
  1188. tableView(comp, compId);
  1189. $("#dimoptmenu").menu("hide");
  1190. return;
  1191. }
  1192. }
  1193. break;
  1194. }
  1195. }
  1196. }
  1197. function getTableHeadJson(compId){
  1198. // var comp = findCompById(compId);
  1199. // var json = {comp:comp, filter:[["92"]] };
  1200. // $.ajax({
  1201. // type:"POST",
  1202. // async:false,
  1203. // url:"Table2JSON!test.action",
  1204. // dataType:"json",
  1205. // data: {json:JSON.stringify(json),"_hideMVDiv":"true"},
  1206. // success: function(resp){
  1207. //
  1208. // }
  1209. // })
  1210. var comp = findCompById(compId);
  1211. if(comp == null){
  1212. msginfo("组件不存在!", "error");
  1213. }
  1214. var ret;
  1215. $.ajax({
  1216. type:"POST",
  1217. async:false,
  1218. url:"Table2JSON.action",
  1219. dataType:"json",
  1220. data: {json:JSON.stringify(comp),"_hideMVDiv":"true"},
  1221. success: function(resp){
  1222. ret = resp;
  1223. }
  1224. });
  1225. return ret;
  1226. }
  1227. function findDimById(dimId, dims){
  1228. var ret = null;
  1229. if(!dims || dims == null){
  1230. return ret;
  1231. }
  1232. for(var i=0; i<dims.length; i++){
  1233. if(dims[i].id == dimId){
  1234. ret = dims[i];
  1235. break;
  1236. }
  1237. }
  1238. return ret;
  1239. }
  1240. function findKpiById(kpiId, kpis){
  1241. var ret = null;
  1242. if(!kpis || kpis == null){
  1243. return ret;
  1244. }
  1245. for(var i=0; i<kpis.length; i++){
  1246. if(kpis[i].kpi_id == kpiId){
  1247. ret = kpis[i];
  1248. break;
  1249. }
  1250. }
  1251. return ret;
  1252. }
  1253. function findParamById(pid){
  1254. var ret = null;
  1255. for(i=0; pageInfo.params&&i<pageInfo.params.length; i++){
  1256. var p = pageInfo.params[i];
  1257. if(p.id == pid){
  1258. ret = p;
  1259. break;
  1260. }
  1261. }
  1262. return ret;
  1263. }
  1264. function kpiExist(kpiId, kpis){
  1265. var ret = false;
  1266. if(!kpis || kpis == null){
  1267. return ret;
  1268. }
  1269. for(var i=0; i<kpis.length; i++){
  1270. if(kpis[i].kpi_id == kpiId){
  1271. ret = true;
  1272. break;
  1273. }
  1274. }
  1275. return ret;
  1276. }
  1277. function dimExist(dimId, dims){
  1278. var ret = false;
  1279. if(!dims || dims == null){
  1280. return ret;
  1281. }
  1282. for(var i=0; i<dims.length; i++){
  1283. if(dims[i].id == dimId){
  1284. ret = true;
  1285. break;
  1286. }
  1287. }
  1288. return ret;
  1289. }
  1290. function findCompById(id){
  1291. var ret = null;
  1292. for(i=0;i<pageInfo.comps.length; i++){
  1293. var t = pageInfo.comps[i];
  1294. if(t.id == id){
  1295. ret = t;
  1296. break;
  1297. }
  1298. }
  1299. return ret;
  1300. }