dinge.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. initParam();
  20. mkRationItemSpread();
  21. });
  22. function initParam(){
  23. var rationLibName = getQueryString("repository");//获取定额库参数
  24. if(rationLibName) {
  25. params.realLibName = LibName;
  26. getRationTree();
  27. } else{
  28. params = JSON.parse(getQueryString("params"));
  29. getRationTree();
  30. }
  31. }
  32. //---------------------------------------------------初始化章节树界面
  33. function getRationTree(){
  34. $.ajax({
  35. type:"POST",
  36. url:"api/getRationTree",
  37. data:{"rationLibName": params.realLibName},
  38. dataType:"json",
  39. cache:false,
  40. timeout:20000,
  41. success:function(result,textStatus,status){
  42. if(status.status == 200) createRationTree(result.data);//根据返回的全部定额章节对象,构架树。
  43. else{
  44. treeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  45. saveTempTree();
  46. }
  47. },
  48. error:function(err){
  49. alert(err.responseText.error)
  50. }
  51. })
  52. }
  53. //根据返回的节点集合构建树节点
  54. function createRationTree(obj){
  55. var treeArr;
  56. treeArr = makeNodes(obj);
  57. var maxIDNode = obj.reduce(function(a,b){
  58. return (a.id> b.id)?a:b;
  59. });
  60. newCount = maxIDNode.id;
  61. treeObj = $.fn.zTree.init($("#treeDemo"), setting, treeArr);
  62. }
  63. function makeNodes(obj){
  64. var arr=[];
  65. arr = obj.filter(function(x){
  66. return x.parentId==0
  67. })
  68. arr.forEach(function(x){
  69. x.id = x.sectionId;
  70. x.pId = x.parentId;
  71. x.nId = x.nextSiblingId;
  72. x.name = x.name;
  73. x.isParent = true
  74. x.lev = 0
  75. });
  76. arr = sortArray(arr);
  77. for(var i=0;i<arr.length;i++){
  78. var L1 = [];
  79. L1 = obj.filter(function(x){
  80. return x.parentId ==arr[i].id;
  81. });
  82. L1.forEach(function(x){
  83. x.id = x.sectionId;
  84. x.pId = x.parentId;
  85. x.nId = x.nextSiblingId;
  86. x.name = x.name;
  87. x.isParent = true
  88. x.lev = 1
  89. });
  90. L1=sortArray(L1);
  91. for(var j=0; j<L1.length;j++){
  92. var L2 = [];
  93. L2 =obj.filter(function(x){
  94. return x.parentId == L1[j].id;
  95. })
  96. L2.forEach(function(x){
  97. x.id = x.sectionId;
  98. x.pId = x.parentId;
  99. x.nId = x.nextSiblingId;
  100. x.name = x.name;
  101. x.isParent = false;
  102. x.lev = 2
  103. })
  104. L2=sortArray(L2)
  105. L1[j].children = L2;
  106. }
  107. arr[i].children = L1;
  108. }
  109. return arr;
  110. }
  111. function sortArray(arr){
  112. var a = [];
  113. for(var i=0;i<arr.length;i++)
  114. if (arr[i].nextSiblingId == -1)
  115. a.push(arr[i])
  116. for(; a.length < arr.length;){
  117. for(var j=0;j<arr.length;j++) {
  118. if (arr[j].nextSiblingId == a[0].sectionId)
  119. {a.unshift(arr[j]); break;}
  120. }
  121. }
  122. return a ;
  123. }
  124. //新建的定额库保存模板节点
  125. function saveTempTree(){
  126. var N = []
  127. for(i=0;i<zNodes.length;i++){
  128. var node ={}
  129. node.sectionId = zNodes[i].id;
  130. node.parentId = zNodes[i].pId;
  131. node.nextSiblingId = zNodes[i].nId;
  132. node.name =zNodes[i].name;
  133. N.push(node);
  134. }
  135. var rationTempTree = JSON.stringify(N)
  136. $.ajax({
  137. type:"POST",
  138. url:"api/saveTempRationTree",
  139. data:{"rationName":rationLibName,"rationTempTree":rationTempTree},
  140. dataType:"json",
  141. cache:false,
  142. timeout:1000,
  143. success:function(result,textStatus,status){},
  144. error:function(){}
  145. })
  146. }
  147. //--------------------------------------------------------树处理事件
  148. var newCount = 13;
  149. //新增树节点
  150. function addHoverDom(treeId, treeNode) {
  151. var sObj = $("#" + treeNode.tId + "_span");
  152. if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0||(treeNode.level==2)) return;
  153. var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
  154. + "' title='add node' onfocus='this.blur();'></span>";
  155. sObj.after(addStr);
  156. var btn = $("#addBtn_"+treeNode.tId);
  157. if (btn) btn.bind("click", function(){
  158. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  159. if((treeNode.level==0)){
  160. var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:true, name:"请输入章节名称",children:[]});
  161. }
  162. else{
  163. var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:false, name:"请输入章节名称"});
  164. }
  165. saveNewSection(newNode[0]);
  166. var pnode = newNode[0].getPreNode()
  167. if(pnode){
  168. pnode.nId = newNode[0].id;
  169. saveNewSection(pnode);
  170. }
  171. return false;
  172. });
  173. };
  174. //保存新增的节点
  175. function saveNewSection(n){
  176. var sec={};
  177. sec.sectionId = n.id;
  178. sec.parentId = n.pId;
  179. sec.nextSiblingId = n.nId;
  180. sec.name = n.name;
  181. var section = JSON.stringify(sec);
  182. $.ajax({
  183. type:"POST",
  184. url:"api/addSection",
  185. data:{"rationLibName":params.realLibName,"rationSection":section},
  186. dataType:"json",
  187. cache:false,
  188. timeout:1000,
  189. success:function(result,textStatus,status){
  190. },
  191. error:function(){
  192. }
  193. })
  194. }
  195. //编辑树节点事件(添加节点到数据库)
  196. function onRename(e, treeId, treeNode, isCancel) {
  197. saveNewSection(treeNode);
  198. }
  199. function onRemove(e, treeId, treeNode) {
  200. var id = treeNode.id;
  201. var pNodes = treeNode.getParentNode().children;
  202. for(var i=0;i<pNodes.length;i++){
  203. if(pNodes[i].nId==id){
  204. pNodes[i].nId = -1;
  205. saveNewSection(pNodes[i]);
  206. }
  207. }
  208. $.ajax({
  209. type:"POST",
  210. url:"api/deleteSection",
  211. data:{"rationLibName":params.realLibName,"sectionID": treeNode.id},
  212. dataType:"json",
  213. cache:false,
  214. timeout:1000,
  215. success:function(result,textStatus,status){
  216. //if(result){
  217. // caseDeleteTreeNode(result.data)
  218. //}
  219. },
  220. error:function(){
  221. }
  222. })
  223. removeSection(id)
  224. $("#rationTbody").html("");
  225. $("#rationGLJTbody").html("");
  226. }
  227. //--------------------------------------------------------定额spreadjs
  228. var spSetting_ration = {
  229. spType:"Ration",
  230. header:[
  231. {headerName:"编码",headerWidth:120,data:"rationCode"},
  232. {headerName:"名称",headerWidth:400,data:"rationName"},
  233. {headerName:"单位",headerWidth:120,data:"unit"},
  234. {headerName:"基价",headerWidth:120,data:"basePrice"},
  235. {headerName:"显示名称(以%s表示参数)",headerWidth:450,data:"caption"},
  236. {headerName:"取费专业",headerWidth:120,data:"feeType"}
  237. ],
  238. view:{
  239. comboBox:[
  240. {row:-1,col:2,rowCount:-1,colCount:1}
  241. ],
  242. lockedCells:[
  243. {row:-1,col:3,rowCount:-1, colCount:1}
  244. ]
  245. }
  246. };
  247. var spSetting_rationGLJ = {
  248. spType:"RationGLJ",
  249. header:[
  250. {headerName:"编码",headerWidth:160},
  251. {headerName:"名称",headerWidth:400},
  252. {headerName:"单位",headerWidth:160},
  253. {headerName:"单位基价",headerWidth:160},
  254. {headerName:"定额消耗",headerWidth:160},
  255. {headerName:"类型",headerWidth:160},
  256. {headerName:"操作",headerWidth:130}
  257. ],
  258. view:{
  259. comboBox:[],
  260. lockedCells:[
  261. {row:-1,col:1,rowCount:-1, colCount:1},
  262. {row:-1,col:2,rowCount:-1, colCount:1},
  263. {row:-1,col:3,rowCount:-1, colCount:1},
  264. {row:-1,col:5,rowCount:-1, colCount:1},
  265. {row:-1,col:6,rowCount:-1, colCount:1}
  266. ]
  267. }
  268. };
  269. function mkRationItemSpread(){
  270. var rationSpread = $.fn.Spread.init($("#rationItemsSheet"),spSetting_ration);
  271. var rationGLJSpread = $.fn.Spread.init($("#rationGLJSheet"),spSetting_rationGLJ);
  272. }