std_ration_lib.js 25 KB

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