bills.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. data.fees.forEach(function (fee) {
  49. data.FeesIndex[fee.fieldName] = fee;
  50. });
  51. data.FlagsIndex = {};
  52. data.flags.forEach(function (flag) {
  53. data.FlagsIndex[flag.fieldName] = flag;
  54. });
  55. });
  56. // datas load to Tree
  57. this.tree.loadDatas(this.datas);
  58. };
  59. // 提交数据后的错误处理方法
  60. bills.prototype.doAfterUpdate = function(err, data){
  61. // to do
  62. };
  63. return new bills(project);
  64. }
  65. };