添加用户新增代理选择
This commit is contained in:
@@ -289,25 +289,39 @@
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="账户类型" prop="accountType">
|
||||
<el-radio-group v-model="userForm.accountType">
|
||||
<el-radio label="normal">普通商户</el-radio>
|
||||
<el-radio label="direct">直营商户</el-radio>
|
||||
<el-radio label="virtual">虚拟商户</el-radio>
|
||||
</el-radio-group>
|
||||
<el-select v-model="userForm.accountType" placeholder="请选择账户类型" style="width: 100%">
|
||||
<el-option label="普通用户" value="user" />
|
||||
<el-option label="直营" value="directly_operated" />
|
||||
<el-option label="代理" value="agent" />
|
||||
<el-option label="直营代理" value="agent_directly" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<div class="account-type-tip" v-if="userForm.accountType === 'virtual'">
|
||||
<el-text size="small" type="info">
|
||||
虚拟商户:用于新用户资金流向,对其他商户显示为普通商户,仅后台可见标识
|
||||
</el-text>
|
||||
</div>
|
||||
<div class="account-type-tip" v-if="userForm.accountType === 'direct'">
|
||||
<el-text size="small" type="warning">
|
||||
直营商户:具有特殊权限
|
||||
</el-text>
|
||||
</div>
|
||||
<!-- 代理选择器 -->
|
||||
<el-row :gutter="20" v-if="userForm.accountType === 'agent' || userForm.accountType === 'agent_directly'">
|
||||
<el-col :span="24">
|
||||
<el-form-item label="选择代理" prop="inviter">
|
||||
<el-select
|
||||
v-model="userForm.inviter"
|
||||
placeholder="请选择代理"
|
||||
style="width: 100%"
|
||||
filterable
|
||||
remote
|
||||
:remote-method="searchAgents"
|
||||
:loading="agentLoading"
|
||||
>
|
||||
<el-option
|
||||
v-for="agent in agentOptions"
|
||||
:key="agent.id"
|
||||
:label="`${agent.username} (${agent.real_name || '未设置姓名'})`"
|
||||
:value="agent.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
@@ -540,6 +554,8 @@ const isEdit = ref(false)
|
||||
const users = ref([])
|
||||
const regions = ref([])
|
||||
const regionOptions = ref([])
|
||||
const agentOptions = ref([])
|
||||
const agentLoading = ref(false)
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = reactive({
|
||||
@@ -565,7 +581,8 @@ const userForm = reactive({
|
||||
username: '',
|
||||
password: '',
|
||||
role: 'user',
|
||||
accountType: 'normal', // 账户类型:normal-普通商户,virtual-虚拟商户
|
||||
accountType: 'user', // 账户类型:user-普通用户,directly_operated-直营,agent-代理,agent_directly-直营代理
|
||||
inviter: null, // 代理人ID
|
||||
avatar: '',
|
||||
realName: '',
|
||||
idCard: '',
|
||||
@@ -610,6 +627,18 @@ const userRules = computed(() => ({
|
||||
],
|
||||
region: [
|
||||
{ required: true, message: '请选择省市区', trigger: 'change' }
|
||||
],
|
||||
inviter: [
|
||||
{
|
||||
validator: (rule, value, callback) => {
|
||||
if ((userForm.accountType === 'agent' || userForm.accountType === 'agent_directly') && !value) {
|
||||
callback(new Error('选择代理类型时必须选择代理人'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
trigger: 'change'
|
||||
}
|
||||
]
|
||||
}))
|
||||
|
||||
@@ -869,7 +898,8 @@ const showEditDialog = (user) => {
|
||||
username: user.username,
|
||||
password: '',
|
||||
role: user.role,
|
||||
accountType: user.is_system_account ? 'virtual' : (user.is_direct_account ? 'direct' : 'normal'),
|
||||
accountType: user.user_type || 'user',
|
||||
inviter: user.inviter || null,
|
||||
avatar: user.avatar || '',
|
||||
realName: user.real_name || '',
|
||||
idCard: user.id_card || '',
|
||||
@@ -901,8 +931,7 @@ const handleSubmit = async () => {
|
||||
const userData = {
|
||||
username: userForm.username,
|
||||
role: userForm.role,
|
||||
isSystemAccount: userForm.accountType === 'virtual', // 转换为后端字段
|
||||
isDirectAccount: userForm.accountType === 'direct', // 转换为后端字段
|
||||
user_type: userForm.accountType, // 使用新的账户类型字段
|
||||
avatar: userForm.avatar,
|
||||
realName: userForm.realName,
|
||||
idCard: userForm.idCard,
|
||||
@@ -920,6 +949,11 @@ const handleSubmit = async () => {
|
||||
businessLicense: userForm.businessLicense
|
||||
}
|
||||
|
||||
// 如果选择了代理类型,添加代理人ID
|
||||
if ((userForm.accountType === 'agent' || userForm.accountType === 'agent_directly') && userForm.inviter) {
|
||||
userData.inviter = userForm.inviter
|
||||
}
|
||||
|
||||
// 如果是创建模式或编辑模式下输入了密码,则包含密码字段
|
||||
if (!isEdit.value || (userForm.password && userForm.password.trim() !== '')) {
|
||||
userData.password = userForm.password
|
||||
@@ -978,7 +1012,8 @@ const resetUserForm = () => {
|
||||
username: '',
|
||||
password: '',
|
||||
role: 'user',
|
||||
accountType: 'normal',
|
||||
accountType: 'user',
|
||||
inviter: null,
|
||||
avatar: '',
|
||||
realName: '',
|
||||
idCard: '',
|
||||
@@ -1100,16 +1135,58 @@ const formatPoints = (points) => {
|
||||
|
||||
// 获取账户类型显示文本
|
||||
const getAccountTypeText = (row) => {
|
||||
if (row.is_system_account) return '虚拟商户'
|
||||
if (row.is_direct_account) return '直营商户'
|
||||
return '普通商户'
|
||||
const typeMap = {
|
||||
'user': '普通用户',
|
||||
'directly_operated': '直营',
|
||||
'agent': '代理',
|
||||
'agent_directly': '直营代理'
|
||||
}
|
||||
return typeMap[row.user_type] || '普通用户'
|
||||
}
|
||||
|
||||
// 获取账户类型标签颜色
|
||||
const getAccountTypeColor = (row) => {
|
||||
if (row.is_system_account) return 'warning'
|
||||
if (row.is_direct_account) return 'danger'
|
||||
return 'success'
|
||||
const colorMap = {
|
||||
'user': 'success',
|
||||
'directly_operated': 'warning',
|
||||
'agent': 'info',
|
||||
'agent_directly': 'danger'
|
||||
}
|
||||
return colorMap[row.user_type] || 'success'
|
||||
}
|
||||
|
||||
// 获取代理列表
|
||||
const fetchAgents = async () => {
|
||||
try {
|
||||
agentLoading.value = true
|
||||
const response = await axios.get('/api/agent')
|
||||
agentOptions.value = response.data?.data || []
|
||||
} catch (error) {
|
||||
console.error('获取代理列表失败:', error)
|
||||
ElMessage.error('获取代理列表失败')
|
||||
} finally {
|
||||
agentLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索代理
|
||||
const searchAgents = async (query) => {
|
||||
if (!query) {
|
||||
await fetchAgents()
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
agentLoading.value = true
|
||||
const response = await axios.get('/api/agent', {
|
||||
params: { search: query }
|
||||
})
|
||||
agentOptions.value = response.data?.data || []
|
||||
} catch (error) {
|
||||
console.error('搜索代理失败:', error)
|
||||
} finally {
|
||||
agentLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 组件挂载时获取数据
|
||||
@@ -1117,6 +1194,7 @@ onMounted(() => {
|
||||
fetchUsers()
|
||||
getRegions()
|
||||
loadRegionOptions()
|
||||
fetchAgents()
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user