project_glj.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. 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}
  152. */
  153. function init() {
  154. // 加载工料机数据
  155. $.ajax({
  156. url: '/glj/getData',
  157. type: 'post',
  158. dataType: 'json',
  159. data: {project_id: scUrlUtil.GetQueryString('project')},
  160. error: function() {
  161. // alert('数据传输错误');
  162. },
  163. beforeSend: function() {
  164. },
  165. success: function(response) {
  166. if (response.err === 1) {
  167. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取工料机数据失败!';
  168. alert(msg);
  169. return false;
  170. }
  171. let data = response.data;
  172. // 赋值
  173. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  174. mixRatioConnectData = data.mixRatioConnectData !== undefined ? data.mixRatioConnectData : mixRatioConnectData;
  175. host = data.constData.hostname !== undefined ? data.constData.hostname : '';
  176. materialIdList = data.constData.materialIdList !== undefined ? data.constData.materialIdList : materialIdList;
  177. roomId = data.constData.roomId !== undefined ? data.constData.roomId : roomId;
  178. canNotChangeTypeId = data.constData.ownCompositionTypes !== undefined ?
  179. data.constData.ownCompositionTypes : canNotChangeTypeId;
  180. GLJTypeConst = data.constData.GLJTypeConst !== undefined ? JSON.parse(data.constData.GLJTypeConst) : GLJTypeConst;
  181. let usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
  182. usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?
  183. data.constData.usedUnitPriceInfo : {};
  184. // 存入缓存
  185. projectObj.project.projectGLJ.datas = jsonData;
  186. spreadInit();
  187. unitPriceFileInit(usedUnitPriceInfo.name, usedTenderList);
  188. }
  189. });
  190. }
  191. /**
  192. * spreadjs相关初始化
  193. *
  194. * @return {void}
  195. */
  196. function spreadInit() {
  197. projectGLJSpread = new ProjectGLJSpread();
  198. projectGLJSpread.successCallback = successTrigger;
  199. projectGLJSheet = projectGLJSpread.init();
  200. // 绑定单击事件
  201. let lastRow = 0;
  202. projectGLJSheet.bind(GC.Spread.Sheets.Events.CellClick, function (element, info) {
  203. let currentRow = info.row;
  204. if (currentRow === undefined || currentRow === lastRow) {
  205. return;
  206. }
  207. if (currentTag !== 'mix-ratio' && currentTag !== 'machine') {
  208. return;
  209. }
  210. let spread = currentTag === 'mix-ratio' ? mixRatioSpread : machineSpread;
  211. if (spread === null) {
  212. return;
  213. }
  214. let projectGLJId = projectGLJSheet.getActiveDataByField('id');
  215. spread.getRatioData(projectGLJId);
  216. lastRow = currentRow;
  217. });
  218. // 切换tab触发refresh
  219. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  220. currentTag = $(e.target).data('name');
  221. if (currentTag === 'ration') {
  222. projectGLJSheet.filterData('unit_price.type', []);
  223. }
  224. });
  225. }
  226. /**
  227. * 单价文件相关初始化
  228. *
  229. * @param {String} name
  230. * @param {Array} data
  231. * @return {void}
  232. */
  233. function unitPriceFileInit(name, data) {
  234. $("#used-name").text(name);
  235. let usedCount = data.length <= 0 ? 1 : data.length;
  236. $("#used-count").text(usedCount);
  237. $('#pop-dj').popover({
  238. placement:"bottom",
  239. html:true,
  240. trigger:"hover | focus",
  241. content: data.join('<br>')
  242. }
  243. );
  244. }
  245. /**
  246. * 成功事件
  247. *
  248. * @param {string} field
  249. * @param {object} info
  250. * @return {void}
  251. */
  252. function successTrigger(field, info) {
  253. switch (field) {
  254. case 'unit_price.market_price':
  255. // 计算价格
  256. projectGLJSpread.priceCalculate(info);
  257. // 触发websocket通知
  258. socket.emit('dataNotify', JSON.stringify(info));
  259. break;
  260. }
  261. }