|
|
@@ -506,44 +506,6 @@ $(document).ready(function() {
|
|
|
const self = this;
|
|
|
const [tree, node, count] = this.getDefaultSelectInfo(sheet);
|
|
|
if (!tree || !node || !count) return;
|
|
|
-
|
|
|
- // if (type === 'delete') {
|
|
|
- // const parent = tree.getParent(node);
|
|
|
- // const children = parent ? parent.children : tree.children;
|
|
|
- // const index = children.indexOf(node);
|
|
|
- // for (let i = 0; i < count; i++) {
|
|
|
- // const child = children[i+index];
|
|
|
- // if (tree.checkNodeUsed(child, pos)) {
|
|
|
- // toastr.warning('选中的节点已计量,不可删除');
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // } else if (type === 'up-level') {
|
|
|
- // const parent = tree.getParent(node);
|
|
|
- // const children = parent ? parent.children : tree.children;
|
|
|
- // const index = children.indexOf(node);
|
|
|
- // const lastSelect = children[index + count - 1];
|
|
|
- // // if (tree.checkNodeUsed(lastSelect, pos) && (!lastSelect.children || lastSelect.children.length === 0) && (children.length > index + count)) {
|
|
|
- // // toastr.warning('选中的节点已计量,不可升级');
|
|
|
- // // return;
|
|
|
- // // }
|
|
|
- // } else if (type === 'down-level') {
|
|
|
- // const parent = tree.getParent(node);
|
|
|
- // const children = parent ? parent.children : tree.children;
|
|
|
- // const index = children.indexOf(node);
|
|
|
- // if (index > 0 && children[index-1].used) {
|
|
|
- // toastr.warning('其前节点已计量,选中的节点不可降级');
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // for (let i = index; i < count; i++) {
|
|
|
- // const child = children[i+index];
|
|
|
- // if (tree.checkNodeUsed(child, pos)) {
|
|
|
- // toastr.warning('选中的节点已计量,不可降级');
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
if (type === 'delete') {
|
|
|
deleteAfterHint(function () {
|
|
|
postData(window.location.pathname + '/update', {
|
|
|
@@ -955,6 +917,142 @@ $(document).ready(function() {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ const moveSpreadSetting = {
|
|
|
+ cols: [
|
|
|
+ {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@', cellType: 'tree'},
|
|
|
+ {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 240, formatter: '@'},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 2,
|
|
|
+ headRowHeight: [25, 25],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ readOnly: true,
|
|
|
+ rowHeader:[
|
|
|
+ ],
|
|
|
+ localCache: {
|
|
|
+ key: 'contract-move-spread',
|
|
|
+ colWidth: true,
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const moveSpread = SpreadJsObj.createNewSpread($('#move-contract-spread')[0]);
|
|
|
+ const moveSheet = moveSpread.getActiveSheet();
|
|
|
+ // sjsSettingObj.setGridSelectStyle(sqSpreadSetting);
|
|
|
+ sjsSettingObj.setFxTreeStyle(moveSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
|
|
|
+ SpreadJsObj.initSheet(moveSheet, moveSpreadSetting);
|
|
|
+ const moveTreeSetting = {
|
|
|
+ id: 'contract_id',
|
|
|
+ pid: 'contract_pid',
|
|
|
+ order: 'order',
|
|
|
+ level: 'level',
|
|
|
+ rootId: -1,
|
|
|
+ keys: ['id', 'tid', 'spid'],
|
|
|
+ autoExpand: 3,
|
|
|
+ markExpandKey: 'contract-move-bills-expand',
|
|
|
+ markExpandSubKey: window.location.pathname.split('/')[2],
|
|
|
+ };
|
|
|
+ const moveTree = createNewPathTree('base', moveTreeSetting);
|
|
|
+ const moveTreeSpreadObj = {
|
|
|
+ selectionChanged: function (e, info) {
|
|
|
+ if (info.newSelections) {
|
|
|
+ if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
|
|
|
+ const node = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
+ $('#move-new-node').text(node ? node.code : '');
|
|
|
+ }
|
|
|
+ info.sheet.setSelection(info.newSelections[0].row, 0, 1, info.sheet.getColumnCount());
|
|
|
+ }
|
|
|
+ },
|
|
|
+ }
|
|
|
+ moveSpread.bind(spreadNS.Events.SelectionChanged, moveTreeSpreadObj.selectionChanged);
|
|
|
+ $('#cons-move').on('shown.bs.modal', function () {
|
|
|
+ const node = SpreadJsObj.getSelectObject(contractSheet);
|
|
|
+ if (!(node && node.c_code)) {
|
|
|
+ toastr.error('合同不存在');
|
|
|
+ $('#cons-move').modal('hide');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $('#move-node').text(node.c_code);
|
|
|
+ const parentNode = _.find(contractTree.nodes, { contract_id: node.contract_pid });
|
|
|
+ $('#move-parent-node').text(parentNode ? parentNode.code : '');
|
|
|
+ $('#move-new-node').text(parentNode ? parentNode.code : '');
|
|
|
+ const onlyTree = _.cloneDeep(_.filter(contractTree.nodes, function (item) {
|
|
|
+ return item.code !== undefined && item.c_code === undefined;
|
|
|
+ }));
|
|
|
+ for (const t of onlyTree) {
|
|
|
+ if (!t.is_leaf && _.findIndex(onlyTree, { contract_pid: t.contract_id }) === -1) {
|
|
|
+ t.is_leaf = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ moveTree.loadDatas(onlyTree);
|
|
|
+ SpreadJsObj.loadSheetData(moveSheet, SpreadJsObj.DataType.Tree, moveTree);
|
|
|
+ // 找出node对应父节点并选中,底色也要跟着更新
|
|
|
+ const parentIndex = _.findIndex(moveTree.nodes, { contract_id: parentNode.contract_id });
|
|
|
+ if (parentIndex !== -1) {
|
|
|
+ moveSheet.setSelection(parentIndex, 0, 1, moveSheet.getColumnCount());
|
|
|
+ SpreadJsObj.reloadRowsBackColor(moveSheet, [0, parentIndex]);
|
|
|
+ }
|
|
|
+ moveSpread.refresh();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#move-contract-btn').click(function () {
|
|
|
+ const node = SpreadJsObj.getSelectObject(contractSheet);
|
|
|
+ if (!(node && node.c_code)) {
|
|
|
+ toastr.error('合同不存在');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const oldParentNode = _.find(contractTree.nodes, { contract_id: node.contract_pid });
|
|
|
+ const newNode = SpreadJsObj.getSelectObject(moveSheet);
|
|
|
+ const newParentNode = _.find(contractTree.nodes, { contract_id: newNode.contract_id });
|
|
|
+ if (oldParentNode.contract_id === newParentNode.contract_id) {
|
|
|
+ toastr.warning('合同所属节点无变化');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const data = [{
|
|
|
+ id: node.id,
|
|
|
+ contract_pid: newParentNode.contract_id,
|
|
|
+ level: newParentNode.level + 1,
|
|
|
+ order: newParentNode.children ? newParentNode.children.length + 1 : 1,
|
|
|
+ full_path: newParentNode.full_path + '-' + node.contract_id,
|
|
|
+ }];
|
|
|
+ if (oldParentNode.children.length === 1) {
|
|
|
+ oldParentNode.is_leaf = 1;
|
|
|
+ data.push({
|
|
|
+ id: oldParentNode.id,
|
|
|
+ is_leaf: 1,
|
|
|
+ });
|
|
|
+ } else if (oldParentNode.children.length > 1) {
|
|
|
+ // 可能需要移动oldParentNode的children数组比node order大的值减1
|
|
|
+ for (const child of oldParentNode.children) {
|
|
|
+ if (child.order > node.order) {
|
|
|
+ child.order -= 1;
|
|
|
+ data.push({
|
|
|
+ id: child.id,
|
|
|
+ order: child.order,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (newParentNode.is_leaf === 1) {
|
|
|
+ newParentNode.is_leaf = 0;
|
|
|
+ data.push({
|
|
|
+ id: newParentNode.id,
|
|
|
+ is_leaf: 0,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ console.log(data);
|
|
|
+ // 更新至服务器
|
|
|
+ postData(window.location.pathname + '/update', {postType: 'update', postData: data, updateAll: true}, function (result) {
|
|
|
+ toastr.success('合同已移动成功');
|
|
|
+ const refreshNode = contractTree.loadPostData(result);
|
|
|
+ contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
|
|
|
+ const newNode = SpreadJsObj.getSelectObject(contractSheet);
|
|
|
+ contractTreeSpreadObj.changeContractTab(newNode, true);
|
|
|
+ $('#cons-move').modal('hide');
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
contractContextMenuOptions.items.create = {
|
|
|
name: '新增节点',
|
|
|
icon: 'fa-plus',
|
|
|
@@ -1159,6 +1257,36 @@ $(document).ready(function() {
|
|
|
// contractContextMenuOptions.items.sprBlock = '----';
|
|
|
// }
|
|
|
if (permission_edit) {
|
|
|
+ contractContextMenuOptions.items.move = {
|
|
|
+ name: '移动至其它节点',
|
|
|
+ icon: 'fa-arrow-left',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ $('#cons-move').modal('show');
|
|
|
+ },
|
|
|
+ visible: function (key, opt) {
|
|
|
+ const sheet = contractSheet;
|
|
|
+ const selection = sheet.getSelections();
|
|
|
+ const sel = selection ? selection[0] : sheet.getSelections()[0];
|
|
|
+ const row = sel ? sel.row : -1;
|
|
|
+ const tree = sheet.zh_tree;
|
|
|
+ if (!tree) return false;
|
|
|
+ const first = sheet.zh_tree.nodes[row];
|
|
|
+ const valid = !sheet.zh_setting.readOnly;
|
|
|
+ return valid && first && first.c_code && first.level > 1;
|
|
|
+ },
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ const sheet = contractSheet;
|
|
|
+ const selection = sheet.getSelections();
|
|
|
+ const sel = selection ? selection[0] : sheet.getSelections()[0];
|
|
|
+ const row = sel ? sel.row : -1;
|
|
|
+ if (sel.rowCount > 1) return true;
|
|
|
+ const tree = sheet.zh_tree;
|
|
|
+ if (!tree) return true;
|
|
|
+ const first = sheet.zh_tree.nodes[row];
|
|
|
+ const valid = !sheet.zh_setting.readOnly;
|
|
|
+ return !(valid && first && first.c_code && !first.settle_code && first.level > 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
contractContextMenuOptions.items.batchInsert = {
|
|
|
name: '批量插入',
|
|
|
type: 'batchInsert',
|