|
@@ -51,7 +51,7 @@ function calcOneBQJC(xmj) {
|
|
|
function getPasteHint (str, row = '') {
|
|
|
let returnObj = str;
|
|
|
if (row) {
|
|
|
- returnObj.msg = '清单第' + (row+1) + '行' + str.msg;
|
|
|
+ returnObj.msg = '清单第' + (row+1) + '行' + (str.msg ? str.msg : str);
|
|
|
}
|
|
|
return returnObj;
|
|
|
}
|
|
@@ -226,10 +226,11 @@ $(document).ready(() => {
|
|
|
const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
|
|
|
const materialSpreadSetting = {
|
|
|
cols: [
|
|
|
- {title: '清单工料含量|编号', colSpan: '4|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
|
|
|
+ {title: '清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
|
|
|
{title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
|
|
|
{title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
|
|
|
- {title: '|数量 �', colSpan: '1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 120, type: 'Number', readOnly: 'readOnly.isEdit'},
|
|
|
+ {title: '|计算式', colSpan: '|1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
|
|
|
+ {title: '|数量 �', colSpan: '1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
|
|
|
],
|
|
|
emptyRows: 0,
|
|
|
headRows: 2,
|
|
@@ -282,7 +283,7 @@ $(document).ready(() => {
|
|
|
loadMaterialData(0, 0);
|
|
|
const sheet = materialSpread.getActiveSheet();
|
|
|
sheet.suspendPaint();
|
|
|
- sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
|
|
|
+ sheet.setCellType(1, 4, new TipCellType(), spreadNS.SheetArea.colHeader);
|
|
|
sheet.resumePaint();
|
|
|
// 不参与调差数据值变灰
|
|
|
function checkNotJoinMaterialData() {
|
|
@@ -520,30 +521,56 @@ $(document).ready(() => {
|
|
|
deletePress: function (sheet) {
|
|
|
return;
|
|
|
},
|
|
|
+ editStarting: function (e, info) {
|
|
|
+ const col = info.sheet.zh_setting.cols[info.col];
|
|
|
+ const select = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
+ if (col.field === 'quantity') {
|
|
|
+ if (select.expr && select.expr !== '') {
|
|
|
+ info.sheet.getCell(info.row, info.col).text(select.expr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
editEnded: function (e, info) {
|
|
|
if (info.sheet.zh_setting) {
|
|
|
const select = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
const col = info.sheet.zh_setting.cols[info.col];
|
|
|
// 未改变值则不提交
|
|
|
// const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
|
|
|
- const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
|
|
|
- const orgValue = select[col.field];
|
|
|
+ // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
|
|
|
+ // let orgValue = select[col.field];
|
|
|
+ const validText = info.editingText ? info.editingText.replace('\n', '') : null;
|
|
|
+ let orgValue;
|
|
|
+ if (col.field === 'quantity') {
|
|
|
+ orgValue = validText && validText !== ''
|
|
|
+ ? _.toNumber(validText) ? select.quantity : select.expr
|
|
|
+ : (select.expr && select.expr !== '') ? select.expr : select.quantity;
|
|
|
+ } else {
|
|
|
+ orgValue = select[col.field];
|
|
|
+ }
|
|
|
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
|
|
|
SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
return;
|
|
|
}
|
|
|
- if (col.field === 'quantity') {
|
|
|
- if (isNaN(validText)) {
|
|
|
- toastr.error('不能输入其它非数字类型字符');
|
|
|
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
- return;
|
|
|
- }
|
|
|
- const num = parseFloat(validText);
|
|
|
- if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
|
|
|
- toastr.error('请输入大于0并且小于6位小数的浮点数');
|
|
|
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
- return;
|
|
|
- }
|
|
|
+ const exprQuantity = {
|
|
|
+ expr: '',
|
|
|
+ quantity: 0,
|
|
|
+ };
|
|
|
+ const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
|
|
|
+ if (!valid) {
|
|
|
+ toastr.error(msg);
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (isNaN(exprQuantity.quantity)) {
|
|
|
+ toastr.error('不能输入其它非数字类型字符');
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const num = parseFloat(exprQuantity.quantity);
|
|
|
+ if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
|
|
|
+ toastr.error('数量值必须大于0并且小于6位小数的浮点数');
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ return;
|
|
|
}
|
|
|
// 更新至服务器
|
|
|
const ledgerSheet = ledgerSpread.getActiveSheet();
|
|
@@ -559,8 +586,8 @@ $(document).ready(() => {
|
|
|
};
|
|
|
datas.push(data);
|
|
|
}
|
|
|
- console.log(validText, datas, select.mb_id);
|
|
|
- postData(window.location.pathname + '/save', { type:'updates', updateData: { xmjs: datas, quantity: validText, mb_id: select.mb_id } }, function (result) {
|
|
|
+ console.log(exprQuantity, datas, select.mb_id);
|
|
|
+ postData(window.location.pathname + '/save', { type:'updates', updateData: { xmjs: datas, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id } }, function (result) {
|
|
|
materialListData = result;
|
|
|
calculateJiaCha(gclGatherData);
|
|
|
// const index = gclGatherData.indexOf(ledgerSelect);
|
|
@@ -604,7 +631,7 @@ $(document).ready(() => {
|
|
|
SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
|
|
|
return;
|
|
|
}
|
|
|
- if (sortData.length > 0 && range.col + range.colCount > 4) {
|
|
|
+ if (sortData.length > 0 && range.col + range.colCount > 5) {
|
|
|
toastMessageUniq(hint.cellError);
|
|
|
SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
|
|
|
SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
|
|
@@ -622,8 +649,9 @@ $(document).ready(() => {
|
|
|
const colSetting = info.sheet.zh_setting.cols[curCol];
|
|
|
if (!colSetting) continue;
|
|
|
|
|
|
- let validText = info.sheet.getText(curRow, curCol);
|
|
|
- validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
|
|
|
+ // let validText = info.sheet.getText(curRow, curCol);
|
|
|
+ // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
|
|
|
+ const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
|
|
|
const orgValue = sortData[curRow][colSetting.field];
|
|
|
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
|
|
|
sameCol++;
|
|
@@ -632,20 +660,30 @@ $(document).ready(() => {
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
- if (colSetting.field === 'quantity') {
|
|
|
- if (isNaN(validText)) {
|
|
|
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
|
|
|
- bPaste = false;
|
|
|
- continue;
|
|
|
- }
|
|
|
- const num = parseFloat(validText);
|
|
|
- if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
|
|
|
- toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
|
|
|
- bPaste = false;
|
|
|
- continue;
|
|
|
- }
|
|
|
+ const exprQuantity = {
|
|
|
+ expr: '',
|
|
|
+ quantity: 0,
|
|
|
+ };
|
|
|
+ const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
|
|
|
+ if (!valid) {
|
|
|
+ toastMessageUniq(getPasteHint(msg, hintRow));
|
|
|
+ bPaste = false;
|
|
|
+ continue;
|
|
|
}
|
|
|
- materialData[colSetting.field] = validText;
|
|
|
+ if (isNaN(exprQuantity.quantity)) {
|
|
|
+ toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
|
|
|
+ bPaste = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ const num = parseFloat(exprQuantity.quantity);
|
|
|
+ if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
|
|
|
+ toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
|
|
|
+ bPaste = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // materialData[colSetting.field] = validText;
|
|
|
+ materialData.expr = exprQuantity.expr;
|
|
|
+ materialData.quantity = exprQuantity.quantity;
|
|
|
}
|
|
|
if (bPaste) {
|
|
|
data.push(materialData);
|
|
@@ -697,7 +735,130 @@ $(document).ready(() => {
|
|
|
// SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
|
|
|
// });
|
|
|
},
|
|
|
+ _checkExprValid(expr) {
|
|
|
+ if (!expr) return [true, null];
|
|
|
+ const param = [];
|
|
|
+ let num = '', base = '';
|
|
|
+ for (let i = 0, iLen = expr.length; i < iLen; i++) {
|
|
|
+ if (/^[\d\.%]+/.test(expr[i])) {
|
|
|
+ if (base !== '') {
|
|
|
+ param.push({type: 'base', value: base});
|
|
|
+ base = '';
|
|
|
+ }
|
|
|
+ num = num + expr[i];
|
|
|
+ } else if (expr[i] === '(') {
|
|
|
+ if (num !== '') {
|
|
|
+ param.push({type: 'num', value: num});
|
|
|
+ num = '';
|
|
|
+ }
|
|
|
+ if (base !== '') {
|
|
|
+ param.push({type: 'base', value: base});
|
|
|
+ base = '';
|
|
|
+ }
|
|
|
+ param.push({type: 'left', value: '('});
|
|
|
+ } else if (expr[i] === ')') {
|
|
|
+ if (num !== '') {
|
|
|
+ param.push({type: 'num', value: num});
|
|
|
+ num = '';
|
|
|
+ }
|
|
|
+ if (base !== '') {
|
|
|
+ param.push({type: 'base', value: base});
|
|
|
+ base = '';
|
|
|
+ }
|
|
|
+ param.push({type: 'right', value: ')'});
|
|
|
+ } else if (/^[\+\-*\/]/.test(expr[i])) {
|
|
|
+ if (num !== '') {
|
|
|
+ param.push({type: 'num', value: num});
|
|
|
+ num = '';
|
|
|
+ }
|
|
|
+ if (base !== '') {
|
|
|
+ param.push({type: 'base', value: base});
|
|
|
+ base = '';
|
|
|
+ }
|
|
|
+ param.push({type: 'calc', value: expr[i]});
|
|
|
+ } else {
|
|
|
+ return [false, '输入的表达式含有非法字符: ' + expr[i]];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (num !== '') {
|
|
|
+ param.push({type: 'num', value: num});
|
|
|
+ num = '';
|
|
|
+ }
|
|
|
+ if (base !== '') {
|
|
|
+ param.push({type: 'base', value: base});
|
|
|
+ base = '';
|
|
|
+ }
|
|
|
+ if (param.length === 0) return true;
|
|
|
+ if (param.length > 1) {
|
|
|
+ if (param[0].value === '-') {
|
|
|
+ param[1].value = '-' + param[1];
|
|
|
+ }
|
|
|
+ param.unshift();
|
|
|
+ }
|
|
|
+ const iLen = param.length;
|
|
|
+ let iLeftCount = 0, iRightCount = 0;
|
|
|
+ for (const [i, p] of param.entries()) {
|
|
|
+ if (p.type === 'calc') {
|
|
|
+ if (i === 0 || i === iLen - 1)
|
|
|
+ return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
|
|
|
+ }
|
|
|
+ if (p.type === 'num') {
|
|
|
+ num = p.value.replace('%', '');
|
|
|
+ if (p.value.length - num.length > 1)
|
|
|
+ return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
|
|
|
+ num = _.toNumber(num);
|
|
|
+ if (num === undefined || num === null || _.isNaN(num))
|
|
|
+ return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
|
|
|
+ if (i > 0) {
|
|
|
+ if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
|
|
|
+ return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
|
|
|
+ } else if (param[i - 1].value === '/' && num === 0) {
|
|
|
+ return [false, '输入的表达式非法:请勿除0'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (p.type === 'base') {
|
|
|
+ if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
|
|
|
+ return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
|
|
|
+ }
|
|
|
+ if (p.type === 'left') {
|
|
|
+ iLeftCount += 1;
|
|
|
+ if (i !== 0 && param[i-1].type !== 'calc')
|
|
|
+ return [false, '输入的表达式非法:(前应有运算符'];
|
|
|
+ }
|
|
|
+ if (p.type === 'right') {
|
|
|
+ iRightCount += 1;
|
|
|
+ if (i !== iLen - 1 && param[i+1].type !== 'calc')
|
|
|
+ return [false, '输入的表达式非法:)后应有运算符'];
|
|
|
+ if (iRightCount > iLeftCount)
|
|
|
+ return [false, '输入的表达式非法:")"前无对应的"("'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iLeftCount > iRightCount)
|
|
|
+ return [false, '输入的表达式非法:"("后无对应的")"'];
|
|
|
+ return [true, ''];
|
|
|
+ },
|
|
|
+ _checkExpr: function (text, data) {
|
|
|
+ if (text) {
|
|
|
+ const num = _.toNumber(text);
|
|
|
+ if (num) {
|
|
|
+ data.quantity = num;
|
|
|
+ data.expr = '';
|
|
|
+ } else {
|
|
|
+ const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
|
|
|
+ const [valid, msg] = this._checkExprValid(expr);
|
|
|
+ if (!valid) return [valid, msg];
|
|
|
+ data.expr = expr;
|
|
|
+ data.quantity = eval(expr);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ data.quantity = 0;
|
|
|
+ data.expr = '';
|
|
|
+ }
|
|
|
+ return [true, ''];
|
|
|
+ },
|
|
|
};
|
|
|
+ materialSpread.bind(spreadNS.Events.EditStarting, materialSpreadObj.editStarting);
|
|
|
materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
|
|
|
materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
|
|
|
SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
|