std_ration_lib.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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. debugger;
  203. if (!sectionName || !datas || datas.length === 0) {
  204. return;
  205. }
  206. //提取需要匹配的章节名称
  207. // 去掉后缀
  208. const suffixReg = /[((]编码[::]\w+[))]/;
  209. const tempName = sectionName.split(suffixReg)[0];
  210. // 获取第一个空格后的内容
  211. const sReg = /\s(.+)/;
  212. const tempTarget = tempName.match(sReg);
  213. const target = tempTarget ? tempTarget[1] : null;
  214. if (!target) {
  215. return;
  216. }
  217. //简化匹配到的定额名称
  218. for (let data of datas) {
  219. if (!data.name) {
  220. continue;
  221. }
  222. //第一个空格前的字符串去进行匹配,没有则不匹配
  223. let nameArr = data.name.split(' ');
  224. if (nameArr.length <= 1) {
  225. continue;
  226. }
  227. let matchName = nameArr[0];
  228. if (matchName === target) {
  229. nameArr.shift();
  230. data.name = nameArr.join(' ');
  231. }
  232. }
  233. }
  234. if (sectionID) {
  235. CommonAjax.post('/complementaryRation/api/getRationGljItemsBySection', {user_Id: userID, sectionId: sectionID, type: me.curLibType}, function (datas) {
  236. let chapterSheet = me.rationChapterSpread.getActiveSheet();
  237. let sectionName = chapterSheet.getText(chapterSheet.getActiveRowIndex(), chapterSheet.getActiveColumnIndex());
  238. simplifyName(sectionName, datas);
  239. showDatas(datas, rationLibObj.sectionRationsSetting);
  240. if(me.doAfterLoadGetRations){
  241. me.doAfterLoadGetRations(datas);
  242. me.doAfterLoadGetRations = null;
  243. }
  244. }, function () {
  245. showDatas([], rationLibObj.sectionRationsSetting);
  246. });
  247. } else {
  248. showDatas([], rationLibObj.sectionRationsSetting);
  249. }
  250. },
  251. onRationSpreadCellDoubleClick: function (sender, args) {
  252. var select = $('#stdRationLibSelect'), rationCode = args.sheet.getText(args.row, 0);
  253. if (rationCode !== '' && projectObj.project.Ration.canAdd(projectObj.project.mainTree.selected)) {
  254. let query = {userID: userID, rationRepId: select.val(), code: rationCode};
  255. //搜索结果全部定额中双击添加定额、有可能同名不同库,更新查询的库ID
  256. if (rationLibObj.resultCache && rationLibObj.resultCache[args.row]) {
  257. query.rationRepId = rationLibObj.resultCache[args.row].type === 'std' ? rationLibObj.resultCache[args.row].rationRepId : rationLibObj.compleRationLibId;
  258. }
  259. projectObj.project.Ration.addNewRation(query,rationType.ration, function () {
  260. projectObj.setActiveCell('quantity', true);
  261. });
  262. }
  263. },
  264. //滚动条到底部加载
  265. onRationSpreadTopRowChanged: function (sender, args) {
  266. let me = rationLibObj;
  267. if(me.searching) {
  268. return;
  269. }
  270. let bottomRow = args.sheet.getViewportBottomRow(1),
  271. rowCount = args.sheet.getRowCount();
  272. //滚到了底部
  273. if (bottomRow + 1 - me.sectionRationsSetting.emptyRows === rowCount - me.sectionRationsSetting.emptyRows) {
  274. seachRation();
  275. }
  276. },
  277. loadStdRationContextMenu: function () {
  278. let rationSpread = rationLibObj.sectionRationsSpread, rationSheet = rationSpread.getActiveSheet(), rationModel = projectObj.project.Ration;;
  279. $.contextMenu({
  280. selector: '#stdSectionRations',
  281. build: function ($trigger, e) {
  282. let target = SheetDataHelper.safeRightClickSelection($trigger, e, rationSpread);
  283. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  284. },
  285. items: {
  286. "insertStdRation": {
  287. name: "插入定额",
  288. icon: 'fa-sign-in',
  289. disabled: function () {
  290. return projectReadOnly || !projectObj.project.Ration.canAdd(projectObj.project.mainTree.selected);
  291. },
  292. callback: function (key, opt) {
  293. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  294. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  295. if (rationCode !== '') {
  296. rationModel.addNewRation({userID: userID, rationRepId: select.val(), code: rationCode},rationType.ration, function () {
  297. });
  298. }
  299. }
  300. },
  301. "replaceStdRation": {
  302. name: "替换定额",
  303. icon: 'fa-sign-in',
  304. disabled: function () {
  305. return projectReadOnly || !projectObj.project.Ration.canAdd(projectObj.project.mainTree.selected);
  306. },
  307. callback: function (key, opt) {
  308. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  309. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  310. let mainTreeSelected = projectObj.project.mainTree.selected;
  311. if (rationCode !== ''&&mainTreeSelected&&mainTreeSelected.sourceType == rationModel.getSourceType()) {
  312. rationModel.updateRationCodes([{'node':mainTreeSelected,value:rationCode}]);
  313. }
  314. }
  315. },
  316. }
  317. });
  318. },
  319. expandSearchNodes: function(nodes){
  320. let that = rationLibObj;
  321. TREE_SHEET_HELPER.massOperationSheet(that.rationChapterSpread.getActiveSheet(), function () {
  322. function expParentNode(node){
  323. if(node.parent){
  324. expParentNode(node.parent);
  325. if(!node.parent.expanded){
  326. node.parent.setExpanded(true);
  327. }
  328. }
  329. }
  330. for(let node of nodes){
  331. expParentNode(node);
  332. }
  333. TREE_SHEET_HELPER.refreshTreeNodeData(that.rationChapterTreeSetting, that.rationChapterSpread.getActiveSheet(), that.tree.roots, true);
  334. TREE_SHEET_HELPER.refreshNodesVisible(that.tree.roots, that.rationChapterSpread.getActiveSheet(), true);
  335. });
  336. },
  337. initSel: function (row) {
  338. let me = this;
  339. let sheet = me.rationChapterSpread.getActiveSheet();
  340. sheet.setActiveCell(row, 0);
  341. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  342. let sectionNode = me.tree.items[row] || null;
  343. me.loadSectionRations(sectionNode && sectionNode.children.length === 0 ? sectionNode.data.ID : null);
  344. },
  345. locateAtRation: function(libID, code){
  346. if(!isDef(libID)) return;
  347. let me = rationLibObj;
  348. if ($('#rationSearchResult').is(':visible')) {
  349. $('#rationSearchResult a').click();
  350. }
  351. //查找定额,以确定定额所在章节节点
  352. let locateRow = 0,
  353. locateSubRow = 0;
  354. CommonAjax.post('/complementaryRation/api/getRationItem', {rationRepIds: [libID], code: code}, function (ration) {
  355. if(ration && ration.sectionId){
  356. let sectionNode = me.tree.findNode(ration.sectionId);
  357. if(sectionNode){
  358. me.expandSearchNodes([sectionNode]);
  359. sessionStorage.setItem('stdRationLibExpState', me.tree.getExpState(me.tree.items));
  360. }
  361. locateRow = sectionNode.serialNo();
  362. me.doAfterLoadGetRations = function (rationItems) {
  363. let rationSheet = me.sectionRationsSpread.getActiveSheet();
  364. locateSubRow = _.findIndex(rationItems, {ID: ration.ID});
  365. rationSheet.setActiveCell(locateSubRow, 0);
  366. rationSheet.showRow(locateSubRow, GC.Spread.Sheets.VerticalPosition.center);
  367. };
  368. me.initSel(locateRow);
  369. }
  370. else {
  371. me.initSel(locateRow);
  372. }
  373. }, function () {
  374. me.initSel(locateRow);
  375. });
  376. },
  377. rationChapterTreeSetting: {
  378. "emptyRowHeader": true,
  379. "rowHeaderWidth": 1,
  380. "emptyRows":0,
  381. "headRows":1,
  382. "headRowHeight":[30],
  383. "defaultRowHeight": 21,
  384. "treeCol": 0,
  385. "cols":[{
  386. "rateWidth": 1,
  387. "width":400,
  388. "readOnly": true,
  389. "head":{
  390. "titleNames":["名称"],
  391. "spanCols":[1],
  392. "spanRows":[1],
  393. "vAlign":[1],
  394. "hAlign":[1],
  395. "font":["Arial"]
  396. },
  397. "data":{
  398. "field":"name",
  399. "vAlign":1,
  400. "hAlign":0,
  401. "font":"Arial"
  402. }
  403. }]
  404. },
  405. sectionRationsSetting: {
  406. "emptyRowHeader": true,
  407. "rowHeaderWidth": 1,
  408. "emptyRows":3,
  409. "headRows":1,
  410. "headRowHeight":[20],
  411. "defaultRowHeight": 21,
  412. "cols":[{
  413. "width":60,
  414. "readOnly": true,
  415. "showHint": true,
  416. "head":{
  417. "titleNames":["编码"],
  418. "spanCols":[1],
  419. "spanRows":[1],
  420. "vAlign":[1],
  421. "hAlign":[1],
  422. "font":["Arial"]
  423. },
  424. "data":{
  425. "field":"code",
  426. "vAlign":1,
  427. "hAlign":0,
  428. "font":"Arial"
  429. }
  430. }, {
  431. "width":220,
  432. "readOnly": true,
  433. "showHint": true,
  434. "head":{
  435. "titleNames":["名称"],
  436. "spanCols":[1],
  437. "spanRows":[1],
  438. "vAlign":[1],
  439. "hAlign":[1],
  440. "font":["Arial"]
  441. },
  442. "data":{
  443. "field":"name",
  444. "vAlign":1,
  445. "hAlign":0,
  446. "font":"Arial"
  447. }
  448. }, {
  449. "width":55,
  450. "readOnly":true,
  451. "head":{
  452. "titleNames":["单位"],
  453. "spanCols":[1],
  454. "spanRows":[1],
  455. "vAlign":[1],
  456. "hAlign":[1],
  457. "font":["Arial"]
  458. },
  459. "data":{
  460. "field":"unit",
  461. "vAlign":1,
  462. "hAlign":1,
  463. "font":"Arial"
  464. }
  465. }, {
  466. "width":60,
  467. "readOnly":true,
  468. "head":{
  469. "titleNames":["基价"],
  470. "spanCols":[1],
  471. "spanRows":[1],
  472. "vAlign":[1],
  473. "hAlign":[1],
  474. "font":["Arial"]
  475. },
  476. "data":{
  477. "field":"basePrice",
  478. "vAlign":1,
  479. "hAlign":2,
  480. "font":"Arial"
  481. }
  482. }]
  483. },
  484. getStdRationLibIDs: function () {
  485. let ids = [];
  486. if(projectObj.project.projectInfo.engineeringInfo.ration_lib.length === 0){
  487. alert('当前项目无定额库,请添加定额库。');
  488. return null;
  489. }
  490. for(let rationLib of projectObj.project.projectInfo.engineeringInfo.ration_lib){
  491. ids.push(rationLib.id);
  492. }
  493. return ids;
  494. },
  495. getCurrentStdRationLibID:function () {
  496. if(projectObj.project.projectInfo.engineeringInfo.ration_lib.length === 0){
  497. alert('当前项目无定额库,请添加定额库。');
  498. return null;
  499. }
  500. if($('#stdRationLibSelect').val()){
  501. return parseInt($('#stdRationLibSelect').val());
  502. }else {
  503. return projectObj.project.projectInfo.engineeringInfo.ration_lib[0].id;
  504. }
  505. },
  506. getFirstStdRationLibID: function () {
  507. if(projectObj.project.projectInfo.engineeringInfo.ration_lib.length === 0){
  508. alert('当前项目无定额库,请添加定额库。');
  509. return null;
  510. }
  511. return parseInt(projectObj.project.projectInfo.engineeringInfo.ration_lib[0].id);
  512. },
  513. getDefaultStdRationLibID:function(){
  514. let ration_lib = projectObj.project.projectInfo.engineeringInfo.ration_lib;
  515. if(ration_lib.length === 0){
  516. alert('当前项目无定额库,请添加定额库。');
  517. return null;
  518. }
  519. let defaultLib = _.find(ration_lib,{'isDefault':true});
  520. let libID = defaultLib?defaultLib.id:ration_lib[0].id;
  521. return parseInt(libID);
  522. },
  523. //@param {Array}datas(resultCache) @return {Object}
  524. //搜索skip信息,不能被每页搜索数整除,则说明上次搜索已经搜索完整
  525. getSearchSkip: function (datas) {
  526. if (datas.length % this.searchLimit !== 0) {
  527. return null;
  528. }
  529. let skip = {std: 0, comple: 0};
  530. if (!datas || !Array.isArray(datas) || datas.length === 0) {
  531. return skip;
  532. }
  533. for (let data of datas) {
  534. if (data.type === 'std') {
  535. skip.std++;
  536. } else {
  537. skip.comple++;
  538. }
  539. }
  540. return skip;
  541. }
  542. };
  543. addEventOnResize(rationLibObj.refreshSettingForHint);
  544. //赋初始高度
  545. if($('#stdRationChapter').height() === 0 || $('#stdSectionRations').height() === 0){
  546. $('#stdRationChapter').height($(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-q").height()-312);
  547. $('#stdSectionRations').height(270);
  548. }
  549. $('#stdRationTab').bind('click', function () {
  550. var select = $('#stdRationLibSelect');
  551. rationLibObj.checkSpread();
  552. if (select[0].options.length === 0) {
  553. rationLibObj.loadStdRationLibs();
  554. rationLibObj.loadStdRationContextMenu();
  555. };
  556. });
  557. $('#stdRationLibSelect').change(function () {
  558. var select = $(this);
  559. if (this.children.length !== 0) {
  560. let rationLibId = select.val();
  561. sessionStorage.setItem('stdRationLib', rationLibId);
  562. sessionStorage.removeItem('stdRationLibExpState');
  563. rationLibObj.loadStdRation(rationLibId);
  564. }
  565. });
  566. //回车键搜索
  567. $('#rationSearchKeyword').bind('keypress', function (event) {
  568. if(event.keyCode === 13){
  569. $(this).blur();
  570. $('#rationSearch').click();
  571. }
  572. });
  573. $('#rationSearchKeyword').keyup(function () {
  574. let keyword = $('#rationSearchKeyword').val();
  575. if(keyword === ''){
  576. if($('#rationSearchResult').is(':visible')){
  577. rationLibObj.resultCache = [];
  578. $('#rationSearchResult').hide();
  579. $(".main-data-side-search", $('#rationSearchResult')).height(0);
  580. switchRationSearchMode(0);
  581. autoFlashHeight();
  582. rationLibObj.refreshSpread();
  583. }
  584. }
  585. });
  586. //变换搜索本定额、全部定额状态
  587. function switchRationSearchMode(mode) {
  588. rationLibObj.resultCache = [];
  589. //搜索本定额
  590. if(mode === 0){
  591. $('#curRationLib').removeClass('btn-light');
  592. $('#curRationLib').addClass('btn-secondary');
  593. $('#allRationLibs').removeClass('btn-secondary');
  594. $('#allRationLibs').addClass('btn-light');
  595. } else {//搜索全部定额
  596. $('#allRationLibs').removeClass('btn-light');
  597. $('#allRationLibs').addClass('btn-secondary');
  598. $('#curRationLib').removeClass('btn-secondary');
  599. $('#curRationLib').addClass('btn-light');
  600. }
  601. }
  602. //搜索本定额
  603. $('#curRationLib').click(function () {
  604. if($(this).hasClass('btn-secondary')){
  605. return;
  606. }
  607. switchRationSearchMode(0);
  608. $('#rationSearch').click();
  609. });
  610. //搜索全部定额
  611. $('#allRationLibs').click(function () {
  612. if($(this).hasClass('btn-secondary')){
  613. return;
  614. }
  615. switchRationSearchMode(1);
  616. $('#rationSearch').click();
  617. });
  618. //搜索
  619. function seachRation(){
  620. let skip = rationLibObj.getSearchSkip(rationLibObj.resultCache);
  621. if (!skip) {
  622. return;
  623. }
  624. rationLibObj.searching = true;
  625. var keyword = $('#rationSearchKeyword').val();
  626. if(keyword === ''){
  627. if($('#rationSearchResult').is(':visible')){
  628. rationLibObj.resultCache = [];
  629. $('#rationSearchResult').hide();
  630. $(".main-data-side-search", $('#rationSearchResult')).height(0);
  631. autoFlashHeight();
  632. rationLibObj.refreshSpread();
  633. }
  634. return;
  635. }
  636. //获取搜索定额的库:本库/所有库
  637. let rationLibIDs = [];
  638. if($('#curRationLib').hasClass('btn-secondary')){
  639. rationLibIDs.push($('#stdRationLibSelect').val());
  640. } else {
  641. for(let lib of projectObj.project.projectInfo.engineeringInfo.ration_lib){
  642. rationLibIDs.push(lib.id);
  643. }
  644. }
  645. let bindContextmenuOpr = function (sheet) {
  646. $.contextMenu({
  647. selector: '#rationSearchResult',
  648. build: function($triggerElement, e){
  649. //控制允许右键菜单在哪个位置出现
  650. let offset = $('.main-data-side-search').offset(),
  651. x = e.pageX - offset.left,
  652. y = e.pageY - offset.top;
  653. let target = sheet.hitTest(x, y);
  654. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  655. sheet.setActiveCell(target.row, target.col);
  656. return {
  657. callback: function(){},
  658. items: {
  659. "locate": {
  660. name: "定位至章节",
  661. disabled: function () {
  662. return target.row >= rationLibObj.resultCache.length;
  663. },
  664. icon: "fa-arrow-left",
  665. callback: function (key, opt) {
  666. let data = rationLibObj.resultCache[target.row],
  667. libId = data.rationRepId ? data.rationRepId : rationLibObj.compleRationLibId;
  668. $('#rationSearchResult').hide();
  669. $(".main-data-side-search", $('#rationSearchResult')).height(0);
  670. autoFlashHeight();
  671. rationLibObj.refreshSpread();
  672. switchRationSearchMode(0);
  673. if($('#stdRationLibSelect').select().val() != libId){
  674. let libOpts = $('#stdRationLibSelect').find('option');
  675. for(let libOpt of libOpts){
  676. if($(libOpt).val() == libId){
  677. $(libOpt).prop('selected', 'selected');
  678. break;
  679. }
  680. }
  681. $('#stdRationLibSelect').change();
  682. rationLibObj.doAfterGetRationTree = function () {
  683. this.locateAtRation(libId, data.code);
  684. this.doAfterGetRationTree = null;
  685. };
  686. } else {
  687. rationLibObj.locateAtRation(libId, data.code);
  688. }
  689. }}
  690. }
  691. };
  692. }
  693. else{
  694. return false;
  695. }
  696. }
  697. });
  698. };
  699. var showResult = function (result) {
  700. if(!rationLibObj.resultSpread){
  701. let resultSpread = SheetDataHelper.createNewSpread($('.main-data-side-search')[0]);
  702. rationLibObj.resultSpread = resultSpread;
  703. bindContextmenuOpr(resultSpread.getActiveSheet());
  704. SheetDataHelper.loadSheetHeader(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet());
  705. if (!projectReadOnly) {
  706. resultSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, rationLibObj.onRationSpreadCellDoubleClick);
  707. }
  708. resultSpread.bind(GC.Spread.Sheets.Events.TopRowChanged, rationLibObj.onRationSpreadTopRowChanged);
  709. }else {
  710. rationLibObj.resultSpread.refresh();
  711. }
  712. SheetDataHelper.loadSheetData(rationLibObj.sectionRationsSetting, rationLibObj.resultSpread.getActiveSheet(), result);
  713. rationLibObj.setTagForHint(rationLibObj.resultSpread.getActiveSheet(), result);
  714. rationLibObj.resultCache = result;
  715. };
  716. $.bootstrapLoading.start();
  717. CommonAjax.post('/complementaryRation/api/findRation', {'user_id': userID, 'rationRepId': rationLibIDs, 'keyword': keyword, skip: skip}, function (result) {
  718. var resultObj = $('#rationSearchResult');
  719. if (result.count !== null) {
  720. $('#rationSearchCount').text(`搜索结果:${result.count}`);
  721. }
  722. $('a', resultObj).unbind('click');
  723. $('a', resultObj).bind('click', function () {
  724. rationLibObj.resultCache = [];
  725. switchRationSearchMode(0);
  726. resultObj.hide();
  727. $(".main-data-side-search", resultObj).height(0);
  728. autoFlashHeight();
  729. loadSideToolsHeight();
  730. });
  731. resultObj.show();
  732. $(".main-data-side-search", resultObj).height($(window).height() - $(".header").height() - $(".toolsbar").height() - 64);
  733. showResult(rationLibObj.resultCache.concat(result.data));
  734. rationLibObj.searching = false;
  735. //以防一开始就需要加载后面的分页数据
  736. if (result.data.length > 0) {
  737. rationLibObj.onRationSpreadTopRowChanged({}, {sheet: rationLibObj.resultSpread.getActiveSheet()});
  738. }
  739. $.bootstrapLoading.end();
  740. }, function () {
  741. rationLibObj.searching = false;
  742. $.bootstrapLoading.end();
  743. });
  744. }
  745. $('#rationSearch').click(function () {
  746. rationLibObj.resultCache = [];
  747. seachRation();
  748. });