bills.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. data.fees.forEach(function (fee) {
  31. data.FeesIndex[fee.fieldName] = fee;
  32. });
  33. data.FlagsIndex = {};
  34. data.flags.forEach(function (flag) {
  35. data.FlagsIndex[flag.fieldName] = flag;
  36. });
  37. });
  38. // datas load to Tree
  39. this.tree.loadDatas(this.datas);
  40. };
  41. return new bills(project);
  42. }
  43. };