|
@@ -16,6 +16,14 @@ const invalidFields = {
|
|
|
posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp'],
|
|
|
posXmj: ['code'],
|
|
|
};
|
|
|
+function getExprInfo (field) {
|
|
|
+ const exprField = [
|
|
|
+ {qty: 'sgfh_qty', expr: 'sgfh_expr'},
|
|
|
+ {qty: 'sjcl_qty', expr: 'sjcl_expr'},
|
|
|
+ {qty: 'qtcl_qty', expr: 'qtcl_expr'},
|
|
|
+ ];
|
|
|
+ return _.find(exprField, {qty: field});
|
|
|
+}
|
|
|
function transExpr(expr) {
|
|
|
return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
|
|
|
}
|
|
@@ -76,7 +84,13 @@ $(document).ready(() => {
|
|
|
if (col && col.type === 'Number') {
|
|
|
const data = SpreadJsObj.getSelectObject(sheet);
|
|
|
if (data) {
|
|
|
- $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
|
|
|
+ const exprInfo = getExprInfo(col.field);
|
|
|
+ if (exprInfo) {
|
|
|
+ $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
|
|
|
+ .attr('field', col.field).attr('org', data[col.field]);
|
|
|
+ } else {
|
|
|
+ $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
|
|
|
+ }
|
|
|
|
|
|
if (col.field.indexOf('dgn') >= 0) {
|
|
|
$('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== ''));
|
|
@@ -126,12 +140,12 @@ $(document).ready(() => {
|
|
|
}
|
|
|
};
|
|
|
const invalidAll = function () {
|
|
|
- setObjEnable($('a[type=add]'), false);
|
|
|
- setObjEnable($('a[type=delete]'), false);
|
|
|
- setObjEnable($('a[type=up-move]'), false);
|
|
|
- setObjEnable($('a[type=down-move]'), false);
|
|
|
- setObjEnable($('a[type=up-level]'), false);
|
|
|
- setObjEnable($('a[type=down-level]'), false);
|
|
|
+ setObjEnable($('a[nam=base-opr][type=add]'), false);
|
|
|
+ setObjEnable($('a[nam=base-opr][type=delete]'), false);
|
|
|
+ setObjEnable($('a[nam=base-opr][type=up-move]'), false);
|
|
|
+ setObjEnable($('a[nam=base-opr][type=down-move]'), false);
|
|
|
+ setObjEnable($('a[nam=base-opr][type=up-level]'), false);
|
|
|
+ setObjEnable($('a[nam=base-opr][type=down-level]'), false);
|
|
|
};
|
|
|
const sel = selection ? selection[0] : sheet.getSelections()[0];
|
|
|
const row = sel ? sel.row : -1;
|
|
@@ -165,20 +179,20 @@ $(document).ready(() => {
|
|
|
const preNode = tree.getPreSiblingNode(first);
|
|
|
const valid = !sheet.zh_setting.readOnly;
|
|
|
|
|
|
- setObjEnable($('a[type=add]'), valid && first && first.level > 1);
|
|
|
- setObjEnable($('a[type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed);
|
|
|
- setObjEnable($('a[type=up-move]'), valid && first && sameParent && first.level > 1 && preNode);
|
|
|
- setObjEnable($('a[type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
|
|
|
+ setObjEnable($('a[nam=base-opr][type=add]'), valid && first && first.level > 1);
|
|
|
+ setObjEnable($('a[nam=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed);
|
|
|
+ setObjEnable($('a[nam=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode);
|
|
|
+ setObjEnable($('a[nam=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
|
|
|
if (isTz) {
|
|
|
const posRange = last ? pos.getLedgerPos(last.id) : [];
|
|
|
- setObjEnable($('a[type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
|
|
|
+ setObjEnable($('a[nam=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
|
|
|
&& first.level > 2 && ((!posRange || posRange.length === 0) || tree.isLastSibling(last)));
|
|
|
const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
|
|
|
- setObjEnable($('a[type=down-level]'), valid && first && sameParent && !nodeUsed
|
|
|
+ setObjEnable($('a[nam=base-opr][type=down-level]'), valid && first && sameParent && !nodeUsed
|
|
|
&& first.level > 1 && preNode && (!preNodePosRange || preNodePosRange.length === 0));
|
|
|
} else {
|
|
|
- setObjEnable($('#up-level'), valid && first && sameParent && first.level > 2 && tree.getParent(first));
|
|
|
- setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode);
|
|
|
+ setObjEnable($('a[nam=base-opr][type=up-level]'), valid && first && sameParent && first.level > 2 && tree.getParent(first));
|
|
|
+ setObjEnable($('a[nam=base-opr][type=down-level]'), valid && first && sameParent && first.level > 1 && preNode);
|
|
|
}
|
|
|
setObjEnable($('#cut'), valid);
|
|
|
setObjEnable($('#paste'), valid);
|
|
@@ -400,6 +414,10 @@ $(document).ready(() => {
|
|
|
} else {
|
|
|
try {
|
|
|
data[col.field] = math.evaluate(transExpr(text));
|
|
|
+ const exprInfo = getExprInfo(col.field);
|
|
|
+ if (exprInfo) {
|
|
|
+ data[exprInfo.expr] = newValue;
|
|
|
+ }
|
|
|
} catch(err) {
|
|
|
toastr.error('输入的表达式非法');
|
|
|
SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
@@ -451,19 +469,30 @@ $(document).ready(() => {
|
|
|
parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
|
|
|
gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
|
|
|
posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
|
|
|
+ sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
|
|
|
};
|
|
|
const datas = [], filterNodes = [];
|
|
|
|
|
|
+ let pid, level, filterRow = 0;
|
|
|
for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
|
|
|
const curRow = info.cellRange.row + iRow;
|
|
|
const node = tree.nodes[curRow];
|
|
|
if (!node) continue;
|
|
|
+ if (!pid) pid = node.ledger_pid;
|
|
|
+ if (!level) level = node.level;
|
|
|
+ if (node.ledger_pid !== pid) {
|
|
|
+ toastMessageUniq(hint.sameParent);
|
|
|
+ filterRow+=1;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (node.level < level) break;
|
|
|
|
|
|
let bPaste = false;
|
|
|
const data = info.sheet.zh_tree.getNodeKeyData(node);
|
|
|
for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
|
|
|
const curCol = info.cellRange.col + iCol;
|
|
|
const colSetting = info.sheet.zh_setting.cols[curCol];
|
|
|
+ const value = trimInvalidChar(pasteData[iRow-filterRow][iCol]);
|
|
|
if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
|
|
|
toastMessageUniq(hint.parent);
|
|
|
continue;
|
|
@@ -491,7 +520,6 @@ $(document).ready(() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const value = trimInvalidChar(pasteData[iRow][iCol]);
|
|
|
if (tree.checkNodeUsed(node, pos) && col.field === 'unit_price') {
|
|
|
toastMessageUniq (hint.usedUp);
|
|
|
continue;
|
|
@@ -503,6 +531,11 @@ $(document).ready(() => {
|
|
|
} else {
|
|
|
try {
|
|
|
data[colSetting.field] = math.evaluate(transExpr(value));
|
|
|
+ const exprInfo = getExprInfo(colSetting.field);
|
|
|
+ if (exprInfo) {
|
|
|
+ data[exprInfo.expr] = value;
|
|
|
+ }
|
|
|
+ bPaste = true;
|
|
|
} catch (err) {
|
|
|
toastMessageUniq(hint.invalidExpr);
|
|
|
continue;
|
|
@@ -636,6 +669,10 @@ $(document).ready(() => {
|
|
|
for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
|
|
|
const col = sheet.zh_setting.cols[iCol];
|
|
|
data[col.field] = null;
|
|
|
+ const exprInfo = getExprInfo(col.field);
|
|
|
+ if (exprInfo) {
|
|
|
+ data[exprInfo.expr] = '';
|
|
|
+ }
|
|
|
}
|
|
|
datas.push(data);
|
|
|
}
|
|
@@ -643,6 +680,7 @@ $(document).ready(() => {
|
|
|
postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
|
|
|
const refreshNode = sheet.zh_tree.loadPostData(result);
|
|
|
billsTreeSpreadObj.refreshTree(sheet, refreshNode);
|
|
|
+ treeOperationObj.loadExprToInput(sheet);
|
|
|
});
|
|
|
}
|
|
|
},
|
|
@@ -736,6 +774,10 @@ $(document).ready(() => {
|
|
|
}
|
|
|
const colSetting = sheet.zh_setting.cols[iCol];
|
|
|
data[colSetting.field] = null;
|
|
|
+ const exprInfo = getExprInfo(colSetting.field);
|
|
|
+ if (exprInfo) {
|
|
|
+ data[exprInfo.expr] = '';
|
|
|
+ }
|
|
|
}
|
|
|
datas.push(data);
|
|
|
}
|
|
@@ -817,6 +859,10 @@ $(document).ready(() => {
|
|
|
} else {
|
|
|
try {
|
|
|
data[field] = math.evaluate(transExpr(newValue));
|
|
|
+ const exprInfo = getExprInfo(field);
|
|
|
+ if (exprInfo) {
|
|
|
+ data[exprInfo.expr] = newValue;
|
|
|
+ }
|
|
|
} catch (err) {
|
|
|
toastr.error('输入的表达式非法');
|
|
|
return;
|
|
@@ -829,7 +875,6 @@ $(document).ready(() => {
|
|
|
// 更新至服务器
|
|
|
postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
|
|
|
const refreshNode = billsTree.loadPostData(result);
|
|
|
- expr.val(select[field]);
|
|
|
billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
|
|
|
});
|
|
|
});
|
|
@@ -1031,6 +1076,39 @@ $(document).ready(() => {
|
|
|
}
|
|
|
// 计量单元 相关方法&绑定spreadjs事件
|
|
|
const posSpreadObj = {
|
|
|
+ refreshOperationValid: function (sheet, selection) {
|
|
|
+ const setObjEnable = function (obj, enable) {
|
|
|
+ if (enable) {
|
|
|
+ obj.removeClass('disabled');
|
|
|
+ } else {
|
|
|
+ obj.addClass('disabled');
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const invalidAll = function () {
|
|
|
+ setObjEnable($('a[name=pos-opr][type=up-move]'), false);
|
|
|
+ setObjEnable($('a[name=pos-opr][type=down-move]'), false);
|
|
|
+ };
|
|
|
+ const sel = selection ? selection[0] : sheet.getSelections()[0];
|
|
|
+ const row = sel ? sel.row : -1;
|
|
|
+ const first = sheet.zh_data[row];
|
|
|
+ if (!first) {
|
|
|
+ invalidAll();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let last = first;
|
|
|
+ if (sel.rowCount > 1 && first) {
|
|
|
+ for (let r = 1; r < sel.rowCount; r++) {
|
|
|
+ const rNode = sheet.zh_data[sel.row + r];
|
|
|
+ if (!rNode) break;
|
|
|
+ last = rNode;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const preNode = sheet.zh_data[row - 1];
|
|
|
+ const valid = !sheet.zh_setting.readOnly;
|
|
|
+
|
|
|
+ setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode);
|
|
|
+ setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1));
|
|
|
+ },
|
|
|
loadExprToInput: function () {
|
|
|
const sel = posSheet.getSelections()[0];
|
|
|
if (!sel) return;
|
|
@@ -1040,7 +1118,11 @@ $(document).ready(() => {
|
|
|
if (col && col.type === 'Number') {
|
|
|
const data = SpreadJsObj.getSelectObject(posSheet);
|
|
|
if (data) {
|
|
|
- $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
|
|
|
+ const exprInfo = getExprInfo(col.field);
|
|
|
+ const value = exprInfo
|
|
|
+ ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
|
|
|
+ : data[col.field];
|
|
|
+ $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
|
|
|
.attr('row', sel.row).attr('readOnly', readOnly || cell.locked());
|
|
|
} else {
|
|
|
$('#pos-expr').val('').attr('readOnly', true);
|
|
@@ -1062,6 +1144,70 @@ $(document).ready(() => {
|
|
|
}
|
|
|
SpreadJsObj.resetFieldReadOnly(posSheet);
|
|
|
posSpreadObj.loadExprToInput();
|
|
|
+ posSpreadObj.refreshOperationValid(posSheet);
|
|
|
+ },
|
|
|
+ baseOpr: function (sheet, type) {
|
|
|
+ const data = {
|
|
|
+ postType: 'pos',
|
|
|
+ posPostType: type === 'delete' ? type : 'update',
|
|
|
+ postData: [],
|
|
|
+ };
|
|
|
+ const selection = sheet.getSelections();
|
|
|
+ const row = selection[0].row, count = selection[0].rowCount;
|
|
|
+ const first = sheet.zh_data[row];
|
|
|
+ if (type === 'delete') {
|
|
|
+ for (let iRow = 0; iRow < count; iRow++) {
|
|
|
+ const posData = sheet.zh_data[iRow + row];
|
|
|
+ if (posData) {
|
|
|
+ if (posData.used) {
|
|
|
+ toastr.error('"' + posData.name + '"已计量,请勿删除');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ data.postData.push(sheet.zh_data[iRow + row].id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (type === 'up-move') {
|
|
|
+ const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
|
|
|
+ for (let iRow = 0; iRow < count; iRow++) {
|
|
|
+ const posData = sheet.zh_data[iRow + row];
|
|
|
+ if (posData) {
|
|
|
+ data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
|
|
|
+ preUpdate.porder = posData.porder;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data.postData.push(preUpdate);
|
|
|
+ } else if (type === 'down-move') {
|
|
|
+ const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
|
|
|
+ for (let iRow = count - 1; iRow >= 0; iRow--) {
|
|
|
+ const posData = sheet.zh_data[iRow + row];
|
|
|
+ if (posData) {
|
|
|
+ data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
|
|
|
+ nextUpdate.porder = posData.porder;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data.postData.push(nextUpdate);
|
|
|
+
|
|
|
+ }
|
|
|
+ if (data.postData.length > 0) {
|
|
|
+ postData(window.location.pathname + '/update', data, function (result) {
|
|
|
+ if (type === 'delete') {
|
|
|
+ pos.removeDatas(result.pos);
|
|
|
+ sheet.deleteRows(row, count);
|
|
|
+ const loadResult = billsTree.loadPostData(result.ledger);
|
|
|
+ billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
|
|
|
+ billsTreeSpreadObj.refreshOperationValid(billsSheet);
|
|
|
+ posSpreadObj.refreshOperationValid(posSheet);
|
|
|
+ } else {
|
|
|
+ pos.updateDatas(result.pos);
|
|
|
+ const sel = selection[0];
|
|
|
+ if (sel) {
|
|
|
+ sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
|
|
|
+ SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
|
|
|
+ }
|
|
|
+ posSpreadObj.loadCurPosData();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
editStarting: function (e, info) {
|
|
|
posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
|
|
@@ -1131,6 +1277,10 @@ $(document).ready(() => {
|
|
|
} else {
|
|
|
try {
|
|
|
data.postData[col.field] = math.evaluate(transExpr(newText));
|
|
|
+ const exprInfo = getExprInfo(col.field);
|
|
|
+ if (exprInfo) {
|
|
|
+ data.updateData[exprInfo.expr] = newText;
|
|
|
+ }
|
|
|
} catch(err) {
|
|
|
toastr.error('输入的表达式非法');
|
|
|
SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
@@ -1181,6 +1331,10 @@ $(document).ready(() => {
|
|
|
if (!style.locked) {
|
|
|
const colSetting = sheet.zh_setting.cols[iCol];
|
|
|
data[colSetting.field] = null;
|
|
|
+ const exprInfo = getExprInfo(colSetting.field);
|
|
|
+ if (exprInfo) {
|
|
|
+ data[exprInfo.expr] = '';
|
|
|
+ }
|
|
|
bDel = true;
|
|
|
}
|
|
|
}
|
|
@@ -1304,6 +1458,10 @@ $(document).ready(() => {
|
|
|
} else {
|
|
|
try {
|
|
|
posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
|
|
|
+ const exprInfo = getExprInfo(colSetting.field);
|
|
|
+ if (exprInfo) {
|
|
|
+ posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
|
|
|
+ }
|
|
|
} catch (err) {
|
|
|
if (!bHint) {
|
|
|
toastr.warning('粘贴了非法表达式,已过滤');
|
|
@@ -1335,6 +1493,7 @@ $(document).ready(() => {
|
|
|
},
|
|
|
selectionChanged: function (e, info) {
|
|
|
posSpreadObj.loadExprToInput();
|
|
|
+ posSpreadObj.refreshOperationValid(posSheet);
|
|
|
},
|
|
|
addPegs: function (pegs) {
|
|
|
if (!pegs || pegs.length <= 0) return;
|
|
@@ -1355,6 +1514,9 @@ $(document).ready(() => {
|
|
|
};
|
|
|
posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
|
|
|
if (!readOnly && isTz) {
|
|
|
+ $('a[name="pos-opr"]').click(function () {
|
|
|
+ posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
|
|
|
+ });
|
|
|
$('#pos-expr').bind('change mouseleave', function () {
|
|
|
if (this.readOnly) return;
|
|
|
if (document.activeElement.id !== 'pos-expr') return;
|
|
@@ -1375,6 +1537,10 @@ $(document).ready(() => {
|
|
|
} else {
|
|
|
try {
|
|
|
data[field] = math.evaluate(transExpr(newValue));
|
|
|
+ const exprInfo = getExprInfo(field);
|
|
|
+ if (exprInfo) {
|
|
|
+ data[exprInfo.expr] = newValue;
|
|
|
+ }
|
|
|
} catch (err) {
|
|
|
toastr.error('输入的表达式非法');
|
|
|
return;
|
|
@@ -1387,7 +1553,6 @@ $(document).ready(() => {
|
|
|
// 更新至服务器
|
|
|
postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
|
|
|
const updateRst = pos.updateDatas(result.pos);
|
|
|
- expr.val(select[field]);
|
|
|
// 刷新当前行, 不适用于新增(在非下一空白行新增)
|
|
|
SpreadJsObj.reLoadRowData(posSheet, row);
|
|
|
const loadResult = billsTree.loadPostData(result.ledger);
|
|
@@ -2107,8 +2272,8 @@ $(document).ready(() => {
|
|
|
searchSpread: billsSpread,
|
|
|
resultSpreadSetting: {
|
|
|
cols: [
|
|
|
- {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
|
|
|
- {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
|
|
|
+ {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@', readOnly: true},
|
|
|
+ {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
|
|
|
{title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
|
|
|
{title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
|
|
|
{title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
|