|
@@ -962,7 +962,7 @@ $(document).ready(() => {
|
|
|
}
|
|
|
},
|
|
|
measureAllPosInNode(node, ratio = 1) {
|
|
|
- const posterity = stageTree.getPosterity(node)
|
|
|
+ const posterity = stageTree.getPosterity(node);
|
|
|
const data = {updateType: 'update', updateData: []};
|
|
|
for (const p of posterity) {
|
|
|
if (p.children && p.children.length > 0) continue;
|
|
@@ -1089,6 +1089,46 @@ $(document).ready(() => {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
+ measureByBatch: function (posNames, ratio, apply2sibling) {
|
|
|
+ if (posNames.length <= 0) return;
|
|
|
+ if (ratio <= 0) return;
|
|
|
+
|
|
|
+ const sheet = slSpread.getActiveSheet();
|
|
|
+ const node = SpreadJsObj.getSelectObject(sheet);
|
|
|
+ const parent = stageTree.getParent(node);
|
|
|
+ const nodes = apply2sibling === true ? (parent ? parent.children : stageTree.children) : [node];
|
|
|
+ const data = {updateType: 'batchUpdate', updateData: []};
|
|
|
+ for (const node of nodes) {
|
|
|
+ const posRange = stagePos.getLedgerPos(node.id);
|
|
|
+ if (!posRange || posRange <= 0) continue;
|
|
|
+
|
|
|
+ for (const p of posRange) {
|
|
|
+ if (posNames.indexOf(p.name) < 0) continue;
|
|
|
+ data.updateData.push({
|
|
|
+ pid: p.id, lid: p.lid,
|
|
|
+ contract_qty: ZhCalc.mul(p.quantity, ratio)
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ postData(window.location.pathname + '/update', {pos: data}, function (result) {
|
|
|
+ if (result.pos) {
|
|
|
+ stagePos.updateDatas(result.pos.pos);
|
|
|
+ stagePos.loadCurStageData(result.pos.curStageData);
|
|
|
+ }
|
|
|
+ const nodes = stageTree.loadPostStageData(result.ledger);
|
|
|
+ stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
|
|
|
+ stagePosSpreadObj.loadCurPosData();
|
|
|
+ if (detail) {
|
|
|
+ detail.loadStagePosUpdateData(result);
|
|
|
+ } else {
|
|
|
+ stageIm.loadUpdatePosData(result);
|
|
|
+ }
|
|
|
+ $('#calc-by-ratio').modal('hide');
|
|
|
+ }, function () {
|
|
|
+ stagePosSpreadObj.loadCurPosData();
|
|
|
+ $('#calc-by-ratio').modal('hide');
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
|
|
|
slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
|
|
@@ -1673,63 +1713,89 @@ $(document).ready(() => {
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
- if (!checkTzMeasureType()) {
|
|
|
- const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
|
|
|
- $.contextMenu({
|
|
|
- selector: '#stage-pos',
|
|
|
- build: function ($trigger, e) {
|
|
|
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
|
|
|
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
|
|
|
- },
|
|
|
- items: {
|
|
|
- 'del': {
|
|
|
- name: '删除',
|
|
|
- icon: 'fa-remove',
|
|
|
- disabled: function (key, opt) {
|
|
|
- const sheet = spSpread.getActiveSheet();
|
|
|
- if (sheet.zh_data && !readOnly) {
|
|
|
- const selection = sheet.getSelections();
|
|
|
- if (selection && selection[0]) {
|
|
|
- let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
|
|
|
- for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
|
|
|
- const posData = sheet.zh_data[selection[0].row + iRow];
|
|
|
- if (posData) {
|
|
|
- if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
|
|
|
- valid = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- } else {
|
|
|
+
|
|
|
+ const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
|
|
|
+ $.contextMenu({
|
|
|
+ selector: '#stage-pos',
|
|
|
+ build: function ($trigger, e) {
|
|
|
+ const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
|
|
|
+ return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
|
|
|
+ },
|
|
|
+ items: {
|
|
|
+ 'del': {
|
|
|
+ name: '删除',
|
|
|
+ icon: 'fa-remove',
|
|
|
+ visible: function (key, opt) {
|
|
|
+ return !checkTzMeasureType();
|
|
|
+ },
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ const sheet = spSpread.getActiveSheet();
|
|
|
+ if (sheet.zh_data && !readOnly) {
|
|
|
+ const selection = sheet.getSelections();
|
|
|
+ if (selection && selection[0]) {
|
|
|
+ let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
|
|
|
+ for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
|
|
|
+ const posData = sheet.zh_data[selection[0].row + iRow];
|
|
|
+ if (posData) {
|
|
|
+ if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
|
|
|
valid = true;
|
|
|
break;
|
|
|
}
|
|
|
+ } else {
|
|
|
+ valid = true;
|
|
|
+ break;
|
|
|
}
|
|
|
- return valid;
|
|
|
- } else {
|
|
|
- return true;
|
|
|
}
|
|
|
+ return valid;
|
|
|
} else {
|
|
|
return true;
|
|
|
}
|
|
|
- },
|
|
|
- callback: function (key, opt) {
|
|
|
- stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
}
|
|
|
},
|
|
|
- 'merge-peg': {
|
|
|
- name: '合并起讫桩号',
|
|
|
- disabled: function (key, opt) {
|
|
|
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
|
|
|
- return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
|
|
|
- },
|
|
|
- callback: function (key, opt) {
|
|
|
- mergePeg.show();
|
|
|
- }
|
|
|
+ callback: function (key, opt) {
|
|
|
+ stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 'merge-peg': {
|
|
|
+ name: '合并起讫桩号',
|
|
|
+ visible: function (key, opt) {
|
|
|
+ return !checkTzMeasureType();
|
|
|
+ },
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
|
|
|
+ return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
|
|
|
+ },
|
|
|
+ callback: function (key, opt) {
|
|
|
+ mergePeg.show();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 'calcByRatio': {
|
|
|
+ name: '按比例计量',
|
|
|
+ visible: function (key, opt) {
|
|
|
+ const data = spSpread.getActiveSheet().zh_data;
|
|
|
+ return data && data.length > 0;
|
|
|
+ },
|
|
|
+ callback: function (key, opt) {
|
|
|
+ $('#cbr-ratio').val('');
|
|
|
+ $('#apply2sibling')[0].checked = false;
|
|
|
+ $('#cbr-check-all')[0].checked = false;
|
|
|
+ const html = [];
|
|
|
+ for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
|
|
|
+ html.push('<tr>');
|
|
|
+ html.push('<td>', i, '</td>');
|
|
|
+ html.push('<td>', p.name, '</td>');
|
|
|
+ html.push('<td>', p.quantity, '</td>');
|
|
|
+ html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
|
|
|
+ html.push('</tr>');
|
|
|
+ }
|
|
|
+ $('#cbr-pos-list').html(html.join(''));
|
|
|
+ $('#calc-by-ratio').modal('show');
|
|
|
}
|
|
|
}
|
|
|
- })
|
|
|
- } else {
|
|
|
- SpreadJsObj.forbiddenSpreadContextMenu('#stage-pos', spSpread);
|
|
|
- }
|
|
|
+ }
|
|
|
+ });
|
|
|
$.subMenu({
|
|
|
menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
|
|
|
toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
|
|
@@ -3622,4 +3688,33 @@ $(document).ready(() => {
|
|
|
|
|
|
SpreadExcelObj.exportSimpleXlsxSheet(setting, data, $('.sidebar-title').attr('data-original-title') + "计量台账.xlsx");
|
|
|
});
|
|
|
+
|
|
|
+ $('#cbr-check-all').click(function () {
|
|
|
+ if (this.checked) {
|
|
|
+ $('input', '#cbr-pos-list').attr('checked', 'checked');
|
|
|
+ } else {
|
|
|
+ $('input', '#cbr-pos-list').removeAttr('checked');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#cbr-ok').click(() => {
|
|
|
+ const ratio = parseInt($('#cbr-ratio').val());
|
|
|
+ if (!ratio) {
|
|
|
+ toastr.warning('请输入计量比例');
|
|
|
+ return;
|
|
|
+ } else if (ratio < 1) {
|
|
|
+ toastr.warning('计量比例不可小于1');
|
|
|
+ return;
|
|
|
+ } else if (ratio > 100) {
|
|
|
+ toastr.warning('计量比例不可大于100');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const apply2sibling = $('#apply2sibling')[0].checked;
|
|
|
+ const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
|
|
|
+ if (posName.length === 0) {
|
|
|
+ toastr.warning('请勾选需要按计量比例的计量单元');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ stageTreeSpreadObj.measureByBatch(posName, ZhCalc.div(ratio, 100), apply2sibling);
|
|
|
+ })
|
|
|
});
|