std_bills_lib.js 11 KB

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