composition.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * 组成物相关数据
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/10/27
  6. * @version
  7. */
  8. function Composition() {
  9. this.datas = null;
  10. this.isLoading = false;
  11. }
  12. /**
  13. * 加载数据
  14. *
  15. * @param {function} callback
  16. * @return {boolean}
  17. */
  18. Composition.prototype.loadData = function (callback = null) {
  19. let self = this;
  20. if (self.isLoading) {
  21. return false;
  22. }
  23. // 加载组成物数据
  24. $.ajax({
  25. url: '/glj/get-composition',
  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.composition = self;
  49. }
  50. });
  51. };
  52. /**
  53. * 获取对应code的组成物数据
  54. *
  55. * @param {String} code
  56. * @param {Number} gljType
  57. * @return {Array}
  58. */
  59. Composition.prototype.getCompositionByCode = function(code, gljType = 0) {
  60. let result = [];
  61. if (code === '') {
  62. return result;
  63. }
  64. if (gljType === 0) {
  65. return this.datas[code] !== undefined ? this.datas[code] : result;
  66. }
  67. for(let composition of this.datas[code]) {
  68. if (composition.glj_type === gljType) {
  69. result.push(composition);
  70. }
  71. }
  72. return result;
  73. };
  74. Composition.prototype.getCompositionByGLJ = function (glj) {
  75. let mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  76. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  77. let connect_index = gljOprObj.getIndex(glj,gljKeyArray);
  78. let gljList=[];
  79. if(mixRatioMap[connect_index]){ //说明是有组成物的类型
  80. gljList = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  81. }
  82. return gljList;
  83. }