Commit 65e1ffce authored by lwy's avatar lwy

fix(用户管理):修复配置制造厂,配置事业部,新建管理员功能

parent ce8a94ec
......@@ -127,6 +127,24 @@ export function updateAuthRole(data) {
})
}
// 配置制造厂
export function updateUserFactory(data) {
return request({
url: '/system/user/addUserFactory',
method: 'put',
params: data,
})
}
// 配置制造厂
export function updateUserUnit(data) {
return request({
url: '/system/user/addUserUnit',
method: 'put',
params: data,
})
}
// 查询部门下拉树结构
export function deptTreeSelect() {
return request({
......
......@@ -94,10 +94,10 @@
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery"
<el-button type="primary" class="btn-A" icon="Search" @click="handleQuery"
>搜索</el-button
>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
<el-button class="btn-B" icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
......@@ -105,6 +105,7 @@
<el-button
v-hasPermi="['system:user:add']"
style="float: right;margin: 12px 0"
class="btn-A"
type="primary"
plain
icon="Plus"
......@@ -257,7 +258,7 @@
v-if="scope.row.userType !== '00'"
type="primary"
v-hasPermi="['system:user:edit']"
@click="divsionDialog = true"
@click="openDivsionDialog(scope.row)"
>配置事业部</el-button>
<el-button
v-hasPermi="['system:user:edit']"
......@@ -277,14 +278,15 @@
@pagination="getList"
/>
</el-col>
<!--事业部 出来再改-->
<!--配置事业部-->
<el-dialog v-model="divsionDialog" title="配置事业部" width="600px" append-to-body>
<el-form ref="userRef" :model="form" label-width="80px">
<el-form-item>
<el-form-item label="事业部" prop="unitNames">
<el-checkbox-group v-model="selecteDivsions">
<div style="display: flex; flex-wrap: wrap;">
<div v-for="(divsion, index) in allDivsions" :key="index" style="width: 33%; margin-bottom: 10px;">
<el-checkbox :label="divsion">{{ divsion }}</el-checkbox>
<div v-for="(businessUnit) in allDivsions" :key="businessUnit" style="width: 33%; margin-bottom: 10px;">
<el-checkbox :value="businessUnit.id">{{ businessUnit.name }}</el-checkbox>
</div>
</div>
</el-checkbox-group>
......@@ -293,7 +295,7 @@
<template #footer>
<span class="dialog-footer">
<el-button @click="cancel">取 消</el-button>
<el-button type="primary" @click="submitForm">保 存</el-button>
<el-button type="primary" @click="submitUnit">保 存</el-button>
</span>
</template>
</el-dialog>
......@@ -301,12 +303,12 @@
<!-- 配置制造工厂 -->
<el-dialog v-model="dialogFactory" title="配置制造工厂" width="600px" append-to-body>
<el-form ref="userRef" :model="form" label-width="80px">
<el-form-item label="制造工厂" prop="factoryName">
<el-form-item label="制造工厂" prop="factoryNames">
<el-checkbox-group v-model="selectedFactories">
<div style="display: flex; flex-wrap: wrap;">
<div v-for="(factory, index) in allFactories" :key="index" style="width: 33%; margin-bottom: 10px;">
<div v-for="(factory) in allFactories" :key="factory.id" style="width: 33%; margin-bottom: 10px;">
<!-- 在 el-checkbox 标签中 -->
<el-checkbox :label="factory">{{ factory }}</el-checkbox>
<el-checkbox :value="factory.id"> {{ factory.name }}</el-checkbox>
</div>
</div>
</el-checkbox-group>
......@@ -315,7 +317,7 @@
<template #footer>
<span class="dialog-footer">
<el-button @click="cancel">取 消</el-button>
<el-button type="primary" @click="submitForm">保 存</el-button>
<el-button type="primary" @click="submitFactory">保 存</el-button>
</span>
</template>
</el-dialog>
......@@ -348,12 +350,19 @@
maxlength="30"
/>
</el-form-item>
<!--事业部数据出来后修改-->
<el-form-item label="所属事业部" prop="divsion">
<el-input
v-model="form.divsion"
placeholder="请输入事业部"
maxlength="30"/>
<el-form-item label="所属事业部" prop="divsions">
<el-select
v-model="form.divsions"
placeholder="请选择"
multiple
>
<el-option
v-for="item in allDivsions"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="联系电话" prop="phonenumber">
<el-input
......@@ -362,17 +371,6 @@
maxlength="11"
/>
</el-form-item>
<el-form-item
v-if="form.userId == undefined"
label="用户名称"
prop="userName"
>
<el-input
v-model="form.userName"
placeholder="请输入用户名称"
maxlength="30"
/>
</el-form-item>
<el-form-item
label="用户密码"
prop="password"
......@@ -399,8 +397,8 @@
v-for="dict in sys_user_status"
:key="dict.value"
:value="dict.value"
>{{ dict.label }}</el-radio
>
>{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注">
......@@ -480,7 +478,10 @@ import {
updateUser,
addUser,
deptTreeSelect,
updateUserFactory,
updateUserUnit
} from '@/api/system/user'
import { getAllBusinessUnitName } from "@/api/system/basicdata/businessunit.js";
import { Splitpanes, Pane } from 'splitpanes'
import 'splitpanes/dist/splitpanes.css'
import { getAllFactoryName } from "@/api/system/factory";
......@@ -495,6 +496,7 @@ const { sys_normal_disable, sys_user_sex, sys_user_status, sys_user_type } = pro
'sys_user_status',
'sys_user_type'
)
const dialogFactory = ref(false)
const divsionDialog = ref(false)
// 选中的工厂列表
......@@ -518,6 +520,11 @@ const enabledDeptOptions = ref(undefined)
const initPassword = ref(undefined)
const postOptions = ref([])
const roleOptions = ref([])
const currentUserId = ref(''); // 当前行用户ID
const allDivsions = ref([]);
// 所有可选的工厂列表
const allFactories = ref([])
/*** 用户导入参数 */
const upload = reactive({
......@@ -549,6 +556,7 @@ const columns = ref([
const data = reactive({
form: {},
queryParams: {
divsions: [], //新建管理员所需事业部
pageNum: 1,
pageSize: 10,
userName: null,
......@@ -558,7 +566,7 @@ const data = reactive({
},
rules: {
userName: [
{ required: true, message: '用户名不能为空', trigger: 'blur' },
{ required: true, message: '用户名不能为空', trigger: 'blur' },
{
min: 2,
max: 20,
......@@ -567,7 +575,7 @@ const data = reactive({
},
],
nickName: [
{ required: true, message: '用户昵称不能为空', trigger: 'blur' },
{ required: true, message: '用户姓名不能为空', trigger: 'blur' },
],
password: [
{ required: true, message: '用户密码不能为空', trigger: 'blur' },
......@@ -601,10 +609,8 @@ const data = reactive({
})
const { queryParams, form, rules } = toRefs(data)
// 所有可选的工厂列表
const allFactories = ref([])
// 所有可选的角色
const allRoles = ref([])
const isEditMode = computed(() => {
return title.value === "编辑";
});
......@@ -620,49 +626,90 @@ watch(deptName, (val) => {
proxy.$refs['deptTreeRef'].filter(val)
})
// 所有可选的事业部
const allDivsions = ref([
'奇瑞', '星途', '智界', '捷途', 'iCAR'
]);
watch(() => form.value.divsion, (newVal) => {
try {
const divsionObj = JSON.parse(newVal || '{}');
selecteDivsions.value = Object.values(factoryObj);
} catch (e) {
selecteDivsions.value = [];
}
}, { immediate: true });
// 打开配置制造工厂对话框
function openFactoryDialog(row) {
dialogFactory.value = true;
currentUserId.value = row.userId;
// 直接使用当前行的 factoryName(假设是数组)
selectedFactories.value = row.factoryName ? row.factoryName.split(',') : [];
const factoryNames = (row.factoryNames || '').split('、').map(name => name.trim());
const selectedIds = factoryNames.map(name => {
const factory = allFactories.value.find(f => f.name === name);
return factory?.id;
}).filter(id => id !== undefined);
selectedFactories.value = selectedIds;
}
// 解析 factoryName(假设存储为 JSON 字符串数组)
// 监听选中的工厂变化,更新表单数据
watch(selectedFactories, (newVal) => {
form.value.factoryNames = JSON.stringify(newVal); // 存储为 JSON 字符串
// 生成名称字符串
// 当selectedFactories发生变化时,从allFactories中过滤出对应工厂名称,并组合成一个名称字符串
const selectedNames = allFactories.value
.filter(factory => newVal.includes(factory.id))
.map(factory => factory.name)
.join(',');
form.value.factoryNames = selectedNames;
// 可选:存储ID数组
form.value.factoryIds = newVal;
}, { deep: true });
// 获取工厂数据的方法
const fetchFactories = async () => {
try {
const response = await getAllFactoryName();
// 提取factoryName字段
allFactories.value = response.data.map(item => item.factoryName);
allFactories.value = response.data.map(item => ({
id: item.id.toString(),
name: item.factoryName
}));
} catch (error) {
console.error('获取工厂列表失败:', error);
}
};
// 获取角色的方法
/*const fetchRoles = async () => {
const response = await listRole();
allRoles.value = response.data.map(item => item.roleName);
};*/
//获取所有事业部名称的方法
const fetchBusinessUnits = async () => {
try {
const response = await getAllBusinessUnitName();
allDivsions.value = response.data.map(item => ({
id: item.id.toString(),
name: item.businessUnitName
}));
} catch (error) {
console.error('获取事业部列表失败:', error);
}
};
//打开分配事业部对话框
function openDivsionDialog(row) {
divsionDialog.value = true;
currentUserId.value = row.userId;
const unitNames = (row.unitNames || '').split('、').map(name => name.trim());
// 根据单位名称数组转换并过滤出对应的单位ID数组
const selectedUnitIds = unitNames.map(name => {
// 在所有划分中查找与当前名称匹配的业务单位
const businessUnit = allDivsions.value.find(f => f.name === name);
// 返回找到的业务单位的ID,如果未找到则返回undefined
return businessUnit?.id;
}).filter(id => id !== undefined);
// 过滤掉未找到的单位ID,确保结果数组中仅包含有效的单位ID
selecteDivsions.value = selectedUnitIds;
}
watch(selecteDivsions, (newVal) => {
// 生成名称字符串
const selectedUnitNames = allDivsions.value
.filter(divsion => newVal.includes(divsion.id))
.map(divsion => divsion.name)
.join(',');
form.value.unitNames = selectedUnitNames;
// 可选:存储ID数组
form.value.unitIds = newVal;
}, { deep: true });
/** 查询用户列表 */
function getList() {
......@@ -856,6 +903,7 @@ function submitFileForm() {
/** 重置操作表单 */
function reset() {
form.value = {
divsions: [],
userId: null,
deptId: null,
userName: null,
......@@ -937,8 +985,54 @@ function submitForm() {
}
})
}
/** 提交制造厂按钮 */
function submitFactory() {
proxy.$refs['userRef'].validate((valid) => {
if (valid) {
const formData = new URLSearchParams();
formData.append('userId', currentUserId.value);
selectedFactories.value.forEach((id) => {
formData.append('factoryIds[]', id);
});
updateUserFactory(formData)
.then(() => {
proxy.$modal.msgSuccess('配置成功');
dialogFactory.value = false;
getList();
})
.catch(() => {
proxy.$modal.msgError('配置失败,请重试');
});
}
})
}
/** 提交事业部按钮 */
function submitUnit() {
proxy.$refs['userRef'].validate((valid) => {
if (valid) {
const formData = new URLSearchParams();
formData.append('userId', currentUserId.value);
selecteDivsions.value.forEach((id) => {
formData.append('unitIds[]', id);
});
updateUserUnit(formData)
.then(() => {
proxy.$modal.msgSuccess('配置成功');
divsionDialog.value = false;
getList();
})
.catch(() => {
proxy.$modal.msgError('配置失败,请重试');
});
}
})
}
onMounted(() => {
fetchFactories();
fetchBusinessUnits();
//fetchRoles();
});
getDeptTree()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment