std_ration_lib.js 26 KB

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