project_glj.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * 工料机汇总相关
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/6/15
  6. * @version
  7. */
  8. let projectGLJSpread = null;
  9. let projectGLJSheet = null;
  10. // websocket所需
  11. let host = '';
  12. let socket = null;
  13. let roomId = 0;
  14. // 判定常量
  15. let materialIdList = [];
  16. let canNotChangeTypeId = [];
  17. let GLJTypeConst = [];
  18. // spreadjs载入数据所需
  19. let jsonData = [];
  20. let mixRatioConnectData = [];
  21. let currentTag = '';
  22. let isChanging = false;
  23. $(document).ready(function () {
  24. $('#tab_gongliaoji').on('shown.bs.tab', function (e) {
  25. init();
  26. });
  27. // 是否主动更改数据
  28. // $("#message").on('click', '#load-data', function() {
  29. // $("#notify").slideUp('fast');
  30. // if (changeInfo.length > 0) {
  31. // for (let index in changeInfo) {
  32. // let cell = gljSheet.getCell(changeInfo[index].row, changeInfo[index].col, GC.Spread.Sheets.SheetArea.viewport);
  33. // cell.value(changeInfo[index].newValue);
  34. // }
  35. // }
  36. // changeInfo = [];
  37. // });
  38. });
  39. /**
  40. * 初始化数据
  41. *
  42. * @return {void}
  43. */
  44. function init() {
  45. // 加载工料机数据
  46. $.ajax({
  47. url: '/glj/getData',
  48. type: 'post',
  49. dataType: 'json',
  50. data: {project_id: scUrlUtil.GetQueryString('project')},
  51. error: function() {
  52. alert('数据传输错误');
  53. },
  54. beforeSend: function() {
  55. },
  56. success: function(response) {
  57. if (response.err === 1) {
  58. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取工料机数据失败!';
  59. alert(msg);
  60. return false;
  61. }
  62. let data = response.data;
  63. // 赋值
  64. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  65. mixRatioConnectData = data.mixRatioConnectData !== undefined ? data.mixRatioConnectData : mixRatioConnectData;
  66. host = data.constData.hostname !== undefined ? data.constData.hostname : '';
  67. materialIdList = data.constData.materialIdList !== undefined ? data.constData.materialIdList : materialIdList;
  68. roomId = data.constData.roomId !== undefined ? data.constData.roomId : roomId;
  69. canNotChangeTypeId = data.constData.ownCompositionTypes !== undefined ?
  70. data.constData.ownCompositionTypes : canNotChangeTypeId;
  71. GLJTypeConst = data.constData.GLJTypeConst !== undefined ? JSON.parse(data.constData.GLJTypeConst) : GLJTypeConst;
  72. spreadInit();
  73. }
  74. });
  75. }
  76. /**
  77. * spreadjs相关初始化
  78. *
  79. * @return {void}
  80. */
  81. function spreadInit() {
  82. projectGLJSpread = new ProjectGLJSpread();
  83. projectGLJSpread.successCallback = successTrigger;
  84. projectGLJSheet = projectGLJSpread.init();
  85. // 绑定单击事件
  86. let lastRow = 0;
  87. projectGLJSheet.bind(GC.Spread.Sheets.Events.CellClick, function (element, info) {
  88. let currentRow = info.row;
  89. if (currentRow === undefined || currentRow === lastRow) {
  90. return;
  91. }
  92. if (currentTag !== 'mix-ratio' && currentTag !== 'machine') {
  93. return;
  94. }
  95. let spread = currentTag === 'mix-ratio' ? mixRatioSpread : machineSpread;
  96. if (spread === null) {
  97. return;
  98. }
  99. let projectGLJId = projectGLJSheet.getActiveDataByField('id');
  100. spread.getRatioData(projectGLJId);
  101. lastRow = currentRow;
  102. });
  103. // 切换tab触发refresh
  104. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  105. currentTag = $(e.target).data('name');
  106. if (currentTag === 'ration') {
  107. projectGLJSheet.filterData('unit_price.type', []);
  108. }
  109. });
  110. }
  111. /**
  112. * 成功事件
  113. *
  114. * @param {string} field
  115. * @param {object} info
  116. * @return {void}
  117. */
  118. function successTrigger(field, info) {
  119. switch (field) {
  120. case 'unit_price.market_price':
  121. // 计算价格
  122. projectGLJSpread.priceCalculate(info);
  123. // 触发websocket通知
  124. socket.emit('dataNotify', JSON.stringify(info));
  125. break;
  126. }
  127. }