std_ration_lib.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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, 1, '');
  114. }
  115. for(let i = 0, len = datas.length; i < len; i++){
  116. sheet.setTag(i, 1, 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. "emptyRows":0,
  187. "headRows":1,
  188. "headRowHeight":[30],
  189. "defaultRowHeight": 21,
  190. "treeCol": 0,
  191. "cols":[{
  192. "width":400,
  193. "readOnly": true,
  194. "head":{
  195. "titleNames":["名称"],
  196. "spanCols":[1],
  197. "spanRows":[1],
  198. "vAlign":[1],
  199. "hAlign":[1],
  200. "font":["Arial"]
  201. },
  202. "data":{
  203. "field":"name",
  204. "vAlign":1,
  205. "hAlign":0,
  206. "font":"Arial"
  207. }
  208. }]
  209. },
  210. sectionRationsSetting: {
  211. "emptyRows":3,
  212. "headRows":1,
  213. "headRowHeight":[20],
  214. "defaultRowHeight": 21,
  215. "cols":[{
  216. "width":60,
  217. "readOnly": true,
  218. "head":{
  219. "titleNames":["编码"],
  220. "spanCols":[1],
  221. "spanRows":[1],
  222. "vAlign":[1],
  223. "hAlign":[1],
  224. "font":["Arial"]
  225. },
  226. "data":{
  227. "field":"code",
  228. "vAlign":1,
  229. "hAlign":0,
  230. "font":"Arial"
  231. }
  232. }, {
  233. "width":220,
  234. "readOnly": true,
  235. "showHint": true,
  236. "head":{
  237. "titleNames":["名称"],
  238. "spanCols":[1],
  239. "spanRows":[1],
  240. "vAlign":[1],
  241. "hAlign":[1],
  242. "font":["Arial"]
  243. },
  244. "data":{
  245. "field":"name",
  246. "vAlign":1,
  247. "hAlign":0,
  248. "font":"Arial"
  249. }
  250. }, {
  251. "width":55,
  252. "readOnly":true,
  253. "head":{
  254. "titleNames":["单位"],
  255. "spanCols":[1],
  256. "spanRows":[1],
  257. "vAlign":[1],
  258. "hAlign":[1],
  259. "font":["Arial"]
  260. },
  261. "data":{
  262. "field":"unit",
  263. "vAlign":1,
  264. "hAlign":1,
  265. "font":"Arial"
  266. }
  267. }, {
  268. "width":60,
  269. "readOnly":true,
  270. "head":{
  271. "titleNames":["基价"],
  272. "spanCols":[1],
  273. "spanRows":[1],
  274. "vAlign":[1],
  275. "hAlign":[1],
  276. "font":["Arial"]
  277. },
  278. "data":{
  279. "field":"basePrice",
  280. "vAlign":1,
  281. "hAlign":2,
  282. "font":"Arial"
  283. }
  284. }]
  285. },
  286. getStdRationLibIDs: function () {
  287. let ids = [];
  288. if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
  289. alert('当前项目无定额库,请添加定额库。');
  290. return null;
  291. }
  292. for(let rationLib of projectInfoObj.projectInfo.engineeringInfo.ration_lib){
  293. ids.push(rationLib.id);
  294. }
  295. return ids;
  296. },
  297. getCurrentStdRationLibID:function () {
  298. if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
  299. alert('当前项目无定额库,请添加定额库。');
  300. return null;
  301. }
  302. if($('#stdRationLibSelect').val()){
  303. return parseInt($('#stdRationLibSelect').val());
  304. }else {
  305. return projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id;
  306. }
  307. },
  308. getFirstStdRationLibID: function () {
  309. if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
  310. alert('当前项目无定额库,请添加定额库。');
  311. return null;
  312. }
  313. return parseInt(projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id);
  314. }
  315. };
  316. addEventOnResize(rationLibObj.refreshSettingForHint);
  317. //赋初始高度
  318. if($('#stdRationChapter').height() === 0 || $('#stdSectionRations').height() === 0){
  319. $('#stdRationChapter').height($(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-q").height()-312);
  320. $('#stdSectionRations').height(270);
  321. }
  322. $('#stdRationTab').bind('click', function () {
  323. var select = $('#stdRationLibSelect');
  324. rationLibObj.checkSpread();
  325. if (select[0].options.length === 0) {
  326. rationLibObj.loadStdRationLibs();
  327. rationLibObj.loadStdRationContextMenu();
  328. };
  329. });
  330. $('#stdRationLibSelect').change(function () {
  331. var select = $(this);
  332. if (this.children.length !== 0) {
  333. let rationLibId = select.val();
  334. sessionStorage.setItem('stdRationLib', rationLibId);
  335. sessionStorage.removeItem('stdRationLibExpState');
  336. rationLibObj.loadStdRation(rationLibId);
  337. }
  338. });
  339. //回车键搜索
  340. $('#rationSearchKeyword').bind('keypress', function (event) {
  341. if(event.keyCode === 13){
  342. $(this).blur();
  343. $('#rationSearch').click();
  344. }
  345. });
  346. $('#rationSearch').click(function () {
  347. var keyword = $('#rationSearchKeyword').val(), rationLibID = $('#stdRationLibSelect').val();
  348. var getResultHtml = function (result) {
  349. var html = [], i, serialNo;
  350. html.push('<div class="d-flex justify-content-between">');
  351. html.push('<span>搜索结果:');
  352. html.push(result.length.toString());
  353. html.push('</span>');
  354. html.push('<a title="关闭搜索" class="btn btn-link btn-sm" href="javascript:void(0)"><i class="fa fa-remove" aria-hidden="true"></i></a>');
  355. html.push('</div>');
  356. html.push('<div class="w-100 main-data-side-search">');
  357. html.push('</div>');
  358. return html.join('');
  359. };
  360. var showResult = function (result) {
  361. var resultSpread = SheetDataHelper.createNewSpread($('.main-data-side-search')[0]);
  362. SheetDataHelper.loadSheetHeader(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet());
  363. SheetDataHelper.loadSheetData(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet(), result);
  364. resultSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, rationLibObj.onRationSpreadCellDoubleClick);
  365. };
  366. CommonAjax.post('/complementaryRation/api/findRation', {'user_id': userID, 'rationRepId': rationLibID, 'keyword': keyword}, function (result) {
  367. //sort
  368. result.sort(function (a, b) {
  369. let rst = 0;
  370. if(a.code > b.code) rst = 1;
  371. else if(a.code < b.code) rst = -1;
  372. return rst;
  373. });
  374. var resultObj = $('#rationSearchResult'), resultSpread = null;
  375. resultObj.empty();
  376. resultObj.append(getResultHtml(result));
  377. $('a', resultObj).click(function () {
  378. resultObj.hide();
  379. $(".main-data-side-search", resultObj).height(0);
  380. autoFlashHeight();
  381. //$(".main-data-side-d").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-d").height() - 202);
  382. rationLibObj.refreshSpread();
  383. });
  384. resultObj.show();
  385. $(".main-data-side-search", resultObj).height($(window).height() - $(".header").height() - $(".toolsbar").height() - 64);
  386. showResult(result);
  387. });
  388. });