dinge.js 8.9 KB

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