|
@@ -117,6 +117,13 @@ $(document).ready(function() {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ batchUpdateFiling(data, callback) {
|
|
|
+ const self = this;
|
|
|
+ postData(`${window.location.pathname}/update`, data, function(result) {
|
|
|
+ self.analysisFiling(result);
|
|
|
+ if (callback) callback();
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
const levelTreeSetting = {
|
|
|
treeId: 'filing',
|
|
@@ -262,4 +269,171 @@ $(document).ready(function() {
|
|
|
'</div>');
|
|
|
$(`.table-file[tempId=${tempId}]`).html(html.join(''));
|
|
|
});
|
|
|
+
|
|
|
+ class MultiObj {
|
|
|
+ constructor(setting) {
|
|
|
+ this.modal = $(`#${setting.modal}`);
|
|
|
+ this.spread = SpreadJsObj.createNewSpread($(`#${setting.spread}`)[0]);
|
|
|
+ this.sheet = this.spread.getActiveSheet();
|
|
|
+ this.spreadSetting = {
|
|
|
+ cols: [
|
|
|
+ { title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 250, formatter: '@', readOnly: true, cellType: 'tree' },
|
|
|
+ { title: '固定', colSpan: '1', rowSpan: '1', field: 'is_fixed', hAlign: 1, width: 50, cellType: 'checkbox' },
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 1,
|
|
|
+ headRowHeight: [32],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ };
|
|
|
+ SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
|
|
|
+ this.checkTree = createNewPathTree('base', {
|
|
|
+ id: 'tree_id',
|
|
|
+ pid: 'tree_pid',
|
|
|
+ order: 'order',
|
|
|
+ level: 'level',
|
|
|
+ isLeaf: 'is_leaf',
|
|
|
+ fullPath: 'full_path',
|
|
|
+ rootId: -1,
|
|
|
+ });
|
|
|
+ const self = this;
|
|
|
+ this.modal.bind('shown.bs.modal', function() {
|
|
|
+ self.spread.refresh();
|
|
|
+ });
|
|
|
+ this.spread.bind(spreadNS.Events.ButtonClicked, function(e, info) {
|
|
|
+ if (!info.sheet.zh_setting) return;
|
|
|
+ const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
|
|
|
+ if (cellType instanceof spreadNS.CellTypes.CheckBox) {
|
|
|
+ if (sheet.isEditing()) sheet.endEdit(true);
|
|
|
+ }
|
|
|
+ const col = info.sheet.zh_setting.cols[info.col];
|
|
|
+ if (col.field !== 'is_fixed') return;
|
|
|
+ const tree = self.checkTree;
|
|
|
+ const node = tree.nodes[info.row];
|
|
|
+ if (node.level <= 1) {
|
|
|
+ toastr.warning('顶层节点不可取消固定');
|
|
|
+ SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!node.is_fixed) {
|
|
|
+ node.is_fixed = true;
|
|
|
+ const row = [tree.nodes.indexOf(node)];
|
|
|
+ const parents = tree.getAllParents(node);
|
|
|
+ for (const p of parents) {
|
|
|
+ if (p.is_fixed) continue;
|
|
|
+ p.is_fixed = true;
|
|
|
+ row.push(tree.nodes.indexOf(p));
|
|
|
+ }
|
|
|
+ SpreadJsObj.reLoadRowsData(info.sheet, row);
|
|
|
+ } else {
|
|
|
+ node.is_fixed = false;
|
|
|
+ const row = [tree.nodes.indexOf(node)];
|
|
|
+ const posterity = tree.getPosterity(node);
|
|
|
+ for (const p of posterity) {
|
|
|
+ if (!p.is_fixed) continue;
|
|
|
+ p.is_fixed = false;
|
|
|
+ row.push(tree.nodes.indexOf(p));
|
|
|
+ }
|
|
|
+ SpreadJsObj.reLoadRowsData(info.sheet, row);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $(`#${setting.modal}-ok`).click(function() {
|
|
|
+ const data = self.getMultiUpdateData();
|
|
|
+ filingObj.batchUpdateFiling(data, function() {
|
|
|
+ self.modal.modal('hide');
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ getMultiUpdateData() {
|
|
|
+ const data = [];
|
|
|
+ for (const [i, node] of this.checkTree.nodes.entries()) {
|
|
|
+ node.source_filing_type = i + 1;
|
|
|
+ let filing_type = node.source_filing_type;
|
|
|
+ if (!node.is_fixed) {
|
|
|
+ const parents = this.checkTree.getAllParents(node);
|
|
|
+ const index = parents.lastIndexOf(x => { return x.is_fixed; });
|
|
|
+ filing_type = parents[index].source_filing_type;
|
|
|
+ }
|
|
|
+ data.push({ id: node.id, is_fixed: node.is_fixed, filing_type });
|
|
|
+ }
|
|
|
+ return {updateType: 'multi', data};
|
|
|
+ }
|
|
|
+ _convertData(sourceTree) {
|
|
|
+ const data = [];
|
|
|
+ for (const node of sourceTree.nodes) {
|
|
|
+ const parent = node.tree_pid === '-1' ? undefined : data.find(x => { return x.id === node.tree_pid; });
|
|
|
+ const child = sourceTree.nodes.find(x => { return x.tree_pid === node.id; });
|
|
|
+ data.push({
|
|
|
+ id: node.id,
|
|
|
+ tree_id: data.length + 1,
|
|
|
+ tree_pid: parent ? parent.tree_id : -1,
|
|
|
+ order: node.tree_order + 1,
|
|
|
+ level: node.tree_level,
|
|
|
+ is_leaf: !child,
|
|
|
+ full_path: '',
|
|
|
+ name: node.name,
|
|
|
+ is_fixed: node.is_fixed,
|
|
|
+ filing_type: node.filing_type,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ reload(sourceTree) {
|
|
|
+ this.checkTree.loadDatas(this._convertData(sourceTree));
|
|
|
+ SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.checkTree);
|
|
|
+ }
|
|
|
+ show() {
|
|
|
+ this.modal.modal('show');
|
|
|
+ }
|
|
|
+ exportFile(sourceTree) {
|
|
|
+ const exportData = sourceTree.nodes.map(node => { return {
|
|
|
+ id: node.id,
|
|
|
+ tree_pid: node.tree_pid,
|
|
|
+ tree_order: node.tree_order,
|
|
|
+ tree_level: node.tree_level,
|
|
|
+ name: node.name,
|
|
|
+ is_fixed: node.is_fixed,
|
|
|
+ filing_type: node.filing_type,
|
|
|
+ }});
|
|
|
+ const blob = new Blob([JSON.stringify(exportData, '', '')], { type: 'application/text'});
|
|
|
+ const template = templateList.find(x => { return x.id === sourceTree.nodes[0].temp_id });
|
|
|
+ saveAs(blob, `${template.name}.json`);
|
|
|
+ }
|
|
|
+ importFromJSON(str) {
|
|
|
+ try {
|
|
|
+ const data = JSON.parse(str);
|
|
|
+ filingObj.batchUpdateFiling({ updateType: 'import', data });
|
|
|
+ } catch(err) {
|
|
|
+ toastr.error('导入文件格式错误,无法解析');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ importFile(file) {
|
|
|
+ if (!file) return;
|
|
|
+ const self = this;
|
|
|
+ let reader = new FileReader();
|
|
|
+ reader.onload = function() {
|
|
|
+ self.importFromJSON(this.result);
|
|
|
+ };
|
|
|
+ reader.readAsText(file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let multiObj = new MultiObj({ modal: 'multi-set', spread: 'multi-spread' });
|
|
|
+ $('#multi-setting').click(() => {
|
|
|
+ multiObj.reload(filingObj.dragTree);
|
|
|
+ multiObj.show();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#export-template').click(() => {
|
|
|
+ multiObj.exportFile(filingObj.dragTree);
|
|
|
+ });
|
|
|
+ $('#import-template').click(() => {
|
|
|
+ selectFile({
|
|
|
+ fileType: '*.json',
|
|
|
+ select: function(file) {
|
|
|
+ multiObj.importFile(file)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|