std_ration_lib.js 37 KB

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