std_ration_lib.js 35 KB

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