std_ration_lib.js 31 KB

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