Files
SaaS-lib/hx-op/src/view/organizationManage/enterpriseManage/index.vue

345 lines
9.0 KiB
Vue
Raw Normal View History

2024-06-07 15:11:04 +08:00
<!-- @format -->
<template>
<ns-view-list-table v-bind="tableConfig" :model="data" ref="mainRef" rowKey="uuid" />
2024-06-11 13:37:10 +08:00
<ns-drawer v-bind="addDrawerConfig">
2024-06-07 15:11:04 +08:00
<ns-form ref="formRef" :schemas="formSchema" :model="formData" formLayout="vertical" />
<template #footer>
2024-06-11 16:13:51 +08:00
<ns-button style="margin-right: 8px" @click="onClose">取消</ns-button>
<ns-button type="primary" @click="operateForm" :disabled="!formDisabled">确定</ns-button>
2024-06-07 15:11:04 +08:00
</template>
2024-06-11 13:37:10 +08:00
</ns-drawer>
2024-06-12 16:41:30 +08:00
<ns-drawer v-bind="boundaryDrawer">
2024-06-11 16:13:51 +08:00
<ns-button type="primary" @click="borderAdd">新增</ns-button>
2024-06-12 16:41:30 +08:00
<ns-button type="primary" style="margin-left: 10px; margin-bottom: 10px" @click="borderAdd"
2024-06-11 16:13:51 +08:00
>新增子集</ns-button
2024-06-07 15:11:04 +08:00
>
2024-06-12 16:41:30 +08:00
<a-tree v-if="linkTree?.length" v-bind="boundaryTree" class="boundaryTree">
<template #title="data">
<span>{{ data.orgInfo.orgName }}</span>
<!-- <ns-button type="link" danger >删除</ns-button> -->
<span v-if="data.orgInfo.orgId !== currentBoundaryRecord.orgId" class="nodeDelete">
<DeleteOutlined @click="deleteTree(data)"
/></span>
2024-06-07 15:11:04 +08:00
</template>
2024-06-12 16:41:30 +08:00
</a-tree>
2024-06-11 16:13:51 +08:00
</ns-drawer>
2024-06-07 15:11:04 +08:00
2024-06-11 16:13:51 +08:00
<ns-drawer v-bind="serverDrawer">
2024-06-12 16:41:30 +08:00
<!-- <ns-input-search
2024-06-07 15:11:04 +08:00
placeholder="请选择开通模块"
v-model:value="searchValue"
style="margin-bottom: 8px"
2024-06-12 16:41:30 +08:00
@search="onSearch" /> -->
2024-06-11 16:13:51 +08:00
<a-tree v-if="treeData?.length" v-model:checkedKeys="checkedKeys" v-bind="serverTree" />
</ns-drawer>
2024-06-07 15:11:04 +08:00
2024-06-12 16:41:30 +08:00
<TreeAdd ref="treeAdd" @ok="handleOk" />
2024-06-07 15:11:04 +08:00
</template>
<script lang="ts" setup>
import { Modal } from 'ant-design-vue';
import { computed, createVNode, defineComponent, reactive, ref, watch } from 'vue';
import { http } from '/nerv-lib/util/http';
import { cloneDeep } from 'lodash-es';
import TreeAdd from './TreeAdd.vue';
2024-06-12 16:41:30 +08:00
import { DeleteOutlined } from '@ant-design/icons-vue';
2024-06-07 15:11:04 +08:00
import { h } from 'vue';
import { formConfig } from './config';
2024-06-12 16:41:30 +08:00
import { NsMessage, NsModal } from '/nerv-lib/component';
2024-06-07 15:11:04 +08:00
import { mockData, treeData } from './mock';
import { enterPrise } from '/@/api/origanizemanage';
import { tableConfig as insertConfig } from './config';
defineOptions({
name: 'EnterpriseManageIndex',
});
const data = reactive({});
const treeAdd = ref();
const mainRef = ref();
let formData = ref({});
const formRef = ref();
const searchValue = ref<string>('');
const checkedKeys = ref<string[]>([]);
const visible = ref(false);
const borderVisible = ref(false);
const serviceVisible = ref(false);
const treeAddVisible = ref(false);
const formSchema = formConfig;
2024-06-12 16:41:30 +08:00
const currentServerRecord = ref({});
const currentBoundaryRecord = ref({});
const currentSelectBoundaryNode = ref({});
const linkTree = ref([]);
const totalCheckedKeys = ref([]);
2024-06-11 16:13:51 +08:00
const opType = ref<string>('add');
const calMap = {
add: enterPrise.save,
edit: enterPrise.edit,
2024-06-12 16:41:30 +08:00
serverAdd: enterPrise.orgPermission,
2024-06-11 16:13:51 +08:00
};
const comApi = computed(() => {
return calMap[opType.value as keyof typeof calMap];
});
2024-06-12 16:41:30 +08:00
// 公共请求方法包含tablereloaddrawerclose
const fetch = (params, isReload = true) => {
http.post(comApi.value, params).then(() => {
NsMessage.success('操作成功');
onClose();
isReload && mainRef.value?.nsTableRef.reload();
});
};
// 表格配置
2024-06-07 15:11:04 +08:00
const tableConfig = computed(() => {
2024-06-11 16:13:51 +08:00
return insertConfig({
visible,
formData,
opType,
getOrgRandomCode,
borderVisible,
serviceVisible,
server: {
getTree,
2024-06-12 16:41:30 +08:00
currentServerRecord,
getPermissionData,
},
boundary: {
getBoundaryTree,
currentBoundaryRecord,
2024-06-11 16:13:51 +08:00
},
});
2024-06-07 15:11:04 +08:00
});
2024-06-11 13:37:10 +08:00
2024-06-12 16:41:30 +08:00
// 随机组织id
2024-06-11 13:37:10 +08:00
const getOrgRandomCode = () => {
http.post(enterPrise.getCode).then((res) => {
2024-06-11 16:13:51 +08:00
formData.value.orgCode = res.data;
2024-06-11 13:37:10 +08:00
});
};
2024-06-12 16:41:30 +08:00
// getOrgRandomCode();
2024-06-11 13:37:10 +08:00
2024-06-12 16:41:30 +08:00
// 公共关闭及后续处理逻辑
2024-06-11 16:13:51 +08:00
const onClose = () => {
visible.value = false;
borderVisible.value = false;
serviceVisible.value = false;
2024-06-12 16:41:30 +08:00
checkedKeys.value = [];
linkTree.value = [];
2024-06-07 15:11:04 +08:00
};
2024-06-11 16:13:51 +08:00
// 企业表单drawer
const addDrawerConfig = ref({
width: '520',
visible: visible,
footerStyle: { textAlign: 'right' },
destroyOnClose: true,
onClose: onClose,
2024-06-07 15:11:04 +08:00
});
2024-06-12 16:41:30 +08:00
// 表单form配置
2024-06-11 16:13:51 +08:00
const formDisabled = computed(() => {
return formRef.value?.validateResult;
});
//企业表单数据操作
const operateForm = () => {
formRef.value?.triggerSubmit().then((res) => {
console.log(formData.value, 'formData.value');
2024-06-12 16:41:30 +08:00
fetch(res);
2024-06-11 16:13:51 +08:00
});
2024-06-07 15:11:04 +08:00
};
2024-06-11 16:13:51 +08:00
// 服务操作逻辑区域
const serverOK = () => {
2024-06-12 16:41:30 +08:00
const params = {
orgId: currentServerRecord.value?.orgId,
orgName: currentServerRecord.value?.orgName,
permissionVoList: totalCheckedKeys.value,
};
fetch(params, false);
2024-06-11 16:13:51 +08:00
};
2024-06-07 15:11:04 +08:00
const ServiceSelect = (selectedKeys: any, info: any) => {
console.log(selectedKeys, 'selectedKeys');
console.log(info, 'info');
};
2024-06-12 16:41:30 +08:00
// 服务树配置
2024-06-11 16:13:51 +08:00
const serverTree = ref({
checkable: true,
2024-06-12 16:41:30 +08:00
selectable: false,
2024-06-11 16:13:51 +08:00
onSelect: ServiceSelect,
defaultExpandAll: true,
treeData: treeData,
fieldNames: { children: 'menus', title: 'label', key: 'code' },
2024-06-12 16:41:30 +08:00
onCheck: (checked, { halfCheckedKeys }) => {
const result = checked.map((item) => {
return {
halfCheck: false,
permissionId: item,
};
});
const finalResult = halfCheckedKeys
.map((item) => {
return {
halfCheck: true,
permissionId: item,
};
})
.concat(result);
totalCheckedKeys.value = finalResult;
},
2024-06-11 16:13:51 +08:00
});
2024-06-12 16:41:30 +08:00
// 获取服务权限树
2024-06-11 16:13:51 +08:00
const getTree = (params) => {
2024-06-12 16:41:30 +08:00
return http.post(enterPrise.permissionTree, params).then((res) => {
treeData.value = res.data?.data;
});
};
getTree({});
// 获取当前企业拥有的权限数据
const getPermissionData = (params) => {
http.post(enterPrise.queryOrgPermission, params).then((res) => {
checkedKeys.value = res.data
?.filter((item) => !item.halfCheck)
.map((item) => {
return item.permissionId;
});
2024-06-11 16:13:51 +08:00
});
2024-06-07 15:11:04 +08:00
};
2024-06-11 16:13:51 +08:00
// 开通服务模块drawer
const serverDrawer = ref({
2024-06-12 16:41:30 +08:00
width: 520,
2024-06-11 16:13:51 +08:00
visible: serviceVisible,
2024-06-11 13:37:10 +08:00
footerStyle: { textAlign: 'right' },
2024-06-12 16:41:30 +08:00
destroyOnClose: true,
2024-06-11 16:13:51 +08:00
ok: serverOK,
2024-06-12 16:41:30 +08:00
onClose: onClose,
2024-06-11 16:13:51 +08:00
cancel: onClose,
2024-06-11 13:37:10 +08:00
});
2024-06-12 16:41:30 +08:00
// 边界drawer配置
const boundaryDrawer = ref({
width: 520,
visible: borderVisible,
footerStyle: { textAlign: 'right' },
destroyOnClose: true,
ok: onClose,
onClose,
cancel: onClose,
2024-06-11 16:13:51 +08:00
});
const handleSelect = (selectedKeys: any, info: any) => {
2024-06-12 16:41:30 +08:00
currentSelectBoundaryNode.value = info;
2024-06-11 16:13:51 +08:00
};
2024-06-12 16:41:30 +08:00
// 获取边界树
const getBoundaryTree = (params) => {
http.post(enterPrise.queryOrgTree, params).then((res) => {
const otherOrg = res.data[0].listOrg;
linkTree.value = res.data;
otherOrg?.map((item) => {
linkTree.value.push({ orgInfo: item } as never);
});
});
};
// 边界树配置
const boundaryTree = ref({
defaultExpandAll: true,
onSelect: handleSelect,
treeData: linkTree,
// blockNode: true,
});
// 新增边界
const handleOk = (res) => {
const params = {
...res,
linkOrgVoList: [
{
linkOrgId: res.orgId,
point: res.point,
type: 1, //1子集 2 关联
},
],
orgId: currentBoundaryRecord.value.orgId || '',
};
http.post(enterPrise.link, params).then(() => {
treeAdd.value?.toggle();
NsMessage.success('操作成功');
getBoundaryTree({
orgId: currentBoundaryRecord.value.orgId,
orgName: currentBoundaryRecord.value.orgName,
});
});
};
2024-06-07 15:11:04 +08:00
const borderAdd = () => {
treeAddVisible.value = true;
treeAdd.value?.toggle();
};
const borderAddSon = () => {
treeAddVisible.value = true;
};
const editTree = (title: any, key: any) => {
console.log(title, 'title');
console.log(key, 'key');
};
2024-06-12 16:41:30 +08:00
const deleteTree = (node: any) => {
console.log(node, 'node');
NsModal.confirm({
2024-06-07 15:11:04 +08:00
title: '是否确定删除',
content: createVNode('div', { style: 'color:red;' }, ''),
onOk() {
2024-06-12 16:41:30 +08:00
const flag = !!node?.children?.length;
if (flag) {
NsMessage.error('请先删除子集');
return;
}
2024-06-07 15:11:04 +08:00
// http
// .post('/api/parking_merchant/objs/gateInfo/delete', {
// uuid: record.uuid,
// })
// .then((res) => {
// mainRef.value.nsTableRef.reload();
// });
},
onCancel() {
console.log('Cancel');
},
class: 'test',
});
};
const onSearch = () => {
console.log(searchValue.value);
};
</script>
2024-06-12 16:41:30 +08:00
<style lang="less" scoped>
.nodeDelete {
// display: none;
margin-left: 40px;
}
.boundaryTree {
background-color: red !important;
}
:deep(.ant-tree) {
background-color: red !important;
// &:hover {
.nodeDelete {
display: block;
}
// }
}
</style>