project_glj.js 3.0 KB

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