std_bills_lib.js 11 KB

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