std_bills_lib.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /**
  2. * Standard Bills Lib
  3. * Created by Mai on 2017/5/16.
  4. */
  5. /**
  6. * showObj = {bills, jobAndFeatureTab, job, feature, remarkTab, remark}
  7. */
  8. /*var stdBillsLibObj = {
  9. createNew: function (sessionID, showObj) {
  10. var tools = {
  11. sessionID: sessionID,
  12. billsSpread: null,
  13. billsJobSpread: null,
  14. billsFeatureSpread: null,
  15. checkSpread: function (spread, spreadObj) {
  16. if (!spread) {
  17. spread = SheetDataHelper.createNewSpread(spreadObj);
  18. }
  19. }
  20. };
  21. var libObj = function () {
  22. this.billsTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  23. this.spread = tools.billsSpread;
  24. };
  25. libObj.prototype.LoadStdBills = function () {
  26. tools.checkSpread(tools.billsSpread, showObj.bills);
  27. };
  28. return new libObj(sessionID);
  29. },
  30. settings: {
  31. stdBillsTreeSetting: {
  32. "treeCol": 0,
  33. "emptyRows":0,
  34. "headRows":1,
  35. "headRowHeight":[
  36. 35
  37. ],
  38. "cols":[{
  39. "width":100,
  40. "readOnly":null,
  41. "head":{
  42. "titleNames":["项目编码"],
  43. "spanCols":[1],
  44. "spanRows":[1],
  45. "vAlign":[1],
  46. "hAlign":[1],
  47. "font":["12px Arial"]
  48. },
  49. "data":{
  50. "field":"code",
  51. "vAlign":0,
  52. "hAlign":3,
  53. "font":"12px Arial"
  54. }
  55. }, {
  56. "width":120,
  57. "readOnly":null,
  58. "head":{
  59. "titleNames":["项目名称"],
  60. "spanCols":[1],
  61. "spanRows":[1],
  62. "vAlign":[1],
  63. "hAlign":[1],
  64. "font":["12px Arial"]
  65. },
  66. "data":{
  67. "field":"name",
  68. "vAlign":0,
  69. "hAlign":3,
  70. "font":"12px Arial"
  71. }
  72. }, {
  73. "width":40,
  74. "readOnly":null,
  75. "head":{
  76. "titleNames":["计量单位"],
  77. "spanCols":[1],
  78. "spanRows":[1],
  79. "vAlign":[1],
  80. "hAlign":[1],
  81. "font":["12px Arial"],
  82. "wordWrap": true
  83. },
  84. "data":{
  85. "field":"unti",
  86. "vAlign":0,
  87. "hAlign":3,
  88. "font":"12px Arial"
  89. }
  90. }, {
  91. "width":100,
  92. "readOnly": true,
  93. "head":{
  94. "titleNames":["工程量计算规则"],
  95. "spanCols":[1],
  96. "spanRows":[1],
  97. "vAlign":[1],
  98. "hAlign":[1],
  99. "font":["12px Arial"]
  100. },
  101. "data":{
  102. "field":"ruleText",
  103. "vAlign":0,
  104. "hAlign":3,
  105. "font":"12px Arial"
  106. }
  107. }]
  108. },
  109. stdBillsJobSetting: {
  110. "emptyRows":0,
  111. "headRows":1,
  112. "headRowHeight":[
  113. 20
  114. ],
  115. "cols":[{
  116. "width":200,
  117. "readOnly":true,
  118. "head":{
  119. "titleNames":["工程内容"],
  120. "spanCols":[1],
  121. "spanRows":[1],
  122. "vAlign":[1],
  123. "hAlign":[1],
  124. "font":["12px Arial"]
  125. },
  126. "data":{
  127. "field":"content",
  128. "vAlign":0,
  129. "hAlign":3,
  130. "font":"12px Arial"
  131. }
  132. }]
  133. },
  134. stdBillsFeatureSetting: {
  135. "emptyRows":0,
  136. "headRows":1,
  137. "headRowHeight":[
  138. 20
  139. ],
  140. "cols":[{
  141. "width":200,
  142. "readOnly":null,
  143. "head":{
  144. "titleNames":["项目特征"],
  145. "spanCols":[1],
  146. "spanRows":[1],
  147. "vAlign":[1],
  148. "hAlign":[1],
  149. "font":["12px Arial"]
  150. },
  151. "data":{
  152. "field":"content",
  153. "vAlign":0,
  154. "hAlign":3,
  155. "font":"12px Arial"
  156. }
  157. }]
  158. }
  159. }
  160. };*/
  161. CommonAjax.post('/stdBillsEditor/getStdBillsLib', {userId: userID}, function (datas) {
  162. var i, select = $('#stdBillsLibSelect');
  163. select.empty();
  164. datas.forEach(function (data) {
  165. var option = $('<option>').val(data.billsLibId).text(data.billsLibName);
  166. select.append(option);
  167. });
  168. if (select.children.length !== 0) {
  169. LoadStdBills(select.val());
  170. }
  171. });
  172. var LoadStdBills = (function () {
  173. var stdBillsSpread = SheetDataHelper.createNewSpread($('#stdBillsSpread')[0]);
  174. var stdBillsJobSpread = null, stdBillsFeatureSpread = null;
  175. var stdBillsTreeSetting = {
  176. "treeCol": 0,
  177. "emptyRows":0,
  178. "headRows":1,
  179. "headRowHeight":[
  180. 40
  181. ],
  182. "defaultRowHeight": 21,
  183. "cols":[{
  184. "width":150,
  185. "readOnly": true,
  186. "head":{
  187. "titleNames":["项目编码"],
  188. "spanCols":[1],
  189. "spanRows":[1],
  190. "vAlign":[1],
  191. "hAlign":[1],
  192. "font":["Arial"]
  193. },
  194. "data":{
  195. "field":"code",
  196. "vAlign":1,
  197. "hAlign":0,
  198. "font":"Arial"
  199. }
  200. }, {
  201. "width":120,
  202. "readOnly": true,
  203. "head":{
  204. "titleNames":["项目名称"],
  205. "spanCols":[1],
  206. "spanRows":[1],
  207. "vAlign":[1],
  208. "hAlign":[1],
  209. "font":["Arial"]
  210. },
  211. "data":{
  212. "field":"name",
  213. "vAlign":1,
  214. "hAlign":0,
  215. "font":"Arial"
  216. }
  217. }, {
  218. "width":40,
  219. "readOnly": true,
  220. "head":{
  221. "titleNames":["计量单位"],
  222. "spanCols":[1],
  223. "spanRows":[1],
  224. "vAlign":[1],
  225. "hAlign":[1],
  226. "font":["Arial"],
  227. "wordWrap": true
  228. },
  229. "data":{
  230. "field":"unit",
  231. "vAlign":1,
  232. "hAlign":1,
  233. "font":"Arial"
  234. }
  235. }, {
  236. "width":100,
  237. "readOnly": true,
  238. "head":{
  239. "titleNames":["工程量计算规则"],
  240. "spanCols":[1],
  241. "spanRows":[1],
  242. "vAlign":[1],
  243. "hAlign":[1],
  244. "font":["Arial"]
  245. },
  246. "data":{
  247. "field":"ruleText",
  248. "vAlign":1,
  249. "hAlign":0,
  250. "font":"Arial"
  251. }
  252. }]
  253. };
  254. var stdBillsData, stdBillsJobData, stdBillsFeatureData;
  255. var stdBillsTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  256. var stdBillsTreeController = TREE_SHEET_CONTROLLER.createNew(stdBillsTree, stdBillsSpread.getActiveSheet(), stdBillsTreeSetting);
  257. var findData = function (value, field, Array) {
  258. var i = 0;
  259. for (i = 0; i < Array.length - 1; i++) {
  260. if (value === Array[i][field]) {
  261. return Array[i];
  262. }
  263. }
  264. return null;
  265. };
  266. var getBillsJobs = function (node) {
  267. var jobs = [], i, jobData = null;
  268. if (stdBillsJobData && node && node.data.jobs) {
  269. for (i = 0; i < node.data.jobs.length - 1; i++) {
  270. jobData = findData(node.data.jobs[i], 'id', stdBillsJobData);
  271. if (jobData) {
  272. jobs.push(jobData);
  273. }
  274. }
  275. }
  276. return jobs;
  277. };
  278. var getBillsFeatures = function (node) {
  279. var features = [], i, featureData = null;
  280. if (stdBillsFeatureData && node && node.data.items) {
  281. for (i = 0; i < node.data.items.length - 1; i++) {
  282. featureData = findData(node.data.items[i], 'id', stdBillsFeatureData);
  283. if (featureData) {
  284. features.push(featureData);
  285. }
  286. }
  287. }
  288. return features;
  289. };
  290. var showJobs = function (jobs) {
  291. var jobsSetting = {
  292. "emptyRows":0,
  293. "headRows":1,
  294. "headRowHeight":[25],
  295. "defaultRowHeight": 21,
  296. "cols":[{
  297. "width":200,
  298. "readOnly":true,
  299. "head":{
  300. "titleNames":["工程内容"],
  301. "spanCols":[1],
  302. "spanRows":[1],
  303. "vAlign":[1],
  304. "hAlign":[1],
  305. "font":["Arial"]
  306. },
  307. "data":{
  308. "field":"content",
  309. "vAlign":0,
  310. "hAlign":3,
  311. "font":"Arial"
  312. }
  313. }]
  314. };
  315. SheetDataHelper.loadSheetHeader(jobsSetting, stdBillsJobSpread.getActiveSheet());
  316. SheetDataHelper.loadSheetData(jobsSetting, stdBillsJobSpread.getActiveSheet(), jobs);
  317. };
  318. var showFeatures = function (features) {
  319. var featuresSetting = {
  320. "emptyRows":0,
  321. "headRows":1,
  322. "headRowHeight":[25],
  323. "defaultRowHeight": 21,
  324. "cols":[{
  325. "width":200,
  326. "readOnly":true,
  327. "head":{
  328. "titleNames":["项目特征"],
  329. "spanCols":[1],
  330. "spanRows":[1],
  331. "vAlign":[1],
  332. "hAlign":[1],
  333. "font":["Arial"]
  334. },
  335. "data":{
  336. "field":"content",
  337. "vAlign":0,
  338. "hAlign":3,
  339. "font":"Arial"
  340. }
  341. }]
  342. };
  343. SheetDataHelper.loadSheetHeader(featuresSetting, stdBillsFeatureSpread.getActiveSheet());
  344. SheetDataHelper.loadSheetData(featuresSetting, stdBillsFeatureSpread.getActiveSheet(), features);
  345. }
  346. var showJobsAndFeatures = function (node) {
  347. $('#stdBillsJobTab').show();
  348. $('#stdBillsRemarkTab').hide();
  349. if (!stdBillsJobSpread) {
  350. stdBillsJobSpread = SheetDataHelper.createNewSpread($('#stdBillsJobs')[0]);
  351. }
  352. showJobs(getBillsJobs(node));
  353. if (!stdBillsFeatureSpread) {
  354. stdBillsFeatureSpread = SheetDataHelper.createNewSpread($('#stdBillsFeatures')[0]);
  355. }
  356. showFeatures(getBillsFeatures(node));
  357. };
  358. var showBillsRemark = function (node) {
  359. $('#stdBillsJobTab').hide();
  360. $('#stdBillsRemarkTab').show();
  361. $('#stdBillsRemark').text(node && node.data.recharge ? node.data.recharge : '');
  362. };
  363. var showBillsRela = function (node) {
  364. if (node && node.children.length === 0) {
  365. showJobsAndFeatures(node);
  366. } else {
  367. showBillsRemark(node);
  368. }
  369. }
  370. var LoadData = function (stdBillsLibID) {
  371. CommonAjax.post('/stdBillsEditor/getJobContent', {userId: userID, billsLibId: stdBillsLibID}, function (datas) {
  372. stdBillsJobData = datas;
  373. }, function () {
  374. stdBillsJobData = [];
  375. });
  376. CommonAjax.post('/stdBillsEditor/getItemCharacter', {userId: userID, billsLibId: stdBillsLibID}, function (datas) {
  377. stdBillsFeatureData = datas;
  378. }, function () {
  379. stdBillsFeatureData = [];
  380. });
  381. CommonAjax.post('/stdBillsEditor/getBills', {userId: userID, billsLibId: stdBillsLibID}, function (datas) {
  382. stdBills = datas;
  383. stdBillsTree.loadDatas(stdBills);
  384. stdBillsTreeController.showTreeData();
  385. showBillsRela(stdBillsTree.firstNode());
  386. stdBillsTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, showBillsRela);
  387. });
  388. };
  389. stdBillsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (sender, args) {
  390. if (stdBillsTree.items[args.row].children.length === 0) {
  391. ProjectController.addBills(project, controller, stdBillsTree.items[args.row]);
  392. }
  393. });
  394. return LoadData;
  395. })();
  396. $('#stdBillsLibSelect').change(function () {
  397. var select = $(this);
  398. if (this.children.length !== 0) {
  399. LoadStdBills(select.val());
  400. }
  401. });