dinge.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /**
  2. * Created by Syusuke on 2017/3/17.
  3. */
  4. var rationLibName = getQueryString("rationname");//获取定额库参数
  5. function getQueryString(key){
  6. var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
  7. var result = window.location.search.substr(1).match(reg);
  8. return result?decodeURIComponent(result[2]):null;
  9. }
  10. //----------------------------------------------------页面初始化
  11. var properties = {};//综合属性
  12. properties.sectionSelected = "";//选择的章节
  13. properties.rationSelected = "";//选择的定额
  14. function getRealLib(){
  15. $.ajax({
  16. type:"POST",
  17. url:"http://localhost:6060/rationLibEditor/getRealLibName",
  18. data:{"rationName":rationLibName},
  19. async:false,
  20. dataType:"json",
  21. cache:false,
  22. timeout:1000,
  23. success:function(result){
  24. properties.realLibName = result.data[0].DBName
  25. },
  26. error:function(){}
  27. })
  28. }
  29. $(document).ready(function(){
  30. getRealLib();
  31. getRationTree();
  32. mkRationItemSpread();
  33. });
  34. //---------------------------------------------------初始化章节树界面
  35. function getRationTree(){
  36. $.ajax({
  37. type:"POST",
  38. url:"http://localhost:6060/rationLibEditor/getRationTree",
  39. data:{"rationLibName": properties.realLibName},
  40. dataType:"json",
  41. cache:false,
  42. timeout:500000,
  43. success:function(result,textStatus,status){
  44. if(status.status == 200) createRationTree(result.data);//根据返回的全部定额章节对象,构架树。
  45. else{
  46. treeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  47. saveTempTree();
  48. }
  49. },
  50. error:function(){
  51. alert("caonima")
  52. }
  53. })
  54. }
  55. //根据返回的节点集合构建树节点
  56. function createRationTree(obj){
  57. var treeArr;
  58. treeArr = makeNodes(obj);
  59. var maxIDNode = obj.reduce(function(a,b){
  60. return (a.id> b.id)?a:b;
  61. });
  62. newCount = maxIDNode.id;
  63. treeObj = $.fn.zTree.init($("#treeDemo"), setting, treeArr);
  64. }
  65. function makeNodes(obj){
  66. var arr=[];
  67. arr = obj.filter(function(x){
  68. return x.ParentID==0
  69. })
  70. arr.forEach(function(x){
  71. x.id = x.SectionID;
  72. x.pId = x.ParentID;
  73. x.nId = x.NextSiblingID;
  74. x.name = x.Name;
  75. x.isParent = true
  76. x.lev = 0
  77. });
  78. arr = sortArray(arr);
  79. for(var i=0;i<arr.length;i++){
  80. var L1 = [];
  81. L1 = obj.filter(function(x){
  82. return x.ParentID ==arr[i].id;
  83. });
  84. L1.forEach(function(x){
  85. x.id = x.SectionID;
  86. x.pId = x.ParentID;
  87. x.nId = x.NextSiblingID;
  88. x.name = x.Name;
  89. x.isParent = true
  90. x.lev = 1
  91. });
  92. L1=sortArray(L1);
  93. for(var j=0; j<L1.length;j++){
  94. var L2 = [];
  95. L2 =obj.filter(function(x){
  96. return x.ParentID == L1[j].id;
  97. })
  98. L2.forEach(function(x){
  99. x.id = x.SectionID;
  100. x.pId = x.ParentID;
  101. x.nId = x.NextSiblingID;
  102. x.name = x.Name;
  103. x.isParent = false;
  104. x.lev = 2
  105. })
  106. L2=sortArray(L2)
  107. L1[j].children = L2;
  108. }
  109. arr[i].children = L1;
  110. }
  111. return arr;
  112. }
  113. function sortArray(arr){
  114. var a = [];
  115. for(var i=0;i<arr.length;i++)
  116. if (arr[i].NextSiblingID == -1)
  117. a.push(arr[i])
  118. for(; a.length < arr.length;){
  119. for(var j=0;j<arr.length;j++) {
  120. if (arr[j].NextSiblingID == a[0].SectionID)
  121. {a.unshift(arr[j]); break;}
  122. }
  123. }
  124. return a ;
  125. }
  126. //新建的定额库保存模板节点
  127. function saveTempTree(){
  128. var N = []
  129. for(i=0;i<zNodes.length;i++){
  130. var node ={}
  131. node.SectionID = zNodes[i].id;
  132. node.ParentID = zNodes[i].pId;
  133. node.NextSiblingID = zNodes[i].nId;
  134. node.Name =zNodes[i].name;
  135. N.push(node);
  136. }
  137. var rationTempTree = JSON.stringify(N)
  138. $.ajax({
  139. type:"POST",
  140. url:"http://localhost:6060/rationLibEditor/saveTempRationTree",
  141. data:{"rationName":rationLibName,"rationTempTree":rationTempTree},
  142. dataType:"json",
  143. cache:false,
  144. timeout:1000,
  145. success:function(result){
  146. },
  147. error:function(){
  148. }
  149. })
  150. }
  151. //--------------------------------------------------------树处理事件
  152. var newCount = 13;
  153. //新增树节点
  154. function addHoverDom(treeId, treeNode) {
  155. var sObj = $("#" + treeNode.tId + "_span");
  156. if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0||(treeNode.level==2)) return;
  157. var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
  158. + "' title='add node' onfocus='this.blur();'></span>";
  159. sObj.after(addStr);
  160. var btn = $("#addBtn_"+treeNode.tId);
  161. if (btn) btn.bind("click", function(){
  162. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  163. if((treeNode.level==0)){
  164. var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:true, name:"请输入章节名称",children:[]});
  165. }
  166. else{
  167. var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:false, name:"请输入章节名称"});
  168. }
  169. saveNewSection(newNode[0]);
  170. var pnode = newNode[0].getPreNode()
  171. if(pnode){
  172. pnode.nId = newNode[0].id;
  173. saveNewSection(pnode);
  174. }
  175. return false;
  176. });
  177. };
  178. //保存新增的节点
  179. function saveNewSection(n){
  180. var sec={};
  181. sec.SectionID = n.id;
  182. sec.ParentID = n.pId;
  183. sec.NextSiblingID = n.nId;
  184. sec.Name = n.name;
  185. var section = JSON.stringify(sec);
  186. $.ajax({
  187. type:"POST",
  188. url:"http://localhost:6060/rationLibEditor/addSection",
  189. data:{"rationLibName":properties.realLibName,"rationSection":section},
  190. dataType:"json",
  191. cache:false,
  192. timeout:1000,
  193. success:function(result){
  194. },
  195. error:function(){
  196. }
  197. })
  198. }
  199. //编辑树节点事件(添加节点到数据库)
  200. function onRename(e, treeId, treeNode, isCancel) {
  201. saveNewSection(treeNode);
  202. }
  203. function onRemove(e, treeId, treeNode) {
  204. var id = treeNode.id;
  205. var pNodes = treeNode.getParentNode().children;
  206. for(var i=0;i<pNodes.length;i++){
  207. if(pNodes[i].nId==id){
  208. pNodes[i].nId = -1;
  209. saveNewSection(pNodes[i]);
  210. }
  211. }
  212. $.ajax({
  213. type:"POST",
  214. url:"http://localhost:6060/rationLibEditor/deleteSection",
  215. data:{"rationLibName":properties.realLibName,"sectionID": treeNode.id},
  216. dataType:"json",
  217. cache:false,
  218. timeout:1000,
  219. success:function(result){
  220. //if(result){
  221. // caseDeleteTreeNode(result.data)
  222. //}
  223. },
  224. error:function(){
  225. }
  226. })
  227. removeSection(id)
  228. $("#rationTbody").html("");
  229. $("#rationGLJTbody").html("");
  230. }
  231. //--------------------------------------------------------定额spreadjs
  232. var spSetting_ration = {
  233. spType:"Ration",
  234. view:{
  235. comboBox:[
  236. {row:-1,col:2,rowCount:-1,colCount:1}
  237. ],
  238. lockedCells:[
  239. {row:-1,col:3,rowCount:-1, colCount:1}
  240. ]
  241. }
  242. };
  243. var spSetting_rationGLJ = {
  244. spType:"RationGLJ",
  245. view:{
  246. comboBox:[],
  247. lockedCells:[
  248. {row:-1,col:1,rowCount:-1, colCount:1},
  249. {row:-1,col:2,rowCount:-1, colCount:1},
  250. {row:-1,col:3,rowCount:-1, colCount:1},
  251. {row:-1,col:5,rowCount:-1, colCount:1},
  252. {row:-1,col:6,rowCount:-1, colCount:1}
  253. ]
  254. }
  255. };
  256. var ration_header = [
  257. {headerName:"编码",headerWidth:120},
  258. {headerName:"名称",headerWidth:400},
  259. {headerName:"单位",headerWidth:120},
  260. {headerName:"基价",headerWidth:120},
  261. {headerName:"显示名称(以%s表示参数)",headerWidth:450},
  262. {headerName:"取费专业",headerWidth:120}
  263. ]
  264. var rationGLJ_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. function editRationStarting(spread_setting,args){
  274. properties.rationSelected = args.editingText;
  275. }
  276. function editRationEnding(spread,spread_setting,args){
  277. if(spread_setting.event.remove)
  278. Remove(spread_setting,args);
  279. else{
  280. var ActiveSheet = spread.getActiveSheet();
  281. var rationItem = {}
  282. // rationItem.RationCode = ActiveSheet.getValue(args.row,0);
  283. rationItem.RationCode = args.editingText;
  284. rationItem.RationName = ActiveSheet.getValue(args.row,1);
  285. rationItem.Unit = ActiveSheet.getValue(args.row,2);
  286. rationItem.BasePrice = Number(ActiveSheet.getValue(args.row,3));
  287. if(properties.sectionSelected = "")
  288. {
  289. alert("请选择章节点")
  290. return;
  291. }
  292. else
  293. rationItem.SectionID = properties.sectionSelected;
  294. rationItem.ContentID = 0;
  295. rationItem.Caption = ActiveSheet.getValue(args.row,4);
  296. rationItem.FeeType = Number(ActiveSheet.getValue(args.row,5))
  297. upsert(spread_setting,rationItem);
  298. }
  299. }
  300. //通用remove
  301. function Remove(spread_setting,args){
  302. AjaxRemove(spread_setting);
  303. }
  304. //通用upsert
  305. function upsert(spread_setting,data){
  306. AjaxUpsert(spread_setting,data)
  307. }
  308. function AjaxRemove(spread_setting){
  309. var pro = JSON.stringify(properties);
  310. $.ajax({
  311. type:"POST",
  312. url:"http://localhost:6060/rationLibEditor/remove"+spread_setting.name,
  313. data:{"setting":spread_setting,"properties":pro},
  314. dataType:"json",
  315. cache:false,
  316. timeout:1000,
  317. success:function(result){
  318. spread_setting.event.remove = false;
  319. },
  320. error:function(){}
  321. })
  322. }
  323. function AjaxUpsert(spread_setting,data){
  324. var pro = JSON.stringify(spread_setting.properties);
  325. var dataStr = JSON.stringify(data);
  326. $.ajax({
  327. type:"POST",
  328. url:"http://localhost:6060/rationLibEditor/upsert"+spread_setting.name,
  329. data:{"properties":pro,"data":dataStr},
  330. dataType:"json",
  331. cache:false,
  332. timeout:1000,
  333. success:function(result){
  334. spread_setting.event.upsert = false;
  335. },
  336. error:function(){}
  337. })
  338. }
  339. function mkRationItemSpread(){
  340. var rationSpread = $.fn.Spread.init($("#rationItemsSheet"),spSetting_ration,ration_header);
  341. var rationGLJSpread = $.fn.Spread.init($("#rationGLJSheet"),spSetting_rationGLJ,rationGLJ_header);
  342. }