std_ration_lib.js 27 KB

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