bills.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 = ModuleNames.bills;
  20. this.getSourceType = function () {
  21. return sourceType;
  22. }
  23. proj.registerModule(ModuleNames.bills, this);
  24. };
  25. // 从后台获取数据
  26. bills.prototype.pullData = function (){
  27. this.project.pullData(
  28. '/bills/getData',
  29. {projectID: this.project.ID},
  30. function(result){
  31. if (result.error ===0){
  32. this.loadDatas(result.data);
  33. }
  34. else {
  35. // to do: ?错误处理需要细化
  36. alert(result.message);
  37. }
  38. },
  39. function (){/* to do: 错误处理需要细化*/}
  40. )
  41. };
  42. // prototype用于定义public方法
  43. bills.prototype.loadDatas = function (datas) {
  44. this.datas = datas;
  45. // generate Fees & Flags Index, For View & Calculate
  46. this.datas.forEach(function (data) {
  47. data.FeesIndex = {};
  48. if (data.fees) {
  49. data.fees.forEach(function (fee) {
  50. data.FeesIndex[fee.fieldName] = fee;
  51. });
  52. }
  53. data.FlagsIndex = {};
  54. if (data.flags) {
  55. data.flags.forEach(function (flag) {
  56. data.FlagsIndex[flag.fieldName] = flag;
  57. });
  58. }
  59. });
  60. // datas load to Tree
  61. this.tree.loadDatas(this.datas);
  62. };
  63. // 提交数据后的错误处理方法
  64. bills.prototype.doAfterUpdate = function(err, data){
  65. // to do
  66. };
  67. return new bills(project);
  68. }
  69. };