bills.js 2.9 KB

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