project_glj.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * 工料机汇总相关数据
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/9/14
  6. * @version
  7. */
  8. function ProjectGLJ() {
  9. this.datas = null;
  10. this.isLoading = false;
  11. }
  12. /**
  13. * 加载数据
  14. *
  15. * @return {boolean}
  16. */
  17. ProjectGLJ.prototype.loadData = function () {
  18. let self = this;
  19. if (self.isLoading) {
  20. return false;
  21. }
  22. // 加载工料机数据
  23. $.ajax({
  24. url: '/glj/getData',
  25. type: 'post',
  26. dataType: 'json',
  27. data: {project_id: scUrlUtil.GetQueryString('project')},
  28. error: function() {
  29. // alert('数据传输错误');
  30. },
  31. beforeSend: function() {
  32. self.isLoading = true;
  33. },
  34. success: function(response) {
  35. self.isLoading = false;
  36. if (response.err === 1) {
  37. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取工料机数据失败!';
  38. alert(msg);
  39. return false;
  40. }
  41. self.datas = response.data;
  42. // 存入缓存
  43. projectObj.project.projectGLJ = self;
  44. }
  45. });
  46. };
  47. /**
  48. * 获取对应工料机数据
  49. *
  50. * @param {String} code
  51. * @return {Object}
  52. */
  53. ProjectGLJ.prototype.getDataByCode = function (code) {
  54. let result = {};
  55. if (this.datas === null) {
  56. return result;
  57. }
  58. let gljList = this.datas.gljList;
  59. if (gljList === undefined) {
  60. return result;
  61. }
  62. for(let tmp of gljList) {
  63. if (tmp.code === code) {
  64. result = tmp;
  65. break;
  66. }
  67. }
  68. return result;
  69. };
  70. /**
  71. * 修改工料机数据
  72. *
  73. * @param {Number} id
  74. * @param {Object} data
  75. * @return {boolean}
  76. */
  77. ProjectGLJ.prototype.updateData = function(id, data) {
  78. let result = false;
  79. if (this.datas === null) {
  80. return result;
  81. }
  82. let gljList = this.datas.gljList;
  83. if (gljList === undefined) {
  84. return result;
  85. }
  86. // 查找对应的index
  87. let index = -1;
  88. for(let tmp in gljList) {
  89. if (gljList[tmp].id === id) {
  90. index = tmp;
  91. break;
  92. }
  93. }
  94. if (index < 0) {
  95. return result;
  96. }
  97. // 修改数据
  98. for(let tmpIndex in data) {
  99. if(tmpIndex.indexOf('_price') >= 0) {
  100. // 修改unit_price中的对象
  101. this.datas.gljList[index]['unit_price'][tmpIndex] = data[tmpIndex];
  102. } else {
  103. this.datas.gljList[index][tmpIndex] = data[tmpIndex];
  104. }
  105. }
  106. };
  107. /**
  108. * 加载缓存数据到spread
  109. *
  110. * @return {void}
  111. */
  112. ProjectGLJ.prototype.loadCacheData = function() {
  113. // 加载工料机数据
  114. let data = this.datas === null ? null : this.datas;
  115. if (data === null) {
  116. return;
  117. }
  118. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  119. projectGLJSheet.setData(jsonData);
  120. };