project_glj.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. let usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
  73. let usedUnitFileName = data.constData.usedUnitPriceName !== undefined ?
  74. data.constData.usedUnitPriceName : '';
  75. // 存入缓存
  76. projectObj.project.projectGLJ.datas = jsonData;
  77. console.log(projectObj.project);
  78. spreadInit();
  79. unitPriceFileInit(usedUnitFileName, usedTenderList);
  80. }
  81. });
  82. }
  83. /**
  84. * spreadjs相关初始化
  85. *
  86. * @return {void}
  87. */
  88. function spreadInit() {
  89. projectGLJSpread = new ProjectGLJSpread();
  90. projectGLJSpread.successCallback = successTrigger;
  91. projectGLJSheet = projectGLJSpread.init();
  92. // 绑定单击事件
  93. let lastRow = 0;
  94. projectGLJSheet.bind(GC.Spread.Sheets.Events.CellClick, function (element, info) {
  95. let currentRow = info.row;
  96. if (currentRow === undefined || currentRow === lastRow) {
  97. return;
  98. }
  99. if (currentTag !== 'mix-ratio' && currentTag !== 'machine') {
  100. return;
  101. }
  102. let spread = currentTag === 'mix-ratio' ? mixRatioSpread : machineSpread;
  103. if (spread === null) {
  104. return;
  105. }
  106. let projectGLJId = projectGLJSheet.getActiveDataByField('id');
  107. spread.getRatioData(projectGLJId);
  108. lastRow = currentRow;
  109. });
  110. // 切换tab触发refresh
  111. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  112. currentTag = $(e.target).data('name');
  113. if (currentTag === 'ration') {
  114. projectGLJSheet.filterData('unit_price.type', []);
  115. }
  116. });
  117. }
  118. /**
  119. * 单价文件相关初始化
  120. *
  121. * @param {String} name
  122. * @param {Array} data
  123. * @return {void}
  124. */
  125. function unitPriceFileInit(name, data) {
  126. $("#used-name").text(name);
  127. let usedCount = data.length <= 0 ? 1 : data.length;
  128. $("#used-count").text(usedCount);
  129. $('#pop-dj').popover({
  130. placement:"bottom",
  131. html:true,
  132. trigger:"hover | focus",
  133. content: data.join('<br>')
  134. }
  135. );
  136. }
  137. /**
  138. * 成功事件
  139. *
  140. * @param {string} field
  141. * @param {object} info
  142. * @return {void}
  143. */
  144. function successTrigger(field, info) {
  145. switch (field) {
  146. case 'unit_price.market_price':
  147. // 计算价格
  148. projectGLJSpread.priceCalculate(info);
  149. // 触发websocket通知
  150. socket.emit('dataNotify', JSON.stringify(info));
  151. break;
  152. }
  153. }