This commit is contained in:
parent
a53b0d4010
commit
b2d7f8bf06
|
|
@ -32,7 +32,7 @@
|
||||||
<!-- 点差表格 -->
|
<!-- 点差表格 -->
|
||||||
<AgentTable :table-data="agentPointTree" :columns="agentPointTableColumnsOptions" row-key="id">
|
<AgentTable :table-data="agentPointTree" :columns="agentPointTableColumnsOptions" row-key="id">
|
||||||
<template #assignedPointDiff="{ row }">
|
<template #assignedPointDiff="{ row }">
|
||||||
<el-form :model="row" :rules="rules()">
|
<el-form :model="row" :rules="rules(agentForm,row)">
|
||||||
<el-form-item prop="assignedPointDifference">
|
<el-form-item prop="assignedPointDifference">
|
||||||
<el-input v-model="row.assignedPointDifference" size="small" placeholder="请输入点差" />
|
<el-input v-model="row.assignedPointDifference" size="small" placeholder="请输入点差" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
@ -51,7 +51,7 @@ import AgentDialog from '@/components/common/Dialog.vue'
|
||||||
import AgentForm from '@/components/common/Form.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'
|
import { rules } from './rules'
|
||||||
|
|
||||||
//接口
|
//接口
|
||||||
|
|
@ -104,12 +104,14 @@ const agentForm = ref({
|
||||||
feeTemplate: '',
|
feeTemplate: '',
|
||||||
positionRatio: '',
|
positionRatio: '',
|
||||||
feeRate: '',
|
feeRate: '',
|
||||||
|
maxPositionRatio: '',
|
||||||
|
maxFeeRate: '',
|
||||||
//存用户id
|
//存用户id
|
||||||
id: '',
|
id: '',
|
||||||
})
|
})
|
||||||
const agentFormRules = rules()
|
const agentFormRules = rules(agentForm.value)
|
||||||
const agentFormRef = ref()
|
const agentFormRef = ref()
|
||||||
const agentFormItemOptions = ref(PointDiffFormItem)
|
const agentFormItemOptions = ref(agentFormItem)
|
||||||
//使用这个判断请求是否完成,去缓存请求
|
//使用这个判断请求是否完成,去缓存请求
|
||||||
const optionsFetched = ref(false)
|
const optionsFetched = ref(false)
|
||||||
interface SelectOption {
|
interface SelectOption {
|
||||||
|
|
@ -124,7 +126,22 @@ const agentFormOptionsMap = ref({
|
||||||
/**
|
/**
|
||||||
* @description 定义弹窗表格数据
|
* @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(() => {
|
const agentPointTableColumnsOptions = computed(() => {
|
||||||
return dialogType.value !== 'view' ? agentPointTableColumns : viewAgentPointTableColumns;
|
return dialogType.value !== 'view' ? agentPointTableColumns : viewAgentPointTableColumns;
|
||||||
});
|
});
|
||||||
|
|
@ -204,7 +221,7 @@ const getAgentList = async () => {
|
||||||
//获取点差配置
|
//获取点差配置
|
||||||
const getPointDiffConfig = async (row: any) => {
|
const getPointDiffConfig = async (row: any) => {
|
||||||
const params = {
|
const params = {
|
||||||
user_id: row.par_uid,
|
user_id: row.id
|
||||||
}
|
}
|
||||||
const data = await getPointDiffConfigApi(params)
|
const data = await getPointDiffConfigApi(params)
|
||||||
// 表格数据
|
// 表格数据
|
||||||
|
|
@ -212,8 +229,8 @@ const getPointDiffConfig = async (row: any) => {
|
||||||
...item,
|
...item,
|
||||||
varietyName: item.name,
|
varietyName: item.name,
|
||||||
varietyCode: item.code,
|
varietyCode: item.code,
|
||||||
pointDifference: item.target_point_diff,
|
pointDifference: item.point_diff,
|
||||||
assignedPointDifference: ''
|
assignedPointDifference: item.target_point_diff
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -281,12 +298,13 @@ const handleViewPointDiff = (row: any) => {
|
||||||
|
|
||||||
// 编辑
|
// 编辑
|
||||||
const handleEdit = async (row: any) => {
|
const handleEdit = async (row: any) => {
|
||||||
console.log('编辑', row);
|
console.log('row', row)
|
||||||
// 并行请求点差配置和下拉选项
|
// 并行请求点差配置和下拉选项
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
getPointDiffConfig(row),
|
// getPointDiffConfig(row),
|
||||||
getOptions()
|
getOptions()
|
||||||
])
|
])
|
||||||
|
// 填充表单数据
|
||||||
agentForm.value = {
|
agentForm.value = {
|
||||||
username: row.username || '',
|
username: row.username || '',
|
||||||
parentUsername: row.parentUsername || '',
|
parentUsername: row.parentUsername || '',
|
||||||
|
|
@ -295,8 +313,9 @@ const handleEdit = async (row: any) => {
|
||||||
positionRatio: row.wallet_capital.toucun_percent || '',
|
positionRatio: row.wallet_capital.toucun_percent || '',
|
||||||
feeRate: row.feeRate || '',
|
feeRate: row.feeRate || '',
|
||||||
id: row.id || '',
|
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
|
dialogVisible.value = true
|
||||||
dialogTitle.value = '编辑'
|
dialogTitle.value = '编辑'
|
||||||
dialogType.value = 'edit'
|
dialogType.value = 'edit'
|
||||||
|
|
@ -341,7 +360,6 @@ const formatPointDiffToObject = () => {
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
await agentFormRef.value.validate()
|
await agentFormRef.value.validate()
|
||||||
const pointDiffObj = formatPointDiffToObject()
|
const pointDiffObj = formatPointDiffToObject()
|
||||||
console.log('agentForm.value', agentForm.value)
|
|
||||||
const params = {
|
const params = {
|
||||||
user_id: agentForm.value.id || '',
|
user_id: agentForm.value.id || '',
|
||||||
toucun_percent: agentForm.value.positionRatio || '',
|
toucun_percent: agentForm.value.positionRatio || '',
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ export const agentTableColumns = [
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
// 查看点差表格列配置
|
// 查看代理点差表格列配置
|
||||||
export const viewAgentPointTableColumns = [
|
export const viewAgentPointTableColumns = [
|
||||||
{ prop: 'varietyName', label: '品种名称', align: 'center' as const },
|
{ prop: 'varietyName', label: '品种名称', align: 'center' as const },
|
||||||
{ prop: 'varietyCode', 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 },
|
{ prop: 'assignedPointDifference', label: '已分配点差', align: 'center' as const },
|
||||||
]
|
]
|
||||||
|
|
||||||
//编辑点差表格列配置
|
//编辑代理表格列配置
|
||||||
export const agentPointTableColumns = ([
|
export const agentPointTableColumns = ([
|
||||||
{ prop: 'varietyName', label: '名称', align: 'center' as const },
|
{ prop: 'varietyName', label: '名称', align: 'center' as const },
|
||||||
{ prop: 'varietyCode', label: '编号', align: 'center' as const },
|
{ prop: 'varietyCode', label: '编号', align: 'center' as const },
|
||||||
|
|
@ -58,8 +58,8 @@ export const agentPointTableColumns = ([
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
//编辑点差form配置
|
//编辑代理form配置
|
||||||
export const PointDiffFormItem = [
|
export const agentFormItem = [
|
||||||
//代理名称
|
//代理名称
|
||||||
{ prop: 'username', label: '代理名称', type: 'input' as const, placeholder: '代理名称', width: '120px' },
|
{ prop: 'username', label: '代理名称', type: 'input' as const, placeholder: '代理名称', width: '120px' },
|
||||||
//所属上级
|
//所属上级
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
return {
|
||||||
name: [
|
username: [
|
||||||
{ required: true, message: '请输入名称', trigger: ['blur'] }
|
{ required: true, message: '请输入名称', trigger: ['blur'] }
|
||||||
],
|
],
|
||||||
pointDiff: [
|
parentUsername: [
|
||||||
{ required: true, message: '请输入点差', trigger: ['blur'] }
|
{ 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']
|
||||||
|
}
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue