823d5c2f9fc219acfa9c422650900bb3d71d02bb.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. //获取用户Id
  2. var userId = top.com.sinosoft.lz.system.user.LoginInfo.getUser_id();
  3. var real_name = top.com.sinosoft.lz.system.user.LoginInfo.getReal_name();
  4. //获取用户部门Id
  5. var corpId = top.com.sinosoft.lz.system.user.LoginInfo.getCorp_ids();
  6. var comp_name = top.com.sinosoft.lz.system.user.LoginInfo.getCorp_names();
  7. var dept_name = top.com.sinosoft.lz.system.user.LoginInfo.getDeptnames();
  8. var _thisUrl = decodeURI(decodeURI(window.location.href));
  9. //报表类型
  10. var report_type = _thisUrl.split("?")[3];
  11. var report_name = _thisUrl.split("?")[4];
  12. //事件类型
  13. var affairId = _thisUrl.split("?")[1];
  14. //事件名称
  15. var affair = _thisUrl.split("?")[2];
  16. //初始已配置的单位数据
  17. var beginCompId = [];
  18. //初始单位及报表字段配置数据
  19. var beginData = "";
  20. //选择的单位及单位名称
  21. var selectedCompId = [];
  22. var selectedCompName = [];
  23. //选择单位后自动配上所有的字段
  24. var columnData = getThing($.pathname() + "/ws/xianlutingyun/XianlutingyunService/getConfigurationColumns",{report_type:report_type},"json");
  25. var grid;
  26. var mycol,title;
  27. var testData;
  28. //var selectData={"list":[{"value":"checked","key":"√"}]};
  29. function initComplete(){
  30. $("#title").text(affair+"【"+report_name+"】"+"配置");
  31. //查询表头
  32. getColumns();
  33. //查询配置
  34. getColumnData();
  35. initGrid();
  36. $(".hand").hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");});
  37. $(".l-grid-hd-cell").removeClass("l-grid-hd-cell-checkbox");
  38. }
  39. function goback(){
  40. window.history.go(-1);
  41. }
  42. //获取(表头)
  43. function getColumns() {
  44. var urls = $.pathname() + "/ws/xianlutingyun/XianlutingyunService/getReportColumns";
  45. $.ajax({
  46. url : urls,
  47. type : 'post',
  48. timeout : 300000,
  49. async : false,
  50. data : {
  51. "report_type" : report_type
  52. },
  53. dataType : 'text',
  54. success : function(data) {
  55. mycol = eval('(' + data + ')');
  56. title = eval('(' + data + ')')[0].display;
  57. },
  58. error : function(e) {
  59. $.messager.alert('查询表头失败!', '访问服务失败!', 'error');
  60. }
  61. });
  62. }
  63. /**
  64. * 加载单位和报表字段配置数据
  65. */
  66. function getColumnData(){
  67. var urls = $.pathname() + "/ws/xianlutingyun/XianlutingyunService/getColumnsData";
  68. $.ajax({
  69. url : urls,
  70. type : 'post',
  71. data : {"report_type":report_type,"corp_id":corpId,"affair":affairId},
  72. dataType : 'json',
  73. async : false,
  74. success : function(result){
  75. var data = result.data;
  76. beginCompId = [];
  77. selectedCompId = [];
  78. for(var i=0;i<data.length;i++){
  79. beginCompId.push(data[i].COMP_ID);
  80. selectedCompId.push(data[i].COMP_ID);
  81. }
  82. testData = result;
  83. },
  84. error : function(){
  85. $.messager.alert('查询配置表字段失败!', '访问服务失败!', 'error');
  86. }
  87. });
  88. }
  89. function initGrid(){
  90. grid = null;
  91. grid = $("#maingrid").quiGrid({
  92. columns : mycol,
  93. data : testData,
  94. usePager : false,//是否分页
  95. headerRowHeight : 50,//表头行的高度
  96. rownumbers : true,//是否显示行号
  97. rownumbersColWidth : 30,
  98. enabledEdit : true,//是否可编辑
  99. checkbox : true,
  100. checkboxColWidth : 30,
  101. width : "auto",
  102. /*height : "100%",*/
  103. multihead : true,//多表头模式时设为true
  104. enabledSort : false,//是否允许排序
  105. alternatingRow : false,//是否启用奇偶行变色效果
  106. //allowUnSelectRow : true,//设为true,则第一次点击选中行,第二次点击可以取消选中行
  107. onBeforeEdit : onBeforeEdit,
  108. onAfterEdit : onAfterEdit,
  109. toolbar : {
  110. items : [
  111. {text: '上移', click:upRow, iconClass: 'shangyi_tem'},
  112. {line:true},
  113. {text: '下移', click:downRow, iconClass: 'xiayi_tem'},
  114. {line:true},
  115. {text: '置顶', click:stickRow, iconClass : 'zhiding_tem'},
  116. {text:"重置",click:reset,iconClass:"icon_add", position : "right"},
  117. {line:true,position : "right"},
  118. {text:"单位配置",click:configuration, iconClass:"icon_edit", position : "right"},
  119. {line:true, position : "right"},
  120. {text:"保存",click:save, iconClass:"icon_add", position : "right"}
  121. ]
  122. },
  123. onAfterShowData : function(){
  124. setContentHeight();
  125. }
  126. });
  127. }
  128. function upRow(){
  129. //选中一行
  130. var rows = grid.getSelectedRows();
  131. if (rows.length == 0) {
  132. top.Dialog.alert('请选择一行记录操作');
  133. return;
  134. }else if(rows.length > 1){
  135. top.Dialog.alert('一次只能选择一行记录操作');
  136. return;
  137. }
  138. grid.up(rows[0]);
  139. }
  140. function downRow(){
  141. //选中一行或多行
  142. var rows = grid.getSelectedRows();
  143. if (rows.length == 0) {
  144. top.Dialog.alert('请选择一行记录操作');
  145. return;
  146. }else if(rows.length > 1){
  147. top.Dialog.alert('一次只能选择一行记录操作');
  148. return;
  149. }
  150. grid.down(rows[0]);
  151. }
  152. function stickRow(){
  153. //选中一行或多行
  154. var rows = grid.getSelectedRows();
  155. if (rows.length == 0) {
  156. top.Dialog.alert('请选择一行记录操作');
  157. return;
  158. }else if(rows.length > 1){
  159. top.Dialog.alert('一次只能选择一行记录操作');
  160. return;
  161. }
  162. var index = rows[0]["__index"];
  163. if(index==0){
  164. top.Dialog.alert('已经在第一行了');
  165. return;
  166. }
  167. grid.move(rows[0],0,false);
  168. }
  169. function onBeforeEdit(e){
  170. var name = e.column.name;
  171. if(e.value=="√"){
  172. // e.column["editor"]["data"]={"list":[{"value":"checked","key":"√"},{"value":"nochecked","key":"x"}]};
  173. e.record[name]="×";
  174. }else{
  175. // e.column["editor"]["data"]={"list":[{"value":"checked","key":"√"}]};
  176. e.record[name]="√";
  177. }
  178. }
  179. function onAfterEdit(e){
  180. }
  181. //表字段列自定义格式
  182. function showSelect(rowdata, rowindex, value, column){
  183. if(value=="√"){
  184. return "√";
  185. }
  186. }
  187. //单位列自定义格式
  188. function _addStatus(rowdata, rowindex, value, column){
  189. var id = '"'+rowdata.COMP_ID+'"';
  190. var name = '"'+rowdata.COMP_NAME+'"';
  191. return "<div class='comp' title='点击可预览表字段'><a href='javascript:void(0)' onclick='newHtml("+id+","+name+")'>"+value+"</a></div>";
  192. }
  193. function newHtml(id,name){
  194. $.indexOpenSelfWindow("/nwyj/page/business/em/report/ViewConfiguration.html?"+affairId+"?"+id+"?"+name+"?"+report_type+"?"+report_name);
  195. }
  196. function headStatus(rowdata, rowindex, value, column){
  197. var flag = rowdata.columns==undefined?true:false;//true--单表头,false--多表头
  198. var columns = flag?rowdata.name:rowdata.columns;
  199. var cols = [];
  200. for(var i=0;i<columns.length;i++){
  201. cols.push(flag?"_"+columns:"_"+columns[i].name);
  202. }
  203. // return '<div class="padding_left10"><span class="icon_lightOn hand" title="全选列操作" data-column=\''+cols+'\' onclick="getAll(this)">'+rowdata.head_name+'</span></div>';
  204. return '<div class="padding_left10"><a class="hand" title="反选列操作" href="javascript:void(0)" onclick="getAll(this)" data-column=\''+cols+'\'>'+rowdata.head_name+'</a></div>';
  205. }
  206. function getAll(obj){
  207. var _this = $(obj);
  208. var columns = _this.attr("data-column");
  209. var data = grid.getData();
  210. for(var i=0;i<data.length;i++){
  211. var rowdata = data[i];
  212. for(var j in rowdata){
  213. if(columns.indexOf("_"+j)>-1 && rowdata[j] == "×"){
  214. rowdata[j] = "√";
  215. }else if(columns.indexOf("_"+j)>-1 && rowdata[j] == "√"){
  216. rowdata[j] = "×";
  217. }
  218. }
  219. }
  220. grid.options.data = {"rows":data};
  221. grid.loadData();
  222. }
  223. /**
  224. * 单位配置
  225. */
  226. function configuration(){
  227. $(this).addClass("selectedButton");
  228. var diag = new top.Dialog();// 定义一个窗口对象
  229. diag.Title = "选择组织";// 窗口标题
  230. diag.URL = "/nwyj/page/business/em/report/selectDept.html";
  231. diag.Height = 450;
  232. diag.Width = 380;
  233. diag.ID = "ORG_IFRAME";
  234. diag.ShowButtonRow = true;
  235. diag.ShowCancelButton = false;// 不显示取消按钮
  236. // diag.ShowOkButton = false;
  237. diag.ButtonAlign = "center";// 按钮居中
  238. diag.OkButtonText=" 确 定 ";
  239. diag.OKEvent = function(){
  240. var data = grid.getData();//表格数据
  241. if(beginCompId.length==0){
  242. data = [];
  243. }else{
  244. var len = data.length;
  245. for(var i=0;i<len;i++){
  246. for(var j in data){
  247. if($.inArray(data[j]["COMP_ID"],beginCompId)==-1){
  248. data.splice(j, 1);
  249. break;
  250. }
  251. }
  252. }
  253. }
  254. var selectedComp = diag.innerFrame.contentWindow.queDing();
  255. selectedCompId = [];//单位
  256. selectedCompname = [];//单位名称
  257. for(var m=0;m<selectedComp.length;m++){
  258. var comp = selectedComp[m].split(",");
  259. selectedCompId.push(comp[0]);
  260. selectedCompname.push(comp[1]);
  261. }
  262. for(var i=0;i<selectedCompId.length;i++){
  263. var id = selectedCompId[i];
  264. var name = selectedCompname[i];
  265. if($.inArray(id,beginCompId)==-1){//不存在,则新增
  266. var addData = {};
  267. addData["COMP_ID"] = id;
  268. addData["COMP_NAME"] = name;
  269. for(var n in columnData[0]){
  270. addData[n] = columnData[0][n];
  271. }
  272. data.push(addData);
  273. }
  274. }
  275. for(var j=0;j<beginCompId.length;j++){
  276. var id = beginCompId[j];
  277. if($.inArray(id,selectedCompId)==-1){//不存在,则删除
  278. for(var k=0;k<data.length;k++){
  279. if(id==data[k].COMP_ID){
  280. data.splice(k,1);
  281. break;
  282. }
  283. }
  284. }
  285. }
  286. grid.options.data = {"rows":data};
  287. grid.loadData();
  288. diag.close();
  289. setContentHeight();
  290. };
  291. diag.CancelEvent = function(){
  292. setContentHeight();
  293. diag.close();
  294. };
  295. diag.show();// 显示窗口
  296. diag.OnLoad=function(){
  297. diag.innerFrame.contentWindow.showData(selectedCompId.join(","),report_type,affair);
  298. };
  299. diag.addButton("testBtn5"," 清除 ",function(){
  300. diag.innerFrame.contentWindow.qingChu();
  301. });
  302. diag.addButton("testBtn6"," 全选 ",function(){
  303. diag.innerFrame.contentWindow.quanXuan();
  304. });
  305. }
  306. /**
  307. * 保存单位和报表字段配置
  308. */
  309. function save(){
  310. var urls = $.pathname() + "/ws/xianlutingyun/XianlutingyunService/saveReportConfiguration";
  311. var data = grid.getData();
  312. var params = {"corp_id":corpId,"corp_name":comp_name,"report_type":report_type,"affair":affairId,"data":JSON.stringify(data)};
  313. $.ajax({
  314. url : urls,
  315. type : 'post',
  316. data : params,
  317. dataType : 'json',
  318. success : function(data){
  319. if(data.Msg.sucsess==true){
  320. var ids = data.Msg.data.split(",");
  321. beginCompId = [];
  322. selectedCompId = [];
  323. for(var c=0;c<ids.length;c++){
  324. if(""!=ids[c]){
  325. beginCompId.push(ids[c]);
  326. selectedCompId.push(ids[c]);
  327. }
  328. }
  329. }
  330. top.Dialog.alert(data.Msg.info);
  331. },
  332. error : function(){
  333. $.messager.alert('保存配置失败!', '访问服务失败!', 'error');
  334. }
  335. });
  336. }
  337. /**
  338. * 重置单位配置,恢复beginCompId
  339. */
  340. function reset(){
  341. top.Dialog.confirm("确定要重置?填写的信息会全部清除,请慎重选择|重置", function() {
  342. getColumnData();
  343. grid.options.data = testData;
  344. grid.loadData();
  345. setContentHeight();
  346. });
  347. }
  348. function setContentHeight(){
  349. var content = $("#maingrid").height();
  350. $(window.document.body).height(content+100);
  351. $(top.document.body).find("#frmright").height($(window.document.body).height());
  352. }