std_bills_lib.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /**
  2. * Standard Bills Lib
  3. * Created by Mai on 2017/5/16.
  4. */
  5. var billsLibObj = {
  6. stdBillsSpread: null,
  7. stdBillsJobSpread: null,
  8. stdBillsFeatureSpread: null,
  9. checkBillsSpread: function () {
  10. if (!this.stdBillsSpread) {
  11. this.stdBillsSpread = SheetDataHelper.createNewSpread($('#stdBillsSpread')[0]);
  12. }
  13. },
  14. refreshBillsSpread: function () {
  15. if (this.stdBillsSpread) {
  16. this.stdBillsSpread.refresh();
  17. }
  18. },
  19. checkBillsRelaSpread: function () {
  20. if (!this.stdBillsJobSpread) {
  21. this.stdBillsJobSpread = SheetDataHelper.createNewSpread($('#stdBillsJobs')[0]);
  22. }
  23. if (!this.stdBillsFeatureSpread) {
  24. this.stdBillsFeatureSpread = SheetDataHelper.createNewSpread($('#stdBillsFeatures')[0]);
  25. }
  26. },
  27. refreshBillsRelaSpread: function () {
  28. if (this.stdBillsJobSpread) {
  29. this.stdBillsJobSpread.refresh();
  30. }
  31. if (this.stdBillsFeatureSpread) {
  32. this.stdBillsFeatureSpread.refresh();
  33. }
  34. },
  35. loadStdBillsLib: function () {
  36. let i, select = $('#stdBillsLibSelect');
  37. select.empty();
  38. let bills_lib = projectInfoObj.projectInfo.engineeringInfo.bill_lib;
  39. bills_lib.forEach(function (data) {
  40. var option = $('<option>').val(data.id).text(data.name);
  41. select.append(option);
  42. });
  43. if (select.children.length !== 0) {
  44. billsLibObj.loadStdBills(select.val());
  45. }
  46. },
  47. loadStdBills: function (stdBillsLibID) {
  48. var that = this;
  49. var stdBillsJobData, stdBillsFeatureData, stdBills;
  50. var stdBillsTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  51. var stdBillsTreeController = TREE_SHEET_CONTROLLER.createNew(stdBillsTree, billsLibObj.stdBillsSpread.getActiveSheet(), billsLibObj.stdBillsTreeSetting);
  52. var findData = function (value, field, Array) {
  53. var i = 0;
  54. for (i = 0; i < Array.length - 1; i++) {
  55. if (value[field] === Array[i][field]) {
  56. return Array[i];
  57. }
  58. }
  59. return null;
  60. };
  61. var getBillsJobs = function (node) {
  62. var jobs = [], i, jobData = null;
  63. if (stdBillsJobData && node && node.data.jobs) {
  64. for (i = 0; i < node.data.jobs.length; i++) {
  65. jobData = findData(node.data.jobs[i], 'id', stdBillsJobData);
  66. if (jobData) {
  67. jobs.push(jobData);
  68. }
  69. }
  70. }
  71. return jobs;
  72. };
  73. var getBillsFeatures = function (node) {
  74. var features = [], i, featureData = null;
  75. if (stdBillsFeatureData && node && node.data.items) {
  76. for (i = 0; i < node.data.items.length; i++) {
  77. featureData = findData(node.data.items[i], 'id', stdBillsFeatureData);
  78. if (featureData) {
  79. features.push(featureData);
  80. }
  81. }
  82. }
  83. return features;
  84. };
  85. var showJobs = function (jobs) {
  86. SheetDataHelper.loadSheetHeader(billsLibObj.jobsSetting, billsLibObj.stdBillsJobSpread.getActiveSheet());
  87. SheetDataHelper.loadSheetData(billsLibObj.jobsSetting, billsLibObj.stdBillsJobSpread.getActiveSheet(), jobs);
  88. };
  89. var showFeatures = function (features) {
  90. SheetDataHelper.loadSheetHeader(billsLibObj.featuresSetting, billsLibObj.stdBillsFeatureSpread.getActiveSheet());
  91. SheetDataHelper.loadSheetData(billsLibObj.featuresSetting, billsLibObj.stdBillsFeatureSpread.getActiveSheet(), features);
  92. };
  93. var showJobsAndFeatures = function (node) {
  94. $('#stdBillsJobTab').show();
  95. $('#stdBillsRemarkTab').hide();
  96. billsLibObj.checkBillsRelaSpread();
  97. showJobs(getBillsJobs(node));
  98. showFeatures(getBillsFeatures(node));
  99. };
  100. var showBillsRemark = function (node) {
  101. $('#stdBillsJobTab').hide();
  102. $('#stdBillsRemarkTab').show();
  103. $('#stdBillsRemark').text(node && node.data.recharge ? node.data.recharge : '');
  104. };
  105. var showBillsRela = function (node) {
  106. if (node && node.children.length === 0) {
  107. showJobsAndFeatures(node);
  108. } else {
  109. showBillsRemark(node);
  110. }
  111. };
  112. CommonAjax.post('/stdBillsEditor/getJobContent', {userId: userID, billsLibId: stdBillsLibID}, function (datas) {
  113. stdBillsJobData = datas;
  114. }, function () {
  115. stdBillsJobData = [];
  116. });
  117. CommonAjax.post('/stdBillsEditor/getItemCharacter', {userId: userID, billsLibId: stdBillsLibID}, function (datas) {
  118. stdBillsFeatureData = datas;
  119. }, function () {
  120. stdBillsFeatureData = [];
  121. });
  122. CommonAjax.post('/stdBillsEditor/getBills', {userId: userID, billsLibId: stdBillsLibID}, function (datas) {
  123. stdBills = datas;
  124. stdBillsTree.loadDatas(stdBills);
  125. stdBillsTreeController.showTreeData();
  126. showBillsRela(stdBillsTree.firstNode());
  127. stdBillsTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, showBillsRela);
  128. that.stdBillsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (sender, args) {
  129. if (stdBillsTree.items[args.row].children.length === 0) {
  130. //特征及内容转化
  131. pageCCOprObj.setItemContentNode(stdBillsTree.items[args.row], getBillsJobs(stdBillsTree.items[args.row]), getBillsFeatures(stdBillsTree.items[args.row]));
  132. ProjectController.addBills(projectObj.project, projectObj.mainController, stdBillsTree.items[args.row]);
  133. }
  134. });
  135. }, function () {
  136. that.stdBillsSpread.unbind(GC.Spread.Sheets.Events.CellDoubleClick);
  137. });
  138. $('#stdBillsSearch>span>button').click(function () {
  139. var keyword = $('#stdBillsSearch>input').val();
  140. if (!keyword || keyword === '') {return}
  141. var result = stdBillsTree.items.filter(function (item) {
  142. var codeIs = item.data.code ? item.data.code.indexOf(keyword) !== -1 : false;
  143. var nameIs = item.data.name ? item.data.name.indexOf(keyword) !== -1 : false;
  144. return codeIs || nameIs;
  145. });
  146. result.sort(function (x, y) {
  147. return x.serialNo() - y.serialNo();
  148. });
  149. if (result.length !== 0) {
  150. var sel = billsLibObj.stdBillsSpread.getActiveSheet().getSelections();
  151. stdBillsTreeController.setTreeSelected(result[0]);
  152. billsLibObj.stdBillsSpread.getActiveSheet().setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  153. $('#nextStdBills').show();
  154. $('#nextStdBills').click(function () {
  155. var cur = stdBillsTree.selected, resultIndex = result.indexOf(cur), sel = billsLibObj.stdBillsSpread.getActiveSheet().getSelections();
  156. if (resultIndex === result.length - 1) {
  157. stdBillsTreeController.setTreeSelected(result[0]);
  158. billsLibObj.stdBillsSpread.getActiveSheet().setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  159. } else {
  160. stdBillsTreeController.setTreeSelected(result[resultIndex + 1]);
  161. billsLibObj.stdBillsSpread.getActiveSheet().setSelection(result[resultIndex + 1].serialNo(), sel[0].col, 1, 1);
  162. }
  163. });
  164. } else {
  165. $('#nextStdBills').hide();
  166. }
  167. $('#stdBillsSearchResultCount').text('搜索结果:' + result.length);
  168. $('#stdBillsSearchResult').show();
  169. });
  170. },
  171. stdBillsTreeSetting: {
  172. "treeCol": 0,
  173. "emptyRows":0,
  174. "headRows":1,
  175. "headRowHeight":[
  176. 40
  177. ],
  178. "defaultRowHeight": 21,
  179. "cols":[{
  180. "width":150,
  181. "readOnly": true,
  182. "head":{
  183. "titleNames":["项目编码"],
  184. "spanCols":[1],
  185. "spanRows":[1],
  186. "vAlign":[1],
  187. "hAlign":[1],
  188. "font":["Arial"]
  189. },
  190. "data":{
  191. "field":"code",
  192. "vAlign":1,
  193. "hAlign":0,
  194. "font":"Arial"
  195. }
  196. }, {
  197. "width":120,
  198. "readOnly": true,
  199. "head":{
  200. "titleNames":["项目名称"],
  201. "spanCols":[1],
  202. "spanRows":[1],
  203. "vAlign":[1],
  204. "hAlign":[1],
  205. "font":["Arial"]
  206. },
  207. "data":{
  208. "field":"name",
  209. "vAlign":1,
  210. "hAlign":0,
  211. "font":"Arial"
  212. }
  213. }, {
  214. "width":40,
  215. "readOnly": true,
  216. "head":{
  217. "titleNames":["计量单位"],
  218. "spanCols":[1],
  219. "spanRows":[1],
  220. "vAlign":[1],
  221. "hAlign":[1],
  222. "font":["Arial"],
  223. "wordWrap": true
  224. },
  225. "data":{
  226. "field":"unit",
  227. "vAlign":1,
  228. "hAlign":1,
  229. "font":"Arial"
  230. }
  231. }, {
  232. "width":100,
  233. "readOnly": true,
  234. "head":{
  235. "titleNames":["工程量计算规则"],
  236. "spanCols":[1],
  237. "spanRows":[1],
  238. "vAlign":[1],
  239. "hAlign":[1],
  240. "font":["Arial"]
  241. },
  242. "data":{
  243. "field":"ruleText",
  244. "vAlign":1,
  245. "hAlign":0,
  246. "font":"Arial"
  247. }
  248. }]
  249. },
  250. jobsSetting: {
  251. "emptyRows":0,
  252. "headRows":1,
  253. "headRowHeight":[25],
  254. "defaultRowHeight": 21,
  255. "cols":[{
  256. "width":200,
  257. "readOnly":true,
  258. "head":{
  259. "titleNames":["工作内容"],
  260. "spanCols":[1],
  261. "spanRows":[1],
  262. "vAlign":[1],
  263. "hAlign":[1],
  264. "font":["Arial"]
  265. },
  266. "data":{
  267. "field":"content",
  268. "vAlign":0,
  269. "hAlign":3,
  270. "font":"Arial"
  271. }
  272. }]
  273. },
  274. featuresSetting: {
  275. "emptyRows":0,
  276. "headRows":1,
  277. "headRowHeight":[25],
  278. "defaultRowHeight": 21,
  279. "cols":[{
  280. "width":200,
  281. "readOnly":true,
  282. "head":{
  283. "titleNames":["项目特征"],
  284. "spanCols":[1],
  285. "spanRows":[1],
  286. "vAlign":[1],
  287. "hAlign":[1],
  288. "font":["Arial"]
  289. },
  290. "data":{
  291. "field":"content",
  292. "vAlign":0,
  293. "hAlign":3,
  294. "font":"Arial"
  295. }
  296. }]
  297. }
  298. };
  299. $('#stdBillsTab').bind('click', function () {
  300. refreshSubSpread();//subSpread、jobSpread、itemSpread显示问题
  301. $(".main-data-side-q").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-q").height() - 202);
  302. var select = $('#stdBillsLibSelect');
  303. billsLibObj.refreshBillsSpread();
  304. billsLibObj.refreshBillsRelaSpread();
  305. billsLibObj.checkBillsSpread();
  306. if (select[0].options.length === 0) {
  307. billsLibObj.loadStdBillsLib();
  308. };
  309. });
  310. $('#stdBillsLibSelect').change(function () {
  311. var select = $(this);
  312. if (this.children.length !== 0) {
  313. LoadStdBills(select.val());
  314. }
  315. });
  316. $('#closeSearchStdBills').click(function () {
  317. $('#stdBillsSearchResult').hide();
  318. $(".main-data-side-q").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-q").height() - 202);
  319. });