123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- /**
- * 工料机汇总相关
- *
- * @author CaiAoLin
- * @date 2017/6/15
- * @version
- */
- let projectGLJSpread = null;
- let projectGLJSheet = null;
- // websocket所需
- let host = '';
- let socket = null;
- let roomId = 0;
- // 判定常量
- let materialIdList = [];
- let canNotChangeTypeId = [];
- let GLJTypeConst = [];
- // spreadjs载入数据所需
- let jsonData = [];
- let mixRatioConnectData = [];
- let currentTag = '';
- let isChanging = false;
- $(document).ready(function () {
- $('#tab_gongliaoji').on('shown.bs.tab', function (e) {
- init();
- });
- // 是否主动更改数据
- // $("#message").on('click', '#load-data', function() {
- // $("#notify").slideUp('fast');
- // if (changeInfo.length > 0) {
- // for (let index in changeInfo) {
- // let cell = gljSheet.getCell(changeInfo[index].row, changeInfo[index].col, GC.Spread.Sheets.SheetArea.viewport);
- // cell.value(changeInfo[index].newValue);
- // }
- // }
- // changeInfo = [];
- // });
- });
- /**
- * 初始化数据
- *
- * @return {void}
- */
- function init() {
- // 加载工料机数据
- $.ajax({
- url: '/glj/getData',
- type: 'post',
- dataType: 'json',
- data: {project_id: scUrlUtil.GetQueryString('project')},
- error: function() {
- // alert('数据传输错误');
- },
- beforeSend: function() {
- },
- success: function(response) {
- if (response.err === 1) {
- let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取工料机数据失败!';
- alert(msg);
- return false;
- }
- let data = response.data;
- // 赋值
- jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
- mixRatioConnectData = data.mixRatioConnectData !== undefined ? data.mixRatioConnectData : mixRatioConnectData;
- host = data.constData.hostname !== undefined ? data.constData.hostname : '';
- materialIdList = data.constData.materialIdList !== undefined ? data.constData.materialIdList : materialIdList;
- roomId = data.constData.roomId !== undefined ? data.constData.roomId : roomId;
- canNotChangeTypeId = data.constData.ownCompositionTypes !== undefined ?
- data.constData.ownCompositionTypes : canNotChangeTypeId;
- GLJTypeConst = data.constData.GLJTypeConst !== undefined ? JSON.parse(data.constData.GLJTypeConst) : GLJTypeConst;
- let usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
- let usedUnitFileName = data.constData.usedUnitPriceName !== undefined ?
- data.constData.usedUnitPriceName : '';
- // 存入缓存
- projectObj.project.projectGLJ.datas = jsonData;
- console.log(projectObj.project);
- spreadInit();
- unitPriceFileInit(usedUnitFileName, usedTenderList);
- }
- });
- }
- /**
- * spreadjs相关初始化
- *
- * @return {void}
- */
- function spreadInit() {
- projectGLJSpread = new ProjectGLJSpread();
- projectGLJSpread.successCallback = successTrigger;
- projectGLJSheet = projectGLJSpread.init();
- // 绑定单击事件
- let lastRow = 0;
- projectGLJSheet.bind(GC.Spread.Sheets.Events.CellClick, function (element, info) {
- let currentRow = info.row;
- if (currentRow === undefined || currentRow === lastRow) {
- return;
- }
- if (currentTag !== 'mix-ratio' && currentTag !== 'machine') {
- return;
- }
- let spread = currentTag === 'mix-ratio' ? mixRatioSpread : machineSpread;
- if (spread === null) {
- return;
- }
- let projectGLJId = projectGLJSheet.getActiveDataByField('id');
- spread.getRatioData(projectGLJId);
- lastRow = currentRow;
- });
- // 切换tab触发refresh
- $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
- currentTag = $(e.target).data('name');
- if (currentTag === 'ration') {
- projectGLJSheet.filterData('unit_price.type', []);
- }
- });
- }
- /**
- * 单价文件相关初始化
- *
- * @param {String} name
- * @param {Array} data
- * @return {void}
- */
- function unitPriceFileInit(name, data) {
- $("#used-name").text(name);
- let usedCount = data.length <= 0 ? 1 : data.length;
- $("#used-count").text(usedCount);
- $('#pop-dj').popover({
- placement:"bottom",
- html:true,
- trigger:"hover | focus",
- content: data.join('<br>')
- }
- );
- }
- /**
- * 成功事件
- *
- * @param {string} field
- * @param {object} info
- * @return {void}
- */
- function successTrigger(field, info) {
- switch (field) {
- case 'unit_price.market_price':
- // 计算价格
- projectGLJSpread.priceCalculate(info);
- // 触发websocket通知
- socket.emit('dataNotify', JSON.stringify(info));
- break;
- }
- }
|