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