project_glj.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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 mixRatioMap = {};
  22. // 单价文件相关
  23. let usedUnitPriceInfo = {};
  24. let usedTenderList = [];
  25. let otherFileData = {};
  26. let currentTag = '';
  27. let isChanging = false;
  28. let initPage = false;
  29. $(document).ready(function () {
  30. $('#tab_gongliaoji').on('show.bs.tab', function (e) {
  31. $(e.relatedTarget.hash).removeClass('active');
  32. init();
  33. });
  34. slideResize($("#glj-main"), function () {
  35. projectGLJSpread.sheetObj.spread.refresh();
  36. });
  37. // 单价文件切换弹框
  38. $('#change-dj').on('shown.bs.modal', function () {
  39. // 获取当前建设项数据
  40. let projectName = projectInfoObj.projectInfo.fullFolder !== undefined &&
  41. projectInfoObj.projectInfo.fullFolder.length > 0 ? projectInfoObj.projectInfo.fullFolder[0] : '';
  42. $("#current-project-name").text(projectName);
  43. // 获取切换单价文件相关数据
  44. $.ajax({
  45. url: '/glj/get-project-info',
  46. type: 'post',
  47. data: {project_id: scUrlUtil.GetQueryString('project')},
  48. dataType: 'json',
  49. success: function (response) {
  50. if (response.err === 1) {
  51. alert('数据传输错误!');
  52. return false;
  53. }
  54. let data = response.data;
  55. // 本项目中的单价文件
  56. if (data.self.length > 0) {
  57. let selfFileHtml = '';
  58. for (let tmp of data.self) {
  59. let select = usedUnitPriceInfo === tmp.id ? ' selected="selected"' : '';
  60. selfFileHtml += '<option' + select + ' value="' + tmp.id + '">' + tmp.name + '</option>';
  61. }
  62. $("#self-file").html(selfFileHtml);
  63. }
  64. // 其他建设项目数据
  65. if (data.other.length > 0) {
  66. let otherProjectHtml = '';
  67. let otherFileHtml = '';
  68. for (let tmp of data.other) {
  69. otherProjectHtml += '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  70. otherFileData[tmp.ID] = tmp.unitPriceList;
  71. if (otherFileHtml !== '') {
  72. continue;
  73. }
  74. for (let unitPrice of tmp.unitPriceList) {
  75. otherFileHtml += '<option value="' + unitPrice.id + '">' + unitPrice.name + '</option>';
  76. }
  77. }
  78. $("#other-project").html(otherProjectHtml);
  79. $("#other-file").html(otherFileHtml);
  80. }
  81. }
  82. });
  83. });
  84. /* // 单价文件另存为弹框
  85. $("#file-save-as-dialog").on('shown.bs.modal', function () {
  86. // 获取当前建设项数据
  87. $("#save-as-name").val(usedUnitPriceInfo.name + '(复件)');
  88. });*/
  89. // 单价文件切换确认
  90. /*$("#change-file-confirm").click(function () {
  91. if (isChanging) {
  92. return false;
  93. }
  94. let type = $("input[name='change-type']:checked").val();
  95. type = parseInt(type);
  96. let changeUnitPriceId = 0;
  97. if (type === 0) {
  98. // 从本项目中选择
  99. changeUnitPriceId = $("#self-file").val();
  100. } else {
  101. // 从其他项目中复制
  102. changeUnitPriceId = $("#other-file").val();
  103. }
  104. $('#change-dj').modal("hide");
  105. $.bootstrapLoading.start();
  106. $.ajax({
  107. url: '/glj/change-file',
  108. type: 'post',
  109. data: {project_id: scUrlUtil.GetQueryString('project'), change_id: changeUnitPriceId, type: type},
  110. error: function () {
  111. isChanging = false;
  112. $.bootstrapLoading.end();
  113. },
  114. beforeSend: function () {
  115. isChanging = true;
  116. },
  117. success: function (response) {
  118. isChanging = false;
  119. if (response.err === 1) {
  120. let msg = response.msg !== undefined ? response.msg : '未知错误';
  121. alert(msg);
  122. $.bootstrapLoading.end();
  123. return false;
  124. }
  125. projectObj.project.projectGLJ.loadData(function () {
  126. let projectGLJ = projectObj.project.projectGLJ;
  127. projectGLJ.loadCacheData();
  128. unitPriceFileInit();
  129. gljOprObj.refreshView();
  130. projectObj.project.calcProgram.calcAllNodesAndSave();
  131. if(socketObject.roomInfo){
  132. let data ={
  133. projectID:projectObj.project.ID(),
  134. oldRoom:socketObject.roomInfo.unitFile,
  135. newRoom:socketObject.getUnitFileRoomID(),
  136. name:'unitFile'
  137. }
  138. socket.emit('changeNewRoom',data);
  139. socketObject.roomInfo.unitFile = socketObject.getUnitFileRoomID();
  140. }
  141. $.bootstrapLoading.end();
  142. });
  143. }
  144. });
  145. });*/
  146. /* // 是否主动更改数据
  147. $("#message").on('click', '#load-data', function () {
  148. $("#message").html('正在加载...');
  149. // 重新加载数据到缓存
  150. projectObj.project.projectGLJ.loadData(function () {
  151. projectObj.project.projectGLJ.loadCacheData();
  152. $("#notify").slideUp('fast');
  153. });
  154. });*/
  155. /*$('#pop-dj').popover({
  156. placement: "bottom",
  157. html: true,
  158. trigger: "hover | focus",
  159. content: getUsedTenderInfo
  160. }
  161. );*/
  162. });
  163. /**
  164. * 初始化数据
  165. *
  166. * @return {void|boolean}
  167. */
  168. function init() {
  169. projectObj.project.projectGLJ.loadData(function (data) {
  170. if (initPage==false||jsonData.length <= 0) {
  171. // 赋值
  172. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  173. jsonData = filterProjectGLJ(jsonData);
  174. jsonData = sortProjectGLJ(jsonData);
  175. mixRatioConnectData = data.mixRatioConnectData !== undefined ? data.mixRatioConnectData : mixRatioConnectData;
  176. mixRatioMap = data.mixRatioMap !== undefined ? data.mixRatioMap : mixRatioMap;
  177. // host = data.constData.hostname !== undefined ? data.constData.hostname : '';
  178. materialIdList = data.constData.materialIdList !== undefined ? data.constData.materialIdList : materialIdList;
  179. //roomId = data.constData.roomId !== undefined ? data.constData.roomId : roomId;
  180. canNotChangeTypeId = data.constData.ownCompositionTypes !== undefined ?
  181. data.constData.ownCompositionTypes : canNotChangeTypeId;
  182. GLJTypeConst = data.constData.GLJTypeConst !== undefined ? JSON.parse(data.constData.GLJTypeConst) : GLJTypeConst;
  183. // 连接socket服务器 这里改成和费率的socket统一管理了,需要在主页面打开后就连接
  184. // socketInit();
  185. unitPriceFileInit();
  186. setTimeout(spreadInit, 1);
  187. initPage=true;
  188. } else {
  189. projectObj.project.projectGLJ.loadCacheData();
  190. }
  191. });
  192. }
  193. /**
  194. * spreadjs相关初始化
  195. *
  196. * @return {void}
  197. */
  198. function spreadInit() {
  199. if(projectGLJSheet&&projectGLJSpread){
  200. projectGLJSheet.spread.destroy();
  201. }
  202. projectGLJSpread = new ProjectGLJSpread();
  203. projectGLJSpread.successCallback = successTrigger;
  204. projectGLJSheet = projectGLJSpread.init();
  205. // 绑定单击事件
  206. let lastRow = 0;
  207. projectGLJSheet.bind(GC.Spread.Sheets.Events.CellClick, function (element, info) {
  208. let currentRow = info.row;
  209. if (currentRow === undefined || currentRow === lastRow) {
  210. return;
  211. }
  212. if (currentTag !== 'mix-ratio' && currentTag !== 'machine') {
  213. return;
  214. }
  215. let spread = currentTag === 'mix-ratio' ? mixRatioSpread : machineSpread;
  216. if (spread === null) {
  217. return;
  218. }
  219. let projectGLJId = projectGLJSheet.getActiveDataByField('id');
  220. spread.getRatioData(projectGLJId);
  221. lastRow = currentRow;
  222. });
  223. if(currentTag){
  224. if (currentTag === 'ration') {
  225. projectGLJSheet.filterData('unit_price.type', []);
  226. }
  227. if(currentTag === "mix-ratio"){
  228. projectGLJSheet.filterData('unit_price.type', [GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR, GLJTypeConst.MIX_RATIO,GLJTypeConst.MAIN_MATERIAL]);
  229. }
  230. if(currentTag === "machine"){
  231. projectGLJSheet.filterData('unit_price.type', [GLJTypeConst.GENERAL_MACHINE]);
  232. }
  233. }
  234. /* // 切换tab触发refresh
  235. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  236. if($(e.target).data('name')==undefined){
  237. return;
  238. }
  239. currentTag = $(e.target).data('name');
  240. if (currentTag === 'ration') {
  241. projectGLJSheet.filterData('unit_price.type', []);
  242. }
  243. });*/
  244. loadSize("glj-main", function () {
  245. projectGLJSpread.sheetObj.spread.refresh();
  246. });
  247. }
  248. /**
  249. * 单价文件相关初始化
  250. *
  251. * @param {String} name
  252. * @param {Array} data
  253. * @return {void}
  254. */
  255. function unitPriceFileInit() {
  256. let projectGLJ = projectObj.project.projectGLJ;
  257. let data = projectGLJ.datas;
  258. usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
  259. usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?
  260. data.constData.usedUnitPriceInfo : {};
  261. $("#used-name").text(usedUnitPriceInfo.name);
  262. let usedCount = usedTenderList.length <= 0 ? 1 : usedTenderList.length;
  263. $("#used-count").text(usedCount);
  264. }
  265. function getUsedTenderInfo() {
  266. return usedTenderList.join("<br>");
  267. }
  268. /**
  269. * 成功事件
  270. *
  271. * @param {string} field
  272. * @param {object} info
  273. * @return {void}
  274. */
  275. function successTrigger(field, info,id) {
  276. let updateData = {};
  277. switch (field) {
  278. case 'unit_price.market_price':
  279. // 计算价格
  280. updateData = projectGLJSpread.priceCalculate(info);
  281. // 触发websocket通知
  282. socket.emit('dataNotify', JSON.stringify(info));
  283. break;
  284. case 'supply':
  285. // 供货方式更改成功后
  286. projectGLJSpread.changeSupplyType(info);
  287. break;
  288. case 'is_evaluate':
  289. projectObj.project.projectGLJ.changeIsEvaluate(id);
  290. break;
  291. }
  292. // 重新加载数据到缓存
  293. projectObj.project.projectGLJ.loadData(function () {
  294. projectObj.project.projectGLJ.loadCacheData();
  295. $.bootstrapLoading.end();
  296. });
  297. // 更新定额工料机
  298. gljOprObj.refreshView();
  299. }
  300. //过滤消耗量为0的项目工料机
  301. function filterProjectGLJ(jsonData) {
  302. if (jsonData.length > 0) {
  303. // 不显示消耗量为0的数据
  304. jsonData= _.filter(jsonData,function (item) {
  305. return item.quantity !== 0 && item.quantity !== '0'
  306. })
  307. }
  308. return jsonData;
  309. }
  310. function sortProjectGLJ(jsonData) {
  311. if (jsonData.length > 0) {
  312. jsonData = _.sortByAll(jsonData, [function (item) {
  313. return item.unit_price.type + "";
  314. }, 'code']);
  315. }
  316. return jsonData
  317. }