std_ration_lib.js 16 KB

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