std_bills_lib.js 12 KB

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