std_ration_lib.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /**
  2. * Standard Ration Lib
  3. * Created by Mai on 2017/5/16.
  4. */
  5. /*var rationChapterSpread, sectionRationsSpread;*/
  6. var rationLibObj = {
  7. doAfterGetRationTree: null, //获取章节树回调
  8. doAfterLoadGetRations: null, //获取章节树下定额后回调
  9. rationChapterSpread: null,
  10. sectionRationsSpread: null,
  11. resultSpread: null,
  12. rationChapterTreeController: null,
  13. refreshSettingForHint: function () {
  14. TREE_SHEET_HELPER.initSetting($('#stdSectionRations')[0], rationLibObj.sectionRationsSetting);
  15. },
  16. checkSpread: function () {
  17. if (!this.rationChapterSpread) {
  18. this.rationChapterSpread = SheetDataHelper.createNewSpread($('#stdRationChapter')[0]);
  19. sheetCommonObj.spreadDefaultStyle(this.rationChapterSpread);
  20. this.rationChapterSpread.getSheet(0).name('stdRationLib_chapter');
  21. this.rationChapterSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onChapterSpreadCellDoubleClick);
  22. }
  23. if (!this.sectionRationsSpread) {
  24. this.sectionRationsSpread = SheetDataHelper.createNewSpread($('#stdSectionRations')[0]);
  25. sheetCommonObj.spreadDefaultStyle(this.sectionRationsSpread);
  26. this.sectionRationsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onRationSpreadCellDoubleClick);
  27. this.refreshSettingForHint();
  28. }
  29. },
  30. refreshSpread: function () {
  31. if (this.rationChapterSpread) {
  32. this.rationChapterSpread.refresh();
  33. }
  34. if (this.sectionRationsSpread) {
  35. this.sectionRationsSpread.refresh();
  36. }
  37. if(this.resultSpread){
  38. this.resultSpread.refresh();
  39. }
  40. },
  41. loadStdRationLibs: function () {
  42. let select = $('#stdRationLibSelect');
  43. select.empty();
  44. let ration_lib = projectInfoObj.projectInfo.engineeringInfo.ration_lib;
  45. let selectedRationLib = sessionStorage.getItem('stdRationLib');
  46. ration_lib.forEach(function (data) {
  47. let option = $('<option>').val(data.id).text(data.name);
  48. //select.append($('<option>').val(data.id).text(data.name));
  49. if(selectedRationLib){
  50. if(data.id == selectedRationLib){
  51. option.attr('selected', 'selected');
  52. }
  53. }else if(data.isDefault == true){
  54. option.attr('selected', 'selected');
  55. }
  56. select.append(option);
  57. });
  58. if (select[0].options.length !== 0) {
  59. rationLibObj.loadStdRation(select.val());
  60. }
  61. },
  62. initQuestionModal: function(row) {
  63. let node = rationLibObj.tree.items[row];
  64. while (node && !node.data.explanation){
  65. node = node.parent;
  66. }
  67. let explanation = node && node.data.explanation ? node.data.explanation : '无内容';
  68. $('#explanationContent').html(explanation);
  69. node = rationLibObj.tree.items[row];
  70. while (node && !node.data.ruleText){
  71. node = node.parent;
  72. }
  73. let ruleText = node && node.data.ruleText ? node.data.ruleText : '无内容';
  74. $('#ruleTextContent').html(ruleText);
  75. $('#rationQuestionModal').modal('show');
  76. },
  77. loadStdRation: function (rationLibID) {
  78. $.bootstrapLoading.start();
  79. var that = this;
  80. var showRationChapterTree = function (datas) {
  81. var rationChapterTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: false});
  82. that.tree = rationChapterTree;
  83. var rationChapterTreeController = TREE_SHEET_CONTROLLER.createNew(rationChapterTree, that.rationChapterSpread.getActiveSheet(), that.rationChapterTreeSetting);
  84. sheetCommonObj.setColumnWidthByRate($('#stdRationChapter').width() - 40, that.rationChapterSpread, that.rationChapterTreeSetting.cols);
  85. rationChapterTree.loadDatas(datas);
  86. //读取展开收起状态
  87. let currentExpState = sessionStorage.getItem('stdRationLibExpState');
  88. if(currentExpState){
  89. that.tree.setExpandedByState(that.tree.items, currentExpState);
  90. }
  91. else {
  92. //展开至第二层
  93. for(let root of that.tree.roots){
  94. root.setExpanded(true);
  95. that.tree.setRootExpanded(root.children, false);
  96. }
  97. }
  98. rationChapterTreeController.showTreeData();
  99. rationChapterTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, function (node) {
  100. rationLibObj.loadSectionRations(node && node.children.length === 0 ? node.getID() : null);
  101. });
  102. if (rationChapterTree.firstNode() && rationChapterTree.firstNode().length === 0) {
  103. rationLibObj.loadSectionRations(rationChapterTree.firstNode().getID());
  104. } else {
  105. rationLibObj.loadSectionRations();
  106. };
  107. };
  108. CommonAjax.post('/complementaryRation/api/getRationTree', {userId: userID, rationRepId: rationLibID}, function (datas) {
  109. showRationChapterTree(datas);
  110. if(that.doAfterGetRationTree){
  111. that.doAfterGetRationTree();
  112. }
  113. $.bootstrapLoading.end();
  114. }, function () {
  115. showRationChapterTree([]);
  116. $.bootstrapLoading.end();
  117. });
  118. },
  119. //双击隐藏显示
  120. onChapterSpreadCellDoubleClick: function (sender, args) {
  121. let me = rationLibObj;
  122. let node = me.tree.items[args.row];
  123. if (!node || node.children.length === 0)
  124. return;
  125. node.setExpanded(!node.expanded);
  126. sessionStorage.setItem('stdRationLibExpState', me.tree.getExpState(me.tree.items));
  127. TREE_SHEET_HELPER.massOperationSheet(args.sheet, function () {
  128. let iCount = node.posterityCount(), i, child;
  129. for (i = 0; i < iCount; i++) {
  130. child = me.tree.items[args.row + i + 1];
  131. args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
  132. }
  133. args.sheet.invalidateLayout();
  134. });
  135. args.sheet.repaint();
  136. },
  137. setTagForHint: function (sheet, datas) {
  138. sheet.suspendPaint();
  139. sheet.suspendEvent();
  140. for(let i = 0, len = sheet.getRowCount(); i < len; i++){
  141. sheet.setTag(i, 0, '');
  142. }
  143. for(let i = 0, len = datas.length; i < len; i++){
  144. sheet.setTag(i, 0, datas[i].hint ? datas[i].hint : '');
  145. }
  146. sheet.resumePaint();
  147. sheet.resumeEvent();
  148. },
  149. loadSectionRations: function (sectionID) {
  150. let me = this;
  151. var showDatas = function (datas, setting) {
  152. let rationSheet = rationLibObj.sectionRationsSpread.getActiveSheet();
  153. TREE_SHEET_HELPER.massOperationSheet(rationSheet, function () {
  154. rationSheet.setColumnWidth(0, 25, GC.Spread.Sheets.SheetArea.rowHeader);
  155. });
  156. SheetDataHelper.loadSheetHeader(setting, rationLibObj.sectionRationsSpread.getActiveSheet());
  157. SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
  158. rationLibObj.setTagForHint(rationSheet, datas);
  159. };
  160. if (sectionID) {
  161. CommonAjax.post('/complementaryRation/api/getRationGljItemsBySection', {user_Id: userID, sectionId: sectionID}, function (datas) {
  162. showDatas(datas, rationLibObj.sectionRationsSetting);
  163. if(me.doAfterLoadGetRations){
  164. me.doAfterLoadGetRations(datas);
  165. me.doAfterLoadGetRations = null;
  166. }
  167. }, function () {
  168. showDatas([], rationLibObj.sectionRationsSetting);
  169. });
  170. } else {
  171. showDatas([], rationLibObj.sectionRationsSetting);
  172. }
  173. },
  174. onRationSpreadCellDoubleClick: function (sender, args) {
  175. var select = $('#stdRationLibSelect'), rationCode = args.sheet.getText(args.row, 0);
  176. if (rationCode !== '') {
  177. projectObj.project.Ration.addNewRation({userID: userID, rationRepId: select.val(), code: rationCode},rationType.ration, function () {
  178. projectObj.setActiveCell('quantity', true);
  179. });
  180. }
  181. },
  182. loadStdRationContextMenu: function () {
  183. let rationSpread = rationLibObj.sectionRationsSpread, rationSheet = rationSpread.getActiveSheet(), rationModel = projectObj.project.Ration;;
  184. $.contextMenu({
  185. selector: '#stdSectionRations',
  186. build: function ($trigger, e) {
  187. let target = SheetDataHelper.safeRightClickSelection($trigger, e, rationSpread);
  188. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  189. },
  190. items: {
  191. "insertStdRation": {
  192. name: "插入定额",
  193. icon: 'fa-sign-in',
  194. callback: function (key, opt) {
  195. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  196. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  197. if (rationCode !== '') {
  198. rationModel.addNewRation({userID: userID, rationRepId: select.val(), code: rationCode},rationType.ration, function () {
  199. });
  200. }
  201. }
  202. },
  203. "replaceStdRation": {
  204. name: "替换定额",
  205. icon: 'fa-sign-in',
  206. callback: function (key, opt) {
  207. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  208. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  209. let mainTreeSelected = projectObj.project.mainTree.selected;
  210. if (rationCode !== ''&&mainTreeSelected&&mainTreeSelected.sourceType == rationModel.getSourceType()) {
  211. rationModel.updateRationCodes([{'node':mainTreeSelected,value:rationCode}]);
  212. }
  213. }
  214. },
  215. }
  216. });
  217. },
  218. expandSearchNodes: function(nodes){
  219. let that = rationLibObj;
  220. TREE_SHEET_HELPER.massOperationSheet(that.rationChapterSpread.getActiveSheet(), function () {
  221. function expParentNode(node){
  222. if(node.parent){
  223. expParentNode(node.parent);
  224. if(!node.parent.expanded){
  225. node.parent.setExpanded(true);
  226. }
  227. }
  228. }
  229. for(let node of nodes){
  230. expParentNode(node);
  231. }
  232. TREE_SHEET_HELPER.refreshTreeNodeData(that.rationChapterTreeSetting, that.rationChapterSpread.getActiveSheet(), that.tree.roots, true);
  233. TREE_SHEET_HELPER.refreshNodesVisible(that.tree.roots, that.rationChapterSpread.getActiveSheet(), true);
  234. });
  235. },
  236. initSel: function (row) {
  237. let me = this;
  238. let sheet = me.rationChapterSpread.getActiveSheet();
  239. sheet.setActiveCell(row, 0);
  240. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  241. let sectionNode = me.tree.items[row] || null;
  242. me.loadSectionRations(sectionNode && sectionNode.children.length === 0 ? sectionNode.data.ID : null);
  243. },
  244. locateAtRation: function(libID, code){
  245. let me = rationLibObj;
  246. //查找定额,以确定定额所在章节节点
  247. let firstLibID = projectInfoObj.projectInfo.engineeringInfo.ration_lib.length > 0 ?
  248. projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id : null;
  249. let locateRow = 0,
  250. locateSubRow = 0;
  251. CommonAjax.post('/complementaryRation/api/getRationItem', {rationRepIds: [libID], code: code}, function (ration) {
  252. if(ration && ration.sectionId){
  253. let sectionNode = me.tree.findNode(ration.sectionId);
  254. if(sectionNode){
  255. me.expandSearchNodes([sectionNode]);
  256. sessionStorage.setItem('stdRationLibExpState', me.tree.getExpState(me.tree.items));
  257. }
  258. locateRow = sectionNode.serialNo();
  259. me.doAfterLoadGetRations = function (rationItems) {
  260. let rationSheet = me.sectionRationsSpread.getActiveSheet();
  261. locateSubRow = _.findIndex(rationItems, {ID: ration.ID});
  262. rationSheet.setActiveCell(locateSubRow, 0);
  263. rationSheet.showRow(locateSubRow, GC.Spread.Sheets.VerticalPosition.center);
  264. };
  265. me.initSel(locateRow);
  266. }
  267. else {
  268. me.initSel(locateRow);
  269. }
  270. }, function () {
  271. me.initSel(locateRow);
  272. });
  273. },
  274. rationChapterTreeSetting: {
  275. "emptyRowHeader": true,
  276. "rowHeaderWidth": 15,
  277. "emptyRows":0,
  278. "headRows":1,
  279. "headRowHeight":[30],
  280. "defaultRowHeight": 21,
  281. "treeCol": 0,
  282. "cols":[{
  283. "rateWidth": 1,
  284. "width":400,
  285. "readOnly": true,
  286. "head":{
  287. "titleNames":["名称"],
  288. "spanCols":[1],
  289. "spanRows":[1],
  290. "vAlign":[1],
  291. "hAlign":[1],
  292. "font":["Arial"]
  293. },
  294. "data":{
  295. "field":"name",
  296. "vAlign":1,
  297. "hAlign":0,
  298. "font":"Arial"
  299. }
  300. }]
  301. },
  302. sectionRationsSetting: {
  303. "emptyRows":3,
  304. "headRows":1,
  305. "headRowHeight":[20],
  306. "defaultRowHeight": 21,
  307. "cols":[{
  308. "width":60,
  309. "readOnly": true,
  310. "showHint": true,
  311. "head":{
  312. "titleNames":["编码"],
  313. "spanCols":[1],
  314. "spanRows":[1],
  315. "vAlign":[1],
  316. "hAlign":[1],
  317. "font":["Arial"]
  318. },
  319. "data":{
  320. "field":"code",
  321. "vAlign":1,
  322. "hAlign":0,
  323. "font":"Arial"
  324. }
  325. }, {
  326. "width":220,
  327. "readOnly": true,
  328. "showHint": true,
  329. "head":{
  330. "titleNames":["名称"],
  331. "spanCols":[1],
  332. "spanRows":[1],
  333. "vAlign":[1],
  334. "hAlign":[1],
  335. "font":["Arial"]
  336. },
  337. "data":{
  338. "field":"name",
  339. "vAlign":1,
  340. "hAlign":0,
  341. "font":"Arial"
  342. }
  343. }, {
  344. "width":55,
  345. "readOnly":true,
  346. "head":{
  347. "titleNames":["单位"],
  348. "spanCols":[1],
  349. "spanRows":[1],
  350. "vAlign":[1],
  351. "hAlign":[1],
  352. "font":["Arial"]
  353. },
  354. "data":{
  355. "field":"unit",
  356. "vAlign":1,
  357. "hAlign":1,
  358. "font":"Arial"
  359. }
  360. }, {
  361. "width":60,
  362. "readOnly":true,
  363. "head":{
  364. "titleNames":["基价"],
  365. "spanCols":[1],
  366. "spanRows":[1],
  367. "vAlign":[1],
  368. "hAlign":[1],
  369. "font":["Arial"]
  370. },
  371. "data":{
  372. "field":"basePrice",
  373. "vAlign":1,
  374. "hAlign":2,
  375. "font":"Arial"
  376. }
  377. }]
  378. },
  379. getStdRationLibIDs: function () {
  380. let ids = [];
  381. if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
  382. alert('当前项目无定额库,请添加定额库。');
  383. return null;
  384. }
  385. for(let rationLib of projectInfoObj.projectInfo.engineeringInfo.ration_lib){
  386. ids.push(rationLib.id);
  387. }
  388. return ids;
  389. },
  390. getCurrentStdRationLibID:function () {
  391. if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
  392. alert('当前项目无定额库,请添加定额库。');
  393. return null;
  394. }
  395. if($('#stdRationLibSelect').val()){
  396. return parseInt($('#stdRationLibSelect').val());
  397. }else {
  398. return projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id;
  399. }
  400. },
  401. getFirstStdRationLibID: function () {
  402. if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
  403. alert('当前项目无定额库,请添加定额库。');
  404. return null;
  405. }
  406. return parseInt(projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id);
  407. },
  408. getDefaultStdRationLibID:function(){
  409. let ration_lib = projectInfoObj.projectInfo.engineeringInfo.ration_lib;
  410. if(ration_lib.length === 0){
  411. alert('当前项目无定额库,请添加定额库。');
  412. return null;
  413. }
  414. let defaultLib = _.find(ration_lib,{'isDefault':true});
  415. let libID = defaultLib?defaultLib.id:ration_lib[0].id;
  416. return parseInt(libID);
  417. }
  418. };
  419. addEventOnResize(rationLibObj.refreshSettingForHint);
  420. //赋初始高度
  421. if($('#stdRationChapter').height() === 0 || $('#stdSectionRations').height() === 0){
  422. $('#stdRationChapter').height($(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-q").height()-312);
  423. $('#stdSectionRations').height(270);
  424. }
  425. $('#stdRationTab').bind('click', function () {
  426. if(!projectReadOnly){
  427. var select = $('#stdRationLibSelect');
  428. rationLibObj.checkSpread();
  429. if (select[0].options.length === 0) {
  430. rationLibObj.loadStdRationLibs();
  431. rationLibObj.loadStdRationContextMenu();
  432. };
  433. }
  434. });
  435. $('#stdRationLibSelect').change(function () {
  436. var select = $(this);
  437. if (this.children.length !== 0) {
  438. let rationLibId = select.val();
  439. sessionStorage.setItem('stdRationLib', rationLibId);
  440. sessionStorage.removeItem('stdRationLibExpState');
  441. rationLibObj.loadStdRation(rationLibId);
  442. }
  443. });
  444. //回车键搜索
  445. $('#rationSearchKeyword').bind('keypress', function (event) {
  446. if(event.keyCode === 13){
  447. $(this).blur();
  448. $('#rationSearch').click();
  449. }
  450. });
  451. $('#rationSearchKeyword').keyup(function () {
  452. let keyword = $('#rationSearchKeyword').val();
  453. if(keyword === ''){
  454. if($('#rationSearchResult').is(':visible')){
  455. $('#rationSearchResult').hide();
  456. $(".main-data-side-search", $('#rationSearchResult')).height(0);
  457. switchRationSearchMode(0);
  458. autoFlashHeight();
  459. rationLibObj.refreshSpread();
  460. }
  461. }
  462. });
  463. //变换搜索本定额、全部定额状态
  464. function switchRationSearchMode(mode) {
  465. //搜索本定额
  466. if(mode === 0){
  467. $('#curRationLib').removeClass('btn-light');
  468. $('#curRationLib').addClass('btn-secondary');
  469. $('#allRationLibs').removeClass('btn-secondary');
  470. $('#allRationLibs').addClass('btn-light');
  471. } else {//搜索全部定额
  472. $('#allRationLibs').removeClass('btn-light');
  473. $('#allRationLibs').addClass('btn-secondary');
  474. $('#curRationLib').removeClass('btn-secondary');
  475. $('#curRationLib').addClass('btn-light');
  476. }
  477. }
  478. //搜索本定额
  479. $('#curRationLib').click(function () {
  480. if($(this).hasClass('btn-secondary')){
  481. return;
  482. }
  483. switchRationSearchMode(0);
  484. $('#rationSearch').click();
  485. });
  486. //搜索全部定额
  487. $('#allRationLibs').click(function () {
  488. if($(this).hasClass('btn-secondary')){
  489. return;
  490. }
  491. switchRationSearchMode(1);
  492. $('#rationSearch').click();
  493. });
  494. //搜索
  495. $('#rationSearch').click(function () {
  496. var keyword = $('#rationSearchKeyword').val();
  497. if(keyword === ''){
  498. if($('#rationSearchResult').is(':visible')){
  499. $('#rationSearchResult').hide();
  500. $(".main-data-side-search", $('#rationSearchResult')).height(0);
  501. autoFlashHeight();
  502. rationLibObj.refreshSpread();
  503. }
  504. return;
  505. }
  506. //获取搜索定额的库:本库/所有库
  507. let rationLibIDs = [];
  508. if($('#curRationLib').hasClass('btn-secondary')){
  509. rationLibIDs.push($('#stdRationLibSelect').val());
  510. } else {
  511. for(let lib of projectInfoObj.projectInfo.engineeringInfo.ration_lib){
  512. rationLibIDs.push(lib.id);
  513. }
  514. }
  515. let bindContextmenuOpr = function (sheet) {
  516. $.contextMenu({
  517. selector: '#rationSearchResult',
  518. build: function($triggerElement, e){
  519. //控制允许右键菜单在哪个位置出现
  520. let offset = $('.main-data-side-search').offset(),
  521. x = e.pageX - offset.left,
  522. y = e.pageY - offset.top;
  523. let target = sheet.hitTest(x, y);
  524. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  525. sheet.setActiveCell(target.row, target.col);
  526. return {
  527. callback: function(){},
  528. items: {
  529. "locate": {
  530. name: "定位至章节",
  531. disabled: function () {
  532. return target.row >= rationLibObj.resultCache.length;
  533. },
  534. icon: "fa-arrow-left",
  535. callback: function (key, opt) {
  536. let data = rationLibObj.resultCache[target.row];
  537. $('#rationSearchResult').hide();
  538. $(".main-data-side-search", $('#rationSearchResult')).height(0);
  539. autoFlashHeight();
  540. rationLibObj.refreshSpread();
  541. switchRationSearchMode(0);
  542. if($('#stdRationLibSelect').select().val() != data.rationRepId){
  543. let libOpts = $('#stdRationLibSelect').find('option');
  544. for(let libOpt of libOpts){
  545. if($(libOpt).val() == data.rationRepId){
  546. $(libOpt).prop('selected', 'selected');
  547. break;
  548. }
  549. }
  550. $('#stdRationLibSelect').change();
  551. rationLibObj.doAfterGetRationTree = function () {
  552. this.locateAtRation(data.rationRepId, data.code);
  553. this.doAfterGetRationTree = null;
  554. };
  555. } else {
  556. rationLibObj.locateAtRation(data.rationRepId, data.code);
  557. }
  558. }}
  559. }
  560. };
  561. }
  562. else{
  563. return false;
  564. }
  565. }
  566. });
  567. };
  568. var showResult = function (result) {
  569. rationLibObj.resultCache = result;
  570. if(!rationLibObj.resultSpread){
  571. let resultSpread = SheetDataHelper.createNewSpread($('.main-data-side-search')[0]);
  572. rationLibObj.resultSpread = resultSpread;
  573. bindContextmenuOpr(resultSpread.getActiveSheet());
  574. SheetDataHelper.loadSheetHeader(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet());
  575. resultSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, rationLibObj.onRationSpreadCellDoubleClick);
  576. }else {
  577. rationLibObj.resultSpread.refresh();
  578. }
  579. SheetDataHelper.loadSheetData(rationLibObj.sectionRationsSetting, rationLibObj.resultSpread.getActiveSheet(), result);
  580. rationLibObj.setTagForHint(rationLibObj.resultSpread.getActiveSheet(), result);
  581. };
  582. $.bootstrapLoading.start();
  583. CommonAjax.post('/complementaryRation/api/findRation', {'user_id': userID, 'rationRepId': rationLibIDs, 'keyword': keyword}, function (result) {
  584. //sort
  585. result.sort(function (a, b) {
  586. let rst = 0;
  587. if(a.code > b.code) rst = 1;
  588. else if(a.code < b.code) rst = -1;
  589. return rst;
  590. });
  591. var resultObj = $('#rationSearchResult');
  592. $('#rationSearchCount').text(`搜索结果:${result.length.toString()}`);
  593. $('a', result).unbind('click');
  594. $('a', resultObj).bind('click', function () {
  595. switchRationSearchMode(0);
  596. resultObj.hide();
  597. $(".main-data-side-search", resultObj).height(0);
  598. autoFlashHeight();
  599. rationLibObj.refreshSpread();
  600. });
  601. resultObj.show();
  602. $(".main-data-side-search", resultObj).height($(window).height() - $(".header").height() - $(".toolsbar").height() - 64);
  603. showResult(result);
  604. $.bootstrapLoading.end();
  605. }, function () {
  606. $.bootstrapLoading.end();
  607. });
  608. });