std_bills_lib.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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){
  124. return false;
  125. }
  126. //设置清单备注
  127. if(node.parent && node.parent.data.recharge){
  128. node.data.comments = node.parent.data.recharge;
  129. }
  130. //特征及内容转化
  131. pageCCOprObj.setItemContentNode(node, this.getBillsJobs(stdBillsJobData, node), this.getBillsFeatures(stdBillsFeatureData, node), node.data.name);
  132. if (/\//.test(node.data.unit)) {
  133. let existB = projectObj.project.Bills.sameStdCodeBillsData(node.data.code);
  134. if (existB) {
  135. let std = JSON.parse(JSON.stringify(node.data));
  136. std.unit = existB.unit;
  137. ProjectController.addBills(projectObj.project, projectObj.mainController, std);
  138. } else {
  139. ConfirmModal.stdBillsUnit.check(node.data, function (std) {
  140. ProjectController.addBills(projectObj.project, projectObj.mainController, std);
  141. });
  142. }
  143. } else {
  144. ProjectController.addBills(projectObj.project, projectObj.mainController, node.data);
  145. }
  146. return true;
  147. },
  148. loadStdBills: function (stdBillsLibID) {
  149. var that = this;
  150. var stdBillsJobData, stdBillsFeatureData, stdBills;
  151. if(that.stdBillsTree){
  152. that.stdBillsTree = null;
  153. }
  154. that.stdBillsTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  155. var stdBillsTreeController = TREE_SHEET_CONTROLLER.createNew(that.stdBillsTree, billsLibObj.stdBillsSpread.getActiveSheet(), billsLibObj.stdBillsTreeSetting);
  156. var showJobs = function (jobs) {
  157. SheetDataHelper.loadSheetHeader(billsLibObj.jobsSetting, billsLibObj.stdBillsJobSpread.getActiveSheet());
  158. SheetDataHelper.loadSheetData(billsLibObj.jobsSetting, billsLibObj.stdBillsJobSpread.getActiveSheet(), jobs);
  159. };
  160. var showFeatures = function (features) {
  161. SheetDataHelper.loadSheetHeader(billsLibObj.featuresSetting, billsLibObj.stdBillsFeatureSpread.getActiveSheet());
  162. SheetDataHelper.loadSheetData(billsLibObj.featuresSetting, billsLibObj.stdBillsFeatureSpread.getActiveSheet(), features);
  163. };
  164. var showJobsAndFeatures = function (node) {
  165. $('#stdBillsJobTab').show();
  166. $('#stdBillsRemarkTab').hide();
  167. billsLibObj.refreshBillsRelaSpread();
  168. billsLibObj.checkBillsRelaSpread();
  169. showJobs(billsLibObj.getBillsJobs(stdBillsJobData, node));
  170. showFeatures(billsLibObj.getBillsFeatures(stdBillsFeatureData, node));
  171. };
  172. var showBillsRemark = function (node) {
  173. $('#stdBillsJobTab').hide();
  174. $('#stdBillsRemarkTab').show();
  175. $('#stdBillsRemark').text(node && node.data.recharge ? node.data.recharge : '');
  176. };
  177. var showBillsRela = function (node) {
  178. if (node && node.children.length === 0) {
  179. showJobsAndFeatures(node);
  180. } else {
  181. showBillsRemark(node);
  182. }
  183. };
  184. CommonAjax.post('/stdBillsEditor/getJobContent', {userId: userID, billsLibId: stdBillsLibID}, function (datas) {
  185. stdBillsJobData = datas;
  186. }, function () {
  187. stdBillsJobData = [];
  188. });
  189. CommonAjax.post('/stdBillsEditor/getItemCharacter', {userId: userID, billsLibId: stdBillsLibID}, function (datas) {
  190. stdBillsFeatureData = datas;
  191. }, function () {
  192. stdBillsFeatureData = [];
  193. });
  194. CommonAjax.post('/stdBillsEditor/getBills', {userId: userID, billsLibId: stdBillsLibID}, function (datas) {
  195. stdBills = datas;
  196. that.stdBillsTree.loadDatas(stdBills);
  197. //读取展开收起状态
  198. let currentExpState = sessionStorage.getItem('stdBillsLibExpState');
  199. if(currentExpState){
  200. that.stdBillsTree.setExpandedByState(that.stdBillsTree.items, currentExpState);
  201. }
  202. //非叶子节点默认收起
  203. else{
  204. that.stdBillsTree.setRootExpanded(that.stdBillsTree.roots, false);
  205. }
  206. stdBillsTreeController.showTreeData();
  207. billsLibObj.setTagForHint(that.stdBillsTree.items);
  208. showBillsRela(that.stdBillsTree.firstNode());
  209. stdBillsTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, showBillsRela);
  210. that.stdBillsSpread.unbind(GC.Spread.Sheets.Events.CellDoubleClick);
  211. that.stdBillsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (sender, args) {
  212. let selectNode = that.stdBillsTree.items[args.row];
  213. let name = selectNode.data.name;
  214. if (that.stdBillsTree.items[args.row].children.length === 0) {
  215. billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, selectNode);
  216. }
  217. else{
  218. let me = billsLibObj;
  219. let node = that.stdBillsTree.items[args.row];
  220. if (!node || node.children.length === 0)
  221. return;
  222. node.setExpanded(!node.expanded);
  223. //设置展开收起状态
  224. sessionStorage.setItem('stdBillsLibExpState', that.stdBillsTree.getExpState(that.stdBillsTree.items));
  225. TREE_SHEET_HELPER.massOperationSheet(args.sheet, function () {
  226. let iCount = node.posterityCount(), i, child;
  227. for (i = 0; i < iCount; i++) {
  228. child = that.stdBillsTree.items[args.row + i + 1];
  229. args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
  230. }
  231. args.sheet.invalidateLayout();
  232. });
  233. args.sheet.repaint();
  234. }
  235. });
  236. }, function () {
  237. that.stdBillsSpread.unbind(GC.Spread.Sheets.Events.CellDoubleClick);
  238. });
  239. $('#stdBillsSearch>span>button').click(function () {
  240. billsLibObj.clearHighLight(billsLibObj.stdBillsSpread);
  241. var keyword = $('#stdBillsSearch>input').val();
  242. if (!keyword || keyword === '') {
  243. $('#stdBillsSearchResult').hide();
  244. return;
  245. }
  246. var result = that.stdBillsTree.items.filter(function (item) {
  247. var codeIs = item.data.code ? item.data.code.indexOf(keyword) !== -1 : false;
  248. var nameIs = item.data.name ? item.data.name.indexOf(keyword) !== -1 : false;
  249. return codeIs || nameIs;
  250. });
  251. result.sort(function (x, y) {
  252. return x.serialNo() - y.serialNo();
  253. });
  254. if (result.length !== 0) {
  255. //展开搜索出来的节点
  256. billsLibObj.expandSearchNodes(result);
  257. //设置记住展开
  258. sessionStorage.setItem('stdBillsLibExpState', that.stdBillsTree.getExpState(that.stdBillsTree.items));
  259. var sel = billsLibObj.stdBillsSpread.getActiveSheet().getSelections();
  260. stdBillsTreeController.setTreeSelected(result[0]);
  261. billsLibObj.stdBillsSpread.getActiveSheet().setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  262. for (let node of result) {
  263. billsLibObj.stdBillsSpread.getActiveSheet().getRange(node.serialNo(), -1, 1, -1).backColor('lemonChiffon');
  264. }
  265. $('#nextStdBills').show();
  266. $('#nextStdBills').unbind('click');
  267. $('#nextStdBills').bind('click', function () {
  268. var cur = that.stdBillsTree.selected, resultIndex = result.indexOf(cur), sel = billsLibObj.stdBillsSpread.getActiveSheet().getSelections();
  269. if (resultIndex === result.length - 1) {
  270. stdBillsTreeController.setTreeSelected(result[0]);
  271. billsLibObj.stdBillsSpread.getActiveSheet().setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  272. billsLibObj.stdBillsSpread.getActiveSheet().showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.top);
  273. } else {
  274. stdBillsTreeController.setTreeSelected(result[resultIndex + 1]);
  275. billsLibObj.stdBillsSpread.getActiveSheet().setSelection(result[resultIndex + 1].serialNo(), sel[0].col, 1, 1);
  276. billsLibObj.stdBillsSpread.getActiveSheet().showRow(result[resultIndex + 1].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  277. }
  278. });
  279. } else {
  280. billsLibObj.clearHighLight(billsLibObj.stdBillsSpread);
  281. $('#nextStdBills').hide();
  282. }
  283. $('#stdBillsSearchResultCount').text('搜索结果:' + result.length);
  284. $('#stdBillsSearchResult').show();
  285. });
  286. },
  287. expandSearchNodes: function(nodes){
  288. let that = this;
  289. TREE_SHEET_HELPER.massOperationSheet(billsLibObj.stdBillsSpread.getActiveSheet(), function () {
  290. function expParentNode(node){
  291. if(node.parent && !node.parent.expanded){
  292. node.parent.setExpanded(true);
  293. expParentNode(node.parent);
  294. }
  295. }
  296. for(let node of nodes){
  297. expParentNode(node);
  298. }
  299. TREE_SHEET_HELPER.refreshTreeNodeData(that.stdBillsTreeSetting, that.stdBillsSpread.getActiveSheet(), that.stdBillsTree.roots, true);
  300. TREE_SHEET_HELPER.refreshNodesVisible(that.stdBillsTree.roots, that.stdBillsSpread.getActiveSheet(), true);
  301. });
  302. },
  303. stdBillsTreeSetting: {
  304. "treeCol": 0,
  305. "emptyRows":0,
  306. "headRows":1,
  307. "headRowHeight":[
  308. 40
  309. ],
  310. "defaultRowHeight": 21,
  311. "cols":[{
  312. "width":160,
  313. "readOnly": true,
  314. "head":{
  315. "titleNames":["项目编码"],
  316. "spanCols":[1],
  317. "spanRows":[1],
  318. "vAlign":[1],
  319. "hAlign":[1],
  320. "font":["Arial"]
  321. },
  322. "data":{
  323. "field":"code",
  324. "vAlign":1,
  325. "hAlign":0,
  326. "font":"Arial"
  327. }
  328. }, {
  329. "width":220,
  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":"name",
  341. "vAlign":1,
  342. "hAlign":0,
  343. "font":"Arial"
  344. }
  345. }, {
  346. "width":45,
  347. "readOnly": true,
  348. "showHint": true,
  349. "head":{
  350. "titleNames":["计量单位"],
  351. "spanCols":[1],
  352. "spanRows":[1],
  353. "vAlign":[1],
  354. "hAlign":[1],
  355. "font":["Arial"],
  356. "wordWrap": true
  357. },
  358. "data":{
  359. "field":"unit",
  360. "vAlign":1,
  361. "hAlign":1,
  362. "font":"Arial"
  363. }
  364. }/*, {
  365. "width":100,
  366. "readOnly": true,
  367. "showHint": true,
  368. "head":{
  369. "titleNames":["工程量计算规则"],
  370. "spanCols":[1],
  371. "spanRows":[1],
  372. "vAlign":[1],
  373. "hAlign":[1],
  374. "font":["Arial"]
  375. },
  376. "data":{
  377. "field":"ruleText",
  378. "vAlign":1,
  379. "hAlign":0,
  380. "font":"Arial"
  381. }
  382. }*/]
  383. },
  384. jobsSetting: {
  385. "emptyRows":0,
  386. "headRows":1,
  387. "headRowHeight":[25],
  388. "defaultRowHeight": 21,
  389. "cols":[{
  390. "width":160,
  391. "readOnly":true,
  392. "head":{
  393. "titleNames":["工作内容"],
  394. "spanCols":[1],
  395. "spanRows":[1],
  396. "vAlign":[1],
  397. "hAlign":[1],
  398. "font":["Arial"]
  399. },
  400. "data":{
  401. "field":"content",
  402. "vAlign":0,
  403. "hAlign":3,
  404. "font":"Arial"
  405. }
  406. }]
  407. },
  408. featuresSetting: {
  409. "emptyRows":0,
  410. "headRows":1,
  411. "headRowHeight":[25],
  412. "defaultRowHeight": 21,
  413. "cols":[{
  414. "width":160,
  415. "readOnly":true,
  416. "head":{
  417. "titleNames":["项目特征"],
  418. "spanCols":[1],
  419. "spanRows":[1],
  420. "vAlign":[1],
  421. "hAlign":[1],
  422. "font":["Arial"]
  423. },
  424. "data":{
  425. "field":"content",
  426. "vAlign":0,
  427. "hAlign":3,
  428. "font":"Arial"
  429. }
  430. }]
  431. }
  432. };
  433. function addEventOnResize(fn){
  434. let originFn = window.onresize;
  435. window.onresize =function () {
  436. originFn && originFn();
  437. fn();
  438. }
  439. }
  440. addEventOnResize(billsLibObj.refreshSettingForHint);
  441. //赋初始高度
  442. if($('#stdBillsSpread').height() === 0 || $('#qd').find('.bottom-content').height() === 0){
  443. $('#stdBillsSpread').height($(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-q").height()-312);
  444. $('#qd').find('.bottom-content').find('.p-0').height(270);
  445. }
  446. $('#stdBillsTab').bind('click', function () {
  447. refreshSubSpread();//subSpread、jobSpread、itemSpread显示问题
  448. //$(".main-data-side-q").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-q").height() - 202);
  449. var select = $('#stdBillsLibSelect');
  450. billsLibObj.refreshBillsSpread();
  451. billsLibObj.refreshBillsRelaSpread();
  452. billsLibObj.checkBillsSpread();
  453. if (select[0].options.length === 0) {
  454. billsLibObj.loadStdBillsLib();
  455. };
  456. });
  457. $('#stdBillsLibSelect').change(function () {
  458. $('#stdBillsSearchResult').hide();
  459. //$(".main-data-side-q").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-q").height() - 202);
  460. billsLibObj.clearHighLight(billsLibObj.stdBillsSpread);
  461. var select = $(this);
  462. if (this.children.length !== 0) {
  463. //设置sessionStorage
  464. let billsLibId = select.val();
  465. sessionStorage.setItem('stdBillsLib', billsLibId);
  466. //清除展开收起状态sessionStorage
  467. sessionStorage.removeItem('stdBillsLibExpState');
  468. billsLibObj.loadStdBills(billsLibId);
  469. }
  470. });
  471. // 关闭搜索结果
  472. $('#closeSearchStdBills').click(function () {
  473. $('#stdBillsSearchResult').hide();
  474. $(".main-data-side-q").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-q").height() - 202);
  475. billsLibObj.clearHighLight(billsLibObj.stdBillsSpread);
  476. billsLibObj.refreshBillsSpread();
  477. billsLibObj.refreshBillsRelaSpread();
  478. });