feat(crm): add tenant-level contract approver setting with submit prefill
Mirror the quote approver setting so contract submit dialogs can prefill ordered approvers from a tenant config page while remaining editable. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
ce75576fb0
commit
06956b742b
13 files changed
+532
-15
No files matched your search
@@ -2,9 +2,16 @@
|
||||
* 合同管理 API(门户 http + Java 对齐 GET/PUT/DELETE 语义)
|
||||
*/
|
||||
import request from '@/utils/http'
|
||||
import type { ContractForm, ContractQuery, ContractVO } from './types'
|
||||
import type {
|
||||
ContractApproverSettingForm,
|
||||
ContractApproverSettingVO,
|
||||
ContractForm,
|
||||
ContractQuery,
|
||||
ContractVO
|
||||
} from './types'
|
||||
|
||||
const BASE = '/web/crm/contract'
|
||||
const SETTING_BASE = '/web/crm/contract-approver-setting'
|
||||
|
||||
function unwrapData(res: any) {
|
||||
return res?.data ?? res ?? {}
|
||||
@@ -323,4 +330,27 @@ export async function listContractOperLog(_contractId: number | string) {
|
||||
return { rows: data.list || data.rows || [], total: data.total ?? 0 }
|
||||
}
|
||||
|
||||
export async function getContractApproverSetting() {
|
||||
const res = await request.post({ url: `${SETTING_BASE}/get`, data: {} })
|
||||
const data = unwrapData(res) || {}
|
||||
return {
|
||||
data: {
|
||||
id: data.id,
|
||||
approverIds: (data.approverIds || []).map(String),
|
||||
status: data.status === '1' ? '1' : '0',
|
||||
updateTime: data.updateTime
|
||||
} as ContractApproverSettingVO
|
||||
}
|
||||
}
|
||||
|
||||
export function saveContractApproverSetting(data: ContractApproverSettingForm) {
|
||||
return request.post({
|
||||
url: `${SETTING_BASE}/save`,
|
||||
data: {
|
||||
approverIds: (data.approverIds || []).map(String),
|
||||
status: data.status
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export * from './types'
|
||||
@@ -379,3 +379,16 @@ export type CreateFromQuoteForm = Pick<
|
||||
ContractForm,
|
||||
'contractNo' | 'contractName' | 'customerId' | 'contractType' | 'amount' | 'signDate' | 'startDate' | 'endDate' | 'remark' | 'products'
|
||||
>
|
||||
|
||||
/** 合同审批人设置 */
|
||||
export interface ContractApproverSettingVO {
|
||||
id?: string
|
||||
approverIds: (string | number)[]
|
||||
status: '0' | '1' | string
|
||||
updateTime?: string
|
||||
}
|
||||
|
||||
export interface ContractApproverSettingForm {
|
||||
approverIds: (string | number)[]
|
||||
status: '0' | '1'
|
||||
}
|
||||
@@ -414,6 +414,17 @@ export const sqxpAdminRoutes: AppRouteRecord[] = [
|
||||
component: '/crm/contract/index',
|
||||
meta: { title: '合同管理', keepAlive: true, menuCode: 'crm:contract:list' }
|
||||
},
|
||||
{
|
||||
id: 'CRM3000000000000000000000000026',
|
||||
name: 'CrmContractApproverSetting',
|
||||
path: 'contract-approver-setting',
|
||||
component: '/crm/contract/approver-setting/index',
|
||||
meta: {
|
||||
title: '合同审批人设置',
|
||||
keepAlive: true,
|
||||
menuCode: 'crm:contract:approverSetting'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'CRM3000000000000000000000000030',
|
||||
name: 'CrmPriceLetter',
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<section class="panel">
|
||||
<div class="panel-top">
|
||||
<h2 class="title-bar-heading">合同审批人设置</h2>
|
||||
</div>
|
||||
<div class="panel-body contract-approver-setting-body">
|
||||
<el-form ref="formRef" :model="form" label-position="top" class="crm-dialog-form">
|
||||
<div class="form-grid-2">
|
||||
<el-form-item class="form-col-span-2">
|
||||
<template #label>
|
||||
默认审批人<span class="form-label-tip">支持多人,按选择顺序依次审批</span>
|
||||
</template>
|
||||
<el-select
|
||||
v-model="form.approverIds"
|
||||
multiple
|
||||
filterable
|
||||
placeholder="请选择审批人"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="user in userList"
|
||||
:key="user.userId"
|
||||
:label="formatApproverOptionLabel(user)"
|
||||
:value="user.userId"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-radio-group v-model="form.status">
|
||||
<el-radio value="0">启用</el-radio>
|
||||
<el-radio value="1">停用</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form>
|
||||
<div class="contract-approver-setting-actions">
|
||||
<el-button class="btn-ghost" :loading="loading" @click="loadSetting">
|
||||
<el-icon><RefreshLeft /></el-icon>重置
|
||||
</el-button>
|
||||
<el-button class="btn-main" type="primary" :loading="saving" @click="handleSave">
|
||||
<el-icon><Check /></el-icon>保存设置
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="CrmContractApproverSetting">
|
||||
import { RefreshLeft, Check } from '@element-plus/icons-vue'
|
||||
import { fetchUserOptions } from '@/api/admin'
|
||||
import { getContractApproverSetting, saveContractApproverSetting } from '@/api/crm/contract'
|
||||
import type { ContractApproverSettingForm } from '@/api/crm/contract/types'
|
||||
import { $modal } from '@/utils/modal'
|
||||
|
||||
interface UserOption {
|
||||
userId: string
|
||||
nickName: string
|
||||
userName: string
|
||||
}
|
||||
|
||||
const formRef = ref()
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const userList = ref<UserOption[]>([])
|
||||
|
||||
const form = ref<ContractApproverSettingForm>({
|
||||
approverIds: [],
|
||||
status: '0'
|
||||
})
|
||||
|
||||
const formatApproverOptionLabel = (user: { nickName?: string; userName?: string }) => {
|
||||
const nick = (user.nickName || '').trim()
|
||||
const account = (user.userName || '').trim()
|
||||
if (nick && account) return `${nick}(${account})`
|
||||
return nick || account
|
||||
}
|
||||
|
||||
const loadUserList = async () => {
|
||||
try {
|
||||
const res = await fetchUserOptions()
|
||||
const options = (res as any)?.data ?? res ?? []
|
||||
userList.value = (Array.isArray(options) ? options : [])
|
||||
.map((item: any) => ({
|
||||
userId: String(item.value ?? item.userId ?? item.id ?? ''),
|
||||
nickName: item.nickName ?? item.label ?? item.userName ?? '',
|
||||
userName: item.userNo ?? item.user_no ?? item.userName ?? ''
|
||||
}))
|
||||
.filter((u) => u.userId)
|
||||
} catch (error) {
|
||||
console.error('加载用户列表失败:', error)
|
||||
userList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const loadSetting = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const { data } = await getContractApproverSetting()
|
||||
form.value = {
|
||||
approverIds: (data.approverIds || []).map(String),
|
||||
status: (data.status === '1' ? '1' : '0') as '0' | '1'
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('加载审批人设置失败:', error)
|
||||
$modal.msgError(error?.msg || '加载审批人设置失败,请稍后重试')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSave = async () => {
|
||||
saving.value = true
|
||||
try {
|
||||
await saveContractApproverSetting({
|
||||
approverIds: form.value.approverIds || [],
|
||||
status: form.value.status
|
||||
})
|
||||
$modal.msgSuccess('保存成功')
|
||||
await loadSetting()
|
||||
} catch (error: any) {
|
||||
console.error('保存审批人设置失败:', error)
|
||||
$modal.msgError(error?.msg || '保存失败,请稍后重试')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await Promise.all([loadUserList(), loadSetting()])
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.contract-approver-setting-body {
|
||||
padding: 16px 20px 24px;
|
||||
}
|
||||
|
||||
.contract-approver-setting-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
</style>
|
||||
@@ -35,6 +35,14 @@
|
||||
<template #label>
|
||||
选择审批人<span class="form-label-tip">支持搜索用户姓名</span>
|
||||
</template>
|
||||
<el-alert
|
||||
v-if="submitPrefillTip"
|
||||
type="success"
|
||||
:closable="false"
|
||||
show-icon
|
||||
title="已按「合同审批人设置」预填审批人,可修改后提交"
|
||||
style="margin-bottom: 12px"
|
||||
/>
|
||||
<el-select
|
||||
v-model="form.approverIds"
|
||||
multiple
|
||||
@@ -127,12 +135,19 @@
|
||||
<script setup lang="ts" name="ApprovalDialog">
|
||||
import { ref, computed } from 'vue'
|
||||
import { Check, Close } from '@element-plus/icons-vue'
|
||||
import { submitContract, batchSubmitContract, approveContract, rejectContract, withdrawContract } from '@/api/crm/contract'
|
||||
import {
|
||||
submitContract,
|
||||
batchSubmitContract,
|
||||
approveContract,
|
||||
rejectContract,
|
||||
withdrawContract,
|
||||
getContractApproverSetting
|
||||
} from '@/api/crm/contract'
|
||||
import { fetchUserOptions } from '@/api/admin'
|
||||
import { $modal } from '@/utils/modal'
|
||||
|
||||
interface ApproverUser {
|
||||
userId: string | number
|
||||
userId: string
|
||||
nickName: string
|
||||
userName: string
|
||||
}
|
||||
@@ -146,7 +161,7 @@ const contractIds = ref<(string | number)[]>()
|
||||
|
||||
const form = ref({
|
||||
approvalType: 'sequential',
|
||||
approverIds: [] as (string | number)[],
|
||||
approverIds: [] as string[],
|
||||
comment: '',
|
||||
remark: '',
|
||||
reason: ''
|
||||
@@ -155,6 +170,7 @@ const form = ref({
|
||||
const approverList = ref<ApproverUser[]>([])
|
||||
const submitLoading = ref(false)
|
||||
const userLoading = ref(false)
|
||||
const submitPrefillTip = ref(false)
|
||||
const formRef = ref<ElFormInstance>()
|
||||
|
||||
const rules = computed(() => {
|
||||
@@ -195,18 +211,19 @@ const confirmButtonText = computed(() => {
|
||||
return textMap[actionType.value]
|
||||
})
|
||||
|
||||
const open = (id: string | number, type: 'submit' | 'approve' | 'reject' | 'withdraw' = 'submit') => {
|
||||
const open = async (id: string | number, type: 'submit' | 'approve' | 'reject' | 'withdraw' = 'submit') => {
|
||||
contractId.value = id
|
||||
contractIds.value = undefined
|
||||
actionType.value = type
|
||||
dialogVisible.value = true
|
||||
resetForm()
|
||||
if (type === 'submit') {
|
||||
loadApproverList()
|
||||
await loadApproverList()
|
||||
await applyPrefillApprovers()
|
||||
}
|
||||
}
|
||||
|
||||
const openBatch = (
|
||||
const openBatch = async (
|
||||
idList: (string | number)[],
|
||||
type: 'submit' | 'approve' | 'reject' | 'withdraw' = 'submit'
|
||||
) => {
|
||||
@@ -216,7 +233,8 @@ const openBatch = (
|
||||
dialogVisible.value = true
|
||||
resetForm()
|
||||
if (type === 'submit') {
|
||||
loadApproverList()
|
||||
await loadApproverList()
|
||||
await applyPrefillApprovers()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,11 +243,13 @@ const loadApproverList = async (nickName?: string) => {
|
||||
try {
|
||||
const res = await fetchUserOptions()
|
||||
const options = (res as any)?.data ?? res ?? []
|
||||
let list = (Array.isArray(options) ? options : []).map((item: any) => ({
|
||||
userId: item.value ?? item.userId ?? item.id,
|
||||
nickName: item.label ?? item.nickName ?? item.userName ?? '',
|
||||
userName: item.userNo ?? item.userName ?? ''
|
||||
}))
|
||||
let list = (Array.isArray(options) ? options : [])
|
||||
.map((item: any) => ({
|
||||
userId: String(item.value ?? item.userId ?? item.id ?? ''),
|
||||
nickName: item.label ?? item.nickName ?? item.userName ?? '',
|
||||
userName: item.userNo ?? item.userName ?? ''
|
||||
}))
|
||||
.filter((u) => u.userId)
|
||||
if (nickName) {
|
||||
const q = nickName.toLowerCase()
|
||||
list = list.filter(
|
||||
@@ -246,6 +266,23 @@ const loadApproverList = async (nickName?: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
async function resolvePrefillApproverIds(userList: ApproverUser[]) {
|
||||
try {
|
||||
const { data } = await getContractApproverSetting()
|
||||
if (!data || String(data.status) !== '0') return [] as string[]
|
||||
const valid = new Set(userList.map((u) => String(u.userId)))
|
||||
return (data.approverIds || []).map(String).filter((id) => valid.has(id))
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
async function applyPrefillApprovers() {
|
||||
const prefillIds = await resolvePrefillApproverIds(approverList.value)
|
||||
form.value.approverIds = prefillIds
|
||||
submitPrefillTip.value = prefillIds.length > 0
|
||||
}
|
||||
|
||||
const handleSearchUser = (query: string) => {
|
||||
if (query) {
|
||||
loadApproverList(query)
|
||||
@@ -299,14 +336,21 @@ const handleClose = () => {
|
||||
resetForm()
|
||||
}
|
||||
|
||||
const defaultComment = (type: typeof actionType.value) => {
|
||||
if (type === 'approve') return '审批通过'
|
||||
if (type === 'reject') return '审批驳回'
|
||||
return ''
|
||||
}
|
||||
|
||||
const resetForm = () => {
|
||||
form.value = {
|
||||
approvalType: 'sequential',
|
||||
approverIds: [],
|
||||
comment: '',
|
||||
comment: defaultComment(actionType.value),
|
||||
remark: '',
|
||||
reason: ''
|
||||
}
|
||||
submitPrefillTip.value = false
|
||||
formRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user