project_glj.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. // 单价文件相关
  22. let usedUnitPriceInfo = {};
  23. let otherFileData = {};
  24. let currentTag = '';
  25. let isChanging = false;
  26. $(document).ready(function () {
  27. $('#tab_gongliaoji').on('shown.bs.tab', function (e) {
  28. init();
  29. });
  30. // 单价文件切换弹框
  31. $('#change-dj').on('shown.bs.modal', function () {
  32. // 获取当前建设项数据
  33. let projectName = projectInfoObj.projectInfo.fullFolder !== undefined &&
  34. projectInfoObj.projectInfo.fullFolder.length > 0 ? projectInfoObj.projectInfo.fullFolder[0] : '';
  35. $("#current-project-name").text(projectName);
  36. // 获取切换单价文件相关数据
  37. $.ajax({
  38. url: '/glj/get-project-info',
  39. type: 'post',
  40. data: {project_id: scUrlUtil.GetQueryString('project')},
  41. dataType: 'json',
  42. success: function(response) {
  43. if (response.err === 1) {
  44. alert('数据传输错误!');
  45. return false;
  46. }
  47. let data = response.data;
  48. // 本项目中的单价文件
  49. if (data.self.length > 0) {
  50. let selfFileHtml = '';
  51. for(let tmp of data.self) {
  52. let select = usedUnitPriceInfo === tmp.id ? ' selected="selected"' : '';
  53. selfFileHtml += '<option'+ select +' value="'+ tmp.id +'">'+ tmp.name +'</option>';
  54. }
  55. $("#self-file").html(selfFileHtml);
  56. }
  57. // 其他建设项目数据
  58. if (data.other.length > 0) {
  59. let otherProjectHtml = '';
  60. let otherFileHtml = '';
  61. for(let tmp of data.other) {
  62. otherProjectHtml += '<option value="'+ tmp.ID +'">'+ tmp.name +'</option>';
  63. otherFileData[tmp.ID] = tmp.unitPriceList;
  64. if (otherFileHtml !== '') {
  65. continue;
  66. }
  67. for(let unitPrice of tmp.unitPriceList) {
  68. otherFileHtml += '<option value="'+ unitPrice.id +'">'+ unitPrice.name +'</option>';
  69. }
  70. }
  71. $("#other-project").html(otherProjectHtml);
  72. $("#other-file").html(otherFileHtml);
  73. }
  74. }
  75. });
  76. });
  77. // 从其他建设项目中复制 选择建设项目
  78. $("#other-project").change(function() {
  79. let projectId = $(this).val();
  80. if (otherFileData[projectId] === undefined) {
  81. return false;
  82. }
  83. let otherFileHtml = '';
  84. for(let unitPrice of otherFileData[projectId]) {
  85. otherFileHtml += '<option value="'+ unitPrice.id +'">'+ unitPrice.name +'</option>';
  86. }
  87. $("#other-file").html(otherFileHtml);
  88. });
  89. // 单价文件选项切换
  90. $("input[name='change-type']").change(function() {
  91. let type = $(this).val();
  92. type = parseInt(type);
  93. $("#change-dj .option").hide();
  94. if (type === 0) {
  95. $(".option.select").show();
  96. } else {
  97. $(".option.copy").show();
  98. }
  99. });
  100. // 单价文件切换确认
  101. $("#change-file-confirm").click(function() {
  102. let type = $("input[name='change-type']:checked").val();
  103. type = parseInt(type);
  104. if (type === 0) {
  105. // 从本项目中选择
  106. } else {
  107. // 从其他项目中复制
  108. }
  109. });
  110. // 是否主动更改数据
  111. // $("#message").on('click', '#load-data', function() {
  112. // $("#notify").slideUp('fast');
  113. // if (changeInfo.length > 0) {
  114. // for (let index in changeInfo) {
  115. // let cell = gljSheet.getCell(changeInfo[index].row, changeInfo[index].col, GC.Spread.Sheets.SheetArea.viewport);
  116. // cell.value(changeInfo[index].newValue);
  117. // }
  118. // }
  119. // changeInfo = [];
  120. // });
  121. });
  122. /**
  123. * 初始化数据
  124. *
  125. * @return {void}
  126. */
  127. function init() {
  128. // 加载工料机数据
  129. $.ajax({
  130. url: '/glj/getData',
  131. type: 'post',
  132. dataType: 'json',
  133. data: {project_id: scUrlUtil.GetQueryString('project')},
  134. error: function() {
  135. // alert('数据传输错误');
  136. },
  137. beforeSend: function() {
  138. },
  139. success: function(response) {
  140. if (response.err === 1) {
  141. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取工料机数据失败!';
  142. alert(msg);
  143. return false;
  144. }
  145. let data = response.data;
  146. // 赋值
  147. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  148. mixRatioConnectData = data.mixRatioConnectData !== undefined ? data.mixRatioConnectData : mixRatioConnectData;
  149. host = data.constData.hostname !== undefined ? data.constData.hostname : '';
  150. materialIdList = data.constData.materialIdList !== undefined ? data.constData.materialIdList : materialIdList;
  151. roomId = data.constData.roomId !== undefined ? data.constData.roomId : roomId;
  152. canNotChangeTypeId = data.constData.ownCompositionTypes !== undefined ?
  153. data.constData.ownCompositionTypes : canNotChangeTypeId;
  154. GLJTypeConst = data.constData.GLJTypeConst !== undefined ? JSON.parse(data.constData.GLJTypeConst) : GLJTypeConst;
  155. let usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
  156. usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?
  157. data.constData.usedUnitPriceInfo : {};
  158. // 存入缓存
  159. projectObj.project.projectGLJ.datas = jsonData;
  160. spreadInit();
  161. unitPriceFileInit(usedUnitPriceInfo.name, usedTenderList);
  162. }
  163. });
  164. }
  165. /**
  166. * spreadjs相关初始化
  167. *
  168. * @return {void}
  169. */
  170. function spreadInit() {
  171. projectGLJSpread = new ProjectGLJSpread();
  172. projectGLJSpread.successCallback = successTrigger;
  173. projectGLJSheet = projectGLJSpread.init();
  174. // 绑定单击事件
  175. let lastRow = 0;
  176. projectGLJSheet.bind(GC.Spread.Sheets.Events.CellClick, function (element, info) {
  177. let currentRow = info.row;
  178. if (currentRow === undefined || currentRow === lastRow) {
  179. return;
  180. }
  181. if (currentTag !== 'mix-ratio' && currentTag !== 'machine') {
  182. return;
  183. }
  184. let spread = currentTag === 'mix-ratio' ? mixRatioSpread : machineSpread;
  185. if (spread === null) {
  186. return;
  187. }
  188. let projectGLJId = projectGLJSheet.getActiveDataByField('id');
  189. spread.getRatioData(projectGLJId);
  190. lastRow = currentRow;
  191. });
  192. // 切换tab触发refresh
  193. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  194. currentTag = $(e.target).data('name');
  195. if (currentTag === 'ration') {
  196. projectGLJSheet.filterData('unit_price.type', []);
  197. }
  198. });
  199. }
  200. /**
  201. * 单价文件相关初始化
  202. *
  203. * @param {String} name
  204. * @param {Array} data
  205. * @return {void}
  206. */
  207. function unitPriceFileInit(name, data) {
  208. $("#used-name").text(name);
  209. let usedCount = data.length <= 0 ? 1 : data.length;
  210. $("#used-count").text(usedCount);
  211. $('#pop-dj').popover({
  212. placement:"bottom",
  213. html:true,
  214. trigger:"hover | focus",
  215. content: data.join('<br>')
  216. }
  217. );
  218. }
  219. /**
  220. * 成功事件
  221. *
  222. * @param {string} field
  223. * @param {object} info
  224. * @return {void}
  225. */
  226. function successTrigger(field, info) {
  227. switch (field) {
  228. case 'unit_price.market_price':
  229. // 计算价格
  230. projectGLJSpread.priceCalculate(info);
  231. // 触发websocket通知
  232. socket.emit('dataNotify', JSON.stringify(info));
  233. break;
  234. }
  235. }