std_ration_lib.js 31 KB

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