会员: 修改会员等级,使用单独的表单、接口
This commit is contained in:
parent
c5a703f488
commit
51738f8f6e
@ -32,3 +32,8 @@ export const getUser = async (id: number) => {
|
|||||||
export const updateUser = async (data: UserVO) => {
|
export const updateUser = async (data: UserVO) => {
|
||||||
return await request.put({ url: `/member/user/update`, data })
|
return await request.put({ url: `/member/user/update`, data })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 修改会员用户等级
|
||||||
|
export const updateUserLevel = async (data: any) => {
|
||||||
|
return await request.put({ url: `/member/user/update-level`, data })
|
||||||
|
}
|
||||||
|
101
src/views/member/user/UpdateLevelForm.vue
Normal file
101
src/views/member/user/UpdateLevelForm.vue
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
<template>
|
||||||
|
<Dialog title="修改用户等级" v-model="dialogVisible" width="600">
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="formRules"
|
||||||
|
label-width="100px"
|
||||||
|
v-loading="formLoading"
|
||||||
|
>
|
||||||
|
<el-form-item label="用户编号" prop="id">
|
||||||
|
<el-input v-model="formData.id" placeholder="请输入用户昵称" class="!w-240px" disabled />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="用户昵称" prop="nickname">
|
||||||
|
<el-input
|
||||||
|
v-model="formData.nickname"
|
||||||
|
placeholder="请输入用户昵称"
|
||||||
|
class="!w-240px"
|
||||||
|
disabled
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="用户等级" prop="levelId">
|
||||||
|
<MemberLevelSelect v-model="formData.levelId" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="修改原因" prop="reason">
|
||||||
|
<el-input type="textarea" v-model="formData.reason" placeholder="请输入修改原因" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
||||||
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import * as UserApi from '@/api/member/user'
|
||||||
|
import MemberLevelSelect from '@/views/member/level/components/MemberLevelSelect.vue'
|
||||||
|
|
||||||
|
const { t } = useI18n() // 国际化
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
|
||||||
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||||
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
|
const formData = ref({
|
||||||
|
id: undefined,
|
||||||
|
nickname: undefined,
|
||||||
|
levelId: undefined,
|
||||||
|
reason: undefined
|
||||||
|
})
|
||||||
|
const formRules = reactive({
|
||||||
|
reason: [{ required: true, message: '修改原因不能为空', trigger: 'blur' }]
|
||||||
|
})
|
||||||
|
const formRef = ref() // 表单 Ref
|
||||||
|
|
||||||
|
/** 打开弹窗 */
|
||||||
|
const open = async (id?: number) => {
|
||||||
|
dialogVisible.value = true
|
||||||
|
resetForm()
|
||||||
|
// 修改时,设置数据
|
||||||
|
if (id) {
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
formData.value = await UserApi.getUser(id)
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||||
|
|
||||||
|
/** 提交表单 */
|
||||||
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||||
|
const submitForm = async () => {
|
||||||
|
// 校验表单
|
||||||
|
if (!formRef) return
|
||||||
|
const valid = await formRef.value.validate()
|
||||||
|
if (!valid) return
|
||||||
|
// 提交请求
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
await UserApi.updateUserLevel(formData.value)
|
||||||
|
|
||||||
|
message.success(t('common.updateSuccess'))
|
||||||
|
dialogVisible.value = false
|
||||||
|
// 发送操作成功的事件
|
||||||
|
emit('success')
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
id: undefined,
|
||||||
|
nickname: undefined,
|
||||||
|
levelId: undefined,
|
||||||
|
reason: undefined
|
||||||
|
}
|
||||||
|
formRef.value?.resetFields()
|
||||||
|
}
|
||||||
|
</script>
|
@ -60,22 +60,6 @@
|
|||||||
<el-form-item label="用户标签" prop="tagIds">
|
<el-form-item label="用户标签" prop="tagIds">
|
||||||
<MemberTagSelect v-model="formData.tagIds" show-add />
|
<MemberTagSelect v-model="formData.tagIds" show-add />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-row>
|
|
||||||
<el-col :span="12">
|
|
||||||
<el-form-item label="用户等级" prop="levelId">
|
|
||||||
<MemberLevelSelect v-model="formData.levelId" />
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="12">
|
|
||||||
<el-form-item
|
|
||||||
label="修改原因"
|
|
||||||
prop="levelReason"
|
|
||||||
v-if="formData.levelId != originLevelId"
|
|
||||||
>
|
|
||||||
<el-input type="text" v-model="formData.levelReason" placeholder="请输入修改原因" />
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
<el-form-item label="用户分组" prop="groupId">
|
<el-form-item label="用户分组" prop="groupId">
|
||||||
<MemberGroupSelect v-model="formData.groupId" />
|
<MemberGroupSelect v-model="formData.groupId" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@ -95,7 +79,6 @@ import * as UserApi from '@/api/member/user'
|
|||||||
import * as AreaApi from '@/api/system/area'
|
import * as AreaApi from '@/api/system/area'
|
||||||
import { defaultProps } from '@/utils/tree'
|
import { defaultProps } from '@/utils/tree'
|
||||||
import MemberTagSelect from '@/views/member/tag/components/MemberTagSelect.vue'
|
import MemberTagSelect from '@/views/member/tag/components/MemberTagSelect.vue'
|
||||||
import MemberLevelSelect from '@/views/member/level/components/MemberLevelSelect.vue'
|
|
||||||
import MemberGroupSelect from '@/views/member/group/components/MemberGroupSelect.vue'
|
import MemberGroupSelect from '@/views/member/group/components/MemberGroupSelect.vue'
|
||||||
|
|
||||||
const { t } = useI18n() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
@ -118,18 +101,14 @@ const formData = ref({
|
|||||||
birthday: undefined,
|
birthday: undefined,
|
||||||
mark: undefined,
|
mark: undefined,
|
||||||
tagIds: [],
|
tagIds: [],
|
||||||
levelId: undefined,
|
|
||||||
levelReason: undefined,
|
|
||||||
groupId: undefined
|
groupId: undefined
|
||||||
})
|
})
|
||||||
const formRules = reactive({
|
const formRules = reactive({
|
||||||
mobile: [{ required: true, message: '手机号不能为空', trigger: 'blur' }],
|
mobile: [{ required: true, message: '手机号不能为空', trigger: 'blur' }],
|
||||||
status: [{ required: true, message: '状态不能为空', trigger: 'blur' }],
|
status: [{ required: true, message: '状态不能为空', trigger: 'blur' }]
|
||||||
levelReason: [{ required: true, message: '修改原因不能为空', trigger: 'blur' }]
|
|
||||||
})
|
})
|
||||||
const formRef = ref() // 表单 Ref
|
const formRef = ref() // 表单 Ref
|
||||||
const areaList = ref([]) // 地区列表
|
const areaList = ref([]) // 地区列表
|
||||||
const originLevelId = ref() // 修改前的会员等级
|
|
||||||
|
|
||||||
/** 打开弹窗 */
|
/** 打开弹窗 */
|
||||||
const open = async (type: string, id?: number) => {
|
const open = async (type: string, id?: number) => {
|
||||||
@ -142,7 +121,6 @@ const open = async (type: string, id?: number) => {
|
|||||||
formLoading.value = true
|
formLoading.value = true
|
||||||
try {
|
try {
|
||||||
formData.value = await UserApi.getUser(id)
|
formData.value = await UserApi.getUser(id)
|
||||||
originLevelId.value = formData.value.levelId
|
|
||||||
} finally {
|
} finally {
|
||||||
formLoading.value = false
|
formLoading.value = false
|
||||||
}
|
}
|
||||||
@ -194,8 +172,6 @@ const resetForm = () => {
|
|||||||
birthday: undefined,
|
birthday: undefined,
|
||||||
mark: undefined,
|
mark: undefined,
|
||||||
tagIds: [],
|
tagIds: [],
|
||||||
levelId: undefined,
|
|
||||||
levelReason: undefined,
|
|
||||||
groupId: undefined
|
groupId: undefined
|
||||||
}
|
}
|
||||||
formRef.value?.resetFields()
|
formRef.value?.resetFields()
|
||||||
|
@ -107,7 +107,7 @@
|
|||||||
:formatter="dateFormatter"
|
:formatter="dateFormatter"
|
||||||
width="180px"
|
width="180px"
|
||||||
/>
|
/>
|
||||||
<el-table-column label="操作" align="center">
|
<el-table-column label="操作" align="center" width="140px" fixed="right">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button
|
<el-button
|
||||||
link
|
link
|
||||||
@ -117,6 +117,15 @@
|
|||||||
>
|
>
|
||||||
编辑
|
编辑
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<!-- todo 放到更多菜单中 -->
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="primary"
|
||||||
|
@click="updateLevelFormRef.open(scope.row.id)"
|
||||||
|
v-hasPermi="['member:user:update-level']"
|
||||||
|
>
|
||||||
|
修改等级
|
||||||
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@ -131,6 +140,8 @@
|
|||||||
|
|
||||||
<!-- 表单弹窗:添加/修改 -->
|
<!-- 表单弹窗:添加/修改 -->
|
||||||
<UserForm ref="formRef" @success="getList" />
|
<UserForm ref="formRef" @success="getList" />
|
||||||
|
<!-- 修改用户等级弹窗 -->
|
||||||
|
<UpdateLevelForm ref="updateLevelFormRef" @success="getList" />
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { dateFormatter } from '@/utils/formatTime'
|
import { dateFormatter } from '@/utils/formatTime'
|
||||||
@ -140,6 +151,7 @@ import { DICT_TYPE } from '@/utils/dict'
|
|||||||
import MemberTagSelect from '@/views/member/tag/components/MemberTagSelect.vue'
|
import MemberTagSelect from '@/views/member/tag/components/MemberTagSelect.vue'
|
||||||
import MemberLevelSelect from '@/views/member/level/components/MemberLevelSelect.vue'
|
import MemberLevelSelect from '@/views/member/level/components/MemberLevelSelect.vue'
|
||||||
import MemberGroupSelect from '@/views/member/group/components/MemberGroupSelect.vue'
|
import MemberGroupSelect from '@/views/member/group/components/MemberGroupSelect.vue'
|
||||||
|
import UpdateLevelForm from '@/views/member/user/UpdateLevelForm.vue'
|
||||||
|
|
||||||
defineOptions({ name: 'MemberUser' })
|
defineOptions({ name: 'MemberUser' })
|
||||||
|
|
||||||
@ -158,6 +170,7 @@ const queryParams = reactive({
|
|||||||
groupId: null
|
groupId: null
|
||||||
})
|
})
|
||||||
const queryFormRef = ref() // 搜索的表单
|
const queryFormRef = ref() // 搜索的表单
|
||||||
|
const updateLevelFormRef = ref() // 修改会员等级表单
|
||||||
|
|
||||||
/** 查询列表 */
|
/** 查询列表 */
|
||||||
const getList = async () => {
|
const getList = async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user