std_ration_lib.js 36 KB

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