std_ration_lib.js 37 KB

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