|
@@ -101,7 +101,7 @@ $(document).ready(function() {
|
|
|
setObjEnable($('#up-move'), valid && node && node.order > 1);
|
|
|
setObjEnable($('#down-move'), valid && node && !tree.isLastSibling(node));
|
|
|
if (checkTzMeasureType()) {
|
|
|
- const posRange = pos.getMasterRange(node.id);
|
|
|
+ const posRange = node ? pos.getMasterRange(node.id) : [];
|
|
|
setObjEnable($('#up-level'), valid && node && tree.getParent(node) && (!posRange || posRange.length === 0));
|
|
|
} else {
|
|
|
setObjEnable($('#up-level'), valid && node && tree.getParent(node));
|
|
@@ -350,7 +350,7 @@ $(document).ready(function() {
|
|
|
nodes.push(node);
|
|
|
}
|
|
|
}
|
|
|
- info.sheet.zh_tree.update('/ledger/update', datas, function (result) {
|
|
|
+ info.sheet.zh_tree.update(preUrl + '/ledger/update', datas, function (result) {
|
|
|
const rows = [];
|
|
|
for (const data of result) {
|
|
|
rows.push(sortData.indexOf(data));
|
|
@@ -586,6 +586,9 @@ $(document).ready(function() {
|
|
|
}
|
|
|
// 绑定部位明细编辑事件
|
|
|
const posOperationObj = {
|
|
|
+ /**
|
|
|
+ * 加载部位明细 根据当前台账选择节点
|
|
|
+ */
|
|
|
loadCurPosData: function () {
|
|
|
const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
|
|
|
if (node) {
|
|
@@ -608,7 +611,11 @@ $(document).ready(function() {
|
|
|
return;
|
|
|
}
|
|
|
const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
|
|
|
- if (info.editingText !== '' && node.children && node.children > 0) {
|
|
|
+ if (!node) {
|
|
|
+ toast('数据错误, 请刷新页面后再试', 'warning')
|
|
|
+ info.cancel = true;
|
|
|
+ return;
|
|
|
+ } else if (info.editingText !== '' && node.children && node.children > 0) {
|
|
|
toast('父节点不可插入部位明细', 'error');
|
|
|
info.cancel = true;
|
|
|
return;
|
|
@@ -656,13 +663,166 @@ $(document).ready(function() {
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 删除按钮响应事件
|
|
|
+ * @param sheet
|
|
|
+ */
|
|
|
+ deletePress: function (sheet) {
|
|
|
+ const self = this;
|
|
|
+ if (sheet.zh_setting) {
|
|
|
+ const sortData = sheet.zh_data;
|
|
|
+ const datas = [], posSelects = [];
|
|
|
+ const sel = sheet.getSelections()[0];
|
|
|
+ for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
|
|
|
+ const node = sortData[iRow];
|
|
|
+ if (node) {
|
|
|
+ const data = {id: node.id};
|
|
|
+ for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
|
|
|
+ const colSetting = sheet.zh_setting.cols[iCol];
|
|
|
+ if (colSetting.field === 'name') {
|
|
|
+ toast('部位名称不能为空', 'error');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ data[colSetting.field] = null;
|
|
|
+ }
|
|
|
+ datas.push(data);
|
|
|
+ posSelects.push(node);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sheet.zh_tree.update(preUrl + '/pos/update', datas, function (result) {
|
|
|
+ pos.updateDatas(result);
|
|
|
+ // todo 只加载改变项
|
|
|
+ self.loadCurPosData();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 删除 部位明细
|
|
|
+ * @param sheet
|
|
|
+ */
|
|
|
+ deletePos: function (sheet) {
|
|
|
+ const selection = sheet.getSelections();
|
|
|
+ const data = {
|
|
|
+ updateType: 'delete',
|
|
|
+ updateData: [],
|
|
|
+ }
|
|
|
+ const row = selection[0].row, count = selection[0].rowCount;
|
|
|
+ const sortData = sheet.zh_data;
|
|
|
+ for (let iRow = 0; iRow < count; iRow++) {
|
|
|
+ data.updateData.push(sortData[iRow + row].id);
|
|
|
+ }
|
|
|
+ postData(preUrl + '/pos/update', data, function (result) {
|
|
|
+ pos.updateDatas(result.pos);
|
|
|
+ sheet.deleteRows(row, count);
|
|
|
+ ledgerTree.loadPostData(result.ledger, function (loadResult) {
|
|
|
+ treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 粘贴单元格响应事件
|
|
|
+ * @param e
|
|
|
+ * @param info
|
|
|
+ */
|
|
|
+ clipboardPasted: function (e, info) {
|
|
|
+ const self = this;
|
|
|
+ const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
|
|
|
+ if (node.code && (node.code !== '')) {
|
|
|
+ toast('项目节不可含有清单明细', 'error');
|
|
|
+ self.loadCurPosData();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (node.children && (node.children.length > 0)) {
|
|
|
+ toast('仅清单子项可以含有部位明细', 'error');
|
|
|
+ self.loadCurPosData();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (info.sheet.zh_setting) {
|
|
|
+ const data = { updateType: '', updateData: [], };
|
|
|
+ const sortData = info.sheet.zh_data;
|
|
|
+ if (sortData && (info.cellRange.row >= sortData.length)) {
|
|
|
+ data.updateType = 'add';
|
|
|
+ if (info.cellRange.col !== 0) {
|
|
|
+ toast('新增部位请先输入名称', 'warning');
|
|
|
+ self.loadCurPosData();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
|
|
|
+ const curRow = info.cellRange.row + iRow;
|
|
|
+ const newData = {};
|
|
|
+ for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
|
|
|
+ const curCol = info.cellRange.col + iCol;
|
|
|
+ const colSetting = info.sheet.zh_setting.cols[curCol];
|
|
|
+ data[colSetting.field] = info.sheet.getText(curRow, curCol);
|
|
|
+ if (colSetting.type === 'Number') {
|
|
|
+ data[colSetting.field] = _.toNumber(data[colSetting.field]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data.updateData.push(newData);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ data.updateType = 'update';
|
|
|
+ for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
|
|
|
+ const curRow = info.cellRange.row + iRow;
|
|
|
+ const curPos = sortData[curRow];
|
|
|
+ if (curPos) {
|
|
|
+ const newData = {id: curPos.id};
|
|
|
+ for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
|
|
|
+ const curCol = info.cellRange.col + iCol;
|
|
|
+ const colSetting = info.sheet.zh_setting.cols[curCol];
|
|
|
+ newData[colSetting.field] = info.sheet.getText(curRow, curCol);
|
|
|
+ if (colSetting.type === 'Number') {
|
|
|
+ newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data.updateData.push(newData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ postData(preUrl + '/pos/update', data, function (result) {
|
|
|
+ pos.updateDatas(result.pos);
|
|
|
+ ledgerTree.loadPostData(result.ledger, function (loadResult) {
|
|
|
+ treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
|
|
|
+ });
|
|
|
+ posOperationObj.loadCurPosData();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
};
|
|
|
posOperationObj.loadCurPosData();
|
|
|
if (!posSpreadSetting.readOnly) {
|
|
|
- SpreadJsObj.addDeleteBind(posSpread, treeOperationObj.deletePress);
|
|
|
+ SpreadJsObj.addDeleteBind(posSpread, posOperationObj.deletePress);
|
|
|
posSpread.bind(GC.Spread.Sheets.Events.EditEnding, posOperationObj.editEnding);
|
|
|
- posSpread.bind(GC.Spread.Sheets.Events.CellClick, function (e, info) {
|
|
|
- console.log(info.sheet.getCell(info.row, info.col));
|
|
|
+ posSpread.bind(GC.Spread.Sheets.Events.ClipboardPasted, posOperationObj.clipboardPasted);
|
|
|
+ // posSpread.bind(GC.Spread.Sheets.Events.CellClick, function (e, info) {
|
|
|
+ // console.log(info.sheet.getCell(info.row, info.col));
|
|
|
+ // });
|
|
|
+ // 右键菜单
|
|
|
+ $.contextMenu({
|
|
|
+ selector: '#pos-spread',
|
|
|
+ build: function ($trigger, e) {
|
|
|
+ const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
|
|
|
+ return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
|
|
|
+ },
|
|
|
+ items: {
|
|
|
+ 'delete': {
|
|
|
+ name: '删除',
|
|
|
+ icon: 'fa-remove',
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ const sheet = posSpread.getActiveSheet();
|
|
|
+ if (sheet.zh_data) {
|
|
|
+ const selection = sheet.getSelections();
|
|
|
+ return sheet.zh_data.length < selection[0].row + selection[0].rowCount;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ callback: function (key, opt) {
|
|
|
+ posOperationObj.deletePos(posSpread.getActiveSheet());
|
|
|
+ }
|
|
|
+ },
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|