21
This commit is contained in:
parent
7f4e80bb5b
commit
b099a72f79
|
|
@ -41,7 +41,7 @@ export interface GenerateResult {
|
|||
}
|
||||
|
||||
export interface AssignInviteCodesRequest {
|
||||
codeIds: number[]
|
||||
inviteCodeIds: number[]
|
||||
userId: number
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -110,13 +110,34 @@
|
|||
</el-dialog>
|
||||
|
||||
<!-- 分配对话框 -->
|
||||
<el-dialog v-model="assignDialogVisible" title="分配邀请码" width="400px">
|
||||
<el-dialog v-model="assignDialogVisible" title="分配邀请码" width="500px">
|
||||
<el-form :model="assignForm" :rules="assignRules" ref="assignFormRef" label-width="100px">
|
||||
<el-form-item label="邀请码数量">
|
||||
<span>{{ assignForm.codeIds.length }} 个</span>
|
||||
<span>{{ assignForm.inviteCodeIds.length }} 个</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="分配用户" prop="userId">
|
||||
<el-input v-model.number="assignForm.userId" placeholder="请输入用户ID" />
|
||||
<el-select
|
||||
v-model="assignForm.userId"
|
||||
filterable
|
||||
remote
|
||||
reserve-keyword
|
||||
placeholder="输入昵称/手机号/UID搜索用户"
|
||||
:remote-method="searchUsers"
|
||||
:loading="userSearchLoading"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="user in userOptions"
|
||||
:key="user.id"
|
||||
:label="`${user.nickname} (${user.uid})`"
|
||||
:value="user.id"
|
||||
>
|
||||
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||
<span>{{ user.nickname }} <span style="color: #909399; font-size: 12px;">{{ user.uid }}</span></span>
|
||||
<span style="color: #909399; font-size: 12px;">{{ user.phone || '未绑定手机' }}</span>
|
||||
</div>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
|
|
@ -162,6 +183,7 @@ import {
|
|||
type InviteCodeQuery,
|
||||
type GenerateResult
|
||||
} from '@/api/business/distribution'
|
||||
import { getUserList, type UserItem } from '@/api/business/user'
|
||||
|
||||
// 列表数据
|
||||
const loading = ref(false)
|
||||
|
|
@ -194,9 +216,36 @@ const resultDialogVisible = ref(false)
|
|||
const assignDialogVisible = ref(false)
|
||||
const assignLoading = ref(false)
|
||||
const assignFormRef = ref<FormInstance>()
|
||||
const assignForm = reactive({ codeIds: [] as number[], userId: undefined as number | undefined })
|
||||
const assignForm = reactive({ inviteCodeIds: [] as number[], userId: undefined as number | undefined })
|
||||
const assignRules: FormRules = {
|
||||
userId: [{ required: true, message: '请输入用户ID', trigger: 'blur' }]
|
||||
userId: [{ required: true, message: '请选择用户', trigger: 'change' }]
|
||||
}
|
||||
|
||||
// 用户搜索
|
||||
const userSearchLoading = ref(false)
|
||||
const userOptions = ref<UserItem[]>([])
|
||||
const searchUsers = async (query: string) => {
|
||||
if (!query || query.length < 1) {
|
||||
userOptions.value = []
|
||||
return
|
||||
}
|
||||
userSearchLoading.value = true
|
||||
try {
|
||||
// 先按昵称搜索
|
||||
const res = await getUserList({ pageIndex: 1, pageSize: 20, nickname: query })
|
||||
if (res.code === 0) {
|
||||
userOptions.value = res.data.list
|
||||
}
|
||||
// 如果没结果,尝试按UID搜索
|
||||
if (userOptions.value.length === 0) {
|
||||
const uidRes = await getUserList({ pageIndex: 1, pageSize: 20, uid: query })
|
||||
if (uidRes.code === 0) {
|
||||
userOptions.value = uidRes.data.list
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
userSearchLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 状态类型映射
|
||||
|
|
@ -254,13 +303,15 @@ const handleSubmitGenerate = async () => {
|
|||
|
||||
// 分配
|
||||
const handleAssign = (row: InviteCodeItem) => {
|
||||
assignForm.codeIds = [row.id]
|
||||
assignForm.inviteCodeIds = [row.id]
|
||||
assignForm.userId = undefined
|
||||
userOptions.value = []
|
||||
assignDialogVisible.value = true
|
||||
}
|
||||
const handleBatchAssign = () => {
|
||||
assignForm.codeIds = selectedRows.value.map(r => r.id)
|
||||
assignForm.inviteCodeIds = selectedRows.value.map(r => r.id)
|
||||
assignForm.userId = undefined
|
||||
userOptions.value = []
|
||||
assignDialogVisible.value = true
|
||||
}
|
||||
const handleSubmitAssign = async () => {
|
||||
|
|
@ -268,7 +319,7 @@ const handleSubmitAssign = async () => {
|
|||
await assignFormRef.value.validate()
|
||||
assignLoading.value = true
|
||||
try {
|
||||
const res = await assignInviteCodes({ codeIds: assignForm.codeIds, userId: assignForm.userId! })
|
||||
const res = await assignInviteCodes({ inviteCodeIds: assignForm.inviteCodeIds, userId: assignForm.userId! })
|
||||
if (res.code === 0) {
|
||||
ElMessage.success('分配成功')
|
||||
assignDialogVisible.value = false
|
||||
|
|
|
|||
|
|
@ -287,14 +287,24 @@ async function submitInviteCode() {
|
|||
const res = await verifyInviteCode(inviteCode.value.trim())
|
||||
|
||||
if (res && res.code === 0) {
|
||||
// 验证成功,关闭弹窗并跳转到答题页
|
||||
closeInvitePopup()
|
||||
uni.redirectTo({
|
||||
url: `/pages/assessment/questions/index?typeId=${typeId.value}&inviteCode=${inviteCode.value}`
|
||||
})
|
||||
// 检查邀请码是否有效
|
||||
if (res.data && res.data.isValid) {
|
||||
// 验证成功,关闭弹窗并跳转到答题页
|
||||
closeInvitePopup()
|
||||
uni.redirectTo({
|
||||
url: `/pages/assessment/questions/index?typeId=${typeId.value}&inviteCode=${inviteCode.value}`
|
||||
})
|
||||
} else {
|
||||
// 邀请码无效
|
||||
const errorMsg = res.data?.errorMessage || '邀请码有误,请重新输入'
|
||||
uni.showToast({
|
||||
title: errorMsg,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// 验证失败
|
||||
const errorMsg = res?.message || '邀请码有误,请重新输入'
|
||||
// 接口调用失败
|
||||
const errorMsg = res?.message || '验证失败,请重试'
|
||||
uni.showToast({
|
||||
title: errorMsg,
|
||||
icon: 'none'
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user