diff --git a/src/views/profile/business/index.vue b/src/views/profile/business/index.vue index 072d8d7..5890e1b 100644 --- a/src/views/profile/business/index.vue +++ b/src/views/profile/business/index.vue @@ -187,7 +187,133 @@ @close="handleRightClickDialogClose" > + + + + { const handleAction = (key: 'account' | 'acceptOrders' | 'transfer' | 'deposit' | 'withdraw') => { console.log('handleAction', key, currentRow.value) if (!currentRow.value) return - switch (key) { - case 'account': - rightClickMarketFormItemOptions.value = accountFormItemList - rightClickMarketFormRules.value = accountFormItemRules - rightClickMarketForm.value = { - target_user_id: currentRow.value!.wallet_capital.user_id, - username: currentRow.value!.username, - currency: 'USD', - amount_old: currentRow.value!.wallet_capital.amount, - amount: null, - amount_new: null, - } - break - case 'acceptOrders': - rightClickMarketFormItemOptions.value = acceptOrdersFormItemList - rightClickMarketFormRules.value = acceptOrdersFormItemRules - rightClickMarketForm.value = { - target_user_id: currentRow.value!.wallet_capital.user_id, - username: currentRow.value!.username, - currency: 'USD', - bail_stop_order_old: currentRow.value!.wallet_capital.bail_stop_order, - bail_stop_order: '', - } - break - case 'transfer': - rightClickMarketFormItemOptions.value = transferFormItemList - rightClickMarketFormRules.value = transferFormItemRules - rightClickMarketForm.value = { - target_user_id: currentRow.value!.wallet_capital.user_id, - username: currentRow.value!.username, - currency: 'USD', - bail_change_order_old: currentRow.value!.wallet_capital.bail_change_order, - bail_change_order: '', - } - break - case 'deposit': - break - case 'withdraw': - return ElMessage.warning('暂无此功能') - break - } - rightClickDialogType.value = key - rightClickDialogVisible.value = true + // 先重置表单数据,确保使用全新对象 + rightClickMarketForm.value = {} + nextTick(() => { + switch (key) { + case 'account': + rightClickMarketFormItemOptions.value = accountFormItemList + rightClickMarketFormRules.value = accountFormItemRules + rightClickMarketForm.value = { + target_user_id: currentRow.value!.wallet_capital.user_id, + username: currentRow.value!.username, + currency: 'USD', + amount_old: currentRow.value!.wallet_capital.amount, + amount: null, + amount_new: null, + } + break + case 'acceptOrders': + rightClickMarketFormItemOptions.value = acceptOrdersFormItemList + rightClickMarketFormRules.value = acceptOrdersFormItemRules + rightClickMarketForm.value = { + target_user_id: currentRow.value!.wallet_capital.user_id, + username: currentRow.value!.username, + currency: 'USD', + bail_stop_order_old: currentRow.value!.wallet_capital.bail_stop_order, + bail_stop_order: '', + } + break + case 'transfer': + rightClickMarketFormItemOptions.value = transferFormItemList + rightClickMarketFormRules.value = transferFormItemRules + rightClickMarketForm.value = { + target_user_id: currentRow.value!.wallet_capital.user_id, + username: currentRow.value!.username, + currency: 'USD', + bail_change_order_old: currentRow.value!.wallet_capital.bail_change_order, + bail_change_order: '', + } + break + case 'deposit': + // 获取当前行的角色ID + const targetRoleId = currentRow.value!.role_id * 1 + // 设置取款表单配置 + rightClickMarketFormItemOptions.value = getWithdrawFormConfig(targetRoleId) + rightClickMarketFormRules.value = getWithdrawFormRules(targetRoleId) + // 获取取款渠道列表 + fetchWithdrawChannel() + // 初始化表单数据 + rightClickMarketForm.value = { + target_user_id: currentRow.value!.wallet_capital.user_id, + username: currentRow.value!.username, + currency: 'USD', + // 各角色的最大金额 + commission_fee_handling_max: currentRow.value!.wallet_capital.commission_fee_handling || '0', // 手续费佣金最大值 + commission_point_diff_max: currentRow.value!.wallet_capital.commission_point_diff || '0', // 点差佣金最大值 + service_max: currentRow.value!.wallet_capital.service || '0', // 服务费最大值 + risk_max: currentRow.value!.wallet_capital.risk || '0', // 风险金最大值 + closing_profit_max: currentRow.value!.wallet_capital.closing_profit || '0', // 盈利最大值 + // 表单输入值 + withdraw_fee_handle: '', + withdraw_point_diff: '', + withdraw_service_fee: '', + withdraw_risk_fee: '', + withdraw_head_fee: '', + // 钱包地址和渠道(必填) + withdraw_address: '', + channel_id: '', + } + break + case 'withdraw': + ElMessage.warning('暂无此功能') + return + } + rightClickDialogType.value = key + rightClickDialogVisible.value = true + }) } const handleRightClickDialogSubmit = () => { @@ -513,6 +675,7 @@ const handleRightClickDialogSubmit = () => { }) break case 'deposit': + handleWithdrawSubmit() break case 'withdraw': ElMessage.warning('暂无此功能') @@ -529,6 +692,102 @@ const handleRightClickDialogClose = () => { rightClickDialogVisible.value = false } +// 取款渠道列表 +const withdrawChannelOptions = ref<{ label: string; value: number }[]>([]) + +// 获取取款渠道列表 +const fetchWithdrawChannel = async () => { + try { + const res = await getAgentWithdrawChannel() + withdrawChannelOptions.value = res.map((item: any) => ({ + label: item.name, + value: item.id, + })) + } catch (error) { + console.error('获取取款渠道列表失败', error) + } +} + +// 处理取款提交 +const handleWithdrawSubmit = async () => { + const form = rightClickMarketForm.value + + // 验证必填字段 + if (!form.withdraw_address) { + ElMessage.warning('请输入钱包地址') + return + } + if (!form.channel_id) { + ElMessage.warning('请选择取款渠道') + return + } + + // 构建提交参数 + const params = { + user_id: form.target_user_id, + amount: calculateTotalWithdrawAmount(form), + channel_id: form.channel_id, + withdraw_address: form.withdraw_address, + withdraw_fee_handle: form.withdraw_fee_handle || '0', + withdraw_point_diff: form.withdraw_point_diff || '0', + withdraw_service_fee: form.withdraw_service_fee || '0', + withdraw_head_fee: form.withdraw_head_fee || '0', + withdraw_risk_fee: form.withdraw_risk_fee || '0', + } + + try { + startSubmitLoading() + await agentWithdraw(params) + ElMessage.success('取款申请提交成功') + rightClickDialogVisible.value = false + // 刷新列表 + getMarketList() + } catch (error) { + console.error('取款提交失败', error) + } finally { + stopSubmitLoading() + } +} + +// 计算取款总金额 +const calculateTotalWithdrawAmount = (form: any): string => { + const feeHandle = parseFloat(form.withdraw_fee_handle) || 0 + const pointDiff = parseFloat(form.withdraw_point_diff) || 0 + const serviceFee = parseFloat(form.withdraw_service_fee) || 0 + const headFee = parseFloat(form.withdraw_head_fee) || 0 + const riskFee = parseFloat(form.withdraw_risk_fee) || 0 + return String(feeHandle + pointDiff + serviceFee + headFee + riskFee) +} + +// 验证输入金额不能超过最大值 +const validateWithdrawAmount = (value: string, maxValue: string): boolean => { + if (!value || !maxValue) return true + return parseFloat(value) <= parseFloat(maxValue) +} + +// 处理取款金额输入 +const handleWithdrawAmountInput = (field: string) => { + const form = rightClickMarketForm.value + const maxFieldMap: Record = { + withdraw_fee_handle: 'commission_fee_handling_max', + withdraw_point_diff: 'commission_point_diff_max', + withdraw_service_fee: 'service_max', + withdraw_risk_fee: 'risk_max', + withdraw_head_fee: 'closing_profit_max', + } + const maxField = maxFieldMap[field] + if (!maxField) return + + const currentValue = parseFloat(form[field]) || 0 + const maxValue = parseFloat(form[maxField]) || 0 + + if (currentValue > maxValue) { + ElMessage.warning(`输入金额不能超过最大可取金额 ${maxValue}`) + // 自动截断到最大值 + form[field] = String(maxValue) + } +} + /** * @description 数据处理方法 * 映射表格数据 @@ -947,11 +1206,9 @@ const handleSubmit = async () => { params.flag = 2 params.role_id = '5' } - // 添加承接特殊做市字段 - if (marketForm.value.level === '3') { - params.is_base_ts = marketForm.value.is_base_ts - params.base_ts = marketForm.value.is_base_ts === 1 ? 0 : marketForm.value.base_ts - } + // 添加承接特殊做市字段(统一传递,未选择时传null) + params.is_base_ts = marketForm.value.level === '3' ? marketForm.value.is_base_ts : null + params.base_ts = marketForm.value.level === '3' && marketForm.value.is_base_ts !== 1 ? marketForm.value.base_ts : null await addMarketApi(params) // 5. 刷新表格数据 await getMarketList() @@ -970,11 +1227,9 @@ const handleSubmit = async () => { flag: flag, fee_setting_id: '', } - // 添加承接特殊做市字段 - if (marketForm.value.level === '3') { - params.is_base_ts = marketForm.value.is_base_ts - params.base_ts = marketForm.value.is_base_ts === 1 ? 0 : marketForm.value.base_ts - } + // 添加承接特殊做市字段(统一传递,未选择时传null) + params.is_base_ts = marketForm.value.level === '3' ? marketForm.value.is_base_ts : null + params.base_ts = marketForm.value.level === '3' && marketForm.value.is_base_ts !== 1 ? marketForm.value.base_ts : null // 4. 调用编辑接口 await editMarketApi(params) // 5. 刷新表格数据 @@ -1096,4 +1351,26 @@ const handleCancel = async () => { .profit-negative { color: #F56C6C; } + +// 取款表单样式 +.withdraw-form { + padding: 0 10px; + + .form-section { + margin-bottom: 24px; + + .section-title { + font-size: 14px; + font-weight: 500; + color: #303133; + margin-bottom: 16px; + padding-bottom: 8px; + border-bottom: 1px solid #ebeef5; + } + + .el-form-item { + margin-bottom: 16px; + } + } +} diff --git a/src/views/profile/business/options.ts b/src/views/profile/business/options.ts index 7bd3764..32ee32e 100644 --- a/src/views/profile/business/options.ts +++ b/src/views/profile/business/options.ts @@ -145,4 +145,131 @@ export const transferFormItemList = [ export const transferFormItemRules = { bail_change_order: [{ required: true, message: '请输入调整金额', trigger: ['blur', 'change'] }], +} + +// 取款表单配置(根据不同角色显示不同字段) +// 平台(1): 币种、手续费佣金、点差佣金、服务费、风险金 +// 承包商(2): 币种、手续费佣金、点差佣金、服务费 +// 特殊做市商(3): 币种、手续费佣金、点差佣金、服务费、盈利 +// 普通做市商(4): 币种、手续费佣金、点差佣金、盈利 +// 代理(5): 币种、手续费佣金、点差佣金 + +export interface WithdrawFormConfig { + prop: string + label: string + type: 'input' | 'select' + disabled?: boolean + required?: boolean + placeholder?: string + max?: number | string +} + +export const getWithdrawFormConfig = (roleId: number): WithdrawFormConfig[] => { + const baseConfig: WithdrawFormConfig[] = [ + { prop: 'currency', label: '币种', type: 'input', disabled: true }, + ] + + // 手续费佣金(所有角色都有) + const feeHandlingConfig: WithdrawFormConfig = { + prop: 'withdraw_fee_handle', + label: '手续费佣金', + type: 'input', + required: true, + placeholder: '请输入手续费佣金', + } + + // 点差佣金(所有角色都有) + const pointDiffConfig: WithdrawFormConfig = { + prop: 'withdraw_point_diff', + label: '点差佣金', + type: 'input', + required: true, + placeholder: '请输入点差佣金', + } + + // 服务费(平台、承包商、特殊做市商) + const serviceFeeConfig: WithdrawFormConfig = { + prop: 'withdraw_service_fee', + label: '服务费', + type: 'input', + required: true, + placeholder: '请输入服务费', + } + + // 风险金(仅平台) + const riskFeeConfig: WithdrawFormConfig = { + prop: 'withdraw_risk_fee', + label: '风险金', + type: 'input', + required: true, + placeholder: '请输入风险金', + } + + // 盈利(特殊做市商、普通做市商) + const headFeeConfig: WithdrawFormConfig = { + prop: 'withdraw_head_fee', + label: '盈利', + type: 'input', + required: true, + placeholder: '请输入盈利', + } + + switch (roleId) { + case 1: // 平台 + return [ + ...baseConfig, + feeHandlingConfig, + pointDiffConfig, + serviceFeeConfig, + riskFeeConfig, + ] + case 2: // 承包商 + return [ + ...baseConfig, + feeHandlingConfig, + pointDiffConfig, + serviceFeeConfig, + ] + case 3: // 特殊做市商 + return [ + ...baseConfig, + feeHandlingConfig, + pointDiffConfig, + serviceFeeConfig, + headFeeConfig, + ] + case 4: // 普通做市商 + return [ + ...baseConfig, + feeHandlingConfig, + pointDiffConfig, + headFeeConfig, + ] + case 5: // 一级代理 + return [ + ...baseConfig, + feeHandlingConfig, + pointDiffConfig, + ] + default: + return baseConfig + } +} + +// 取款表单验证规则 +export const getWithdrawFormRules = (roleId: number) => { + const rules: Record = { + withdraw_address: [{ required: true, message: '请输入钱包地址', trigger: ['blur', 'change'] }], + channel_id: [{ required: true, message: '请选择取款渠道', trigger: ['change'] }], + } + + // 添加各角色的验证规则 + const config = getWithdrawFormConfig(roleId) + config.forEach((item) => { + if (item.required) { + rules[item.prop] = [{ required: true, message: `请输入${item.label}`, trigger: ['blur', 'change'] }] + } + }) + + return rules } \ No newline at end of file