You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

631 lines
18 KiB

10 months ago
<!-- @format -->
<template>
10 months ago
<div class="main">
<div class="left">
<div class="top">
<div class="ns-table-title">关联企业</div>
10 months ago
<div>
10 months ago
<a-input-search
v-model:value="searchValue"
style="margin-bottom: 8px"
placeholder="请输入关联企业"
@search="onSearch" />
10 months ago
<a-tree
v-if="treeData?.length"
:tree-data="treeData"
defaultExpandAll
@select="handleSelect">
<template #title="data">
{{ data.orgInfo?.orgName }}
10 months ago
</template>
</a-tree>
</div>
</div>
10 months ago
<div class="top">
10 months ago
<div class="ns-table-title">关联部门</div>
10 months ago
<a-input-search
v-model:value="searchValue2"
style="margin-bottom: 8px"
placeholder="请输入关联部门"
@search="onSearch2" />
10 months ago
<a-tree
v-if="treeData2?.length"
:tree-data="treeData2"
defaultExpandAll
@select="handleSelect2">
<template #title="data">
{{ data.deptInfo?.deptName }}
10 months ago
</template>
</a-tree>
</div>
</div>
<div class="right">
10 months ago
<ns-view-list-table v-bind="tableConfig" :model="data" ref="mainRef" />
10 months ago
</div>
10 months ago
<a-drawer
10 months ago
:width="500"
10 months ago
:visible="visible"
:body-style="{ paddingBottom: '80px' }"
:footer-style="{ textAlign: 'right' }"
10 months ago
destroyOnClose
10 months ago
@close="onClose">
10 months ago
<ns-form
ref="formRef"
:schemas="formSchema"
:model="formData"
class="form"
:wrapperCol="{ span: 20 }"
formLayout="vertical" />
10 months ago
<span class="admin">用户权限</span>
10 months ago
<ns-view-list-table
v-bind="tableConfig2"
class="drawerTable"
:model="data"
:pagination="false"
rowKey="uuid" />
<template #footer>
<a-button style="margin-right: 8px" @click="onClose">取消</a-button>
10 months ago
<a-button :disabled="!dynamicDisabled" type="primary" @click="onEdit">确定</a-button>
10 months ago
</template>
10 months ago
</a-drawer>
10 months ago
10 months ago
<a-modal
title="用户信息"
10 months ago
:width="520"
10 months ago
:visible="addformvisible"
cancelText="取消"
@ok="handleOk"
@cancel="handleClose">
10 months ago
<ns-form
ref="modalFormRef"
:wrapperCol="{ span: 24 }"
:schemas="formSchema2"
:model="formData2"
formLayout="vertical" />
10 months ago
</a-modal>
</div>
10 months ago
</template>
<script lang="ts">
10 months ago
import { computed, createVNode, defineComponent, reactive, ref, watchEffect } from 'vue';
10 months ago
import { http } from '/nerv-lib/util/http';
10 months ago
import { NsMessage, NsModal } from '/nerv-lib/component';
10 months ago
import { formConfig, formConfig2 } from './config';
10 months ago
import { origanizemanage } from '/@/api/origanizemanage';
10 months ago
10 months ago
export default defineComponent({
name: 'OrderListIndex',
setup() {
const mainRef = ref();
const data = reactive({});
10 months ago
let formData = ref({});
10 months ago
let formData2 = ref({});
10 months ago
const formRef = ref();
10 months ago
const modalFormRef = ref();
10 months ago
const visible = ref(false);
10 months ago
const addformvisible = ref(false);
10 months ago
const searchValue = ref<string>('');
const searchValue2 = ref<string>('');
10 months ago
const disabled = ref(false);
const opMap: any = ref({
type: 'add',
fuc: () => {},
record: {},
});
watchEffect(() => {
disabled.value = opMap.value.type === 'edit';
});
const formSchema = formConfig(disabled);
10 months ago
const casData = ref([]);
const formSchema2 = formConfig2(casData);
10 months ago
const treeData = ref([]);
const treeData2 = ref([]);
const userAuthList = ref([]);
const orgId = JSON.parse(sessionStorage.getItem('userInfo')).orgId;
10 months ago
const dynamicDisabled = computed(() => {
return formRef.value?.validateResult && userAuthList.value?.length;
});
10 months ago
const fetch = (api, params = { orgId }) => {
return http.post(api, params);
};
// 企业树
10 months ago
const getOrgTree = (params?) => {
fetch(origanizemanage.queryOrgTree, params).then((res) => {
const otherOrg = res.data[0].listOrg;
// 特殊处理
if (res.data[0].orgInfo) {
treeData.value = res.data;
}
10 months ago
otherOrg?.map((item) => {
treeData.value.push({ orgInfo: item } as never);
});
});
10 months ago
};
getOrgTree();
10 months ago
// 部门树
fetch(origanizemanage.queryDeptTree).then((res) => {
treeData2.value = res.data;
});
10 months ago
10 months ago
const onSearch = () => {
console.log(searchValue.value);
10 months ago
getOrgTree({ orgName: searchValue.value, orgId });
10 months ago
};
const onSearch2 = () => {
console.log(searchValue2.value);
10 months ago
fetch(origanizemanage.queryDeptTree, { deptName: searchValue2.value, orgId }).then(
(res) => {
treeData2.value = res.data;
},
);
};
const tableFetch = (params) => {
10 months ago
console.log(mainRef.value);
10 months ago
tableConfig.value.params = {
10 months ago
...mainRef.value.params,
10 months ago
...params,
};
mainRef.value?.nsTableRef.reload();
10 months ago
};
const handleSelect = (selectedKeys: any, info: any) => {
10 months ago
fetch(origanizemanage.queryDeptTree, { orgId: info.node?.orgInfo.orgId }).then((res) => {
treeData2.value = res.data;
});
tableFetch({ orgId: info.node?.orgInfo.orgId });
10 months ago
};
10 months ago
10 months ago
const handleSelect2 = (selectedKeys: any, info: any) => {
10 months ago
tableFetch({ deptId: info.node?.deptInfo.deptId });
10 months ago
};
const onClose = () => {
visible.value = false;
10 months ago
formData.value = {};
userAuthList.value.splice(0);
10 months ago
};
10 months ago
10 months ago
const onEdit = () => {
10 months ago
formRef.value?.triggerSubmit().then(() => {
console.log(formData.value, 'formData.value');
10 months ago
if (!userAuthList.value.length) {
NsMessage.error('请添加用户权限');
return;
}
10 months ago
opMap.value.fuc &&
opMap.value.fuc({ ...formData.value, userRoleList: userAuthList.value, orgId });
10 months ago
});
10 months ago
};
const handleOk = () => {
10 months ago
if (casData.value?.length !== 3) {
NsMessage.error('未选择角色');
10 months ago
}
10 months ago
const currentOrgId = casData.value[0].value;
const isSameOrg = userAuthList.value.filter(({ orgId }) => {
return orgId === currentOrgId;
});
if (isSameOrg?.length) {
NsMessage.error('同一组织只能添加一个角色');
return;
}
console.log(casData.value, userAuthList.value, 'formData2.value');
10 months ago
const str = casData.value.map((item) => item?.label).join('/');
10 months ago
userAuthList.value.push({
10 months ago
deptRoleInfoList: str,
10 months ago
roleId: casData.value[2].value,
roleName: casData.value[2].label,
10 months ago
orgId: casData.value[0].value,
10 months ago
} as never);
handleClose();
10 months ago
};
const handleClose = () => {
addformvisible.value = false;
10 months ago
casData.value = [];
10 months ago
modalFormRef.value.reset();
10 months ago
};
10 months ago
const tableConfig = ref({
10 months ago
title: '用户管理',
api: origanizemanage.userList,
params: {
10 months ago
orgId,
10 months ago
},
10 months ago
headerActions: [
{
label: '新增',
name: 'userAdd',
10 months ago
type: 'primary',
handle: () => {
10 months ago
opMap.value.type = 'add';
setTimeout(() => {
formData.value = {
orgName: JSON.parse(sessionStorage.getItem('userInfo')).orgName,
};
userAuthList.value.splice(0);
});
opMap.value.fuc = (formData: any) => {
return http.post(origanizemanage.addUser, formData).then(() => {
10 months ago
mainRef.value?.nsTableRef.reload();
10 months ago
visible.value = false;
10 months ago
NsMessage.success('操作成功');
10 months ago
});
10 months ago
};
10 months ago
visible.value = true;
},
},
{
label: '导入',
type: 'primary',
name: 'userImport',
10 months ago
handle: () => {},
},
{
label: '模板下载',
type: 'primary',
name: 'userTemDownload',
10 months ago
handle: () => {},
},
{
label: '导出',
type: 'primary',
name: 'userExports',
10 months ago
},
{
label: '批量删除',
type: 'primary',
10 months ago
name: 'userBatchDel',
10 months ago
dynamicDisabled: (data: any) => {
return data.list.length === 0;
},
confirm: true,
isReload: true,
10 months ago
api: origanizemanage.batchDel,
dynamicParams: { userIds: 'userId[]' },
10 months ago
},
],
columns: [
{
title: '序号',
dataIndex: 'address',
customRender: (text: any) => {
return text.index + 1;
},
sorter: {
compare: (a, b) => a.address - b.address,
},
},
{
title: '账号',
10 months ago
dataIndex: 'accountNo',
10 months ago
sorter: {
10 months ago
compare: (a, b) => a.accountNo - b.accountNo,
10 months ago
},
},
{
title: '姓名',
10 months ago
dataIndex: 'realName',
10 months ago
sorter: {
10 months ago
compare: (a, b) => a.realName - b.realName,
10 months ago
},
},
{
title: '性别',
dataIndex: 'sex',
sorter: {
compare: (a, b) => a.name - b.name,
},
},
{
title: '手机号',
10 months ago
dataIndex: 'telephone',
10 months ago
},
{
title: '邮箱',
dataIndex: 'email',
},
{
title: '组织关系',
10 months ago
dataIndex: 'orgName',
10 months ago
},
{
10 months ago
title: '部门/角色',
10 months ago
dataIndex: 'userRoleInfos',
10 months ago
customRender: ({ value }) => {
if (!value) return '-';
return createVNode('div', {}, [
10 months ago
createVNode('span', {}, value[0]?.deptRoleInfoList),
10 months ago
value.length > 1 &&
createVNode(
'a',
{
onClick: () =>
NsModal.info({
icon: null,
10 months ago
content: createVNode('div', {
innerHTML: value.map((item) => item?.deptRoleInfoList).join('<br>'),
}),
10 months ago
}),
},
`+${value.length}`,
),
]);
10 months ago
},
10 months ago
},
{
title: '状态',
10 months ago
dataIndex: 'userStatus',
10 months ago
customRender: ({ value }) => ['正常', '冻结'][value],
10 months ago
},
],
columnActions: {
title: '操作',
actions: [
{
label: '编辑',
name: 'userEdit',
10 months ago
// dynamicParams: 'uuid',
handle: (record: any) => {
10 months ago
userAuthList.value.splice(0);
setTimeout(() => {
formData.value = record;
userAuthList.value.push(...record.userRoleInfos);
}, 10);
10 months ago
opMap.value.type = 'edit';
opMap.value.fuc = (formData: any) => {
return http.post(origanizemanage.editUser, formData).then(() => {
10 months ago
mainRef.value?.nsTableRef.reload();
visible.value = false;
NsMessage.success('操作成功');
});
10 months ago
};
10 months ago
visible.value = true;
},
},
{
label: '冻结',
10 months ago
name: 'userFrozen',
confirm: true,
defaultParams: { userStatus: 1 },
dynamicParams: 'userId',
isReload: true,
10 months ago
ifShow: ({ userStatus }) => userStatus === 0,
api: origanizemanage.frozen,
},
{
label: '解冻',
name: 'userUnFrozen',
confirm: true,
defaultParams: { userStatus: 0 },
dynamicParams: 'userId',
ifShow: ({ userStatus }) => userStatus === 1,
isReload: true,
10 months ago
api: origanizemanage.frozen,
10 months ago
},
{
label: '重置密码',
10 months ago
name: 'userCodeReset',
confirm: true,
handle: ({ userId }: any) => {
http
10 months ago
.post(origanizemanage.resetPwd, { userId, password: 123456 })
10 months ago
.then(() => NsModal.success({ content: '密码重置成功,初始密码123456' }));
10 months ago
},
},
{
label: '删除',
10 months ago
name: 'userDelete',
dynamicParams: 'userId',
10 months ago
confirm: true,
10 months ago
isReload: true,
api: origanizemanage.del,
10 months ago
},
],
},
formConfig: {
schemas: [
{
10 months ago
field: 'accountNo',
10 months ago
label: '账号名',
component: 'NsInput',
componentProps: {
placeholder: '请输入账号名',
10 months ago
maxLength: 30,
10 months ago
},
},
{
10 months ago
field: 'realName',
10 months ago
label: '姓名',
component: 'NsInput',
componentProps: {
placeholder: '请输入姓名',
10 months ago
maxLength: 30,
10 months ago
},
},
{
10 months ago
field: 'telephone',
10 months ago
label: '手机号',
component: 'NsInput',
componentProps: {
placeholder: '请输入手机号',
10 months ago
maxLength: 11,
10 months ago
},
},
{
field: 'email',
label: '邮箱',
component: 'NsInput',
componentProps: {
placeholder: '请输入邮箱',
10 months ago
maxLength: 30,
10 months ago
},
},
{
10 months ago
field: 'userStatus',
10 months ago
label: '用户状态',
component: 'NsSelect',
componentProps: {
placeholder: '请选择',
10 months ago
allowClear: true,
10 months ago
options: [
{
label: '正常',
10 months ago
value: 0,
10 months ago
},
{
label: '冻结',
10 months ago
value: 1,
10 months ago
},
],
},
},
],
params: {},
},
// pagination: { defaultPageSize: 10 },
10 months ago
rowKey: 'userId',
10 months ago
});
10 months ago
const tableConfig2 = {
10 months ago
// api: {
// url: '/carbon_emission/device/getGatewayList',
// method: 'post',
// },
10 months ago
value: userAuthList.value,
10 months ago
rowSelection: null,
headerActions: [
{
label: '新增',
name: 'userAdd',
10 months ago
type: 'primary',
handle: () => {
addformvisible.value = true;
},
},
],
columns: [
{
title: '角色信息',
10 months ago
dataIndex: 'userRoleList',
customRender: ({ record }) => {
if (record) {
10 months ago
// const res = record.userAuthList.reduce((pre, cur) => {
// pre.push(cur.label);
// return pre;
// }, []);
return record.deptRoleInfoList;
10 months ago
}
return '-';
},
10 months ago
},
],
columnActions: {
title: '操作',
actions: [
{
label: '删除',
name: 'userAdd',
10 months ago
confirm: true,
10 months ago
handle: (record: any, name: any, reload: any) => {
10 months ago
const id = record.roleId;
console.log(userAuthList.value, id);
let idx = 0;
userAuthList.value?.some((item, index) => {
idx = index;
if (item.roleId === id) return true;
});
userAuthList.value.splice(idx, 1);
10 months ago
},
},
],
},
};
return {
10 months ago
formRef,
10 months ago
tableConfig,
tableConfig2,
data,
mainRef,
visible,
10 months ago
addformvisible,
10 months ago
formSchema,
10 months ago
formSchema2,
10 months ago
formData,
10 months ago
formData2,
10 months ago
treeData,
treeData2,
searchValue,
searchValue2,
10 months ago
handleSelect,
handleSelect2,
onClose,
onEdit,
10 months ago
onSearch,
onSearch2,
handleOk,
handleClose,
10 months ago
dynamicDisabled,
modalFormRef,
10 months ago
};
},
});
</script>
10 months ago
<style lang="less" scoped>
10 months ago
.main {
display: flex;
}
.left {
10 months ago
width: 350px;
10 months ago
max-height: calc(100vh - 96px);
overflow: hidden;
border-right: 16px solid rgb(229, 235, 240);
10 months ago
min-width: fit-content;
10 months ago
.top:first-child {
border-bottom: 16px solid #e5ebf0;
}
10 months ago
}
10 months ago
.right {
flex: 1;
10 months ago
min-width: 0;
10 months ago
}
10 months ago
.top {
10 months ago
height: 50%;
10 months ago
// border-bottom: 5px solid rgb(229, 235, 240);
overflow-y: auto;
10 months ago
}
10 months ago
.ns-table-title {
10 months ago
text-align: left;
10 months ago
// height: 46px;
10 months ago
line-height: 46px;
font-size: 18px;
font-weight: bold;
padding-left: 16px;
}
.admin {
text-align: left;
height: 42px;
line-height: 42px;
font-size: 16px;
font-weight: bold;
user-select: text;
width: calc(100% + 32px);
}
10 months ago
.drawerTable {
:deep(.ns-table-container),
:deep(.ns-table-main) {
border-top: 0;
padding: 0;
}
10 months ago
}
</style>