std_bills_lib.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 - 1; 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 - 1; 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. ProjectController.addBills(projectObj.project, projectObj.mainController, stdBillsTree.items[args.row]);
  131. }
  132. });
  133. }, function () {
  134. that.stdBillsSpread.unbind(GC.Spread.Sheets.Events.CellDoubleClick);
  135. });
  136. $('#stdBillsSearch>span>button').click(function () {
  137. var keyword = $('#stdBillsSearch>input').val();
  138. if (!keyword || keyword === '') {return}
  139. var result = stdBillsTree.items.filter(function (item) {
  140. var codeIs = item.data.code ? item.data.code.indexOf(keyword) !== -1 : false;
  141. var nameIs = item.data.name ? item.data.name.indexOf(keyword) !== -1 : false;
  142. return codeIs || nameIs;
  143. });
  144. result.sort(function (x, y) {
  145. return x.serialNo() - y.serialNo();
  146. });
  147. if (result.length !== 0) {
  148. var sel = billsLibObj.stdBillsSpread.getActiveSheet().getSelections();
  149. stdBillsTreeController.setTreeSelected(result[0]);
  150. billsLibObj.stdBillsSpread.getActiveSheet().setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  151. $('#nextStdBills').show();
  152. $('#nextStdBills').click(function () {
  153. var cur = stdBillsTree.selected, resultIndex = result.indexOf(cur), sel = billsLibObj.stdBillsSpread.getActiveSheet().getSelections();
  154. if (resultIndex === result.length - 1) {
  155. stdBillsTreeController.setTreeSelected(result[0]);
  156. billsLibObj.stdBillsSpread.getActiveSheet().setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  157. } else {
  158. stdBillsTreeController.setTreeSelected(result[resultIndex + 1]);
  159. billsLibObj.stdBillsSpread.getActiveSheet().setSelection(result[resultIndex + 1].serialNo(), sel[0].col, 1, 1);
  160. }
  161. });
  162. } else {
  163. $('#nextStdBills').hide();
  164. }
  165. $('#stdBillsSearchResultCount').text('搜索结果:' + result.length);
  166. $('#stdBillsSearchResult').show();
  167. });
  168. },
  169. stdBillsTreeSetting: {
  170. "treeCol": 0,
  171. "emptyRows":0,
  172. "headRows":1,
  173. "headRowHeight":[
  174. 40
  175. ],
  176. "defaultRowHeight": 21,
  177. "cols":[{
  178. "width":150,
  179. "readOnly": true,
  180. "head":{
  181. "titleNames":["项目编码"],
  182. "spanCols":[1],
  183. "spanRows":[1],
  184. "vAlign":[1],
  185. "hAlign":[1],
  186. "font":["Arial"]
  187. },
  188. "data":{
  189. "field":"code",
  190. "vAlign":1,
  191. "hAlign":0,
  192. "font":"Arial"
  193. }
  194. }, {
  195. "width":120,
  196. "readOnly": true,
  197. "head":{
  198. "titleNames":["项目名称"],
  199. "spanCols":[1],
  200. "spanRows":[1],
  201. "vAlign":[1],
  202. "hAlign":[1],
  203. "font":["Arial"]
  204. },
  205. "data":{
  206. "field":"name",
  207. "vAlign":1,
  208. "hAlign":0,
  209. "font":"Arial"
  210. }
  211. }, {
  212. "width":40,
  213. "readOnly": true,
  214. "head":{
  215. "titleNames":["计量单位"],
  216. "spanCols":[1],
  217. "spanRows":[1],
  218. "vAlign":[1],
  219. "hAlign":[1],
  220. "font":["Arial"],
  221. "wordWrap": true
  222. },
  223. "data":{
  224. "field":"unit",
  225. "vAlign":1,
  226. "hAlign":1,
  227. "font":"Arial"
  228. }
  229. }, {
  230. "width":100,
  231. "readOnly": true,
  232. "head":{
  233. "titleNames":["工程量计算规则"],
  234. "spanCols":[1],
  235. "spanRows":[1],
  236. "vAlign":[1],
  237. "hAlign":[1],
  238. "font":["Arial"]
  239. },
  240. "data":{
  241. "field":"ruleText",
  242. "vAlign":1,
  243. "hAlign":0,
  244. "font":"Arial"
  245. }
  246. }]
  247. },
  248. jobsSetting: {
  249. "emptyRows":0,
  250. "headRows":1,
  251. "headRowHeight":[25],
  252. "defaultRowHeight": 21,
  253. "cols":[{
  254. "width":200,
  255. "readOnly":true,
  256. "head":{
  257. "titleNames":["工作内容"],
  258. "spanCols":[1],
  259. "spanRows":[1],
  260. "vAlign":[1],
  261. "hAlign":[1],
  262. "font":["Arial"]
  263. },
  264. "data":{
  265. "field":"content",
  266. "vAlign":0,
  267. "hAlign":3,
  268. "font":"Arial"
  269. }
  270. }]
  271. },
  272. featuresSetting: {
  273. "emptyRows":0,
  274. "headRows":1,
  275. "headRowHeight":[25],
  276. "defaultRowHeight": 21,
  277. "cols":[{
  278. "width":200,
  279. "readOnly":true,
  280. "head":{
  281. "titleNames":["项目特征"],
  282. "spanCols":[1],
  283. "spanRows":[1],
  284. "vAlign":[1],
  285. "hAlign":[1],
  286. "font":["Arial"]
  287. },
  288. "data":{
  289. "field":"content",
  290. "vAlign":0,
  291. "hAlign":3,
  292. "font":"Arial"
  293. }
  294. }]
  295. }
  296. };
  297. $('#stdBillsTab').bind('click', function () {
  298. $(".main-data-side-q").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-q").height() - 202);
  299. var select = $('#stdBillsLibSelect');
  300. billsLibObj.refreshBillsSpread();
  301. billsLibObj.refreshBillsRelaSpread();
  302. billsLibObj.checkBillsSpread();
  303. if (select[0].options.length === 0) {
  304. billsLibObj.loadStdBillsLib();
  305. };
  306. });
  307. $('#stdBillsLibSelect').change(function () {
  308. var select = $(this);
  309. if (this.children.length !== 0) {
  310. LoadStdBills(select.val());
  311. }
  312. });
  313. $('#closeSearchStdBills').click(function () {
  314. $('#stdBillsSearchResult').hide();
  315. $(".main-data-side-q").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-q").height() - 202);
  316. });