ration.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. var Ration = {
  5. createNew: function (project) {
  6. // 用户定义private方法
  7. var tools = {};
  8. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  9. var ration = function (proj) {
  10. this.project = proj;
  11. this.datas = null;
  12. var sourceType = ModuleNames.ration;
  13. this.getSourceType = function () {
  14. return sourceType;
  15. }
  16. proj.registerModule(ModuleNames.ration, this);
  17. };
  18. // 从后台获取数据
  19. /*ration.prototype.pullData = function (){
  20. this.project.pullData(
  21. '/ration/getData',
  22. {projectID: this.project.ID},
  23. function(result){
  24. if (result.error ===0){
  25. this.loadDatas(result.data);
  26. }
  27. else {
  28. // to do: 错误处理需要细化
  29. alert(result.message);
  30. }
  31. },
  32. function (){}//to do: 错误处理需要细化
  33. )
  34. };*/
  35. // prototype用于定义public方法
  36. ration.prototype.loadData = function (datas) {
  37. this.datas = datas;
  38. // generate Fees & Flags Index,For View & Calculate
  39. this.datas.forEach(function (data) {
  40. data.FeesIndex = {};
  41. data.fees.forEach(function (fee) {
  42. data.FeesIndex[fee.fieldName] = fee;
  43. });
  44. data.FlagsIndex = {};
  45. data.flags.forEach(function (flag) {
  46. data.FlagsIndex[flag.fieldName] = flag;
  47. });
  48. });
  49. };
  50. // 提交数据后的错误处理方法
  51. ration.prototype.doAfterUpdate = function(err, data){
  52. // to do
  53. };
  54. return new ration(project);
  55. }
  56. };