std_ration_lib.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /**
  2. * Standard Ration Lib
  3. * Created by Mai on 2017/5/16.
  4. */
  5. /*var rationChapterSpread, sectionRationsSpread;*/
  6. var rationLibObj = {
  7. rationChapterSpread: null,
  8. sectionRationsSpread: null,
  9. rationChapterTreeController: null,
  10. refreshSettingForHint: function () {
  11. TREE_SHEET_HELPER.initSetting($('#stdSectionRations')[0], rationLibObj.sectionRationsSetting);
  12. },
  13. checkSpread: function () {
  14. if (!this.rationChapterSpread) {
  15. this.rationChapterSpread = SheetDataHelper.createNewSpread($('#stdRationChapter')[0]);
  16. this.rationChapterSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onChapterSpreadCellDoubleClick);
  17. }
  18. if (!this.sectionRationsSpread) {
  19. this.sectionRationsSpread = SheetDataHelper.createNewSpread($('#stdSectionRations')[0]);
  20. this.sectionRationsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onRationSpreadCellDoubleClick);
  21. this.refreshSettingForHint();
  22. }
  23. },
  24. refreshSpread: function () {
  25. if (this.rationChapterSpread) {
  26. this.rationChapterSpread.refresh();
  27. }
  28. if (this.sectionRationsSpread) {
  29. this.sectionRationsSpread.refresh();
  30. }
  31. },
  32. loadStdRationLibs: function () {
  33. let select = $('#stdRationLibSelect');
  34. select.empty();
  35. let ration_lib = projectInfoObj.projectInfo.engineeringInfo.ration_lib;
  36. ration_lib.forEach(function (data) {
  37. select.append($('<option>').val(data.id).text(data.name));
  38. });
  39. if (select[0].options.length !== 0) {
  40. rationLibObj.loadStdRation(select.val());
  41. }
  42. },
  43. loadStdRation: function (rationLibID) {
  44. var that = this;
  45. var showRationChapterTree = function (datas) {
  46. var rationChapterTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: false});
  47. that.tree = rationChapterTree;
  48. var rationChapterTreeController = TREE_SHEET_CONTROLLER.createNew(rationChapterTree, that.rationChapterSpread.getActiveSheet(), that.rationChapterTreeSetting);
  49. rationChapterTree.loadDatas(datas);
  50. //非叶子节点默认收起
  51. that.tree.setRootExpanded(that.tree.roots, false);
  52. rationChapterTreeController.showTreeData();
  53. rationChapterTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, function (node) {
  54. rationLibObj.loadSectionRations(node.getID());
  55. });
  56. if (rationChapterTree.firstNode()) {
  57. rationLibObj.loadSectionRations(rationChapterTree.firstNode().getID());
  58. } else {
  59. rationLibObj.loadSectionRations();
  60. };
  61. };
  62. CommonAjax.post('/complementaryRation/api/getRationTree', {userId: userID, rationRepId: rationLibID}, function (datas) {
  63. showRationChapterTree(datas);
  64. }, function () {
  65. showRationChapterTree([]);
  66. });
  67. },
  68. //双击隐藏显示
  69. onChapterSpreadCellDoubleClick: function (sender, args) {
  70. let me = rationLibObj;
  71. let node = me.tree.items[args.row];
  72. if (!node || node.children.length === 0)
  73. return;
  74. node.setExpanded(!node.expanded);
  75. TREE_SHEET_HELPER.massOperationSheet(args.sheet, function () {
  76. let iCount = node.posterityCount(), i, child;
  77. for (i = 0; i < iCount; i++) {
  78. child = me.tree.items[args.row + i + 1];
  79. args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
  80. }
  81. args.sheet.invalidateLayout();
  82. });
  83. args.sheet.repaint();
  84. },
  85. setTagForHint: function (datas) {
  86. let sheet = this.sectionRationsSpread.getActiveSheet();
  87. sheet.suspendPaint();
  88. sheet.suspendEvent();
  89. for(let i = 0, len = sheet.getRowCount(); i < len; i++){
  90. sheet.setTag(i, 1, '');
  91. }
  92. for(let i = 0, len = datas.length; i < len; i++){
  93. sheet.setTag(i, 1, datas[i].hint ? datas[i].hint : '');
  94. }
  95. sheet.resumePaint();
  96. sheet.resumeEvent();
  97. },
  98. loadSectionRations: function (sectionID) {
  99. var showDatas = function (datas, setting) {
  100. SheetDataHelper.loadSheetHeader(setting, rationLibObj.sectionRationsSpread.getActiveSheet());
  101. SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
  102. rationLibObj.setTagForHint(datas);
  103. };
  104. if (sectionID) {
  105. CommonAjax.post('/complementaryRation/api/getRationGljItemsBySection', {user_Id: userID, sectionId: sectionID}, function (datas) {
  106. showDatas(datas, rationLibObj.sectionRationsSetting);
  107. }, function () {
  108. showDatas([], rationLibObj.sectionRationsSetting);
  109. });
  110. } else {
  111. showDatas([], rationLibObj.sectionRationsSetting);
  112. }
  113. },
  114. onRationSpreadCellDoubleClick: function (sender, args) {
  115. var select = $('#stdRationLibSelect'), rationCode = args.sheet.getText(args.row, 0);
  116. if (rationCode !== '') {
  117. projectObj.project.Ration.addNewRation({userID: userID, rationRepId: select.val(), code: rationCode},rationType.ration);
  118. }
  119. },
  120. loadStdRationContextMenu: function () {
  121. let rationSpread = rationLibObj.sectionRationsSpread, rationSheet = rationSpread.getActiveSheet(), rationModel = projectObj.project.Ration;;
  122. $.contextMenu({
  123. selector: '#stdSectionRations',
  124. build: function ($trigger, e) {
  125. let target = SheetDataHelper.safeRightClickSelection($trigger, e, rationSpread);
  126. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  127. },
  128. items: {
  129. "insertStdRation": {
  130. name: "插入定额",
  131. icon: 'fa-sign-in',
  132. callback: function (key, opt) {
  133. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  134. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  135. if (rationCode !== '') {
  136. rationModel.addNewRation({userID: userID, rationRepId: select.val(), code: rationCode},rationType.ration);
  137. }
  138. }
  139. },
  140. "replaceStdRation": {
  141. name: "替换定额",
  142. icon: 'fa-sign-in',
  143. callback: function (key, opt) {
  144. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  145. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  146. let mainTreeSelected = projectObj.project.mainTree.selected;
  147. if (rationCode !== ''&&mainTreeSelected&&mainTreeSelected.sourceType == rationModel.getSourceType()) {
  148. rationModel.updateRationCodes([{'node':mainTreeSelected,value:rationCode}]);
  149. }
  150. }
  151. },
  152. }
  153. });
  154. },
  155. rationChapterTreeSetting: {
  156. "emptyRows":0,
  157. "headRows":1,
  158. "headRowHeight":[30],
  159. "defaultRowHeight": 21,
  160. "treeCol": 0,
  161. "cols":[{
  162. "width":400,
  163. "readOnly": true,
  164. "head":{
  165. "titleNames":["名称"],
  166. "spanCols":[1],
  167. "spanRows":[1],
  168. "vAlign":[1],
  169. "hAlign":[1],
  170. "font":["Arial"]
  171. },
  172. "data":{
  173. "field":"name",
  174. "vAlign":1,
  175. "hAlign":0,
  176. "font":"Arial"
  177. }
  178. }]
  179. },
  180. sectionRationsSetting: {
  181. "emptyRows":3,
  182. "headRows":1,
  183. "headRowHeight":[20],
  184. "defaultRowHeight": 21,
  185. "cols":[{
  186. "width":60,
  187. "readOnly": true,
  188. "head":{
  189. "titleNames":["编码"],
  190. "spanCols":[1],
  191. "spanRows":[1],
  192. "vAlign":[1],
  193. "hAlign":[1],
  194. "font":["Arial"]
  195. },
  196. "data":{
  197. "field":"code",
  198. "vAlign":1,
  199. "hAlign":0,
  200. "font":"Arial"
  201. }
  202. }, {
  203. "width":220,
  204. "readOnly": true,
  205. "showHint": true,
  206. "head":{
  207. "titleNames":["名称"],
  208. "spanCols":[1],
  209. "spanRows":[1],
  210. "vAlign":[1],
  211. "hAlign":[1],
  212. "font":["Arial"]
  213. },
  214. "data":{
  215. "field":"name",
  216. "vAlign":1,
  217. "hAlign":0,
  218. "font":"Arial"
  219. }
  220. }, {
  221. "width":55,
  222. "readOnly":true,
  223. "head":{
  224. "titleNames":["单位"],
  225. "spanCols":[1],
  226. "spanRows":[1],
  227. "vAlign":[1],
  228. "hAlign":[1],
  229. "font":["Arial"]
  230. },
  231. "data":{
  232. "field":"unit",
  233. "vAlign":1,
  234. "hAlign":1,
  235. "font":"Arial"
  236. }
  237. }, {
  238. "width":60,
  239. "readOnly":true,
  240. "head":{
  241. "titleNames":["基价"],
  242. "spanCols":[1],
  243. "spanRows":[1],
  244. "vAlign":[1],
  245. "hAlign":[1],
  246. "font":["Arial"]
  247. },
  248. "data":{
  249. "field":"basePrice",
  250. "vAlign":1,
  251. "hAlign":2,
  252. "font":"Arial"
  253. }
  254. }]
  255. },
  256. getStdRationLibIDs: function () {
  257. let ids = [];
  258. if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
  259. alert('当前项目无定额库,请添加定额库。');
  260. return null;
  261. }
  262. for(let rationLib of projectInfoObj.projectInfo.engineeringInfo.ration_lib){
  263. ids.push(rationLib.id);
  264. }
  265. return ids;
  266. },
  267. getCurrentStdRationLibID:function () {
  268. if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
  269. alert('当前项目无定额库,请添加定额库。');
  270. return null;
  271. }
  272. if($('#stdRationLibSelect').val()){
  273. return parseInt($('#stdRationLibSelect').val());
  274. }else {
  275. return projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id;
  276. }
  277. },
  278. getFirstStdRationLibID: function () {
  279. if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
  280. alert('当前项目无定额库,请添加定额库。');
  281. return null;
  282. }
  283. return parseInt(projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id);
  284. }
  285. };
  286. addEventOnResize(rationLibObj.refreshSettingForHint);
  287. //赋初始高度
  288. if($('#stdRationChapter').height() === 0 || $('#stdSectionRations').height() === 0){
  289. $('#stdRationChapter').height($(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-q").height()-312);
  290. $('#stdSectionRations').height(270);
  291. }
  292. $('#stdRationTab').bind('click', function () {
  293. var select = $('#stdRationLibSelect');
  294. rationLibObj.checkSpread();
  295. if (select[0].options.length === 0) {
  296. rationLibObj.loadStdRationLibs();
  297. rationLibObj.loadStdRationContextMenu();
  298. };
  299. });
  300. $('#stdRationLibSelect').change(function () {
  301. var select = $(this);
  302. if (this.children.length !== 0) {
  303. rationLibObj.loadStdRation(select.val());
  304. }
  305. });
  306. $('#rationSearch').click(function () {
  307. var keyword = $('#rationSearchKeyword').val(), rationLibID = $('#stdRationLibSelect').val();
  308. var getResultHtml = function (result) {
  309. var html = [], i, serialNo;
  310. html.push('<div class="d-flex justify-content-between">');
  311. html.push('<span>搜索结果:');
  312. html.push(result.length.toString());
  313. html.push('</span>');
  314. html.push('<a title="关闭搜索" class="btn btn-link btn-sm" href="javascript:void(0)"><i class="fa fa-remove" aria-hidden="true"></i></a>');
  315. html.push('</div>');
  316. html.push('<div class="w-100 main-data-side-search">');
  317. html.push('</div>');
  318. return html.join('');
  319. };
  320. var showResult = function (result) {
  321. var resultSpread = SheetDataHelper.createNewSpread($('.main-data-side-search')[0]);
  322. SheetDataHelper.loadSheetHeader(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet());
  323. SheetDataHelper.loadSheetData(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet(), result);
  324. resultSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, rationLibObj.onRationSpreadCellDoubleClick);
  325. };
  326. CommonAjax.post('/complementaryRation/api/findRation', {'user_id': userID, 'rationRepId': rationLibID, 'keyword': keyword}, function (result) {
  327. //sort
  328. result.sort(function (a, b) {
  329. let rst = 0;
  330. if(a.code > b.code) rst = 1;
  331. else if(a.code < b.code) rst = -1;
  332. return rst;
  333. });
  334. var resultObj = $('#rationSearchResult'), resultSpread = null;
  335. resultObj.empty();
  336. resultObj.append(getResultHtml(result));
  337. $('a', resultObj).click(function () {
  338. resultObj.hide();
  339. //$(".main-data-side-d").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-d").height() - 202);
  340. rationLibObj.refreshSpread();
  341. $(".main-data-side-search", resultObj).height(0);
  342. });
  343. resultObj.show();
  344. $(".main-data-side-search", resultObj).height($(window).height() - $(".header").height() - $(".toolsbar").height() - 64);
  345. showResult(result);
  346. });
  347. });