dinge.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /**
  2. * Created by Syusuke on 2017/3/17.
  3. */
  4. function getQueryString(key){
  5. var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
  6. var result = window.location.search.substr(1).match(reg);
  7. return result?decodeURIComponent(result[2]):null;
  8. }
  9. //---------------------------------------------------页面跳转
  10. var params = {}
  11. $("#dinge").click(function(){
  12. $(this).attr('href', "/rationLibEditor/rationLib" + "?params=" + JSON.stringify(params))
  13. })
  14. $("#gongliao").click(function(){
  15. $(this).attr('href', "/rationLibEditor/gongliao" + "?params=" + JSON.stringify(params))
  16. });
  17. //----------------------------------------------------页面初始化
  18. $(document).ready(function(){
  19. rationOprObj.initParam();
  20. mkRationItemSpread();
  21. });
  22. var rationOprObj = {
  23. initParam : function() {
  24. var me = this, rationLibName = getQueryString("repository");//获取定额库参数
  25. if (rationLibName) {
  26. params.realLibName = rationLibName;
  27. me.getRationTree();
  28. } else{
  29. params = JSON.parse(getQueryString("params"));
  30. me.getRationTree();
  31. }
  32. },
  33. getRationTree: function(){
  34. var me = this;
  35. $.ajax({
  36. type:"POST",
  37. url:"api/getRationTree",
  38. data:{"rationLibName": params.realLibName},
  39. dataType:"json",
  40. cache:false,
  41. timeout:20000,
  42. success:function(result,textStatus,status){
  43. if(status.status == 200) {
  44. me.createRationTree(result.data);
  45. }
  46. },
  47. error:function(err){
  48. alert(err.responseText.error)
  49. }
  50. })
  51. },
  52. createRationTree: function(sourceData){
  53. var treeArr = tree_Data_Helper.buildTreeNodeDirectly(sourceData);
  54. treeObj = $.fn.zTree.init($("#treeDemo"), setting, treeArr);
  55. }
  56. }
  57. function addRootNode(){
  58. var rawNode = {ParentID: -1, NextSiblingID: -1, name: "新增节点"};
  59. addNewNode(rawNode, function(err, rst){
  60. if (!(err)) {
  61. var newNodes = [], isSilent = false;
  62. newNodes.push({ rationRepId: rst.data.rationRepId, ID: rst.data.ID, ParentID:-1, NextSiblingID:-1, name:"新增节点",isParent:true, items:[]});
  63. if (treeObj) {
  64. treeObj.addNodes(null, -1, newNodes, isSilent);
  65. } else {
  66. treeObj = $.fn.zTree.init($("#treeDemo"), setting, newNodes);
  67. }
  68. }
  69. });
  70. }
  71. //--------------------------------------------------------树处理事件
  72. var newCount = 13;
  73. //新增树节点
  74. function addHoverDom(treeId, treeNode) {
  75. var sObj = $("#" + treeNode.tId + "_span");
  76. if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0||(treeNode.level==2)) return;
  77. var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
  78. + "' title='add node' onfocus='this.blur();'></span>";
  79. sObj.after(addStr);
  80. var btn = $("#addBtn_"+treeNode.tId);
  81. if (btn) btn.bind("click", function(){
  82. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  83. if((treeNode.level==0)){
  84. var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:true, name:"请输入章节名称",items:[]});
  85. }
  86. else{
  87. var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:false, name:"请输入章节名称"});
  88. }
  89. saveNewSection(newNode[0]);
  90. var pnode = newNode[0].getPreNode()
  91. if(pnode){
  92. pnode.nId = newNode[0].id;
  93. saveNewSection(pnode);
  94. }
  95. return false;
  96. });
  97. };
  98. //增加新节点
  99. function addNewNode(rawNode, callback) {
  100. $.ajax({
  101. type:"POST",
  102. url:"api/createNewNode",
  103. data:{"rationLibName":params.realLibName,"rawNodeData": JSON.stringify(rawNode)},
  104. dataType:"json",
  105. cache:false,
  106. timeout:1000,
  107. success: function(result,textStatus,status){
  108. callback(false, result);
  109. },
  110. error:function(err){
  111. callback(err);
  112. }
  113. })
  114. };
  115. //保存新增的节点
  116. function saveNewSection(n){
  117. var sec={};
  118. sec.sectionId = n.id;
  119. sec.parentId = n.pId;
  120. sec.nextSiblingId = n.nId;
  121. sec.name = n.name;
  122. var section = JSON.stringify(sec);
  123. $.ajax({
  124. type:"POST",
  125. url:"api/addSection",
  126. data:{"rationLibName":params.realLibName,"rationSection":section},
  127. dataType:"json",
  128. cache:false,
  129. timeout:1000,
  130. success:function(result,textStatus,status){
  131. },
  132. error:function(){
  133. }
  134. })
  135. }
  136. //编辑树节点事件(添加节点到数据库)
  137. function onRename(e, treeId, treeNode, isCancel) {
  138. saveNewSection(treeNode);
  139. }
  140. function onRemove(e, treeId, treeNode) {
  141. var id = treeNode.id;
  142. var pNodes = treeNode.getParentNode().items;
  143. for(var i=0;i<pNodes.length;i++){
  144. if(pNodes[i].nId==id){
  145. pNodes[i].nId = -1;
  146. saveNewSection(pNodes[i]);
  147. }
  148. }
  149. $.ajax({
  150. type:"POST",
  151. url:"api/deleteSection",
  152. data:{"rationLibName":params.realLibName,"sectionID": treeNode.id},
  153. dataType:"json",
  154. cache:false,
  155. timeout:1000,
  156. success:function(result,textStatus,status){
  157. //if(result){
  158. // caseDeleteTreeNode(result.data)
  159. //}
  160. },
  161. error:function(){
  162. }
  163. })
  164. removeSection(id)
  165. $("#rationTbody").html("");
  166. $("#rationGLJTbody").html("");
  167. }
  168. //--------------------------------------------------------定额spreadjs
  169. var spSetting_ration = {
  170. spType:"Ration",
  171. header:[
  172. {headerName:"编码",headerWidth:120,data:"rationCode"},
  173. {headerName:"名称",headerWidth:400,data:"rationName"},
  174. {headerName:"单位",headerWidth:120,data:"unit"},
  175. {headerName:"基价",headerWidth:120,data:"basePrice"},
  176. {headerName:"显示名称(以%s表示参数)",headerWidth:450,data:"caption"},
  177. {headerName:"取费专业",headerWidth:120,data:"feeType"}
  178. ],
  179. view:{
  180. comboBox:[
  181. {row:-1,col:2,rowCount:-1,colCount:1}
  182. ],
  183. lockedCells:[
  184. {row:-1,col:3,rowCount:-1, colCount:1}
  185. ]
  186. }
  187. };
  188. var spSetting_rationGLJ = {
  189. spType:"RationGLJ",
  190. header:[
  191. {headerName:"编码",headerWidth:160},
  192. {headerName:"名称",headerWidth:400},
  193. {headerName:"单位",headerWidth:160},
  194. {headerName:"单位基价",headerWidth:160},
  195. {headerName:"定额消耗",headerWidth:160},
  196. {headerName:"类型",headerWidth:160},
  197. {headerName:"操作",headerWidth:130}
  198. ],
  199. view:{
  200. comboBox:[],
  201. lockedCells:[
  202. {row:-1,col:1,rowCount:-1, colCount:1},
  203. {row:-1,col:2,rowCount:-1, colCount:1},
  204. {row:-1,col:3,rowCount:-1, colCount:1},
  205. {row:-1,col:5,rowCount:-1, colCount:1},
  206. {row:-1,col:6,rowCount:-1, colCount:1}
  207. ]
  208. }
  209. };
  210. function mkRationItemSpread(){
  211. var rationSpread = $.fn.Spread.init($("#rationItemsSheet"),spSetting_ration);
  212. var rationGLJSpread = $.fn.Spread.init($("#rationGLJSheet"),spSetting_rationGLJ);
  213. }