8388a55481
Co-authored-by: Cursor <cursoragent@cursor.com>
1667 lines
54 KiB
Vue
1667 lines
54 KiB
Vue
<template>
|
||
<basic-container>
|
||
<avue-crud
|
||
:option="option"
|
||
:table-loading="loading"
|
||
:data="data"
|
||
ref="crud"
|
||
v-model="form"
|
||
:permission="permissionList"
|
||
:before-open="beforeOpen"
|
||
:before-close="beforeClose"
|
||
@row-del="rowDel"
|
||
@row-update="rowUpdate"
|
||
@row-save="rowSave"
|
||
@search-change="searchChange"
|
||
@search-reset="searchReset"
|
||
@selection-change="selectionChange"
|
||
@current-change="currentChange"
|
||
@size-change="sizeChange"
|
||
@refresh-change="refreshChange"
|
||
@on-load="onLoad"
|
||
@tree-load="treeLoad"
|
||
>
|
||
<template #menu-left>
|
||
<el-button
|
||
type="danger"
|
||
icon="el-icon-delete"
|
||
v-if="permission.dept_delete"
|
||
plain
|
||
@click="handleDelete"
|
||
>删除
|
||
</el-button>
|
||
<el-button
|
||
type="primary"
|
||
plain
|
||
:loading="oaSyncLoading"
|
||
v-if="isAdministrator"
|
||
@click="handleOaOrgFullSync"
|
||
>全量同步
|
||
</el-button>
|
||
<el-button
|
||
type="primary"
|
||
plain
|
||
:loading="oaSyncLoading"
|
||
v-if="isAdministrator"
|
||
@click="handleOaOrgIncrementalSync"
|
||
>增量同步
|
||
</el-button>
|
||
</template>
|
||
<template #menu="scope">
|
||
<el-link
|
||
type="primary"
|
||
@click.stop="handleAdd(scope.row, scope.index)"
|
||
v-if="isAdministrator"
|
||
>新增子项
|
||
</el-link>
|
||
</template>
|
||
<template #deptCategory="{ row }">
|
||
<el-tag>{{ row.deptCategoryName || getDeptCategoryLabel(row.deptCategory) }}</el-tag>
|
||
</template>
|
||
<template #status="{ row }">
|
||
<el-tag :type="Number(row.status) === 1 ? 'success' : 'info'" class="status-text">
|
||
{{ Number(row.status) === 1 ? '启用' : '停用' }}
|
||
</el-tag>
|
||
</template>
|
||
</avue-crud>
|
||
<el-dialog v-model="carrierDialogVisible" title="选择承运商" width="1100px" append-to-body>
|
||
<el-form :inline="true" :model="carrierQuery" class="carrier-search-form">
|
||
<el-form-item label="名称">
|
||
<el-input v-model="carrierQuery.fullName" placeholder="请输入承运商名称" clearable />
|
||
</el-form-item>
|
||
<el-form-item label="准入类型">
|
||
<el-select v-model="carrierQuery.accessType" placeholder="全部" clearable>
|
||
<el-option label="临时" value="temporary" />
|
||
<el-option label="正式" value="formal" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="审批状态">
|
||
<el-select v-model="carrierQuery.approvalStatus" placeholder="全部" clearable>
|
||
<el-option label="草稿" value="draft" />
|
||
<el-option label="审核中" value="reviewing" />
|
||
<el-option label="审核通过" value="approved" />
|
||
<el-option label="审核不通过" value="rejected" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="状态">
|
||
<el-select v-model="carrierQuery.status" placeholder="全部" clearable>
|
||
<el-option label="启用" :value="1" />
|
||
<el-option label="停用" :value="2" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button type="primary" @click="searchCarrier">搜索</el-button>
|
||
<el-button @click="resetCarrierQuery">清空</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
<el-table :data="carrierData" border stripe height="420" @row-dblclick="selectCarrier">
|
||
<el-table-column prop="customerCode" label="客商编号" min-width="130" />
|
||
<el-table-column prop="shortName" label="客商简称" min-width="140" />
|
||
<el-table-column prop="fullName" label="客商名称" min-width="200" show-overflow-tooltip />
|
||
<el-table-column prop="customerType" label="客户类型" min-width="120" />
|
||
<el-table-column prop="customerNature" label="客户性质" min-width="120" />
|
||
<el-table-column prop="unifiedCreditCode" label="统一信用代码" min-width="180" />
|
||
<el-table-column prop="deptName" label="所属组织" min-width="150" />
|
||
<el-table-column prop="accessType" label="准入类型" min-width="110">
|
||
<template #default="{ row }">{{ formatAccessType(row.accessType) }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="approvalStatus" label="审批状态" min-width="120">
|
||
<template #default="{ row }">{{ formatApprovalStatus(row.approvalStatus) }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="currentNode" label="当前节点" min-width="130" />
|
||
<el-table-column prop="currentProcessor" label="当前处理人" min-width="130" />
|
||
<el-table-column prop="approvedTime" label="审核通过时间" min-width="170" sortable />
|
||
<el-table-column prop="status" label="状态" width="90">
|
||
<template #default="{ row }">{{ Number(row.status) === 1 ? '启用' : '停用' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" width="90" fixed="right">
|
||
<template #default="{ row }">
|
||
<el-link type="primary" @click="selectCarrier(row)">选择</el-link>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<div class="carrier-pagination">
|
||
<el-pagination
|
||
v-model:current-page="carrierPage.current"
|
||
v-model:page-size="carrierPage.size"
|
||
:total="carrierPage.total"
|
||
:page-sizes="[10, 20, 50]"
|
||
layout="total, sizes, prev, pager, next"
|
||
@current-change="loadCarrierList"
|
||
@size-change="handleCarrierSizeChange"
|
||
/>
|
||
</div>
|
||
</el-dialog>
|
||
<el-dialog
|
||
v-model="oaSyncVisible"
|
||
width="480px"
|
||
append-to-body
|
||
:close-on-click-modal="false"
|
||
:close-on-press-escape="!oaSyncRunning"
|
||
:show-close="!oaSyncRunning"
|
||
class="oa-sync-dialog"
|
||
@close="closeOaSyncDialog"
|
||
>
|
||
<template #header>
|
||
<span class="dialog-title">{{ oaSyncDialogTitle }}</span>
|
||
</template>
|
||
<div class="oa-sync-body">
|
||
<el-progress
|
||
:percentage="oaSyncPercent"
|
||
:status="oaSyncProgressStatus"
|
||
:stroke-width="12"
|
||
/>
|
||
<div class="oa-sync-meta" v-if="oaSyncStage === 'clear'">当前阶段:{{ oaSyncStageLabel }}</div>
|
||
<div class="oa-sync-meta" v-else>
|
||
当前阶段:{{ oaSyncStageLabel }}
|
||
<template v-if="oaSyncStage === 'department' && oaSyncProgress.companyTotal">
|
||
,公司 {{ oaSyncProgress.companyIndex || 0 }} / {{ oaSyncProgress.companyTotal }}
|
||
<template v-if="oaSyncProgress.companyOaId">(oaId={{ oaSyncProgress.companyOaId }})</template>
|
||
</template>
|
||
,第 {{ oaSyncProgress.current || 0 }} / {{ oaSyncTotalPage }} 页
|
||
</div>
|
||
<div class="oa-sync-stats">
|
||
<div class="oa-sync-stat">
|
||
<span class="oa-sync-stat__label">同步成功</span>
|
||
<span class="oa-sync-stat__value oa-sync-stat__value--success">{{ oaSyncProgress.synced }}</span>
|
||
</div>
|
||
<div class="oa-sync-stat">
|
||
<span class="oa-sync-stat__label">跳过</span>
|
||
<span class="oa-sync-stat__value oa-sync-stat__value--skip">{{ oaSyncProgress.skipped }}</span>
|
||
</div>
|
||
</div>
|
||
<div v-if="oaSyncProgress.dumpFilePath" class="oa-sync-meta">
|
||
原始数据 JSON:{{ oaSyncProgress.dumpFilePath }}
|
||
</div>
|
||
</div>
|
||
<template #footer>
|
||
<span class="dialog-footer">
|
||
<el-button v-if="oaSyncRunning" @click="cancelOaSync">取消</el-button>
|
||
<el-button v-else type="primary" @click="closeOaSyncDialog">关闭</el-button>
|
||
</span>
|
||
</template>
|
||
</el-dialog>
|
||
</basic-container>
|
||
</template>
|
||
|
||
<script>
|
||
import {
|
||
getLazyList,
|
||
remove,
|
||
update,
|
||
add,
|
||
getDept,
|
||
getDeptTree,
|
||
syncOaCompany,
|
||
syncOaDepartment,
|
||
clearNonTopDept,
|
||
} from '@/api/system/dept';
|
||
import { getLeaderList } from '@/api/system/user';
|
||
import { getDictionary } from '@/api/system/dictbiz';
|
||
import { getList as getCustomerArchiveList } from '@/api/vehicle/customer-archive';
|
||
import { mapGetters } from 'vuex';
|
||
import website from '@/config/website';
|
||
import func from '@/utils/func';
|
||
|
||
const escapeRegExp = value => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||
const ORGANIZATION_TYPE_DICT_CODE = 'organization_type';
|
||
/**
|
||
* 组织类型名称 → 字典数字键(兼容 dictKey 配成中文的情况)
|
||
* 与业务字典 organization_type 及历史别名对齐;优先仍以数字 dictKey 为准
|
||
*/
|
||
const ORGANIZATION_TYPE_CODE_BY_LABEL = {
|
||
集团: 1,
|
||
一级集团: 1,
|
||
公司: 2,
|
||
事业部: 2,
|
||
二级事业部: 2,
|
||
部门: 3,
|
||
分公司: 4,
|
||
三级分公司: 4,
|
||
物流园区: 5,
|
||
承运商: 6,
|
||
};
|
||
|
||
export default {
|
||
data() {
|
||
return {
|
||
form: {},
|
||
leaderOptions: [],
|
||
organizationTypeOptions: [],
|
||
parentDeptCode: '',
|
||
parentDept: null,
|
||
carrierDialogVisible: false,
|
||
carrierData: [],
|
||
carrierQuery: {
|
||
fullName: '',
|
||
accessType: '',
|
||
approvalStatus: '',
|
||
status: undefined,
|
||
},
|
||
carrierPage: {
|
||
current: 1,
|
||
size: 10,
|
||
total: 0,
|
||
},
|
||
selectionList: [],
|
||
query: {},
|
||
loading: true,
|
||
oaSyncLoading: false,
|
||
oaSyncVisible: false,
|
||
oaSyncRunning: false,
|
||
oaSyncCancelled: false,
|
||
oaSyncStatus: 'running',
|
||
oaSyncStage: 'company',
|
||
oaSyncMode: 'full',
|
||
oaSyncClearNonTop: false,
|
||
oaSyncController: null,
|
||
oaSyncProgress: {
|
||
current: 0,
|
||
size: 20,
|
||
total: 0,
|
||
synced: 0,
|
||
skipped: 0,
|
||
dumpFilePath: '',
|
||
companyOaId: '',
|
||
companyIndex: 0,
|
||
companyTotal: 0,
|
||
},
|
||
parentId: 0,
|
||
page: {
|
||
pageSize: 10,
|
||
currentPage: 1,
|
||
total: 0,
|
||
},
|
||
option: {
|
||
lazy: true,
|
||
tip: false,
|
||
simplePage: true,
|
||
searchShow: true,
|
||
searchMenuSpan: 24,
|
||
searchIcon: true,
|
||
searchIndex: 4,
|
||
searchMenuPosition: 'right',
|
||
tree: true,
|
||
rowKey: 'id',
|
||
border: true,
|
||
index: true,
|
||
selection: true,
|
||
viewBtn: true,
|
||
menuWidth: 320,
|
||
dialogWidth: 800,
|
||
dialogClickModal: false,
|
||
labelPosition: 'right',
|
||
labelWidth: 'auto',
|
||
// 禁用 Avue 列状态持久化,避免增列后表头/单元格错位
|
||
columnState: false,
|
||
column: [
|
||
{
|
||
label: '组织名称',
|
||
prop: 'deptName',
|
||
minWidth: 320,
|
||
align: 'left',
|
||
headerAlign: 'left',
|
||
order: 80,
|
||
search: true,
|
||
searchOrder: 3,
|
||
rules: [
|
||
{
|
||
required: true,
|
||
message: '请输入组织名称',
|
||
trigger: 'blur',
|
||
},
|
||
],
|
||
},
|
||
{
|
||
label: '组织编码',
|
||
prop: 'deptCode',
|
||
minWidth: 140,
|
||
order: 70,
|
||
maxlength: 30,
|
||
showWordLimit: true,
|
||
rules: [
|
||
{
|
||
validator: (rule, value, callback) => {
|
||
const deptCode = String(value || '').trim();
|
||
// 组织编码非必填,为空直接通过
|
||
if (!deptCode) {
|
||
callback();
|
||
return;
|
||
}
|
||
if (deptCode.length > 30) {
|
||
callback(new Error('组织编码不能超过30个字符'));
|
||
return;
|
||
}
|
||
const parentId = this.normalizeParentId(this.form?.parentId);
|
||
// 顶级组织不选择上级时,编码不依赖上级编码
|
||
if (!parentId) {
|
||
callback();
|
||
return;
|
||
}
|
||
if (!this.parentDept || String(this.parentDept.id) !== String(parentId)) {
|
||
this.loadParentDeptCode(parentId);
|
||
callback(new Error('正在加载上级组织编码,请稍后重试'));
|
||
return;
|
||
}
|
||
if (!this.parentDeptCode) {
|
||
callback(new Error('上级组织未配置组织编码,请先完善上级组织编码'));
|
||
return;
|
||
}
|
||
// 公司:GWWL+三位数字;部门:所属公司编码+三位数字;其他:上级编码+三位数字(中间不加-)
|
||
let expectedPrefix = this.parentDeptCode;
|
||
const category = Number(this.form?.deptCategory);
|
||
if (category === 2) {
|
||
expectedPrefix = 'GWWL';
|
||
} else if (category === 3 && this.form?.belongCompanyCode) {
|
||
expectedPrefix = String(this.form.belongCompanyCode).trim();
|
||
}
|
||
const pattern = new RegExp(`^${escapeRegExp(expectedPrefix)}\\d{3}$`);
|
||
if (!pattern.test(deptCode)) {
|
||
callback(new Error(`组织编码格式应为:${expectedPrefix}三位数字(不足补零,中间不加-)`));
|
||
return;
|
||
}
|
||
callback();
|
||
},
|
||
trigger: 'blur',
|
||
},
|
||
],
|
||
},
|
||
{
|
||
label: '组织简称',
|
||
prop: 'shortName',
|
||
minWidth: 140,
|
||
order: 60,
|
||
search: true,
|
||
searchOrder: 4,
|
||
},
|
||
{
|
||
label: '助记码',
|
||
prop: 'mnemonicCode',
|
||
minWidth: 120,
|
||
order: 50,
|
||
},
|
||
{
|
||
label: '拼音助记码',
|
||
prop: 'pinyinMnemonic',
|
||
minWidth: 140,
|
||
order: 45,
|
||
},
|
||
{
|
||
label: '组织类型',
|
||
type: 'select',
|
||
dicData: [],
|
||
dataType: 'number',
|
||
minWidth: 120,
|
||
order: 90,
|
||
prop: 'deptCategory',
|
||
slot: true,
|
||
change: ({ value }) => this.handleDeptCategoryChange(value),
|
||
rules: [
|
||
{
|
||
required: true,
|
||
message: '请选择组织类型',
|
||
trigger: 'change',
|
||
},
|
||
],
|
||
},
|
||
{
|
||
label: '负责人',
|
||
prop: 'leaderId',
|
||
minWidth: 120,
|
||
addDisplay: false,
|
||
editDisplay: false,
|
||
viewDisplay: false,
|
||
formatter: row => this.getLeaderValue(row.leaderId, 'realName'),
|
||
},
|
||
{
|
||
label: '联系电话',
|
||
prop: 'leaderPhone',
|
||
minWidth: 140,
|
||
addDisplay: false,
|
||
editDisplay: false,
|
||
viewDisplay: false,
|
||
formatter: row => this.getLeaderValue(row.leaderId, 'phone'),
|
||
},
|
||
{
|
||
label: '是否平台公司',
|
||
prop: 'isPlatformCompany',
|
||
type: 'select',
|
||
dicData: [
|
||
{ label: '否', value: 0 },
|
||
{ label: '是', value: 1 },
|
||
],
|
||
dataType: 'number',
|
||
value: 0,
|
||
width: 120,
|
||
order: 36,
|
||
search: true,
|
||
searchOrder: 2,
|
||
searchPlaceholder: '请选择是否平台公司',
|
||
formatter: row => (Number(row.isPlatformCompany) === 1 ? '是' : '否'),
|
||
change: ({ value }) => this.handlePlatformCompanyChange(value),
|
||
rules: [
|
||
{
|
||
required: true,
|
||
message: '请选择是否平台公司',
|
||
trigger: 'change',
|
||
},
|
||
],
|
||
},
|
||
{
|
||
label: '金蝶部门代码',
|
||
prop: 'kingdeeDeptCode',
|
||
minWidth: 140,
|
||
order: 35,
|
||
maxlength: 64,
|
||
showWordLimit: true,
|
||
// 仅平台公司维护/展示金蝶组织代码;非平台公司列表留空
|
||
addDisplay: false,
|
||
editDisplay: false,
|
||
viewDisplay: false,
|
||
formatter: row =>
|
||
Number(row.isPlatformCompany) === 1 ? String(row.kingdeeDeptCode || '').trim() : '',
|
||
rules: [
|
||
{
|
||
validator: (rule, value, callback) => {
|
||
const code = String(value || '').trim();
|
||
if (!code) {
|
||
callback();
|
||
return;
|
||
}
|
||
if (code.length > 64) {
|
||
callback(new Error('金蝶部门代码不能超过64个字符'));
|
||
return;
|
||
}
|
||
callback();
|
||
},
|
||
trigger: 'blur',
|
||
},
|
||
],
|
||
},
|
||
{
|
||
label: '是否业务部门',
|
||
prop: 'isBusinessDept',
|
||
type: 'select',
|
||
dicData: [
|
||
{ label: '否', value: 0 },
|
||
{ label: '是', value: 1 },
|
||
],
|
||
dataType: 'number',
|
||
value: 0,
|
||
width: 120,
|
||
order: 34,
|
||
search: true,
|
||
searchOrder: 1,
|
||
searchPlaceholder: '请选择是否业务部门',
|
||
formatter: row => (Number(row.isBusinessDept) === 1 ? '是' : '否'),
|
||
rules: [
|
||
{
|
||
required: true,
|
||
message: '请选择是否业务部门',
|
||
trigger: 'change',
|
||
},
|
||
],
|
||
},
|
||
{
|
||
label: '排序',
|
||
prop: 'sort',
|
||
type: 'input',
|
||
align: 'right',
|
||
width: 80,
|
||
order: 30,
|
||
change: ({ value }) => {
|
||
if (value === undefined || value === null || value === '') {
|
||
return;
|
||
}
|
||
const digits = String(value).replace(/\D/g, '');
|
||
if (String(value) !== digits) {
|
||
this.form.sort = digits;
|
||
}
|
||
},
|
||
rules: [
|
||
{
|
||
validator: (rule, value, callback) => {
|
||
if (value === '' || value === undefined || value === null) {
|
||
callback();
|
||
return;
|
||
}
|
||
if (!/^\d+$/.test(String(value).trim())) {
|
||
callback(new Error('排序只能输入数字'));
|
||
return;
|
||
}
|
||
callback();
|
||
},
|
||
trigger: ['blur', 'change'],
|
||
},
|
||
],
|
||
},
|
||
{
|
||
label: '状态',
|
||
prop: 'status',
|
||
width: 100,
|
||
slot: true,
|
||
addDisplay: false,
|
||
editDisplay: false,
|
||
viewDisplay: false,
|
||
},
|
||
{
|
||
label: '上级组织',
|
||
prop: 'parentId',
|
||
dicData: [],
|
||
type: 'tree',
|
||
hide: true,
|
||
addDisabled: false,
|
||
order: 100,
|
||
change: ({ value }) => this.handleParentChange(value),
|
||
props: {
|
||
label: 'title',
|
||
},
|
||
},
|
||
{
|
||
label: '所属租户',
|
||
prop: 'tenantId',
|
||
type: 'tree',
|
||
dicUrl: '/blade-system/tenant/select',
|
||
addDisplay: false,
|
||
editDisplay: false,
|
||
viewDisplay: website.tenantMode,
|
||
props: {
|
||
label: 'tenantName',
|
||
value: 'tenantId',
|
||
},
|
||
hide: true,
|
||
},
|
||
{
|
||
label: '机构全称',
|
||
prop: 'fullName',
|
||
hide: true,
|
||
addDisplay: false,
|
||
editDisplay: false,
|
||
},
|
||
{
|
||
label: '备注',
|
||
prop: 'remark',
|
||
type: 'textarea',
|
||
hide: true,
|
||
addDisplay: false,
|
||
editDisplay: false,
|
||
},
|
||
],
|
||
},
|
||
data: [],
|
||
};
|
||
},
|
||
created() {
|
||
// 清除可能错乱的表格列顺序/列状态缓存,避免新增列后表头/单元格错位
|
||
try {
|
||
const path = this.$route?.path || '/system/dept';
|
||
Object.keys(localStorage).forEach(key => {
|
||
if (
|
||
(key.startsWith('tms:table-column-order:') && key.includes(path)) ||
|
||
(key.startsWith('AVUE_COLUMN_STATE:') && key.includes('dept'))
|
||
) {
|
||
localStorage.removeItem(key);
|
||
}
|
||
});
|
||
} catch (error) {
|
||
// ignore storage errors
|
||
}
|
||
this.loadLeaderOptions();
|
||
this.loadOrganizationTypeOptions();
|
||
},
|
||
computed: {
|
||
...mapGetters(['userInfo', 'permission', 'isAdministrator']),
|
||
permissionList() {
|
||
return {
|
||
addBtn: this.validData(this.permission.dept_add, false),
|
||
viewBtn: this.validData(this.permission.dept_view, false),
|
||
delBtn: this.validData(this.permission.dept_delete, false),
|
||
editBtn: this.validData(this.permission.dept_edit, false),
|
||
};
|
||
},
|
||
ids() {
|
||
let ids = [];
|
||
this.selectionList.forEach(ele => {
|
||
ids.push(ele.id);
|
||
});
|
||
return ids.join(',');
|
||
},
|
||
oaSyncDialogTitle() {
|
||
const modeLabel = this.oaSyncMode === 'incremental' ? '增量同步' : '全量同步';
|
||
if (this.oaSyncStatus === 'done') {
|
||
return `${modeLabel}完成`;
|
||
}
|
||
if (this.oaSyncStatus === 'cancelled') {
|
||
return `已取消${modeLabel}`;
|
||
}
|
||
if (this.oaSyncStatus === 'error') {
|
||
return `${modeLabel}失败`;
|
||
}
|
||
return modeLabel;
|
||
},
|
||
oaSyncStageLabel() {
|
||
if (this.oaSyncStage === 'clear') {
|
||
return '清除非顶级组织';
|
||
}
|
||
return this.oaSyncStage === 'department' ? '同步部门' : '同步公司';
|
||
},
|
||
oaSyncTotalPage() {
|
||
const total = Number(this.oaSyncProgress.total) || 0;
|
||
const size = Number(this.oaSyncProgress.size) || 20;
|
||
if (total <= 0) {
|
||
return this.oaSyncProgress.current || 0;
|
||
}
|
||
return Math.max(1, Math.ceil(total / size));
|
||
},
|
||
oaSyncPercent() {
|
||
if (this.oaSyncStatus === 'done') {
|
||
return 100;
|
||
}
|
||
const totalPage = this.oaSyncTotalPage;
|
||
const current = Number(this.oaSyncProgress.current) || 0;
|
||
if (this.oaSyncStage === 'department') {
|
||
const companyTotal = Math.max(1, Number(this.oaSyncProgress.companyTotal) || 1);
|
||
const companyIndex = Math.max(1, Number(this.oaSyncProgress.companyIndex) || 1);
|
||
const companyBase = ((companyIndex - 1) / companyTotal) * 50;
|
||
const pageRatio = totalPage > 0 ? Math.min(1, current / totalPage) : 0;
|
||
const companyPagePercent = (pageRatio * 50) / companyTotal;
|
||
return Math.min(99, Math.round(50 + companyBase + companyPagePercent));
|
||
}
|
||
if (totalPage <= 0) {
|
||
return 0;
|
||
}
|
||
return Math.min(49, Math.round((current / totalPage) * 50));
|
||
},
|
||
oaSyncProgressStatus() {
|
||
if (this.oaSyncStatus === 'done') {
|
||
return 'success';
|
||
}
|
||
if (this.oaSyncStatus === 'error') {
|
||
return 'exception';
|
||
}
|
||
return undefined;
|
||
},
|
||
},
|
||
methods: {
|
||
handleOaOrgFullSync() {
|
||
this.startOaOrgSync({ clearNonTop: false, incremental: false });
|
||
},
|
||
handleOaOrgIncrementalSync() {
|
||
this.$confirm(
|
||
'增量同步仅拉取本地最大 OA 更新时间之后有变更的组织;不存在的新增,已存在且更新时间不一致的修改,一致的跳过。是否继续?',
|
||
'增量同步',
|
||
{
|
||
confirmButtonText: '确定',
|
||
cancelButtonText: '取消',
|
||
closeOnClickModal: false,
|
||
type: 'info',
|
||
}
|
||
)
|
||
.then(() => {
|
||
this.startOaOrgSync({ clearNonTop: false, incremental: true });
|
||
})
|
||
.catch(() => {});
|
||
},
|
||
startOaOrgSync({ clearNonTop = false, incremental = false } = {}) {
|
||
this.oaSyncLoading = true;
|
||
this.oaSyncVisible = true;
|
||
this.oaSyncRunning = true;
|
||
this.oaSyncCancelled = false;
|
||
this.oaSyncStatus = 'running';
|
||
this.oaSyncMode = incremental ? 'incremental' : 'full';
|
||
this.oaSyncClearNonTop = !!clearNonTop;
|
||
this.oaSyncStage = clearNonTop ? 'clear' : 'company';
|
||
this.oaSyncController = new AbortController();
|
||
this.oaSyncProgress = {
|
||
current: 0,
|
||
size: 20,
|
||
total: 0,
|
||
synced: 0,
|
||
skipped: 0,
|
||
dumpFilePath: '',
|
||
companyOaId: '',
|
||
companyIndex: 0,
|
||
companyTotal: 0,
|
||
};
|
||
this.runOaOrgSyncPages();
|
||
},
|
||
isOaSyncCanceledError(error) {
|
||
return (
|
||
this.oaSyncCancelled ||
|
||
error?.code === 'ERR_CANCELED' ||
|
||
error?.name === 'CanceledError' ||
|
||
error?.name === 'AbortError'
|
||
);
|
||
},
|
||
applyOaOrgSyncPage(page, current, size) {
|
||
this.oaSyncProgress.current = page.current || current;
|
||
this.oaSyncProgress.size = page.size || size;
|
||
this.oaSyncProgress.total = page.total || 0;
|
||
this.oaSyncProgress.synced += page.syncedCount || 0;
|
||
this.oaSyncProgress.skipped += page.skippedCount || 0;
|
||
if (page.dumpFilePath) {
|
||
this.oaSyncProgress.dumpFilePath = page.dumpFilePath;
|
||
}
|
||
if (page.companyOaId != null) {
|
||
this.oaSyncProgress.companyOaId = page.companyOaId || '';
|
||
}
|
||
if (page.companyIndex != null) {
|
||
this.oaSyncProgress.companyIndex = page.companyIndex || 0;
|
||
}
|
||
if (page.companyTotal != null) {
|
||
this.oaSyncProgress.companyTotal = page.companyTotal || 0;
|
||
}
|
||
},
|
||
async runOaOrgSyncStage(syncApi) {
|
||
const size = 20;
|
||
const incremental = this.oaSyncMode === 'incremental';
|
||
let current = 1;
|
||
let modifiedSince = '';
|
||
while (!this.oaSyncCancelled) {
|
||
const res = await syncApi(
|
||
current,
|
||
size,
|
||
this.oaSyncController?.signal,
|
||
incremental,
|
||
modifiedSince
|
||
);
|
||
const page = res?.data?.data || {};
|
||
if (!modifiedSince && page.modifiedSince) {
|
||
modifiedSince = page.modifiedSince;
|
||
}
|
||
this.applyOaOrgSyncPage(page, current, size);
|
||
if (page.finished) {
|
||
break;
|
||
}
|
||
current += 1;
|
||
}
|
||
},
|
||
/**
|
||
* 部门阶段:公司同步完成后,按公司 oaId 轮询;当前公司部门拉完后切换下一公司并重置页码
|
||
*/
|
||
async runOaOrgDepartmentSyncStage() {
|
||
const size = 20;
|
||
const incremental = this.oaSyncMode === 'incremental';
|
||
let current = 1;
|
||
let modifiedSince = '';
|
||
let companyOaId = '';
|
||
while (!this.oaSyncCancelled) {
|
||
const res = await syncOaDepartment(
|
||
current,
|
||
size,
|
||
this.oaSyncController?.signal,
|
||
incremental,
|
||
modifiedSince,
|
||
companyOaId
|
||
);
|
||
const page = res?.data?.data || {};
|
||
if (!modifiedSince && page.modifiedSince) {
|
||
modifiedSince = page.modifiedSince;
|
||
}
|
||
if (page.companyOaId) {
|
||
companyOaId = page.companyOaId;
|
||
}
|
||
this.applyOaOrgSyncPage(page, current, size);
|
||
if (page.finished) {
|
||
break;
|
||
}
|
||
if (page.companyFinished && page.nextCompanyOaId) {
|
||
companyOaId = page.nextCompanyOaId;
|
||
current = 1;
|
||
this.oaSyncProgress.current = 0;
|
||
this.oaSyncProgress.total = 0;
|
||
// 单公司部门拉完并重建层级后刷新树,便于中途核对挂载结果
|
||
this.parentId = 0;
|
||
this.data = [];
|
||
this.$refs.crud?.refreshTable?.();
|
||
this.onLoad(this.page, this.query);
|
||
continue;
|
||
}
|
||
current += 1;
|
||
}
|
||
},
|
||
async runOaOrgSyncPages() {
|
||
try {
|
||
if (this.oaSyncClearNonTop) {
|
||
this.oaSyncStage = 'clear';
|
||
await clearNonTopDept(this.oaSyncController?.signal);
|
||
if (this.oaSyncCancelled) {
|
||
this.oaSyncStatus = 'cancelled';
|
||
return;
|
||
}
|
||
}
|
||
this.oaSyncStage = 'company';
|
||
await this.runOaOrgSyncStage(syncOaCompany);
|
||
if (this.oaSyncCancelled) {
|
||
this.oaSyncStatus = 'cancelled';
|
||
return;
|
||
}
|
||
this.oaSyncStage = 'department';
|
||
this.oaSyncProgress.current = 0;
|
||
this.oaSyncProgress.total = 0;
|
||
this.oaSyncProgress.companyOaId = '';
|
||
this.oaSyncProgress.companyIndex = 0;
|
||
this.oaSyncProgress.companyTotal = 0;
|
||
await this.runOaOrgDepartmentSyncStage();
|
||
if (this.oaSyncCancelled) {
|
||
this.oaSyncStatus = 'cancelled';
|
||
return;
|
||
}
|
||
this.oaSyncStatus = 'done';
|
||
} catch (error) {
|
||
if (this.isOaSyncCanceledError(error)) {
|
||
this.oaSyncStatus = 'cancelled';
|
||
} else {
|
||
this.oaSyncStatus = 'error';
|
||
this.$message.error(error?.message || 'OA组织同步失败');
|
||
}
|
||
} finally {
|
||
this.oaSyncRunning = false;
|
||
this.oaSyncLoading = false;
|
||
if (this.oaSyncStatus === 'done' || this.oaSyncStatus === 'cancelled') {
|
||
this.parentId = 0;
|
||
this.data = [];
|
||
this.$refs.crud?.refreshTable?.();
|
||
this.onLoad(this.page, this.query);
|
||
}
|
||
}
|
||
},
|
||
cancelOaSync() {
|
||
if (!this.oaSyncRunning) {
|
||
return;
|
||
}
|
||
this.oaSyncCancelled = true;
|
||
this.oaSyncController?.abort();
|
||
},
|
||
closeOaSyncDialog() {
|
||
if (this.oaSyncRunning) {
|
||
this.cancelOaSync();
|
||
return;
|
||
}
|
||
this.oaSyncVisible = false;
|
||
},
|
||
initData(tenantId) {
|
||
getDeptTree(tenantId).then(res => {
|
||
const column = this.findColumn(this.option.column, 'parentId');
|
||
column.dicData = res.data.data;
|
||
});
|
||
},
|
||
handleParentChange(parentId) {
|
||
// Avue tree 选择时可能先触发空值 change,避免把已加载的上级编码清掉
|
||
const normalizedId = this.normalizeParentId(parentId);
|
||
if (!normalizedId && this.form?.parentId) {
|
||
return;
|
||
}
|
||
this.loadParentDeptCode(normalizedId || this.form?.parentId);
|
||
},
|
||
normalizeParentId(parentId) {
|
||
if (Array.isArray(parentId)) {
|
||
parentId = parentId[0];
|
||
}
|
||
if (parentId && typeof parentId === 'object') {
|
||
parentId = parentId.value ?? parentId.id ?? parentId.key;
|
||
}
|
||
if (!parentId || String(parentId) === '0') {
|
||
return '';
|
||
}
|
||
return parentId;
|
||
},
|
||
loadParentDeptCode(parentId) {
|
||
const normalizedId = this.normalizeParentId(parentId);
|
||
if (!normalizedId) {
|
||
this.parentDeptCode = '';
|
||
this.parentDept = null;
|
||
return;
|
||
}
|
||
getDept(normalizedId).then(res => {
|
||
// 防止异步乱序:仅采纳当前表单上级对应的结果
|
||
if (
|
||
this.form?.parentId &&
|
||
String(this.form.parentId) !== '0' &&
|
||
String(this.form.parentId) !== String(normalizedId)
|
||
) {
|
||
return;
|
||
}
|
||
this.parentDept = res.data.data || null;
|
||
this.parentDeptCode = this.parentDept?.deptCode || '';
|
||
this.updateDeptCategoryOptions();
|
||
this.$nextTick(() => {
|
||
this.$refs.crud?.clearValidate?.('deptCode');
|
||
});
|
||
});
|
||
},
|
||
loadOrganizationTypeOptions() {
|
||
return getDictionary({ code: ORGANIZATION_TYPE_DICT_CODE }).then(res => {
|
||
const list = res.data.data || [];
|
||
this.organizationTypeOptions = list
|
||
.map(item => this.normalizeOrganizationTypeOption(item))
|
||
.filter(Boolean);
|
||
this.resetDeptCategoryOptions();
|
||
if (list.length && !this.organizationTypeOptions.length) {
|
||
this.$message.warning('组织类型字典无法解析,请检查业务字典 organization_type 的字典键配置');
|
||
}
|
||
// 字典异步返回后触发表格组织类型标签重绘
|
||
if (Array.isArray(this.data) && this.data.length) {
|
||
this.data = [...this.data];
|
||
}
|
||
});
|
||
},
|
||
/**
|
||
* 业务字典项转下拉选项。后端 deptCategory 为 Integer,value 必须始终为数字。
|
||
* 优先用数字 dictKey;其次按名称映射;再回退 sort,避免字典项被静默丢弃。
|
||
*/
|
||
normalizeOrganizationTypeOption(item) {
|
||
const label = item?.dictValue ?? item?.label;
|
||
if (label === undefined || label === null || String(label).trim() === '') {
|
||
return null;
|
||
}
|
||
const labelText = String(label).trim();
|
||
const rawKey = item?.dictKey ?? item?.value;
|
||
const keyText = rawKey === undefined || rawKey === null ? '' : String(rawKey).trim();
|
||
const keyNumber = Number(keyText);
|
||
const isPureNumber = keyText !== '' && !Number.isNaN(keyNumber) && String(keyNumber) === keyText;
|
||
if (isPureNumber) {
|
||
return {
|
||
label: labelText,
|
||
value: keyNumber,
|
||
};
|
||
}
|
||
// dictKey / 名称 配成中文时,按标准名称映射到数字键
|
||
const codeByLabel =
|
||
ORGANIZATION_TYPE_CODE_BY_LABEL[labelText] ?? ORGANIZATION_TYPE_CODE_BY_LABEL[keyText];
|
||
if (codeByLabel) {
|
||
return {
|
||
label: labelText,
|
||
value: codeByLabel,
|
||
};
|
||
}
|
||
// 未命中名称映射时,用排序号兜底,保证与业务字典项一致展示
|
||
const sortNumber = Number(item?.sort);
|
||
if (!Number.isNaN(sortNumber) && sortNumber >= 1) {
|
||
return {
|
||
label: labelText,
|
||
value: sortNumber,
|
||
};
|
||
}
|
||
return null;
|
||
},
|
||
/**
|
||
* 提交前将组织类型规范为 Integer;空状态/排序字段去掉,避免 "" 反序列化失败。
|
||
* 排序为空时由后端默认填充 1。
|
||
*/
|
||
prepareDeptSubmitRow(row) {
|
||
const category = this.resolveDeptCategoryValue(row.deptCategory);
|
||
if (category === null) {
|
||
return false;
|
||
}
|
||
row.deptCategory = category;
|
||
if (row.status === '' || row.status === null || row.status === undefined) {
|
||
delete row.status;
|
||
} else {
|
||
row.status = Number(row.status);
|
||
}
|
||
if (row.sort === '' || row.sort === null || row.sort === undefined) {
|
||
delete row.sort;
|
||
} else {
|
||
row.sort = Number(String(row.sort).trim());
|
||
}
|
||
return true;
|
||
},
|
||
resolveDeptCategoryValue(value) {
|
||
if (value === null || value === undefined || value === '') {
|
||
this.$message.warning('请选择组织类型');
|
||
return null;
|
||
}
|
||
if (typeof value === 'number' && !Number.isNaN(value)) {
|
||
return value;
|
||
}
|
||
const asNumber = Number(value);
|
||
if (!Number.isNaN(asNumber) && String(asNumber) === String(value).trim()) {
|
||
return asNumber;
|
||
}
|
||
// 容错:表单里残留了中文标签时,按字典项 label / 标准名称反查数字编码
|
||
const matched = this.organizationTypeOptions.find(
|
||
item => String(item.label) === String(value) || this.isSameDeptCategory(item.value, value)
|
||
);
|
||
if (matched && typeof matched.value === 'number' && !Number.isNaN(matched.value)) {
|
||
return matched.value;
|
||
}
|
||
const codeByLabel = ORGANIZATION_TYPE_CODE_BY_LABEL[String(value).trim()];
|
||
if (codeByLabel) {
|
||
return codeByLabel;
|
||
}
|
||
this.$message.warning('组织类型无效,请重新选择');
|
||
return null;
|
||
},
|
||
resetDeptCategoryOptions() {
|
||
const categoryColumn = this.findColumn(this.option.column, 'deptCategory');
|
||
if (!categoryColumn) {
|
||
return;
|
||
}
|
||
categoryColumn.dicData = [...this.organizationTypeOptions];
|
||
},
|
||
isSameDeptCategory(left, right) {
|
||
if (
|
||
left === null ||
|
||
left === undefined ||
|
||
left === '' ||
|
||
right === null ||
|
||
right === undefined ||
|
||
right === ''
|
||
) {
|
||
return false;
|
||
}
|
||
if (String(left) === String(right)) {
|
||
return true;
|
||
}
|
||
const leftNumber = Number(left);
|
||
const rightNumber = Number(right);
|
||
return !Number.isNaN(leftNumber) && !Number.isNaN(rightNumber) && leftNumber === rightNumber;
|
||
},
|
||
isCarrierDeptCategory(value) {
|
||
if (Number(value) === 6) {
|
||
return true;
|
||
}
|
||
const matched = this.organizationTypeOptions.find(item => this.isSameDeptCategory(item.value, value));
|
||
const text = matched?.label || value;
|
||
return String(text).includes('承运商');
|
||
},
|
||
updateDeptCategoryOptions() {
|
||
// 组织层级仅由 parentId 决定,组织类型不再按上级过滤,始终展示全部字典项
|
||
this.resetDeptCategoryOptions();
|
||
if (this.isCarrierDeptCategory(this.form.deptCategory)) {
|
||
this.openCarrierDialog();
|
||
}
|
||
},
|
||
handleDeptCategoryChange(value) {
|
||
if (this.isCarrierDeptCategory(value)) {
|
||
this.openCarrierDialog();
|
||
}
|
||
},
|
||
openCarrierDialog() {
|
||
this.carrierDialogVisible = true;
|
||
this.loadCarrierList();
|
||
},
|
||
loadCarrierList() {
|
||
getCustomerArchiveList(this.carrierPage.current, this.carrierPage.size, {
|
||
...this.carrierQuery,
|
||
customerType: '承运商',
|
||
}).then(res => {
|
||
const page = res.data.data || {};
|
||
this.carrierData = page.records || [];
|
||
this.carrierPage.total = page.total || 0;
|
||
});
|
||
},
|
||
searchCarrier() {
|
||
this.carrierPage.current = 1;
|
||
this.loadCarrierList();
|
||
},
|
||
resetCarrierQuery() {
|
||
this.carrierQuery = { fullName: '', accessType: '', approvalStatus: '', status: undefined };
|
||
this.searchCarrier();
|
||
},
|
||
handleCarrierSizeChange(size) {
|
||
this.carrierPage.size = size;
|
||
this.carrierPage.current = 1;
|
||
this.loadCarrierList();
|
||
},
|
||
selectCarrier(row) {
|
||
this.form.carrierCustomerId = row.id;
|
||
this.form.deptName = row.fullName;
|
||
this.form.shortName = row.shortName;
|
||
this.form.mnemonicCode = row.mnemonicCode;
|
||
this.carrierDialogVisible = false;
|
||
},
|
||
formatAccessType(value) {
|
||
return value === 'formal' ? '正式' : value === 'temporary' ? '临时' : '-';
|
||
},
|
||
formatApprovalStatus(value) {
|
||
const statusMap = {
|
||
draft: '草稿',
|
||
reviewing: '审核中',
|
||
approved: '审核通过',
|
||
rejected: '审核不通过',
|
||
};
|
||
return statusMap[value] || '-';
|
||
},
|
||
loadLeaderOptions(tenantId) {
|
||
getLeaderList(tenantId).then(res => {
|
||
this.leaderOptions = res.data.data || [];
|
||
// formatter 依赖负责人字典,异步返回后触发表格重绘
|
||
if (Array.isArray(this.data) && this.data.length) {
|
||
this.data = [...this.data];
|
||
}
|
||
});
|
||
},
|
||
getDeptCategoryLabel(deptCategory) {
|
||
if (deptCategory === null || deptCategory === undefined || deptCategory === '') {
|
||
return '-';
|
||
}
|
||
const matched = this.organizationTypeOptions.find(item =>
|
||
this.isSameDeptCategory(item.value, deptCategory)
|
||
);
|
||
return matched?.label || String(deptCategory);
|
||
},
|
||
getLeaderValue(leaderId, field) {
|
||
// func.split 空值时返回 '',需兼容为数组,避免表格 formatter 渲染崩溃导致列错位
|
||
const splitResult = func.split(leaderId);
|
||
const values = Array.isArray(splitResult)
|
||
? splitResult
|
||
: String(splitResult || '')
|
||
.split(',')
|
||
.filter(Boolean);
|
||
if (!values.length) {
|
||
return '-';
|
||
}
|
||
const result = values
|
||
.map(id => this.leaderOptions.find(item => String(item.id) === String(id))?.[field])
|
||
.filter(Boolean);
|
||
return result.length ? result.join('、') : '-';
|
||
},
|
||
normalizeTopParent(row) {
|
||
if (!this.normalizeParentId(row?.parentId)) {
|
||
row.parentId = 0;
|
||
}
|
||
},
|
||
handlePlatformCompanyChange(value) {
|
||
const isPlatform = Number(value) === 1;
|
||
this.syncKingdeeDeptCodeDisplay(isPlatform);
|
||
if (!isPlatform && this.form) {
|
||
this.form.kingdeeDeptCode = '';
|
||
}
|
||
},
|
||
syncKingdeeDeptCodeDisplay(isPlatformCompany) {
|
||
const column = this.findColumn(this.option.column, 'kingdeeDeptCode');
|
||
if (!column) return;
|
||
const visible = Number(isPlatformCompany) === 1;
|
||
column.addDisplay = visible;
|
||
column.editDisplay = visible;
|
||
column.viewDisplay = visible;
|
||
},
|
||
isRootDept(row) {
|
||
return row && (row.parentId === 0 || String(row.parentId) === '0');
|
||
},
|
||
handleAdd(row) {
|
||
this.parentId = row.id;
|
||
this.loadParentDeptCode(row.id);
|
||
const column = this.findColumn(this.option.column, 'parentId');
|
||
column.value = row.id;
|
||
column.addDisabled = true;
|
||
this.$refs.crud.rowAdd();
|
||
},
|
||
getDeptTableRef() {
|
||
return this.$refs.crud?.$refs?.table;
|
||
},
|
||
getDeptTableScrollWrap() {
|
||
const table = this.getDeptTableRef();
|
||
const root = table?.$el || this.$refs.crud?.$el;
|
||
if (!root || typeof root.querySelector !== 'function') {
|
||
return null;
|
||
}
|
||
return (
|
||
root.querySelector('.el-table__body-wrapper .el-scrollbar__wrap') ||
|
||
root.querySelector('.el-scrollbar__wrap') ||
|
||
root.querySelector('.el-table__body-wrapper')
|
||
);
|
||
},
|
||
getDeptTableScrollTop() {
|
||
const wrap = this.getDeptTableScrollWrap();
|
||
return wrap ? wrap.scrollTop : 0;
|
||
},
|
||
restoreDeptTableScroll(scrollTop) {
|
||
const wrap = this.getDeptTableScrollWrap();
|
||
if (!wrap) {
|
||
return;
|
||
}
|
||
wrap.scrollTop = scrollTop;
|
||
},
|
||
findDeptRowById(list, id) {
|
||
if (!Array.isArray(list) || id === undefined || id === null || id === '') {
|
||
return null;
|
||
}
|
||
for (let index = 0; index < list.length; index += 1) {
|
||
const item = list[index];
|
||
if (String(item.id) === String(id)) {
|
||
return item;
|
||
}
|
||
const child = this.findDeptRowById(item.children, id);
|
||
if (child) {
|
||
return child;
|
||
}
|
||
}
|
||
return null;
|
||
},
|
||
syncLazyTreeAfterAdd(row, parentId) {
|
||
const table = this.getDeptTableRef();
|
||
if (!table || !parentId || String(parentId) === '0') {
|
||
return;
|
||
}
|
||
const parentRow = this.findDeptRowById(this.data, parentId);
|
||
if (parentRow) {
|
||
parentRow.hasChildren = true;
|
||
if (!Array.isArray(parentRow.children)) {
|
||
parentRow.children = [];
|
||
}
|
||
if (!parentRow.children.some(item => String(item.id) === String(row.id))) {
|
||
parentRow.children.push(row);
|
||
}
|
||
}
|
||
const lazyMapRef = table.store?.states?.lazyTreeNodeMap;
|
||
const treeDataRef = table.store?.states?.treeData;
|
||
const lazyMap = lazyMapRef?.value ?? lazyMapRef;
|
||
const treeData = treeDataRef?.value ?? treeDataRef;
|
||
const mapKey =
|
||
(lazyMap && Object.prototype.hasOwnProperty.call(lazyMap, parentId) && parentId) ||
|
||
(lazyMap && Object.prototype.hasOwnProperty.call(lazyMap, String(parentId)) && String(parentId)) ||
|
||
(parentRow && parentRow.id);
|
||
if (mapKey !== undefined && mapKey !== null && lazyMap) {
|
||
const currentChildren = Array.isArray(lazyMap[mapKey])
|
||
? lazyMap[mapKey]
|
||
: parentRow?.children || [];
|
||
const nextChildren = currentChildren.some(item => String(item.id) === String(row.id))
|
||
? [...currentChildren]
|
||
: [...currentChildren, row];
|
||
if (
|
||
Object.prototype.hasOwnProperty.call(lazyMap, mapKey) &&
|
||
typeof table.updateKeyChildren === 'function'
|
||
) {
|
||
table.updateKeyChildren(mapKey, nextChildren);
|
||
} else if (lazyMapRef && Object.prototype.hasOwnProperty.call(lazyMapRef, 'value')) {
|
||
// 首次挂子节点:直接写入懒加载缓存,避免再次 treeLoad 导致滚动回顶
|
||
lazyMapRef.value = {
|
||
...lazyMapRef.value,
|
||
[mapKey]: nextChildren,
|
||
};
|
||
} else {
|
||
lazyMap[mapKey] = nextChildren;
|
||
}
|
||
}
|
||
if (treeData && parentRow) {
|
||
const treeKey = Object.prototype.hasOwnProperty.call(treeData, parentRow.id)
|
||
? parentRow.id
|
||
: Object.prototype.hasOwnProperty.call(treeData, String(parentRow.id))
|
||
? String(parentRow.id)
|
||
: parentRow.id;
|
||
const nextNode = {
|
||
...(treeData[treeKey] || {}),
|
||
lazy: true,
|
||
loaded: true,
|
||
loading: false,
|
||
expanded: true,
|
||
hasChildren: true,
|
||
};
|
||
if (treeDataRef && Object.prototype.hasOwnProperty.call(treeDataRef, 'value')) {
|
||
treeDataRef.value = {
|
||
...treeDataRef.value,
|
||
[treeKey]: nextNode,
|
||
};
|
||
} else {
|
||
treeData[treeKey] = nextNode;
|
||
}
|
||
}
|
||
if (parentRow && typeof table.toggleRowExpansion === 'function') {
|
||
table.toggleRowExpansion(parentRow, true);
|
||
}
|
||
},
|
||
scrollDeptRowIntoView(rowId) {
|
||
if (rowId === undefined || rowId === null || rowId === '') {
|
||
return;
|
||
}
|
||
const table = this.getDeptTableRef();
|
||
const root = table?.$el || this.$refs.crud?.$el;
|
||
if (!root || typeof root.querySelector !== 'function') {
|
||
return;
|
||
}
|
||
const rowEl =
|
||
root.querySelector(`tr[data-row-key="${rowId}"]`) ||
|
||
root.querySelector(`tr[data-row-key='${rowId}']`);
|
||
if (rowEl && typeof rowEl.scrollIntoView === 'function') {
|
||
rowEl.scrollIntoView({ block: 'nearest', behavior: 'auto' });
|
||
}
|
||
},
|
||
rowSave(row, done, loading) {
|
||
row.tenantId = row.tenantId || this.userInfo.tenantId || website.tenantId;
|
||
row.deptCode = String(row.deptCode || '').trim();
|
||
// 合同前缀/流水已迁至业务部门配置;组织管理仅维护平台公司金蝶代码
|
||
row.kingdeeDeptCode =
|
||
Number(row.isPlatformCompany) === 1 ? String(row.kingdeeDeptCode || '').trim() : '';
|
||
row.leaderId = func.join(row.leaderId);
|
||
this.normalizeTopParent(row);
|
||
if (!this.prepareDeptSubmitRow(row)) {
|
||
loading();
|
||
return;
|
||
}
|
||
if (this.isCarrierDeptCategory(row.deptCategory) && !row.carrierCustomerId) {
|
||
this.$message.warning('请选择承运商');
|
||
loading();
|
||
return;
|
||
}
|
||
const scrollTop = this.getDeptTableScrollTop();
|
||
add(row).then(
|
||
res => {
|
||
// 获取新增数据的相关字段
|
||
const data = res.data.data;
|
||
row.id = data.id;
|
||
row.deptCategoryName = data.deptCategoryName;
|
||
row.tenantId = data.tenantId;
|
||
if (row.hasChildren === undefined || row.hasChildren === null) {
|
||
row.hasChildren = false;
|
||
}
|
||
this.$message({
|
||
type: 'success',
|
||
message: '操作成功!',
|
||
});
|
||
// 数据回调进行刷新(局部插入,避免整树重载跳回顶部)
|
||
done(row);
|
||
this.$nextTick(() => {
|
||
this.syncLazyTreeAfterAdd(row, this.normalizeParentId(row.parentId));
|
||
this.restoreDeptTableScroll(scrollTop);
|
||
this.$nextTick(() => {
|
||
this.scrollDeptRowIntoView(row.id);
|
||
});
|
||
});
|
||
},
|
||
error => {
|
||
window.console.log(error);
|
||
loading();
|
||
}
|
||
);
|
||
},
|
||
rowUpdate(row, index, done, loading) {
|
||
row.tenantId = row.tenantId || this.userInfo.tenantId || website.tenantId;
|
||
row.deptCode = String(row.deptCode || '').trim();
|
||
// 合同前缀/流水已迁至业务部门配置;组织管理仅维护平台公司金蝶代码
|
||
row.kingdeeDeptCode =
|
||
Number(row.isPlatformCompany) === 1 ? String(row.kingdeeDeptCode || '').trim() : '';
|
||
row.leaderId = func.join(row.leaderId);
|
||
this.normalizeTopParent(row);
|
||
if (!this.prepareDeptSubmitRow(row)) {
|
||
loading();
|
||
return;
|
||
}
|
||
if (this.isCarrierDeptCategory(row.deptCategory) && !row.carrierCustomerId) {
|
||
this.$message.warning('请选择承运商');
|
||
loading();
|
||
return;
|
||
}
|
||
update(row).then(
|
||
() => {
|
||
this.$message({
|
||
type: 'success',
|
||
message: '操作成功!',
|
||
});
|
||
// 数据回调进行刷新
|
||
done(row);
|
||
},
|
||
error => {
|
||
window.console.log(error);
|
||
loading();
|
||
}
|
||
);
|
||
},
|
||
rowDel(row, index, done) {
|
||
if (this.isRootDept(row)) {
|
||
this.$message.warning('根节点不能删除');
|
||
return;
|
||
}
|
||
this.$confirm('确定将选择数据删除?', {
|
||
confirmButtonText: '确定',
|
||
cancelButtonText: '取消',
|
||
type: 'warning',
|
||
})
|
||
.then(() => {
|
||
return remove(row.id);
|
||
})
|
||
.then(() => {
|
||
this.$message({
|
||
type: 'success',
|
||
message: '操作成功!',
|
||
});
|
||
// 数据回调进行刷新
|
||
done(row);
|
||
});
|
||
},
|
||
handleDelete() {
|
||
if (this.selectionList.length === 0) {
|
||
this.$message.warning('请选择至少一条数据');
|
||
return;
|
||
}
|
||
const deletableRows = this.selectionList.filter(row => !this.isRootDept(row));
|
||
if (deletableRows.length === 0) {
|
||
this.$message.warning('根节点不能删除');
|
||
return;
|
||
}
|
||
if (deletableRows.length !== this.selectionList.length) {
|
||
this.$message.warning('根节点不能删除,已忽略根节点');
|
||
}
|
||
const deletableIds = deletableRows.map(row => row.id).join(',');
|
||
this.$confirm('确定将选择数据删除?', {
|
||
confirmButtonText: '确定',
|
||
cancelButtonText: '取消',
|
||
type: 'warning',
|
||
})
|
||
.then(() => {
|
||
return remove(deletableIds);
|
||
})
|
||
.then(() => {
|
||
// 刷新表格数据并重载
|
||
this.data = [];
|
||
this.parentId = 0;
|
||
this.$refs.crud.refreshTable();
|
||
this.$refs.crud.toggleSelection();
|
||
// 表格数据重载
|
||
this.onLoad(this.page);
|
||
this.$message({
|
||
type: 'success',
|
||
message: '操作成功!',
|
||
});
|
||
});
|
||
},
|
||
searchReset() {
|
||
this.query = {};
|
||
this.parentId = 0;
|
||
this.onLoad(this.page);
|
||
},
|
||
searchChange(params, done) {
|
||
this.query = params;
|
||
this.parentId = '';
|
||
this.page.currentPage = 1;
|
||
this.onLoad(this.page, params);
|
||
done();
|
||
},
|
||
selectionChange(list) {
|
||
this.selectionList = list;
|
||
},
|
||
selectionClear() {
|
||
this.selectionList = [];
|
||
this.$refs.crud.toggleSelection();
|
||
},
|
||
beforeOpen(done, type) {
|
||
if (type === 'add') {
|
||
this.form.tenantId = this.form.tenantId || this.userInfo.tenantId || website.tenantId;
|
||
if (this.form.isPlatformCompany === undefined || this.form.isPlatformCompany === null) {
|
||
this.form.isPlatformCompany = 0;
|
||
}
|
||
if (this.form.isBusinessDept === undefined || this.form.isBusinessDept === null) {
|
||
this.form.isBusinessDept = 0;
|
||
}
|
||
this.syncKingdeeDeptCodeDisplay(this.form.isPlatformCompany);
|
||
this.initData(this.form.tenantId);
|
||
this.loadParentDeptCode(this.form.parentId);
|
||
}
|
||
if (type === 'edit') {
|
||
this.initData(this.form.tenantId || this.userInfo.tenantId || website.tenantId);
|
||
}
|
||
if (['edit', 'view'].includes(type)) {
|
||
getDept(this.form.id).then(res => {
|
||
this.form = Object.assign(res.data.data, {
|
||
hasChildren: this.form.hasChildren,
|
||
});
|
||
if (this.form.parentId === '0') {
|
||
this.form.parentId = '';
|
||
}
|
||
this.syncKingdeeDeptCodeDisplay(this.form.isPlatformCompany);
|
||
this.loadParentDeptCode(this.form.parentId);
|
||
if (this.form.hasOwnProperty('leaderId')) {
|
||
const splitResult = func.split(this.form.leaderId);
|
||
this.form.leaderId = Array.isArray(splitResult) ? splitResult : [];
|
||
}
|
||
});
|
||
}
|
||
done();
|
||
},
|
||
beforeClose(done) {
|
||
// 保持为根级查询条件,避免关闭弹窗后若触发重载时 parentId 为空导致整树重置
|
||
this.parentId = 0;
|
||
this.parentDeptCode = '';
|
||
this.parentDept = null;
|
||
const column = this.findColumn(this.option.column, 'parentId');
|
||
column.value = '';
|
||
column.addDisabled = false;
|
||
this.resetDeptCategoryOptions();
|
||
done();
|
||
},
|
||
currentChange(currentPage) {
|
||
this.page.currentPage = currentPage;
|
||
},
|
||
sizeChange(pageSize) {
|
||
this.page.pageSize = pageSize;
|
||
},
|
||
refreshChange() {
|
||
this.onLoad(this.page, this.query);
|
||
},
|
||
onLoad(page, params = {}) {
|
||
this.loading = true;
|
||
getLazyList(this.parentId, Object.assign(params, this.query)).then(res => {
|
||
this.data = res.data.data;
|
||
this.loading = false;
|
||
this.selectionClear();
|
||
});
|
||
},
|
||
treeLoad(tree, treeNode, resolve) {
|
||
const parentId = tree.id;
|
||
getLazyList(parentId).then(res => {
|
||
resolve(res.data.data);
|
||
});
|
||
},
|
||
},
|
||
};
|
||
</script>
|
||
|
||
<style scoped>
|
||
/* 覆盖全站表格居中:树形组织名称需左对齐,展开后缩进才可读 */
|
||
:deep(.el-table th.el-table__cell.is-left .cell),
|
||
:deep(.el-table td.el-table__cell.is-left .cell) {
|
||
text-align: left;
|
||
}
|
||
|
||
.carrier-search-form {
|
||
padding: 12px 12px 4px;
|
||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
|
||
}
|
||
|
||
.carrier-pagination {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
margin-top: 12px;
|
||
}
|
||
|
||
/* 操作列布局修正:
|
||
1) 全局样式对 .cell.avue-crud__menu 设了 width:auto !important + overflow:visible(为避免 tooltip 裁切),
|
||
会覆盖 Avue menuWidth 导致列宽塌陷、flex-wrap 把 4 个按钮压成竖排并溢出列边界。
|
||
2) 此处用更具体的选择器 + !important 恢复固定宽度,确保按钮在操作列内横向排列。 */
|
||
:deep(.avue-crud .el-table__body-wrapper .cell.avue-crud__menu) {
|
||
width: 320px !important;
|
||
overflow: hidden;
|
||
text-overflow: clip;
|
||
}
|
||
|
||
:deep(.avue-crud__menu) {
|
||
display: inline-flex !important;
|
||
flex-wrap: wrap;
|
||
gap: 8px;
|
||
align-items: center;
|
||
justify-content: flex-start;
|
||
|
||
> .el-button,
|
||
> .el-link,
|
||
> .el-dropdown {
|
||
flex-shrink: 0;
|
||
display: inline-flex;
|
||
}
|
||
}
|
||
|
||
/* 操作列删除按钮使用危险色 */
|
||
:deep(.avue-crud__menu > .el-button.is-text.avue-crud__delBtn) {
|
||
color: var(--el-color-danger);
|
||
}
|
||
|
||
:deep(.avue-crud__menu > .el-button.is-text.avue-crud__delBtn:hover),
|
||
:deep(.avue-crud__menu > .el-button.is-text.avue-crud__delBtn:focus) {
|
||
color: var(--el-color-danger-light-3);
|
||
}
|
||
</style>
|
||
|
||
<style>
|
||
.oa-sync-dialog .dialog-title {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
font-size: 16px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.oa-sync-dialog .dialog-title::before {
|
||
width: 4px;
|
||
height: 18px;
|
||
margin-right: 8px;
|
||
background: #409eff;
|
||
content: '';
|
||
}
|
||
|
||
.oa-sync-body {
|
||
padding: 8px 4px 0;
|
||
}
|
||
|
||
.oa-sync-meta {
|
||
margin-top: 12px;
|
||
color: #606266;
|
||
font-size: 13px;
|
||
}
|
||
|
||
.oa-sync-stats {
|
||
display: flex;
|
||
gap: 16px;
|
||
margin-top: 16px;
|
||
}
|
||
|
||
.oa-sync-stat {
|
||
flex: 1;
|
||
padding: 12px 16px;
|
||
background: #fafafa;
|
||
border: 1px solid #eff1f7;
|
||
border-radius: 4px;
|
||
}
|
||
|
||
.oa-sync-stat__label {
|
||
display: block;
|
||
color: #909399;
|
||
font-size: 12px;
|
||
}
|
||
|
||
.oa-sync-stat__value {
|
||
display: block;
|
||
margin-top: 6px;
|
||
font-size: 22px;
|
||
font-weight: 600;
|
||
line-height: 1.2;
|
||
}
|
||
|
||
.oa-sync-stat__value--success {
|
||
color: #409eff;
|
||
}
|
||
|
||
.oa-sync-stat__value--skip {
|
||
color: #909399;
|
||
}
|
||
</style>
|