/** * 进度台账相关js * * @author Ellisran * @date 2020/11/6 * @version */ function getTenderId() { return window.location.pathname.split('/')[2]; } $(function () { autoFlashHeight(); if(schedule && !schedule.mode) { $('#mode').modal('show'); } // 初始化台账 const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]); const treeSetting = { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, fullPath: 'full_path', calcFields: ['total_price'] //treeCacheKey: 'ledger_bills_fold' + '_' + getTenderId(), // markFoldKey: 'bills-fold', // markFoldSubKey: window.location.pathname.split('/')[2], }; treeSetting.calcFun = function (node) { node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2); }; const ledgerTree = createNewPathTree('base', treeSetting); const static_cols = [ {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', readOnly: true, cellType: 'tree'}, {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@', readOnly: true}, {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}, {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'dgn_price', hAlign: 2, width: 60, type: 'Number', readOnly: true}, {title: '总设计|工程量', colSpan: '2|1', rowSpan: '1|1', field: 'dgn_qty1', hAlign: 2, width: 70, type: 'Number', readOnly: true}, {title: '|金额(万元)', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 70, type: 'Number', readOnly: true}, ]; const ledgerSpreadSetting = { emptyRows: 0, headRows: 2, headRowHeight: [25, 25], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', // readOnly: true, localCache: { key: 'ledger-bills', colWidth: true, } }; const monthsCols = []; if(scheduleMonth.length > 0) { for (const sm of scheduleMonth) { const yearmonth = sm.yearmonth.split('-')[0] + '年' + parseInt(sm.yearmonth.split('-')[1]) + '月'; const cols = {title: yearmonth + '|计划工程量', colSpan: '2|1', rowSpan: '1|1', field: sm.yearmonth+'_gcl', hAlign: 2, width: 90, type: 'Number', readOnly: 'readOnly.gcl'}; const cols2 = {title: '|计划金额(万元)', colSpan: '|1', rowSpan: '|1', field: sm.yearmonth+'_tp', hAlign: 2, width: 90, type: 'Number', readOnly: 'readOnly.tp'}; monthsCols.push(cols); monthsCols.push(cols2); } } const spreadHeaderCols = static_cols.concat(monthsCols); ledgerSpreadSetting.cols = spreadHeaderCols; const ledgerCol = { readOnly: { tp: function (data) { let flag = data.is_leaf; if (data.is_leaf) { flag = schedule && schedule.mode === mode.tp; } return !flag; }, gcl: function (data) { let flag = data.is_leaf; if (data.is_leaf) { flag = schedule && schedule.mode === mode.gcl; } return !flag; }, }, }; sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz); if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting); SpreadJsObj.initSpreadSettingEvents(ledgerSpreadSetting, ledgerCol); SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting); SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet()); postData('/tender/' + getTenderId() + '/schedule/ledger/load', {}, function (data) { let treeData = []; for(const sl of selectedLedgerList) { const one = _.find(data, { 'ledger_id' : sl }); treeData.push(one); } treeData = setLeafData(treeData); ledgerTree.loadDatas(treeData); treeCalc.calculateAll(ledgerTree); console.log(ledgerTree); SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, ledgerTree); }, null, true); const ledgerSpreadObj = { refreshTree: function (sheet, data) { SpreadJsObj.massOperationSheet(sheet, function () { const tree = sheet.zh_tree; // 处理删除 if (data.delete) { data.delete.sort(function (x, y) { return y.deleteIndex - x.deleteIndex; }); for (const d of data.delete) { sheet.deleteRows(d.deleteIndex, 1); } } // 处理新增 if (data.create) { const newNodes = data.create; if (newNodes) { newNodes.sort(function (a, b) { return a.index - b.index; }); for (const node of newNodes) { sheet.addRows(node.index, 1); SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1); } } } // 处理更新 if (data.update) { const rows = []; for (const u of data.update) { rows.push(tree.nodes.indexOf(u)); } SpreadJsObj.reLoadRowsData(sheet, rows); } // 处理展开 if (data.expand) { const expanded = []; for (const e of data.expand) { if (expanded.indexOf(e) === -1) { const posterity = tree.getPosterity(e); for (const p of posterity) { sheet.setRowVisible(tree.nodes.indexOf(p), p.visible); expanded.push(p); } } } } }); }, }; // 进度计算方式选择 $('.mode-select').on('click', function () { const _self = $(this); postData(window.location.pathname + '/save', {type: 'mode', postData: $(this).data('mode')}, function (result) { _self.addClass('disabled').attr('disabled', true); _self.parents('.col-6').siblings('.col-6').find('button').removeClass('disabled').removeAttr('disabled'); $('#mode-tips').show(); $('#mode-cancel').show(); $('#mode').modal('hide'); schedule.mode = _self.data('mode'); SpreadJsObj.reLoadSheetData(ledgerSpread.getActiveSheet()); }) }); // 月份添加 $('#add-month').click(function () { const range = $('#month-range').val(); if(range === '') { toastr.error('请选择计划周期时间'); return; } const addMonthList = []; const cycle = range.split(' ~ '); if(cycle.length === 1) { addMonthList.push(cycle[0]); } else { // 多个月份 const back_year = parseInt(cycle[1].split('-')[0]); const back_month = parseInt(cycle[1].split('-')[1]); const front_year = parseInt(cycle[0].split('-')[0]); const front_month = parseInt(cycle[0].split('-')[1]); if(back_year > front_year) { const num = getDistanceMonth(cycle[0], cycle[1]); let j = 1; for (let i = 0; i <= num; i++) { if(front_month + i > 12*j) { j = j + 1; } const m = (front_month + i)%12 === 0 ? 12 : (front_month + i)%12; addMonthList.push((front_year + (j-1)) + '-' + (m < 10 ? '0' + m : m)); } } else if (back_year === front_year) { // 小于1年并没有跨年 for (let i = front_month; i <= back_month; i++) { addMonthList.push(back_year + '-' + (i < 10 ? '0' + i : i)); } } } // 判断是否已添加本月份 if (addMonthList.length > 0) { const hadmonth = []; for (const m of addMonthList) { const one = _.find(scheduleMonth, { yearmonth: m }); console.log(one, m); if (one) { hadmonth.push(m); } } if (hadmonth.length > 0) { let html = ''; for (const hm of hadmonth) { html += `