diff --git a/src/api/modules/user.ts b/src/api/modules/user.ts index 9b79257..48ad565 100644 --- a/src/api/modules/user.ts +++ b/src/api/modules/user.ts @@ -61,3 +61,28 @@ export async function logoutApi(params: { device_no: string }) { export async function sendCodeApi(params: SendCodeParams) { return request.post('/sendCode', params); } + +/** + * 调整用户金额 + * @param params 调整金额参数(目标用户ID/调整金额) + * @returns Promise 调整成功返回true + */ +export async function updateCapitalApi(params: { target_user_id: number; amount: string }) { + return request.post('/user/updateCapital', params); +} + +/** + * 修改用户信息 + * @param params 修改用户参数(用户ID/风控模板ID/手续费模板ID/用户名/是否升级/状态) + * @returns Promise 修改成功返回true + */ +export async function editUserApi(params: { + user_id: number; + risk_control_id?: string | number; + fee_setting_id?: string | number; + username?: string; + is_levelup?: number; + status?: number; +}) { + return request.post('/user/editUser', params); +} diff --git a/src/views/agent/user/index.vue b/src/views/agent/user/index.vue index 1f2803d..24379d3 100644 --- a/src/views/agent/user/index.vue +++ b/src/views/agent/user/index.vue @@ -1,40 +1,20 @@ - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 正常 + 封禁 + + + - + @@ -127,6 +142,11 @@ import { getSelfVarietyPointDiffConfigApi, editCustomerApi, } from '@/api/modules/agent/customerList' +import { updateCapitalApi, editUserApi } from '@/api/modules/user' +import { + getFeeTemplateOptionsApi, + getRiskTemplateOptionsApi, +} from '@/api/modules/account/client' // 公用方法 import { getStorage } from '@/utils/storage' @@ -231,6 +251,60 @@ const commissionRatioFormRules = { const commissionRatioFormItemOptions = ref(commissionRatioFormItem) const selectId = ref('') +/** + * @description 定义修改客户弹窗数据 + */ +const editCustomerVisible = ref(false) +const editCustomerFormRef = ref() +const editCustomerUserId = ref(0) +const editCustomerForm = ref({ + feeSettingId: '', + riskControlId: '', + username: '', + isLevelUp: 2, + status: 1, +}) +const editCustomerRules = { + feeSettingId: [{ required: true, message: '请选择手续费模板', trigger: 'change' }], + riskControlId: [{ required: true, message: '请选择风控模板', trigger: 'change' }], + isLevelUp: [{ required: true, message: '请选择是否升级成代理', trigger: 'change' }], + status: [{ required: true, message: '请选择状态', trigger: 'change' }], +} +const feeTemplateOptions = ref([]) +const riskTemplateOptions = ref([]) +const templateOptionsFetched = ref(false) + +/** + * @description 定义调整金额弹窗数据 + */ +const adjustAmountVisible = ref(false) +const adjustAmountFormRef = ref() +const adjustUserId = ref(0) +const adjustAmountForm = ref({ + username: '', + currency: '', + currentBalance: '', + adjustAmount: '', + afterBalance: '', +}) +const adjustAmountRules = { + adjustAmount: [ + { required: true, message: '请输入调整金额', trigger: 'blur' }, + { + validator: (rule: any, value: any, callback: any) => { + if (value === '' || value === null || value === undefined) { + callback(new Error('请输入调整金额')) + } else if (!/^-?\d+(\.\d{1,5})?$/.test(value)) { + callback(new Error('请输入有效的金额格式,最多五位小数')) + } else { + callback() + } + }, + trigger: 'blur' + } + ] +} + /** * @description: 角色映射方法 */ @@ -277,10 +351,10 @@ const getCustomerList = async (id: string) => { children: item.role_id === 5 ? [ - { - hasChildren: true, - }, - ] + { + hasChildren: true, + }, + ] : undefined, })) console.log('tableTree', tableTree.value) @@ -399,10 +473,10 @@ const handleGetSubList = async (row: any) => { children: item.role_id === 5 ? [ - { - hasChildren: true, - }, - ] + { + hasChildren: true, + }, + ] : undefined, })) } @@ -478,6 +552,133 @@ const handleClose = () => { dialogVisible.value = false } +/** + * @description 调整金额相关方法 + */ +// 打开调整金额弹窗 +const handleAdjustAmount = (row: any) => { + adjustAmountVisible.value = true + adjustUserId.value = row.userId + // 注意:这里需要从原始数据中获取余额,如果row中没有balance字段,可能需要重新获取 + // 暂时使用默认值,实际使用时需要根据数据结构调整 + const balance = row.balance || row.wallet_capital?.amount || '0' + adjustAmountForm.value = { + username: row.accountName, + currency: 'USDT', // 默认币种,可根据实际情况调整 + currentBalance: balance, + adjustAmount: '', + afterBalance: balance, + } +} + +// 调整金额输入变化时计算调整后余额 +const handleAdjustAmountInput = () => { + const currentBalance = parseFloat(adjustAmountForm.value.currentBalance) || 0 + const adjustAmount = parseFloat(adjustAmountForm.value.adjustAmount) || 0 + const afterBalance = currentBalance + adjustAmount + adjustAmountForm.value.afterBalance = afterBalance.toFixed(5) +} + +// 提交调整金额 +const handleAdjustAmountSubmit = async () => { + try { + await adjustAmountFormRef.value?.validate() + await updateCapitalApi({ + target_user_id: adjustUserId.value, + amount: adjustAmountForm.value.adjustAmount, + }) + await getCustomerList(userId.value) + adjustAmountVisible.value = false + } catch (err) { + console.error('调整金额表单验证失败', err) + } +} + +// 取消调整金额 +const handleAdjustAmountCancel = () => { + adjustAmountVisible.value = false +} + +// 关闭调整金额弹窗 +const handleAdjustAmountClose = () => { + adjustAmountVisible.value = false +} + +/** + * @description 修改客户相关方法 + */ +// 获取模板选项 +const getTemplateOptions = async () => { + if (templateOptionsFetched.value) return + + try { + const [feeTemplateRes, riskTemplateRes] = await Promise.all([ + getFeeTemplateOptionsApi(), + getRiskTemplateOptionsApi(), + ]) + + feeTemplateOptions.value = Object.entries(feeTemplateRes as Record).map( + ([label, value]) => ({ + label, + value, + }), + ) + riskTemplateOptions.value = Object.entries(riskTemplateRes as Record).map( + ([label, value]) => ({ + label, + value, + }), + ) + + templateOptionsFetched.value = true + } catch (error) { + console.error('获取模板选项失败:', error) + } +} + +// 打开修改客户弹窗 +const handleEditCustomer = async (row: any) => { + await getTemplateOptions() + editCustomerVisible.value = true + editCustomerUserId.value = row.userId + editCustomerForm.value = { + feeSettingId: row.feeSettingId || '', + riskControlId: row.riskControlId || '', + username: row.accountName || '', + isLevelUp: row.isLevelUp || 2, + status: row.status === '正常' ? 1 : 2, + } +} + +// 提交修改客户 +const handleEditCustomerSubmit = async () => { + try { + await editCustomerFormRef.value?.validate() + await editUserApi({ + user_id: editCustomerUserId.value, + fee_setting_id: editCustomerForm.value.feeSettingId, + risk_control_id: editCustomerForm.value.riskControlId, + username: editCustomerForm.value.username, + is_levelup: editCustomerForm.value.isLevelUp, + status: editCustomerForm.value.status, + }) + await getCustomerList(userId.value) + editCustomerVisible.value = false + } catch (err) { + console.error('修改客户表单验证失败', err) + } +} + +// 取消修改客户 +const handleEditCustomerCancel = () => { + editCustomerVisible.value = false +} + +// 关闭修改客户弹窗 +const handleEditCustomerClose = () => { + editCustomerVisible.value = false +} + \ No newline at end of file diff --git a/src/views/agent/user/options.ts b/src/views/agent/user/options.ts index 2fdac52..febbbc2 100644 --- a/src/views/agent/user/options.ts +++ b/src/views/agent/user/options.ts @@ -17,23 +17,23 @@ export const search = [ export const tableColumns = [ // 账号名称 - { label: '账号名称', prop: 'accountName'}, + { label: '账号名称', prop: 'accountName', }, // 账号id { prop: 'userId', label: '账号id' }, // 状态 { prop: 'status', label: '状态' }, // 账号角色 - { prop: 'role', label: '账号角色' }, + { prop: 'role', label: '账号角色', width: 100 }, // 账号数量 - { prop: 'accountQty', label: '账号数量' }, + { prop: 'accountQty', label: '账号数量', width: 100 }, // 点差分配比例 - { prop: 'marginRatio', label: '点差分配比例', slotName: 'marginRatio' }, + { prop: 'marginRatio', label: '点差分配比例', slotName: 'marginRatio' , minWidth: 140}, // 手续费分成比例 - { prop: 'commissionRatio', label: '手续费分成比例', slotName: 'commissionRatio' }, + { prop: 'commissionRatio', label: '手续费分成比例', slotName: 'commissionRatio' , minWidth: 140}, // 注册时间 - { prop: 'createTime', label: '注册时间', sortable: true }, + { prop: 'createTime', label: '注册时间', sortable: true , minWidth: 180}, // 操作 - { label: '操作', slotName: 'action' } + { label: '操作', slotName: 'action', minWidth: 200} ] // 点差表格配置 diff --git a/src/views/profile/user/index.vue b/src/views/profile/user/index.vue index 822a617..4fe9eec 100644 --- a/src/views/profile/user/index.vue +++ b/src/views/profile/user/index.vue @@ -23,6 +23,9 @@ 修改 + + 调整金额 + @@ -92,6 +95,38 @@ + + + + + + + + + + + + + + + + + + + + +