std_bills_lib.js 21 KB

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