会员: 修改会员等级,使用单独的表单、接口

This commit is contained in:
owen 2023-08-22 11:23:08 +08:00
parent c5a703f488
commit 51738f8f6e
4 changed files with 121 additions and 26 deletions

View File

@ -32,3 +32,8 @@ export const getUser = async (id: number) => {
export const updateUser = async (data: UserVO) => {
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 })
}

View 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) // 12
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>

View File

@ -60,22 +60,6 @@
<el-form-item label="用户标签" prop="tagIds">
<MemberTagSelect v-model="formData.tagIds" show-add />
</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">
<MemberGroupSelect v-model="formData.groupId" />
</el-form-item>
@ -95,7 +79,6 @@ import * as UserApi from '@/api/member/user'
import * as AreaApi from '@/api/system/area'
import { defaultProps } from '@/utils/tree'
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'
const { t } = useI18n() //
@ -118,18 +101,14 @@ const formData = ref({
birthday: undefined,
mark: undefined,
tagIds: [],
levelId: undefined,
levelReason: undefined,
groupId: undefined
})
const formRules = reactive({
mobile: [{ required: true, message: '手机号不能为空', trigger: 'blur' }],
status: [{ required: true, message: '状态不能为空', trigger: 'blur' }],
levelReason: [{ required: true, message: '修改原因不能为空', trigger: 'blur' }]
status: [{ required: true, message: '状态不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
const areaList = ref([]) //
const originLevelId = ref() //
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
@ -142,7 +121,6 @@ const open = async (type: string, id?: number) => {
formLoading.value = true
try {
formData.value = await UserApi.getUser(id)
originLevelId.value = formData.value.levelId
} finally {
formLoading.value = false
}
@ -194,8 +172,6 @@ const resetForm = () => {
birthday: undefined,
mark: undefined,
tagIds: [],
levelId: undefined,
levelReason: undefined,
groupId: undefined
}
formRef.value?.resetFields()

View File

@ -107,7 +107,7 @@
:formatter="dateFormatter"
width="180px"
/>
<el-table-column label="操作" align="center">
<el-table-column label="操作" align="center" width="140px" fixed="right">
<template #default="scope">
<el-button
link
@ -117,6 +117,15 @@
>
编辑
</el-button>
<!-- todo 放到更多菜单中 -->
<el-button
link
type="primary"
@click="updateLevelFormRef.open(scope.row.id)"
v-hasPermi="['member:user:update-level']"
>
修改等级
</el-button>
</template>
</el-table-column>
</el-table>
@ -131,6 +140,8 @@
<!-- 表单弹窗添加/修改 -->
<UserForm ref="formRef" @success="getList" />
<!-- 修改用户等级弹窗 -->
<UpdateLevelForm ref="updateLevelFormRef" @success="getList" />
</template>
<script setup lang="ts">
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 MemberLevelSelect from '@/views/member/level/components/MemberLevelSelect.vue'
import MemberGroupSelect from '@/views/member/group/components/MemberGroupSelect.vue'
import UpdateLevelForm from '@/views/member/user/UpdateLevelForm.vue'
defineOptions({ name: 'MemberUser' })
@ -158,6 +170,7 @@ const queryParams = reactive({
groupId: null
})
const queryFormRef = ref() //
const updateLevelFormRef = ref() //
/** 查询列表 */
const getList = async () => {