std_ration_lib.js 28 KB

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