std_bills_lib.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /**
  2. * Standard Bills Lib
  3. * Created by Mai on 2017/5/16.
  4. */
  5. var billsLibObj = {
  6. stdBillsTree: null,
  7. stdBillsSpread: null,
  8. stdBillsJobSpread: null,
  9. stdBillsFeatureSpread: null,
  10. refreshSettingForHint: function () {
  11. TREE_SHEET_HELPER.initSetting($('#stdBillsSpread')[0], billsLibObj.stdBillsTreeSetting);
  12. },
  13. checkBillsSpread: function () {
  14. if (!this.stdBillsSpread) {
  15. this.stdBillsSpread = SheetDataHelper.createNewSpread($('#stdBillsSpread')[0]);
  16. this.stdBillsSpread.getSheet(0).name('stdBillsLib_bills');
  17. // 刷新setting中记录的spread的位置
  18. this.refreshSettingForHint();
  19. }
  20. },
  21. refreshBillsSpread: function () {
  22. if (this.stdBillsSpread) {
  23. this.stdBillsSpread.refresh();
  24. }
  25. },
  26. checkBillsRelaSpread: function () {
  27. if (!this.stdBillsJobSpread) {
  28. this.stdBillsJobSpread = SheetDataHelper.createNewSpread($('#stdBillsJobs')[0]);
  29. }
  30. if (!this.stdBillsFeatureSpread) {
  31. this.stdBillsFeatureSpread = SheetDataHelper.createNewSpread($('#stdBillsFeatures')[0]);
  32. }
  33. },
  34. refreshBillsRelaSpread: function () {
  35. if (this.stdBillsJobSpread) {
  36. this.stdBillsJobSpread.refresh();
  37. }
  38. if (this.stdBillsFeatureSpread) {
  39. this.stdBillsFeatureSpread.refresh();
  40. }
  41. },
  42. clearHighLight: function (spread) {
  43. if (spread) {
  44. let sheet = spread.getActiveSheet();
  45. sheet.suspendPaint();
  46. let orgColor = optionsOprObj.getOption('COLOROPTS', 'DEFAULT').backColor;
  47. sheet.getRange(0, -1, sheet.getRowCount(), -1, GC.Spread.Sheets.SheetArea.viewport).backColor(orgColor);
  48. sheet.resumePaint();
  49. }
  50. },
  51. setTagForHint: function (nodes) {
  52. let sheet = this.stdBillsSpread.getActiveSheet();
  53. sheet.suspendPaint();
  54. sheet.suspendEvent();
  55. for(let node of nodes){
  56. sheet.setTag(node.serialNo(), 2, node.data.ruleText ? node.data.ruleText : '');
  57. }
  58. sheet.resumePaint();
  59. sheet.resumeEvent();
  60. },
  61. loadStdBillsLib: function () {
  62. let i, select = $('#stdBillsLibSelect');
  63. select.empty();
  64. let bills_lib = projectInfoObj.projectInfo.engineeringInfo.bill_lib;
  65. let selectedBillsLib = sessionStorage.getItem('stdBillsLib');
  66. bills_lib.forEach(function (data) {
  67. var option = $('<option>').val(data.id).text(data.name);
  68. if(selectedBillsLib && data.id == selectedBillsLib){
  69. option.attr('selected', 'selected');
  70. }
  71. select.append(option);
  72. });
  73. if (select.children.length !== 0) {
  74. billsLibObj.loadStdBills(select.val());
  75. }
  76. },
  77. sortJobsAndFeatures: function (arr) {
  78. arr.sort(function (a, b) {
  79. let rst = 0;
  80. if(a.serialNo > b.serialNo) rst = 1;
  81. else if(a.serialNo < b.serialNo) rst = -1;
  82. return rst;
  83. });
  84. },
  85. findData: function (value, field, Array) {
  86. var i = 0;
  87. for (i = 0; i < Array.length; i++) {
  88. if (value[field] == Array[i][field]) {
  89. return Array[i];
  90. }
  91. }
  92. return null;
  93. },
  94. getBillsJobs: function (stdBillsJobData, node) {
  95. var jobs = [], i, jobData = null;
  96. if (stdBillsJobData && node && node.data.jobs) {
  97. for (i = 0; i < node.data.jobs.length; i++) {
  98. jobData = this.findData(node.data.jobs[i], 'id', stdBillsJobData);
  99. if (jobData) {
  100. jobData.serialNo = node.data.jobs[i].serialNo;
  101. jobs.push(jobData);
  102. }
  103. }
  104. }
  105. this.sortJobsAndFeatures(jobs);
  106. return jobs;
  107. },
  108. getBillsFeatures: function (stdBillsFeatureData, node) {
  109. var features = [], i, featureData = null;
  110. if (stdBillsFeatureData && node && node.data.items) {
  111. for (i = 0; i < node.data.items.length; i++) {
  112. featureData = this.findData(node.data.items[i], 'id', stdBillsFeatureData);
  113. if (featureData) {
  114. featureData.serialNo = node.data.items[i].serialNo;
  115. features.push(featureData);
  116. }
  117. }
  118. }
  119. this.sortJobsAndFeatures(features);
  120. return features;
  121. },
  122. insertBills: function (stdBillsJobData, stdBillsFeatureData, node) {
  123. if(projectInfoObj.projectInfo.property.lockBills == true && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
  124. return false;
  125. }
  126. $.bootstrapLoading.start();
  127. //设置清单备注
  128. if(node.parent && node.parent.data.recharge){
  129. node.data.comments = node.parent.data.recharge;
  130. }
  131. //特征及内容转化
  132. pageCCOprObj.setItemContentNode(node, this.getBillsJobs(stdBillsJobData, node), this.getBillsFeatures(stdBillsFeatureData, node), node.data.name);
  133. if (/\//.test(node.data.unit)) {
  134. let existB = projectObj.project.Bills.sameStdCodeBillsData(node.data.code);
  135. if (existB) {
  136. let std = JSON.parse(JSON.stringify(node.data));
  137. std.unit = existB.unit;
  138. let canAdd = ProjectController.addBills(projectObj.project, projectObj.mainController, std);
  139. if(canAdd === false && $.bootstrapLoading.isLoading()){
  140. $.bootstrapLoading.end();
  141. }
  142. } else {
  143. ConfirmModal.stdBillsUnit.check(node.data, function (std) {
  144. let canAdd = ProjectController.addBills(projectObj.project, projectObj.mainController, std);
  145. if(canAdd === false && $.bootstrapLoading.isLoading()){
  146. $.bootstrapLoading.end();
  147. }
  148. }, function () {
  149. if($.bootstrapLoading.isLoading()){
  150. $.bootstrapLoading.end();
  151. }
  152. });
  153. }
  154. } else {
  155. let canAdd = ProjectController.addBills(projectObj.project, projectObj.mainController, node.data);
  156. if(canAdd === false && $.bootstrapLoading.isLoading()){
  157. $.bootstrapLoading.end();
  158. }
  159. }
  160. return true;
  161. },
  162. loadStdBills: function (stdBillsLibID) {
  163. var that = this;
  164. var stdBillsJobData, stdBillsFeatureData, stdBills;
  165. if(that.stdBillsTree){
  166. that.stdBillsTree = null;
  167. }
  168. that.stdBillsTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  169. var stdBillsTreeController = TREE_SHEET_CONTROLLER.createNew(that.stdBillsTree, billsLibObj.stdBillsSpread.getActiveSheet(), billsLibObj.stdBillsTreeSetting);
  170. var showJobs = function (jobs) {
  171. SheetDataHelper.loadSheetHeader(billsLibObj.jobsSetting, billsLibObj.stdBillsJobSpread.getActiveSheet());
  172. SheetDataHelper.loadSheetData(billsLibObj.jobsSetting, billsLibObj.stdBillsJobSpread.getActiveSheet(), jobs);
  173. };
  174. var showFeatures = function (features) {
  175. SheetDataHelper.loadSheetHeader(billsLibObj.featuresSetting, billsLibObj.stdBillsFeatureSpread.getActiveSheet());
  176. SheetDataHelper.loadSheetData(billsLibObj.featuresSetting, billsLibObj.stdBillsFeatureSpread.getActiveSheet(), features);
  177. };
  178. var showJobsAndFeatures = function (node) {
  179. $('#stdBillsJobTab').show();
  180. $('#stdBillsRemarkTab').hide();
  181. billsLibObj.refreshBillsRelaSpread();
  182. billsLibObj.checkBillsRelaSpread();
  183. showJobs(billsLibObj.getBillsJobs(stdBillsJobData, node));
  184. showFeatures(billsLibObj.getBillsFeatures(stdBillsFeatureData, node));
  185. };
  186. var showBillsRemark = function (node) {
  187. $('#stdBillsJobTab').hide();
  188. $('#stdBillsRemarkTab').show();
  189. $('#stdBillsRemark').text(node && node.data.recharge ? node.data.recharge : '');
  190. };
  191. var showBillsRela = function (node) {
  192. if (node && node.children.length === 0) {
  193. showJobsAndFeatures(node);
  194. } else {
  195. showBillsRemark(node);
  196. }
  197. };
  198. CommonAjax.post('/stdBillsEditor/getJobContent', {userId: userID, billsLibId: stdBillsLibID}, function (datas) {
  199. stdBillsJobData = datas;
  200. }, function () {
  201. stdBillsJobData = [];
  202. });
  203. CommonAjax.post('/stdBillsEditor/getItemCharacter', {userId: userID, billsLibId: stdBillsLibID}, function (datas) {
  204. stdBillsFeatureData = datas;
  205. }, function () {
  206. stdBillsFeatureData = [];
  207. });
  208. CommonAjax.post('/stdBillsEditor/getBills', {userId: userID, billsLibId: stdBillsLibID}, function (datas) {
  209. stdBills = datas;
  210. that.stdBillsTree.loadDatas(stdBills);
  211. //读取展开收起状态
  212. let currentExpState = sessionStorage.getItem('stdBillsLibExpState');
  213. if(currentExpState){
  214. that.stdBillsTree.setExpandedByState(that.stdBillsTree.items, currentExpState);
  215. }
  216. //非叶子节点默认收起
  217. else{
  218. that.stdBillsTree.setRootExpanded(that.stdBillsTree.roots, false);
  219. }
  220. stdBillsTreeController.showTreeData();
  221. billsLibObj.setTagForHint(that.stdBillsTree.items);
  222. showBillsRela(that.stdBillsTree.firstNode());
  223. stdBillsTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, showBillsRela);
  224. that.stdBillsSpread.unbind(GC.Spread.Sheets.Events.CellDoubleClick);
  225. that.stdBillsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (sender, args) {
  226. let selectNode = that.stdBillsTree.items[args.row];
  227. let name = selectNode.data.name;
  228. if (that.stdBillsTree.items[args.row].children.length === 0) {
  229. billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, selectNode);
  230. }
  231. else{
  232. let me = billsLibObj;
  233. let node = that.stdBillsTree.items[args.row];
  234. if (!node || node.children.length === 0)
  235. return;
  236. node.setExpanded(!node.expanded);
  237. //设置展开收起状态
  238. sessionStorage.setItem('stdBillsLibExpState', that.stdBillsTree.getExpState(that.stdBillsTree.items));
  239. TREE_SHEET_HELPER.massOperationSheet(args.sheet, function () {
  240. let iCount = node.posterityCount(), i, child;
  241. for (i = 0; i < iCount; i++) {
  242. child = that.stdBillsTree.items[args.row + i + 1];
  243. args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
  244. }
  245. args.sheet.invalidateLayout();
  246. });
  247. args.sheet.repaint();
  248. }
  249. });
  250. }, function () {
  251. that.stdBillsSpread.unbind(GC.Spread.Sheets.Events.CellDoubleClick);
  252. });
  253. $('#stdBillsSearch>span>button').click(function () {
  254. billsLibObj.clearHighLight(billsLibObj.stdBillsSpread);
  255. var keyword = $('#stdBillsSearch>input').val();
  256. if (!keyword || keyword === '') {
  257. $('#stdBillsSearchResult').hide();
  258. return;
  259. }
  260. var result = that.stdBillsTree.items.filter(function (item) {
  261. var codeIs = item.data.code ? item.data.code.indexOf(keyword) !== -1 : false;
  262. var nameIs = item.data.name ? item.data.name.indexOf(keyword) !== -1 : false;
  263. return codeIs || nameIs;
  264. });
  265. result.sort(function (x, y) {
  266. return x.serialNo() - y.serialNo();
  267. });
  268. if (result.length !== 0) {
  269. //展开搜索出来的节点
  270. billsLibObj.expandSearchNodes(result);
  271. //设置记住展开
  272. sessionStorage.setItem('stdBillsLibExpState', that.stdBillsTree.getExpState(that.stdBillsTree.items));
  273. TREE_SHEET_HELPER.massOperationSheet(billsLibObj.stdBillsSpread.getActiveSheet(), function () {
  274. var sel = billsLibObj.stdBillsSpread.getActiveSheet().getSelections();
  275. stdBillsTreeController.setTreeSelected(result[0]);
  276. billsLibObj.stdBillsSpread.getActiveSheet().setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  277. for (let node of result) {
  278. billsLibObj.stdBillsSpread.getActiveSheet().getRange(node.serialNo(), -1, 1, -1).backColor('lemonChiffon');
  279. }
  280. });
  281. billsLibObj.stdBillsSpread.getActiveSheet().showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  282. $('#nextStdBills').show();
  283. $('#nextStdBills').unbind('click');
  284. $('#nextStdBills').bind('click', function () {
  285. var cur = that.stdBillsTree.selected, resultIndex = result.indexOf(cur), sel = billsLibObj.stdBillsSpread.getActiveSheet().getSelections();
  286. if (resultIndex === result.length - 1) {
  287. stdBillsTreeController.setTreeSelected(result[0]);
  288. billsLibObj.stdBillsSpread.getActiveSheet().setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  289. billsLibObj.stdBillsSpread.getActiveSheet().showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.top);
  290. } else {
  291. stdBillsTreeController.setTreeSelected(result[resultIndex + 1]);
  292. billsLibObj.stdBillsSpread.getActiveSheet().setSelection(result[resultIndex + 1].serialNo(), sel[0].col, 1, 1);
  293. billsLibObj.stdBillsSpread.getActiveSheet().showRow(result[resultIndex + 1].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  294. }
  295. });
  296. } else {
  297. billsLibObj.clearHighLight(billsLibObj.stdBillsSpread);
  298. $('#nextStdBills').hide();
  299. }
  300. $('#stdBillsSearchResultCount').text('搜索结果:' + result.length);
  301. $('#stdBillsSearchResult').show();
  302. });
  303. },
  304. expandSearchNodes: function(nodes){
  305. let that = this;
  306. TREE_SHEET_HELPER.massOperationSheet(billsLibObj.stdBillsSpread.getActiveSheet(), function () {
  307. function expParentNode(node){
  308. if(node.parent && !node.parent.expanded){
  309. node.parent.setExpanded(true);
  310. expParentNode(node.parent);
  311. }
  312. }
  313. for(let node of nodes){
  314. expParentNode(node);
  315. }
  316. TREE_SHEET_HELPER.refreshTreeNodeData(that.stdBillsTreeSetting, that.stdBillsSpread.getActiveSheet(), that.stdBillsTree.roots, true);
  317. TREE_SHEET_HELPER.refreshNodesVisible(that.stdBillsTree.roots, that.stdBillsSpread.getActiveSheet(), true);
  318. });
  319. },
  320. stdBillsTreeSetting: {
  321. "treeCol": 0,
  322. "emptyRows":0,
  323. "headRows":1,
  324. "headRowHeight":[
  325. 40
  326. ],
  327. "defaultRowHeight": 21,
  328. "cols":[{
  329. "width":160,
  330. "readOnly": true,
  331. "head":{
  332. "titleNames":["项目编码"],
  333. "spanCols":[1],
  334. "spanRows":[1],
  335. "vAlign":[1],
  336. "hAlign":[1],
  337. "font":["Arial"]
  338. },
  339. "data":{
  340. "field":"code",
  341. "vAlign":1,
  342. "hAlign":0,
  343. "font":"Arial"
  344. }
  345. }, {
  346. "width":220,
  347. "readOnly": true,
  348. "head":{
  349. "titleNames":["项目名称"],
  350. "spanCols":[1],
  351. "spanRows":[1],
  352. "vAlign":[1],
  353. "hAlign":[1],
  354. "font":["Arial"]
  355. },
  356. "data":{
  357. "field":"name",
  358. "vAlign":1,
  359. "hAlign":0,
  360. "font":"Arial"
  361. }
  362. }, {
  363. "width":45,
  364. "readOnly": true,
  365. "showHint": true,
  366. "head":{
  367. "titleNames":["计量单位"],
  368. "spanCols":[1],
  369. "spanRows":[1],
  370. "vAlign":[1],
  371. "hAlign":[1],
  372. "font":["Arial"],
  373. "wordWrap": true
  374. },
  375. "data":{
  376. "field":"unit",
  377. "vAlign":1,
  378. "hAlign":1,
  379. "font":"Arial"
  380. }
  381. }/*, {
  382. "width":100,
  383. "readOnly": true,
  384. "showHint": true,
  385. "head":{
  386. "titleNames":["工程量计算规则"],
  387. "spanCols":[1],
  388. "spanRows":[1],
  389. "vAlign":[1],
  390. "hAlign":[1],
  391. "font":["Arial"]
  392. },
  393. "data":{
  394. "field":"ruleText",
  395. "vAlign":1,
  396. "hAlign":0,
  397. "font":"Arial"
  398. }
  399. }*/]
  400. },
  401. jobsSetting: {
  402. "emptyRows":0,
  403. "headRows":1,
  404. "headRowHeight":[25],
  405. "defaultRowHeight": 21,
  406. "cols":[{
  407. "width":160,
  408. "readOnly":true,
  409. "head":{
  410. "titleNames":["工作内容"],
  411. "spanCols":[1],
  412. "spanRows":[1],
  413. "vAlign":[1],
  414. "hAlign":[1],
  415. "font":["Arial"]
  416. },
  417. "data":{
  418. "field":"content",
  419. "vAlign":0,
  420. "hAlign":3,
  421. "font":"Arial"
  422. }
  423. }]
  424. },
  425. featuresSetting: {
  426. "emptyRows":0,
  427. "headRows":1,
  428. "headRowHeight":[25],
  429. "defaultRowHeight": 21,
  430. "cols":[{
  431. "width":160,
  432. "readOnly":true,
  433. "head":{
  434. "titleNames":["项目特征"],
  435. "spanCols":[1],
  436. "spanRows":[1],
  437. "vAlign":[1],
  438. "hAlign":[1],
  439. "font":["Arial"]
  440. },
  441. "data":{
  442. "field":"content",
  443. "vAlign":0,
  444. "hAlign":3,
  445. "font":"Arial"
  446. }
  447. }]
  448. }
  449. };
  450. function addEventOnResize(fn){
  451. let originFn = window.onresize;
  452. window.onresize =function () {
  453. originFn && originFn();
  454. fn();
  455. }
  456. }
  457. addEventOnResize(billsLibObj.refreshSettingForHint);
  458. //赋初始高度
  459. if($('#stdBillsSpread').height() === 0 || $('#qd').find('.bottom-content').height() === 0){
  460. $('#stdBillsSpread').height($(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-q").height()-312);
  461. $('#qd').find('.bottom-content').find('.p-0').height(270);
  462. }
  463. $('#stdBillsTab').bind('click', function () {
  464. refreshSubSpread();//subSpread、jobSpread、itemSpread显示问题
  465. //$(".main-data-side-q").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-q").height() - 202);
  466. var select = $('#stdBillsLibSelect');
  467. billsLibObj.refreshBillsSpread();
  468. billsLibObj.refreshBillsRelaSpread();
  469. billsLibObj.checkBillsSpread();
  470. if (select[0].options.length === 0) {
  471. billsLibObj.loadStdBillsLib();
  472. };
  473. });
  474. $('#stdBillsLibSelect').change(function () {
  475. $('#stdBillsSearchResult').hide();
  476. //$(".main-data-side-q").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-q").height() - 202);
  477. billsLibObj.clearHighLight(billsLibObj.stdBillsSpread);
  478. var select = $(this);
  479. if (this.children.length !== 0) {
  480. //设置sessionStorage
  481. let billsLibId = select.val();
  482. sessionStorage.setItem('stdBillsLib', billsLibId);
  483. //清除展开收起状态sessionStorage
  484. sessionStorage.removeItem('stdBillsLibExpState');
  485. billsLibObj.loadStdBills(billsLibId);
  486. }
  487. });
  488. //搜索框回车
  489. $('#stdBillsSearch>input').bind('keypress', function (event) {
  490. if(event.keyCode === 13){
  491. $(this).blur();
  492. $('#stdBillsSearch>span>button').click();
  493. }
  494. });
  495. // 关闭搜索结果
  496. $('#closeSearchStdBills').click(function () {
  497. $('#stdBillsSearchResult').hide();
  498. $(".main-data-side-q").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-q").height() - 202);
  499. billsLibObj.clearHighLight(billsLibObj.stdBillsSpread);
  500. billsLibObj.refreshBillsSpread();
  501. billsLibObj.refreshBillsRelaSpread();
  502. });