bills.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. var Bills = {
  5. createNew: function (project) {
  6. var billsTreeSetting = {
  7. id: 'ID',
  8. pid: 'ParentID',
  9. nid: 'NextSiblingID',
  10. rootId: -1
  11. };
  12. // 用户定义private方法
  13. var tools = {};
  14. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  15. var bills = function (proj) {
  16. this.project = proj;
  17. this.datas = null;
  18. this.tree = idTree.createNew(billsTreeSetting);
  19. var sourceType = 'bills';
  20. this.getSourceType = function () {
  21. return sourceType;
  22. }
  23. };
  24. // prototype用于定义public方法
  25. bills.prototype.loadDatas = function (datas) {
  26. this.datas = datas;
  27. // generate Fees & Flags Index, For View & Calculate
  28. this.datas.forEach(function (data) {
  29. data.FeesIndex = {};
  30. if (data.fees) {
  31. data.fees.forEach(function (fee) {
  32. data.FeesIndex[fee.fieldName] = fee;
  33. });
  34. }
  35. data.FlagsIndex = {};
  36. if (data.flags) {
  37. data.flags.forEach(function (flag) {
  38. data.FlagsIndex[flag.fieldName] = flag;
  39. });
  40. }
  41. });
  42. // datas load to Tree
  43. this.tree.loadDatas(this.datas);
  44. };
  45. return new bills(project);
  46. }
  47. };