bills.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. autoUpdate: false
  12. };
  13. // 用户定义private方法
  14. var tools = {};
  15. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  16. var bills = function (proj) {
  17. this.project = proj;
  18. this.datas = null;
  19. this.tree = idTree.createNew(billsTreeSetting);
  20. var sourceType = ModuleNames.bills;
  21. this.getSourceType = function () {
  22. return sourceType;
  23. }
  24. proj.registerModule(ModuleNames.bills, this);
  25. };
  26. // 从后台获取数据
  27. /*bills.prototype.pullData = function (){
  28. this.project.pullData(
  29. '/bills/getData',
  30. {projectID: this.project.ID},
  31. function(result){
  32. if (result.error ===0){
  33. this.loadDatas(result.data);
  34. }
  35. else {
  36. // to do: ?错误处理需要细化
  37. alert(result.message);
  38. }
  39. },
  40. function (){}// to do: 错误处理需要细化
  41. )
  42. };*/
  43. // prototype用于定义public方法
  44. bills.prototype.loadData = function (datas) {
  45. this.datas = datas;
  46. // generate Fees & Flags Index, For View & Calculate
  47. this.datas.forEach(function (data) {
  48. data.FeesIndex = {};
  49. if (data.fees) {
  50. data.fees.forEach(function (fee) {
  51. data.FeesIndex[fee.fieldName] = fee;
  52. });
  53. }
  54. data.FlagsIndex = {};
  55. if (data.flags) {
  56. data.flags.forEach(function (flag) {
  57. data.FlagsIndex[flag.fieldName] = flag;
  58. });
  59. }
  60. });
  61. // datas load to Tree
  62. this.tree.loadDatas(this.datas);
  63. };
  64. // 提交数据后的错误处理方法
  65. bills.prototype.doAfterUpdate = function(err, data){
  66. // to do
  67. };
  68. return new bills(project);
  69. }
  70. };