project_glj.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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('show.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. if (isChanging) {
  103. return false;
  104. }
  105. let type = $("input[name='change-type']:checked").val();
  106. type = parseInt(type);
  107. let changeUnitPriceId = 0;
  108. if (type === 0) {
  109. // 从本项目中选择
  110. changeUnitPriceId = $("#self-file").val();
  111. } else {
  112. // 从其他项目中复制
  113. changeUnitPriceId = $("#other-file").val();
  114. }
  115. $.ajax({
  116. url: '/glj/change-file',
  117. type: 'post',
  118. data: {project_id: scUrlUtil.GetQueryString('project'), change_id: changeUnitPriceId},
  119. error: function() {
  120. isChanging = false;
  121. },
  122. beforeSend: function() {
  123. isChanging = true;
  124. },
  125. success: function(response) {
  126. isChanging = false;
  127. if (response.err === 1) {
  128. let msg = response.msg !== undefined ? response.msg : '未知错误';
  129. alert(msg);
  130. return false;
  131. }
  132. $('#change-dj').modal("hide");
  133. }
  134. });
  135. });
  136. // 是否主动更改数据
  137. // $("#message").on('click', '#load-data', function() {
  138. // $("#notify").slideUp('fast');
  139. // if (changeInfo.length > 0) {
  140. // for (let index in changeInfo) {
  141. // let cell = gljSheet.getCell(changeInfo[index].row, changeInfo[index].col, GC.Spread.Sheets.SheetArea.viewport);
  142. // cell.value(changeInfo[index].newValue);
  143. // }
  144. // }
  145. // changeInfo = [];
  146. // });
  147. });
  148. /**
  149. * 初始化数据
  150. *
  151. * @return {void|boolean}
  152. */
  153. function init() {
  154. // 加载工料机数据
  155. let data = projectObj.project.projectGLJ === null ? null : projectObj.project.projectGLJ.datas;
  156. if (data === null) {
  157. return false;
  158. }
  159. // 赋值
  160. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  161. mixRatioConnectData = data.mixRatioConnectData !== undefined ? data.mixRatioConnectData : mixRatioConnectData;
  162. host = data.constData.hostname !== undefined ? data.constData.hostname : '';
  163. materialIdList = data.constData.materialIdList !== undefined ? data.constData.materialIdList : materialIdList;
  164. roomId = data.constData.roomId !== undefined ? data.constData.roomId : roomId;
  165. canNotChangeTypeId = data.constData.ownCompositionTypes !== undefined ?
  166. data.constData.ownCompositionTypes : canNotChangeTypeId;
  167. GLJTypeConst = data.constData.GLJTypeConst !== undefined ? JSON.parse(data.constData.GLJTypeConst) : GLJTypeConst;
  168. let usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
  169. usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?
  170. data.constData.usedUnitPriceInfo : {};
  171. unitPriceFileInit(usedUnitPriceInfo.name, usedTenderList);
  172. setTimeout(spreadInit, 1);
  173. }
  174. /**
  175. * spreadjs相关初始化
  176. *
  177. * @return {void}
  178. */
  179. function spreadInit() {
  180. projectGLJSpread = new ProjectGLJSpread();
  181. projectGLJSpread.successCallback = successTrigger;
  182. projectGLJSheet = projectGLJSpread.init();
  183. // 绑定单击事件
  184. let lastRow = 0;
  185. projectGLJSheet.bind(GC.Spread.Sheets.Events.CellClick, function (element, info) {
  186. let currentRow = info.row;
  187. if (currentRow === undefined || currentRow === lastRow) {
  188. return;
  189. }
  190. if (currentTag !== 'mix-ratio' && currentTag !== 'machine') {
  191. return;
  192. }
  193. let spread = currentTag === 'mix-ratio' ? mixRatioSpread : machineSpread;
  194. if (spread === null) {
  195. return;
  196. }
  197. let projectGLJId = projectGLJSheet.getActiveDataByField('id');
  198. spread.getRatioData(projectGLJId);
  199. lastRow = currentRow;
  200. });
  201. // 切换tab触发refresh
  202. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  203. currentTag = $(e.target).data('name');
  204. if (currentTag === 'ration') {
  205. projectGLJSheet.filterData('unit_price.type', []);
  206. }
  207. });
  208. }
  209. /**
  210. * 单价文件相关初始化
  211. *
  212. * @param {String} name
  213. * @param {Array} data
  214. * @return {void}
  215. */
  216. function unitPriceFileInit(name, data) {
  217. $("#used-name").text(name);
  218. let usedCount = data.length <= 0 ? 1 : data.length;
  219. $("#used-count").text(usedCount);
  220. $('#pop-dj').popover({
  221. placement:"bottom",
  222. html:true,
  223. trigger:"hover | focus",
  224. content: data.join('<br>')
  225. }
  226. );
  227. }
  228. /**
  229. * 成功事件
  230. *
  231. * @param {string} field
  232. * @param {object} info
  233. * @return {void}
  234. */
  235. function successTrigger(field, info) {
  236. switch (field) {
  237. case 'unit_price.market_price':
  238. // 计算价格
  239. projectGLJSpread.priceCalculate(info);
  240. // 触发websocket通知
  241. socket.emit('dataNotify', JSON.stringify(info));
  242. break;
  243. }
  244. }