std_ration_lib.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. rationChapterTreeController.showTreeData();
  51. rationChapterTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, function (node) {
  52. rationLibObj.loadSectionRations(node.getID());
  53. });
  54. if (rationChapterTree.firstNode()) {
  55. rationLibObj.loadSectionRations(rationChapterTree.firstNode().getID());
  56. } else {
  57. rationLibObj.loadSectionRations();
  58. };
  59. };
  60. CommonAjax.post('/complementaryRation/api/getRationTree', {userId: userID, rationRepId: rationLibID}, function (datas) {
  61. showRationChapterTree(datas);
  62. }, function () {
  63. showRationChapterTree([]);
  64. });
  65. },
  66. //双击隐藏显示
  67. onChapterSpreadCellDoubleClick: function (sender, args) {
  68. let me = rationLibObj;
  69. let node = me.tree.items[args.row];
  70. if (!node || node.children.length === 0)
  71. return;
  72. node.setExpanded(!node.expanded);
  73. TREE_SHEET_HELPER.massOperationSheet(args.sheet, function () {
  74. let iCount = node.posterityCount(), i, child;
  75. for (i = 0; i < iCount; i++) {
  76. child = me.tree.items[args.row + i + 1];
  77. args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
  78. }
  79. args.sheet.invalidateLayout();
  80. });
  81. args.sheet.repaint();
  82. },
  83. setTagForHint: function (datas) {
  84. let sheet = this.sectionRationsSpread.getActiveSheet();
  85. sheet.suspendPaint();
  86. sheet.suspendEvent();
  87. for(let i = 0, len = sheet.getRowCount(); i < len; i++){
  88. sheet.setTag(i, 1, '');
  89. }
  90. for(let i = 0, len = datas.length; i < len; i++){
  91. sheet.setTag(i, 1, datas[i].hint ? datas[i].hint : '');
  92. }
  93. sheet.resumePaint();
  94. sheet.resumeEvent();
  95. },
  96. loadSectionRations: function (sectionID) {
  97. var showDatas = function (datas, setting) {
  98. SheetDataHelper.loadSheetHeader(setting, rationLibObj.sectionRationsSpread.getActiveSheet());
  99. SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
  100. rationLibObj.setTagForHint(datas);
  101. };
  102. if (sectionID) {
  103. CommonAjax.post('/complementaryRation/api/getRationGljItemsBySection', {user_Id: userID, sectionId: sectionID}, function (datas) {
  104. showDatas(datas, rationLibObj.sectionRationsSetting);
  105. }, function () {
  106. showDatas([], rationLibObj.sectionRationsSetting);
  107. });
  108. } else {
  109. showDatas([], rationLibObj.sectionRationsSetting);
  110. }
  111. },
  112. onRationSpreadCellDoubleClick: function (sender, args) {
  113. var select = $('#stdRationLibSelect'), rationCode = args.sheet.getText(args.row, 0);
  114. if (rationCode !== '') {
  115. projectObj.project.Ration.addNewRation({userID: userID, rationRepId: select.val(), code: rationCode},rationType.ration);
  116. }
  117. },
  118. loadStdRationContextMenu: function () {
  119. let rationSpread = rationLibObj.sectionRationsSpread, rationSheet = rationSpread.getActiveSheet(), rationModel = projectObj.project.Ration;;
  120. $.contextMenu({
  121. selector: '#stdSectionRations',
  122. build: function ($trigger, e) {
  123. let target = SheetDataHelper.safeRightClickSelection($trigger, e, rationSpread);
  124. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  125. },
  126. items: {
  127. "insertStdRation": {
  128. name: "插入定额",
  129. icon: 'fa-sign-in',
  130. callback: function (key, opt) {
  131. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  132. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  133. if (rationCode !== '') {
  134. rationModel.addNewRation({userID: userID, rationRepId: select.val(), code: rationCode},rationType.ration);
  135. }
  136. }
  137. },
  138. "replaceStdRation": {
  139. name: "替换定额",
  140. icon: 'fa-sign-in',
  141. callback: function (key, opt) {
  142. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  143. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  144. let mainTreeSelected = projectObj.project.mainTree.selected;
  145. if (rationCode !== ''&&mainTreeSelected&&mainTreeSelected.sourceType == rationModel.getSourceType()) {
  146. rationModel.updateRationCodes([{'node':mainTreeSelected,value:rationCode}]);
  147. }
  148. }
  149. },
  150. }
  151. });
  152. },
  153. rationChapterTreeSetting: {
  154. "emptyRows":0,
  155. "headRows":1,
  156. "headRowHeight":[30],
  157. "defaultRowHeight": 21,
  158. "treeCol": 0,
  159. "cols":[{
  160. "width":400,
  161. "readOnly": true,
  162. "head":{
  163. "titleNames":["名称"],
  164. "spanCols":[1],
  165. "spanRows":[1],
  166. "vAlign":[1],
  167. "hAlign":[1],
  168. "font":["Arial"]
  169. },
  170. "data":{
  171. "field":"name",
  172. "vAlign":1,
  173. "hAlign":0,
  174. "font":"Arial"
  175. }
  176. }]
  177. },
  178. sectionRationsSetting: {
  179. "emptyRows":3,
  180. "headRows":1,
  181. "headRowHeight":[20],
  182. "defaultRowHeight": 21,
  183. "cols":[{
  184. "width":60,
  185. "readOnly": true,
  186. "head":{
  187. "titleNames":["编码"],
  188. "spanCols":[1],
  189. "spanRows":[1],
  190. "vAlign":[1],
  191. "hAlign":[1],
  192. "font":["Arial"]
  193. },
  194. "data":{
  195. "field":"code",
  196. "vAlign":1,
  197. "hAlign":0,
  198. "font":"Arial"
  199. }
  200. }, {
  201. "width":220,
  202. "readOnly": true,
  203. "showHint": true,
  204. "head":{
  205. "titleNames":["名称"],
  206. "spanCols":[1],
  207. "spanRows":[1],
  208. "vAlign":[1],
  209. "hAlign":[1],
  210. "font":["Arial"]
  211. },
  212. "data":{
  213. "field":"name",
  214. "vAlign":1,
  215. "hAlign":0,
  216. "font":"Arial"
  217. }
  218. }, {
  219. "width":55,
  220. "readOnly":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":"unit",
  231. "vAlign":1,
  232. "hAlign":1,
  233. "font":"Arial"
  234. }
  235. }, {
  236. "width":60,
  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":"basePrice",
  248. "vAlign":1,
  249. "hAlign":2,
  250. "font":"Arial"
  251. }
  252. }]
  253. }
  254. };
  255. addEventOnResize(rationLibObj.refreshSettingForHint);
  256. $('#stdRationTab').bind('click', function () {
  257. refreshSubSpread();//subSpread、jobSpread、itemSpread显示问题
  258. var select = $('#stdRationLibSelect');
  259. $(".main-data-side-d").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-d").height() - 202);
  260. rationLibObj.refreshSpread();
  261. rationLibObj.checkSpread();
  262. if (select[0].options.length === 0) {
  263. rationLibObj.loadStdRationLibs();
  264. rationLibObj.loadStdRationContextMenu();
  265. };
  266. });
  267. $('#stdRationLibSelect').change(function () {
  268. var select = $(this);
  269. if (this.children.length !== 0) {
  270. rationLibObj.loadStdRation(select.val());
  271. }
  272. });
  273. $('#rationSearch').click(function () {
  274. var keyword = $('#rationSearchKeyword').val(), rationLibID = $('#stdRationLibSelect').val();
  275. var getResultHtml = function (result) {
  276. var html = [], i, serialNo;
  277. html.push('<div class="d-flex justify-content-between">');
  278. html.push('<span>搜索结果:');
  279. html.push(result.length.toString());
  280. html.push('</span>');
  281. html.push('<a title="关闭搜索" class="btn btn-link btn-sm" href="javascript:void(0)"><i class="fa fa-remove" aria-hidden="true"></i></a>');
  282. html.push('</div>');
  283. html.push('<div class="w-100 main-data-side-search">');
  284. html.push('</div>');
  285. return html.join('');
  286. };
  287. var showResult = function (result) {
  288. var resultSpread = SheetDataHelper.createNewSpread($('.main-data-side-search')[0]);
  289. SheetDataHelper.loadSheetHeader(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet());
  290. SheetDataHelper.loadSheetData(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet(), result);
  291. resultSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, rationLibObj.onRationSpreadCellDoubleClick);
  292. };
  293. CommonAjax.post('/complementaryRation/api/findRation', {'user_id': userID, 'rationRepId': rationLibID, 'keyword': keyword}, function (result) {
  294. //sort
  295. result.sort(function (a, b) {
  296. let rst = 0;
  297. if(a.code > b.code) rst = 1;
  298. else if(a.code < b.code) rst = -1;
  299. return rst;
  300. });
  301. var resultObj = $('#rationSearchResult'), resultSpread = null;
  302. resultObj.empty();
  303. resultObj.append(getResultHtml(result));
  304. $('a', resultObj).click(function () {
  305. resultObj.hide();
  306. $(".main-data-side-d").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-d").height() - 202);
  307. $(".main-data-side-search", resultObj).height(0);
  308. });
  309. resultObj.show();
  310. $(".main-data-side-search", resultObj).height($(window).height() - $(".header").height() - $(".toolsbar").height() - 64);
  311. showResult(result);
  312. });
  313. });