|
@@ -8,6 +8,7 @@
|
|
|
function getTenderId() {
|
|
|
return window.location.pathname.split('/')[2];
|
|
|
}
|
|
|
+const selects = [];
|
|
|
$(function () {
|
|
|
autoFlashHeight();
|
|
|
// 初始化台账
|
|
@@ -45,7 +46,7 @@ $(function () {
|
|
|
defaultRowHeight: 21,
|
|
|
headerFont: '12px 微软雅黑',
|
|
|
font: '12px 微软雅黑',
|
|
|
- readOnly: true,
|
|
|
+ // readOnly: true,
|
|
|
localCache: {
|
|
|
key: 'ledger-bills',
|
|
|
colWidth: true,
|
|
@@ -58,11 +59,91 @@ $(function () {
|
|
|
SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());
|
|
|
|
|
|
postData(window.location.pathname + '/load', {}, function (data) {
|
|
|
+ data = addIsSelect(data);
|
|
|
ledgerTree.loadDatas(data);
|
|
|
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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ buttonClicked: function (e, info) {
|
|
|
+ if (info.sheet.zh_setting) {
|
|
|
+ const select = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
+ const col = info.sheet.zh_setting.cols[info.col];
|
|
|
+ // if (materialCol.readOnly.isEdit(select)) {
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ if (col.field === 'is_select') {
|
|
|
+ if (info.sheet.isEditing()) {
|
|
|
+ info.sheet.endEdit(true);
|
|
|
+ }
|
|
|
+ // 选中和去除关联
|
|
|
+ select.is_select = info.sheet.getValue(info.row, info.col) ? 1 : 0;
|
|
|
+ selects.splice(0, selects.length);
|
|
|
+ selects.push(select);
|
|
|
+ updateChildrenSelect(select.children, select.is_select);
|
|
|
+ updateParentSelect(info.sheet.zh_tree, select.ledger_pid, select.is_select);
|
|
|
+ // console.log(selects);
|
|
|
+ const refreshNode = ledgerTree.loadPostData({update: selects});
|
|
|
+ ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ ledgerSpread.bind(spreadNS.Events.ButtonClicked, ledgerSpreadObj.buttonClicked);
|
|
|
+
|
|
|
+
|
|
|
// // 显示层次
|
|
|
// (function (select, sheet) {
|
|
|
// $(select).click(function () {
|
|
@@ -90,3 +171,31 @@ $(function () {
|
|
|
// });
|
|
|
// })('a[name=showLevel]', ledgerSpread.getActiveSheet());
|
|
|
});
|
|
|
+function addIsSelect(datas) {
|
|
|
+ for (const d of datas) {
|
|
|
+ d.is_select = selectedLedgerList.length === 0 ? 1: selectedLedgerList.indexOf(d.ledger_id) !== -1 ? 1 : 0;
|
|
|
+ }
|
|
|
+ return datas;
|
|
|
+}
|
|
|
+
|
|
|
+function updateChildrenSelect(datas, is_select) {
|
|
|
+ for (const data of datas) {
|
|
|
+ data.is_select = is_select;
|
|
|
+ if(data.children && data.children.length > 0) {
|
|
|
+ updateChildrenSelect(data.children, is_select);
|
|
|
+ }
|
|
|
+ selects.push(data);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function updateParentSelect(tree, pid, is_select) {
|
|
|
+ if (pid !== -1) {
|
|
|
+ const parent = _.find(tree.nodes, { 'ledger_id': pid });
|
|
|
+ if (parent) {
|
|
|
+ const hadselectInfo = is_select === 0 ? _.findIndex(parent.children, { 'is_select': 1 }) : 1;
|
|
|
+ parent.is_select = (hadselectInfo !== -1 && is_select === 0) || is_select === 1 ? 1 : 0;
|
|
|
+ selects.push(parent);
|
|
|
+ updateParentSelect(tree, parent.ledger_pid, is_select);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|