dinge.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. var zTreeOprObj = {
  58. addRootNode: function() {
  59. var me = this, rawNode = {ParentID: -1, NextSiblingID: -1, name: "新增节点"};
  60. me.addNewNode(rawNode, function(err, rst){
  61. if (!(err)) {
  62. var newNodes = [], isSilent = false;
  63. newNodes.push({ rationRepId: rst.data.rationRepId, ID: rst.data.ID, ParentID:-1, NextSiblingID:-1, name:"新增节点",isParent:true, items:[]});
  64. if (treeObj) {
  65. treeObj.addNodes(null, -1, newNodes, isSilent);
  66. } else {
  67. treeObj = $.fn.zTree.init($("#treeDemo"), setting, newNodes);
  68. }
  69. }
  70. });
  71. },
  72. addNewNode : function(rawNode, callback){
  73. $.ajax({
  74. type:"POST",
  75. url:"api/createNewNode",
  76. data:{"rationLibName":params.realLibName,"rawNodeData": JSON.stringify(rawNode)},
  77. dataType:"json",
  78. cache:false,
  79. timeout:1000,
  80. success: function(result,textStatus,status){
  81. callback(false, result);
  82. },
  83. error:function(err){
  84. callback(err);
  85. }
  86. })
  87. },
  88. onRename : function(e, treeId, treeNode, isCancel) {
  89. var nodes = [];
  90. nodes.push(treeNode);
  91. zTreeOprObj.updateNodes(nodes);
  92. },
  93. onBeforeRemove: function(treeId, treeNode){
  94. var nodeIds = [], preNode = treeNode.getPreNode(), preNodeId = -1;
  95. if (preNode) {
  96. preNodeId = preNode.ID;
  97. }
  98. nodeIds.push(treeNode.ID);
  99. for (var i = 0; i < treeNode.items.length; i++) {
  100. nodeIds.push(treeNode.items[i].ID);
  101. }
  102. $.ajax({
  103. type:"POST",
  104. url:"api/deleteNodes",
  105. data:{"nodes": JSON.stringify(nodeIds), "preNodeId": preNodeId, "preNodeNextId": treeNode.NextSiblingID},
  106. dataType:"json",
  107. cache:false,
  108. timeout:5000,
  109. success:function(result,textStatus,status){
  110. //if(result){
  111. // caseDeleteTreeNode(result.data)
  112. //}
  113. },
  114. error:function(){
  115. }
  116. });
  117. return true;
  118. },
  119. updateNodes: function(nodes){
  120. if (nodes && nodes.length > 0) {
  121. var reqData = []
  122. for (var i = 0; i < nodes.length; i++) {
  123. var node = {};
  124. node.rationRepId = nodes[i].rationRepId;
  125. node.ID = nodes[i].ID;
  126. node.ParentID = nodes[i].ParentID;
  127. node.NextSiblingID = nodes[i].NextSiblingID;
  128. node.name = nodes[i].name;
  129. node.__v = nodes[i].__v + 1;
  130. reqData.push(node);
  131. }
  132. $.ajax({
  133. type:"POST",
  134. url:"api/updateNodes",
  135. data:{"nodes": JSON.stringify(reqData)},
  136. dataType:"json",
  137. cache:false,
  138. timeout:5000,
  139. success:function(result,textStatus,status){
  140. console.log(status + ' : ' + result);
  141. },
  142. error:function(){
  143. }
  144. })
  145. }
  146. }
  147. };
  148. //--------------------------------------------------------树处理事件
  149. var newCount = 13;
  150. //新增树节点
  151. function addHoverDom(treeId, treeNode) {
  152. var sObj = $("#" + treeNode.tId + "_span");
  153. if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0||(treeNode.level==2)) return;
  154. var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
  155. + "' title='add node' onfocus='this.blur();'></span>";
  156. sObj.after(addStr);
  157. var btn = $("#addBtn_"+treeNode.tId);
  158. if (btn) btn.bind("click", function(){
  159. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  160. if((treeNode.level==0)){
  161. var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:true, name:"请输入章节名称",items:[]});
  162. }
  163. else{
  164. var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:false, name:"请输入章节名称"});
  165. }
  166. saveNewSection(newNode[0]);
  167. var pnode = newNode[0].getPreNode()
  168. if(pnode){
  169. pnode.nId = newNode[0].id;
  170. saveNewSection(pnode);
  171. }
  172. return false;
  173. });
  174. };
  175. //保存新增的节点
  176. function saveNewSection(n){
  177. var sec={};
  178. sec.sectionId = n.id;
  179. sec.parentId = n.pId;
  180. sec.nextSiblingId = n.nId;
  181. sec.name = n.name;
  182. var section = JSON.stringify(sec);
  183. $.ajax({
  184. type:"POST",
  185. url:"api/addSection",
  186. data:{"rationLibName":params.realLibName,"rationSection":section},
  187. dataType:"json",
  188. cache:false,
  189. timeout:1000,
  190. success:function(result,textStatus,status){
  191. },
  192. error:function(){
  193. }
  194. })
  195. }
  196. //--------------------------------------------------------定额spreadjs
  197. var spSetting_ration = {
  198. spType:"Ration",
  199. header:[
  200. {headerName:"编码",headerWidth:120,data:"rationCode"},
  201. {headerName:"名称",headerWidth:400,data:"rationName"},
  202. {headerName:"单位",headerWidth:120,data:"unit"},
  203. {headerName:"基价",headerWidth:120,data:"basePrice"},
  204. {headerName:"显示名称(以%s表示参数)",headerWidth:450,data:"caption"},
  205. {headerName:"取费专业",headerWidth:120,data:"feeType"}
  206. ],
  207. view:{
  208. comboBox:[
  209. {row:-1,col:2,rowCount:-1,colCount:1}
  210. ],
  211. lockedCells:[
  212. {row:-1,col:3,rowCount:-1, colCount:1}
  213. ]
  214. }
  215. };
  216. var spSetting_rationGLJ = {
  217. spType:"RationGLJ",
  218. header:[
  219. {headerName:"编码",headerWidth:160},
  220. {headerName:"名称",headerWidth:400},
  221. {headerName:"单位",headerWidth:160},
  222. {headerName:"单位基价",headerWidth:160},
  223. {headerName:"定额消耗",headerWidth:160},
  224. {headerName:"类型",headerWidth:160},
  225. {headerName:"操作",headerWidth:130}
  226. ],
  227. view:{
  228. comboBox:[],
  229. lockedCells:[
  230. {row:-1,col:1,rowCount:-1, colCount:1},
  231. {row:-1,col:2,rowCount:-1, colCount:1},
  232. {row:-1,col:3,rowCount:-1, colCount:1},
  233. {row:-1,col:5,rowCount:-1, colCount:1},
  234. {row:-1,col:6,rowCount:-1, colCount:1}
  235. ]
  236. }
  237. };
  238. function mkRationItemSpread(){
  239. var rationSpread = $.fn.Spread.init($("#rationItemsSheet"),spSetting_ration);
  240. var rationGLJSpread = $.fn.Spread.init($("#rationGLJSheet"),spSetting_rationGLJ);
  241. }