|
@@ -477,7 +477,48 @@ $(document).ready(() => {
|
|
|
self.refreshOperationValid(sheet);
|
|
|
removeLocalCache(copyBlockTag);
|
|
|
}, null, true);
|
|
|
- }
|
|
|
+ },
|
|
|
+ sortCode: function (sheet) {
|
|
|
+ const tree = sheet.zh_tree;
|
|
|
+ if (!tree) return;
|
|
|
+
|
|
|
+ const select = SpreadJsObj.getSelectObject(sheet);
|
|
|
+ if (!select || !select.code) return;
|
|
|
+
|
|
|
+ const getChildSort = function (i, split) {
|
|
|
+ if (i <= 0) throw '参数错误';
|
|
|
+ switch(split) {
|
|
|
+ case '0':
|
|
|
+ return i < 10 ? split + i : i + '';
|
|
|
+ case '-':
|
|
|
+ default:
|
|
|
+ return split + i;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const recursiveSortCode = function (data, parentCode, children, split) {
|
|
|
+ if (!children || children.length === 0) return;
|
|
|
+
|
|
|
+ for (const [i, child] of children.entries()) {
|
|
|
+ if (!child.b_code || child.b_code === '') {
|
|
|
+ const code = parentCode + getChildSort(i + 1, split);
|
|
|
+ const cData = tree.getNodeKeyData(child);
|
|
|
+ cData.code = code;
|
|
|
+ data.push(cData);
|
|
|
+ if (!tree.isLeafXmj(child)) {
|
|
|
+ recursiveSortCode(data, code, child.children, split);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const data = [];
|
|
|
+ recursiveSortCode(data, select.code, select.children, tree.getCodeSplit());
|
|
|
+ if (data.length > 0) {
|
|
|
+ postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
|
|
|
+ const refreshNode = tree.loadPostData(result);
|
|
|
+ budgetTreeOpr.refreshTree(sheet, refreshNode);
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
};
|
|
|
budgetSpread.bind(spreadNS.Events.SelectionChanged, budgetTreeOpr.selectionChanged);
|
|
|
if (!readOnly) {
|
|
@@ -582,7 +623,18 @@ $(document).ready(() => {
|
|
|
visible: function (key, opt) {
|
|
|
return !readOnly;
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ sortChildren: {
|
|
|
+ name: '顺序重排子项编号',
|
|
|
+ icon: 'fa-sort-numeric-asc',
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ const node = SpreadJsObj.getSelectObject(budgetSheet);
|
|
|
+ return !node || !node.code || !node.children || node.children === 0 || node.code.length < 3;
|
|
|
+ },
|
|
|
+ callback: function (key, opt) {
|
|
|
+ budgetTreeOpr.sortCode(budgetSheet);
|
|
|
+ },
|
|
|
+ },
|
|
|
}
|
|
|
});
|
|
|
}
|