std_ration_lib.js 33 KB

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