project_glj.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. // 存入缓存
  73. projectObj.project.projectGLJ.datas = jsonData;
  74. console.log(projectObj.project);
  75. spreadInit();
  76. }
  77. });
  78. }
  79. /**
  80. * spreadjs相关初始化
  81. *
  82. * @return {void}
  83. */
  84. function spreadInit() {
  85. projectGLJSpread = new ProjectGLJSpread();
  86. projectGLJSpread.successCallback = successTrigger;
  87. projectGLJSheet = projectGLJSpread.init();
  88. // 绑定单击事件
  89. let lastRow = 0;
  90. projectGLJSheet.bind(GC.Spread.Sheets.Events.CellClick, function (element, info) {
  91. let currentRow = info.row;
  92. if (currentRow === undefined || currentRow === lastRow) {
  93. return;
  94. }
  95. if (currentTag !== 'mix-ratio' && currentTag !== 'machine') {
  96. return;
  97. }
  98. let spread = currentTag === 'mix-ratio' ? mixRatioSpread : machineSpread;
  99. if (spread === null) {
  100. return;
  101. }
  102. let projectGLJId = projectGLJSheet.getActiveDataByField('id');
  103. spread.getRatioData(projectGLJId);
  104. lastRow = currentRow;
  105. });
  106. // 切换tab触发refresh
  107. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  108. currentTag = $(e.target).data('name');
  109. if (currentTag === 'ration') {
  110. projectGLJSheet.filterData('unit_price.type', []);
  111. }
  112. });
  113. }
  114. /**
  115. * 成功事件
  116. *
  117. * @param {string} field
  118. * @param {object} info
  119. * @return {void}
  120. */
  121. function successTrigger(field, info) {
  122. switch (field) {
  123. case 'unit_price.market_price':
  124. // 计算价格
  125. projectGLJSpread.priceCalculate(info);
  126. // 触发websocket通知
  127. socket.emit('dataNotify', JSON.stringify(info));
  128. break;
  129. }
  130. }