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