| | |
| | | </el-dialog> |
| | | |
| | | <!-- 新增:用户管理分公司配置对话框 --> |
| | | <el-dialog title="配置管理分公司" :visible.sync="branchDialog.open" width="500px" append-to-body> |
| | | <el-form label-width="100px"> |
| | | <el-form-item label="可管理分公司"> |
| | | <el-dialog title="配置管理分公司" :visible.sync="branchDialog.open" width="520px" append-to-body> |
| | | <el-form label-width="100px" v-loading="branchDialog.loading"> |
| | | <el-form-item label="已关联分公司"> |
| | | <div style="margin-bottom:8px;color:#666;font-size:12px;">OA自动关联(只读):</div> |
| | | <div> |
| | | <el-tag v-for="bc in branchDialog.companies" :key="bc.deptId" type="info" size="small" style="margin-right:6px;margin-bottom:6px">{{ bc.deptName }}</el-tag> |
| | | <span v-if="branchDialog.companies.length === 0" style="color:#999">暂无分公司</span> |
| | | <el-tag v-for="bc in branchDialog.companies" :key="'oa-'+bc.deptId" type="success" size="small" style="margin-right:6px;margin-bottom:6px">{{ bc.deptName }}</el-tag> |
| | | <span v-if="branchDialog.companies.length === 0" style="color:#999;font-size:12px">无OA自动关联</span> |
| | | </div> |
| | | </el-form-item> |
| | | <el-form-item label="手动添加"> |
| | | <div style="margin-bottom:6px;color:#666;font-size:12px;">选择需要额外添加的分公司:</div> |
| | | <el-checkbox-group v-model="branchDialog.selectedDeptIds"> |
| | | <el-checkbox |
| | | v-for="branch in branchDialog.allBranches" |
| | | :key="branch.deptId" |
| | | :label="branch.deptId" |
| | | style="display:block;margin-bottom:4px;" |
| | | >{{ branch.deptName }}</el-checkbox> |
| | | </el-checkbox-group> |
| | | <div v-if="branchDialog.allBranches.length === 0" style="color:#999;font-size:12px">暂无分公司数据</div> |
| | | </el-form-item> |
| | | </el-form> |
| | | <div slot="footer" class="dialog-footer"> |
| | | <el-button type="primary" @click="submitBranchCompanies" :loading="branchDialog.loading">保 存</el-button> |
| | | <el-button @click="branchDialog.open = false">关 闭</el-button> |
| | | </div> |
| | | </el-dialog> |
| | |
| | | |
| | | <script> |
| | | import { listUser, getUser, delUser, addUser, updateUser, resetUserPwd, changeUserStatus, deptTreeSelect } from "@/api/system/user"; |
| | | import { updateUserBranch } from "@/api/system/user"; |
| | | import { getToken } from "@/utils/auth"; |
| | | import Treeselect from "@riophae/vue-treeselect"; |
| | | import "@riophae/vue-treeselect/dist/vue-treeselect.css"; |
| | | import { Splitpanes, Pane } from "splitpanes"; |
| | | import "splitpanes/dist/splitpanes.css"; |
| | | import request from "@/utils/request"; |
| | | import { listDept, listBranchByUser } from "@/api/system/dept"; |
| | | import { listDept, listBranchByUser, listAllBranches } from "@/api/system/dept"; |
| | | |
| | | export default { |
| | | name: "User", |
| | |
| | | branchDialog: { |
| | | open: false, |
| | | userId: null, |
| | | deptOptions: [], |
| | | allBranches: [], |
| | | selectedDeptIds: [], |
| | | companies: [] |
| | | companies: [], |
| | | loading: false |
| | | }, |
| | | // 基于 oa_order_class 计算的分公司列表(只读展示) |
| | | userBranchCompanies: [] |
| | |
| | | handleManageBranch(row) { |
| | | const userId = row.userId; |
| | | this.branchDialog.userId = userId; |
| | | // 加载分公司列表(OA自动控制,只读展示) |
| | | listBranchByUser(userId).then(res => { |
| | | const list = res.data || []; |
| | | this.branchDialog.companies = (list || []).map(d => ({ deptId: d.deptId, deptName: d.deptName })); |
| | | this.branchDialog.companies = []; |
| | | this.branchDialog.allBranches = []; |
| | | this.branchDialog.selectedDeptIds = []; |
| | | this.branchDialog.loading = true; |
| | | this.branchDialog.open = true; |
| | | // 并行加载:当前用户OA关联分公司 + 所有分公司列表 |
| | | const p1 = listBranchByUser(userId).then(res => { |
| | | return (res.data || []).map(d => ({ deptId: d.deptId, deptName: d.deptName })); |
| | | }); |
| | | const p2 = listAllBranches().then(res => { |
| | | return res.data || []; |
| | | }); |
| | | Promise.all([p1, p2]).then(([oaCompanies, allBranches]) => { |
| | | this.branchDialog.companies = oaCompanies; |
| | | this.branchDialog.allBranches = allBranches; |
| | | // 初始化已选:从 userList 中找到该用户的 oaOrderClass,匹配分公司 |
| | | const userRow = (this.userList || []).find(u => u.userId === userId); |
| | | if (userRow && userRow.oaOrderClass) { |
| | | const codes = userRow.oaOrderClass.split(',').map(s => s.trim()).filter(s => s); |
| | | const codeSet = new Set(codes); |
| | | const selected = allBranches |
| | | .filter(d => { |
| | | return (d.serviceOrderClass && codeSet.has(d.serviceOrderClass.trim())) |
| | | || (d.dispatchOrderClass && codeSet.has(d.dispatchOrderClass.trim())); |
| | | }) |
| | | .map(d => d.deptId); |
| | | this.branchDialog.selectedDeptIds = selected; |
| | | } |
| | | this.branchDialog.loading = false; |
| | | }).catch(() => { |
| | | this.$modal.msgError('加载分公司配置失败'); |
| | | this.branchDialog.loading = false; |
| | | }); |
| | | }, |
| | | /** 保存分公司配置 */ |
| | | // 已取消保存,OA自动控制(仅只读展示) |
| | | // submitBranchCompanies() { |
| | | // const userId = this.branchDialog.userId; |
| | | // const deptIds = this.branchDialog.selectedDeptIds || []; |
| | | // // 保留占位,避免误调用 |
| | | // }, |
| | | submitBranchCompanies() { |
| | | this.branchDialog.loading = true; |
| | | updateUserBranch(this.branchDialog.userId, this.branchDialog.selectedDeptIds).then(() => { |
| | | this.$modal.msgSuccess('分公司配置保存成功'); |
| | | this.branchDialog.loading = false; |
| | | this.branchDialog.open = false; |
| | | this.getList(); |
| | | }).catch(() => { |
| | | this.$modal.msgError('保存分公司配置失败'); |
| | | this.branchDialog.loading = false; |
| | | }); |
| | | }, |
| | | /** 提交按钮 */ |
| | | submitForm: function() { |
| | | this.$refs["form"].validate(valid => { |