This commit is contained in:
李远 2026-03-17 16:45:45 +08:00
parent a53b0d4010
commit b2d7f8bf06
3 changed files with 149 additions and 21 deletions

View File

@ -32,7 +32,7 @@
<!-- 点差表格 -->
<AgentTable :table-data="agentPointTree" :columns="agentPointTableColumnsOptions" row-key="id">
<template #assignedPointDiff="{ row }">
<el-form :model="row" :rules="rules()">
<el-form :model="row" :rules="rules(agentForm,row)">
<el-form-item prop="assignedPointDifference">
<el-input v-model="row.assignedPointDifference" size="small" placeholder="请输入点差" />
</el-form-item>
@ -51,7 +51,7 @@ import AgentDialog from '@/components/common/Dialog.vue'
import AgentForm from '@/components/common/Form.vue'
//
import { agentSearch, agentTableColumns, viewAgentPointTableColumns, agentPointTableColumns, PointDiffFormItem } from './options'
import { agentSearch, agentTableColumns, viewAgentPointTableColumns, agentPointTableColumns, agentFormItem } from './options'
import { rules } from './rules'
//
@ -104,12 +104,14 @@ const agentForm = ref({
feeTemplate: '',
positionRatio: '',
feeRate: '',
maxPositionRatio: '',
maxFeeRate: '',
//id
id: '',
})
const agentFormRules = rules()
const agentFormRules = rules(agentForm.value)
const agentFormRef = ref()
const agentFormItemOptions = ref(PointDiffFormItem)
const agentFormItemOptions = ref(agentFormItem)
//使
const optionsFetched = ref(false)
interface SelectOption {
@ -124,7 +126,22 @@ const agentFormOptionsMap = ref({
/**
* @description 定义弹窗表格数据
*/
const agentPointTree = ref([])
const agentPointTree = ref([
{
id: '1001', //
varietyName: '欧元/美元', //
varietyCode: 'EURUSD', //
pointDifference: '50.00', //
assignedPointDifference: '' //
},
{
id: '1002',
varietyName: '英镑/美元',
varietyCode: 'GBPUSD',
pointDifference: '45.50',
assignedPointDifference: ''
}
])
const agentPointTableColumnsOptions = computed(() => {
return dialogType.value !== 'view' ? agentPointTableColumns : viewAgentPointTableColumns;
});
@ -204,7 +221,7 @@ const getAgentList = async () => {
//
const getPointDiffConfig = async (row: any) => {
const params = {
user_id: row.par_uid,
user_id: row.id
}
const data = await getPointDiffConfigApi(params)
//
@ -212,8 +229,8 @@ const getPointDiffConfig = async (row: any) => {
...item,
varietyName: item.name,
varietyCode: item.code,
pointDifference: item.target_point_diff,
assignedPointDifference: ''
pointDifference: item.point_diff,
assignedPointDifference: item.target_point_diff
}));
}
@ -281,12 +298,13 @@ const handleViewPointDiff = (row: any) => {
//
const handleEdit = async (row: any) => {
console.log('编辑', row);
console.log('row', row)
//
await Promise.all([
getPointDiffConfig(row),
// getPointDiffConfig(row),
getOptions()
])
//
agentForm.value = {
username: row.username || '',
parentUsername: row.parentUsername || '',
@ -295,8 +313,9 @@ const handleEdit = async (row: any) => {
positionRatio: row.wallet_capital.toucun_percent || '',
feeRate: row.feeRate || '',
id: row.id || '',
maxPositionRatio: row.wallet_capital.toucun_percent || '',
maxFeeRate: row.wallet_capital.fee_handling_percent || '',
}
console.log('agentForm.value', agentForm.value)
dialogVisible.value = true
dialogTitle.value = '编辑'
dialogType.value = 'edit'
@ -341,7 +360,6 @@ const formatPointDiffToObject = () => {
const handleSubmit = async () => {
await agentFormRef.value.validate()
const pointDiffObj = formatPointDiffToObject()
console.log('agentForm.value', agentForm.value)
const params = {
user_id: agentForm.value.id || '',
toucun_percent: agentForm.value.positionRatio || '',

View File

@ -41,7 +41,7 @@ export const agentTableColumns = [
]
// 查看点差表格列配置
// 查看代理点差表格列配置
export const viewAgentPointTableColumns = [
{ prop: 'varietyName', label: '品种名称', align: 'center' as const },
{ prop: 'varietyCode', label: '品种编号', align: 'center' as const },
@ -49,7 +49,7 @@ export const viewAgentPointTableColumns = [
{ prop: 'assignedPointDifference', label: '已分配点差', align: 'center' as const },
]
//编辑点差表格列配置
//编辑代理表格列配置
export const agentPointTableColumns = ([
{ prop: 'varietyName', label: '名称', align: 'center' as const },
{ prop: 'varietyCode', label: '编号', align: 'center' as const },
@ -58,8 +58,8 @@ export const agentPointTableColumns = ([
])
//编辑点差form配置
export const PointDiffFormItem = [
//编辑代理form配置
export const agentFormItem = [
//代理名称
{ prop: 'username', label: '代理名称', type: 'input' as const, placeholder: '代理名称', width: '120px' },
//所属上级

View File

@ -1,12 +1,122 @@
import type{ FormRules } from 'element-plus'
import type { FormRules } from 'element-plus'
export const rules = (): FormRules => {
export const rules = (form: any, row?: any): FormRules => {
return {
name: [
username: [
{ required: true, message: '请输入名称', trigger: ['blur'] }
],
pointDiff: [
{ required: true, message: '请输入点差', trigger: ['blur'] }
parentUsername: [
{ required: true, message: '请输入所属上级', trigger: ['blur'] }
],
riskTemplate: [
{ required: true, message: '请选择风险模板', trigger: ['change'] }
],
feeTemplate: [
{ required: true, message: '请选择手续费模板', trigger: ['change'] }
],
positionRatio: [
{ required: true, message: '请输入头寸', trigger: ['blur'] },
{
validator: (rule, value, callback) => {
// 空值已经由 required 校验处理
if (value === '' || value === undefined || value === null) {
return callback();
}
// 尝试转换为数字
const numValue = Number(value);
// 转换失败 → 不是有效数字
if (isNaN(numValue)) {
return callback(new Error('头寸必须为数字'));
}
// 范围校验0-100
if (numValue < 0 || numValue > 100) {
return callback(new Error('头寸需在0-100之间'));
}
// 精度校验最多2位小数
if (!/^\d+(\.\d{1,2})?$/.test(value.toString())) {
return callback(new Error('头寸最多保留2位小数'));
}
// 不超过上级最大头寸校验
if (form.maxPositionRatio && numValue > Number(form.maxPositionRatio)) {
return callback(new Error(`头寸不能超过上级账户的最大头寸(${form.maxPositionRatio})`));
}
callback();
},
trigger: ['blur', 'change']
}
],
feeRate: [
{ required: true, message: '请输入手续费率', trigger: ['blur'] },
{
validator: (rule, value, callback) => {
// 空值已经由 required 校验处理
if (value === '' || value === undefined || value === null) {
return callback();
}
// 尝试转换为数字
const numValue = Number(value);
// 转换失败 → 不是有效数字
if (isNaN(numValue)) {
return callback(new Error('头寸必须为数字'));
}
// 范围校验0-100
if (numValue < 0 || numValue > 100) {
return callback(new Error('头寸需在0-100之间'));
}
// 精度校验最多5位小数
if (!/^\d+(\.\d{1,5})?$/.test(value.toString())) {
return callback(new Error('手续费率最多保留5位小数'));
}
// 不超过上级最大头寸校验
if (form.maxFeeRate && numValue > Number(form.maxFeeRate)) {
return callback(new Error(`头寸不能超过上级账户的最大头寸(${form.maxFeeRate})`));
}
callback();
},
trigger: ['blur', 'change']
}
],
assignedPointDifference: [
{ required: true, message: '请输入点差', trigger: 'blur' },
{
validator: (rule, value, callback) => {
if (value === '' || value === undefined || value === null) {
return callback()
}
const numValue = Number(value)
// 1. 基础数字校验
if (isNaN(numValue)) {
return callback(new Error('点差必须为数字'))
}
if (numValue < 0) {
return callback(new Error('点差不能为负数'))
}
if (!/^\d+(\.\d{1,5})?$/.test(value.toString())) {
return callback(new Error('点差最多保留5位小数'))
}
// 2. 核心校验:已分配点差 ≤ 可分配点差
if (row && row.pointDifference !== undefined) {
const maxPointDiff = Number(row.pointDifference)
if (numValue > maxPointDiff) {
return callback(new Error(`可分配点差为(${maxPointDiff})`))
}
}
callback()
},
trigger: ['blur', 'change']
}
],
}
}