feat: 角色默认信用与店铺实际额度管理
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 6m12s
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 6m12s
This commit is contained in:
@@ -80,6 +80,27 @@
|
||||
:inactive-value="CommonStatus.DISABLED"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<template v-if="isCustomerRoleForm">
|
||||
<ElFormItem label="新建代理默认信用">
|
||||
<ElSwitch
|
||||
v-model="form.credit_enabled"
|
||||
@change="handleDefaultCreditEnabledChange"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="默认信用额度">
|
||||
<ElInputNumber
|
||||
v-model="form.credit_limit_yuan"
|
||||
:disabled="!form.credit_enabled"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
:step="100"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
placeholder="请输入默认信用额度"
|
||||
/>
|
||||
<div class="credit-form-tip">单位:元。修改后不会影响已有店铺</div>
|
||||
</ElFormItem>
|
||||
</template>
|
||||
</ElForm>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
@@ -226,11 +247,12 @@
|
||||
ElOption
|
||||
} from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { RoleType } from '@/types/api'
|
||||
import type { PlatformRole, PermissionTreeNode } from '@/types/api'
|
||||
import type { SearchFormItem } from '@/types'
|
||||
import { useCheckedColumns } from '@/composables/useCheckedColumns'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { formatDateTime } from '@/utils/business/format'
|
||||
import { fenToYuan, formatDateTime, yuanToFen } from '@/utils/business/format'
|
||||
import {
|
||||
CommonStatus,
|
||||
getStatusText,
|
||||
@@ -343,9 +365,27 @@
|
||||
role_name: '',
|
||||
role_desc: '',
|
||||
role_type: 1,
|
||||
status: CommonStatus.ENABLED
|
||||
status: CommonStatus.ENABLED,
|
||||
credit_enabled: false,
|
||||
credit_limit_yuan: 0
|
||||
})
|
||||
|
||||
const isCustomerRoleForm = computed(() => form.role_type === RoleType.CUSTOMER)
|
||||
|
||||
const handleDefaultCreditEnabledChange = (enabled: boolean | string | number) => {
|
||||
if (!enabled) {
|
||||
form.credit_limit_yuan = 0
|
||||
}
|
||||
}
|
||||
|
||||
const getDefaultCreditPayload = () => {
|
||||
const creditEnabled = Boolean(form.credit_enabled)
|
||||
return {
|
||||
credit_enabled: creditEnabled,
|
||||
credit_limit: creditEnabled ? yuanToFen(form.credit_limit_yuan) || 0 : 0
|
||||
}
|
||||
}
|
||||
|
||||
const roleList = ref<PlatformRole[]>([])
|
||||
|
||||
// 动态列配置
|
||||
@@ -997,23 +1037,38 @@
|
||||
const dialogType = ref('add')
|
||||
|
||||
// 显示新增/编辑对话框
|
||||
const showDialog = (type: string, row?: any) => {
|
||||
dialogVisible.value = true
|
||||
const showDialog = async (type: string, row?: any) => {
|
||||
dialogType.value = type
|
||||
|
||||
if (type === 'edit' && row) {
|
||||
form.id = row.ID
|
||||
form.role_name = row.role_name
|
||||
form.role_desc = row.role_desc
|
||||
form.role_type = row.role_type
|
||||
form.status = row.status
|
||||
let roleDetail = row
|
||||
try {
|
||||
const res = await RoleService.getRole(row.ID)
|
||||
if (res.code === 0 && res.data) {
|
||||
roleDetail = res.data
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取角色详情失败:', error)
|
||||
}
|
||||
|
||||
form.id = roleDetail.ID
|
||||
form.role_name = roleDetail.role_name
|
||||
form.role_desc = roleDetail.role_desc
|
||||
form.role_type = roleDetail.role_type
|
||||
form.status = roleDetail.status
|
||||
form.credit_enabled = Boolean(roleDetail.credit_enabled)
|
||||
form.credit_limit_yuan = fenToYuan(roleDetail.credit_limit)
|
||||
} else {
|
||||
form.id = 0
|
||||
form.role_name = ''
|
||||
form.role_desc = ''
|
||||
form.role_type = 1
|
||||
form.status = CommonStatus.ENABLED
|
||||
form.credit_enabled = false
|
||||
form.credit_limit_yuan = 0
|
||||
}
|
||||
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
// 删除角色
|
||||
@@ -1052,7 +1107,11 @@
|
||||
role_type: form.role_type,
|
||||
status: form.status
|
||||
}
|
||||
await RoleService.createRole(data)
|
||||
const res = await RoleService.createRole(data)
|
||||
const createdRoleId = res.data?.ID ?? res.data?.id ?? res.data?.role_id
|
||||
if (form.role_type === RoleType.CUSTOMER && createdRoleId) {
|
||||
await RoleService.updateRoleDefaultCredit(createdRoleId, getDefaultCreditPayload())
|
||||
}
|
||||
ElMessage.success('新增成功')
|
||||
} else {
|
||||
// 更新角色时只发送允许的字段
|
||||
@@ -1063,6 +1122,9 @@
|
||||
status: form.status
|
||||
}
|
||||
await RoleService.updateRole(form.id, data)
|
||||
if (form.role_type === RoleType.CUSTOMER) {
|
||||
await RoleService.updateRoleDefaultCredit(form.id, getDefaultCreditPayload())
|
||||
}
|
||||
ElMessage.success('修改成功')
|
||||
}
|
||||
|
||||
@@ -1118,6 +1180,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
.credit-form-tip {
|
||||
margin-top: 6px;
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.permission-tree-transfer-container {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
|
||||
Reference in New Issue
Block a user