修改bug
This commit is contained in:
@ -121,22 +121,48 @@
|
||||
|
||||
<script setup name="User" lang="ts">
|
||||
import api from '@/api/customerManagement';
|
||||
import { UserForm, UserQuery, UserVO } from '@/api/customerManagement/types';
|
||||
import { to } from 'await-to-js';
|
||||
import { ComponentInternalInstance, getCurrentInstance, onMounted, reactive, ref, toRefs } from 'vue';
|
||||
import { ElDialog, ElForm, ElFormItem, ElInput, ElRow, ElCol, ElButton, ElCard, ElSelect, ElOption, ElDatePicker, ElTable, ElTableColumn, ElTooltip, ElSwitch } from 'element-plus';
|
||||
|
||||
// 定义接口
|
||||
interface UserVO {
|
||||
customerId: string | number;
|
||||
nickName: string;
|
||||
userName: string;
|
||||
status: string;
|
||||
createTime: string;
|
||||
userId: number;
|
||||
}
|
||||
|
||||
interface UserForm extends UserVO {
|
||||
password?: string;
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
interface UserQuery {
|
||||
pageNum: number;
|
||||
pageSize: number;
|
||||
blurry: string;
|
||||
status: string;
|
||||
enabled: string;
|
||||
}
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
const customerList = ref<UserVO[]>();
|
||||
const loading = ref(true);
|
||||
const showSearch = ref(true);
|
||||
const ids = ref<Array<number | string>>([]);
|
||||
const ids = ref<UserVO[]>([]);
|
||||
const single = ref(true);
|
||||
const multiple = ref(true);
|
||||
const total = ref(0);
|
||||
const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
|
||||
const initPassword = ref<string>('');
|
||||
const queryFormRef = ref<ElFormInstance>();
|
||||
const userFormRef = ref<ElFormInstance>();
|
||||
const formDialogRef = ref<ElDialogInstance>();
|
||||
const queryFormRef = ref<InstanceType<typeof ElForm>>();
|
||||
const userFormRef = ref<InstanceType<typeof ElForm>>();
|
||||
const formDialogRef = ref<InstanceType<typeof ElDialog>>();
|
||||
const loadingIng = ref(false)
|
||||
|
||||
const dialog = reactive<DialogOption>({
|
||||
visible: false,
|
||||
title: ''
|
||||
@ -144,19 +170,27 @@ const dialog = reactive<DialogOption>({
|
||||
|
||||
const initFormData: UserForm = {
|
||||
userName: '',
|
||||
nickName: undefined,
|
||||
nickName: '',
|
||||
password: '',
|
||||
enabled: true,
|
||||
customerId: ''
|
||||
customerId: '',
|
||||
status: '',
|
||||
createTime: '',
|
||||
userId: 0,
|
||||
};
|
||||
|
||||
const initData: PageData<UserForm, UserQuery> = {
|
||||
const initData: {
|
||||
form: UserForm,
|
||||
queryParams: UserQuery,
|
||||
rules: any
|
||||
} = {
|
||||
form: { ...initFormData },
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
blurry: '',
|
||||
enabled: '',
|
||||
status: ''
|
||||
},
|
||||
rules: {
|
||||
nickName: [
|
||||
@ -184,9 +218,9 @@ const initData: PageData<UserForm, UserQuery> = {
|
||||
],
|
||||
}
|
||||
};
|
||||
const data = reactive<PageData<UserForm, UserQuery>>(initData);
|
||||
const data = reactive(initData);
|
||||
|
||||
const { queryParams, form, rules } = toRefs<PageData<UserForm, UserQuery>>(data);
|
||||
const { queryParams, form, rules } = toRefs(data);
|
||||
|
||||
/** 查询用户列表 */
|
||||
const getList = async () => {
|
||||
@ -206,6 +240,7 @@ const handleQuery = () => {
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
dateRange.value = ['', ''];
|
||||
queryFormRef.value?.resetFields();
|
||||
queryParams.value.pageNum = 1;
|
||||
queryParams.value.status=''
|
||||
handleQuery();
|
||||
@ -214,21 +249,15 @@ const resetQuery = () => {
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (row?: UserVO) => {
|
||||
// 批量删除逻辑
|
||||
let arrey = ids.value.map((item) => item.customerId);
|
||||
if (!row) {
|
||||
const [err] = await to(proxy?.$modal.confirm(`是否确认删除选中的 ${ids.value.length} 条数据?`) as any);
|
||||
if (!err) {
|
||||
await api.deleteCustomer(arrey);
|
||||
await getList();
|
||||
proxy?.$modal.msgSuccess('删除成功');
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 单行删除逻辑
|
||||
const [err] = await to(proxy?.$modal.confirm('是否确认删除"' + row.nickName + '"的数据项?') as any);
|
||||
const customerIds = row ? [row.customerId] : ids.value.map(item => item.customerId);
|
||||
const nickNames = row ? row.nickName : ids.value.map(item => item.nickName).join(',');
|
||||
const [err] = await to(proxy?.$modal.confirm('是否确认删除"' + nickNames + '"的数据项?', '系统提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}) as any);
|
||||
if (!err) {
|
||||
await api.deleteCustomer([row.customerId]);
|
||||
await api.deleteCustomer(customerIds);
|
||||
await getList();
|
||||
proxy?.$modal.msgSuccess('删除成功');
|
||||
}
|
||||
@ -236,11 +265,14 @@ const handleDelete = async (row?: UserVO) => {
|
||||
|
||||
/** 用户状态修改 */
|
||||
const handleStatusChange = async (row: any) => {
|
||||
// 计算新状态(取反)
|
||||
const originalStatus = row.status;
|
||||
const actionText = row.status == 0 ? '启用' : '停用';
|
||||
try {
|
||||
await proxy?.$modal.confirm(`确认要${actionText}"${row.nickName}"客户吗?`);
|
||||
await proxy?.$modal.confirm(`确认要${actionText}"${row.nickName}"客户吗?`, '系统提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
});
|
||||
await api.updateCustomer({
|
||||
customerId: row.customerId,
|
||||
enabled: originalStatus == 0 ? true : false
|
||||
@ -248,18 +280,18 @@ const handleStatusChange = async (row: any) => {
|
||||
proxy?.$modal.msgSuccess(actionText + '成功');
|
||||
await getList();
|
||||
} catch (err) {
|
||||
if (err == 'cancel') { // 这里假设confirm方法在用户取消时reject with 'cancel'
|
||||
if (err == 'cancel') {
|
||||
console.log(err, 'errr');
|
||||
proxy?.$modal.msgWarning('操作已取消');
|
||||
await getList();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** 选择条数 */
|
||||
const handleSelectionChange = (selection: UserVO[]) => {
|
||||
ids.value = selection.map((item) => item);
|
||||
ids.value = selection;
|
||||
single.value = selection.length != 1;
|
||||
multiple.value = !selection.length;
|
||||
};
|
||||
@ -291,11 +323,10 @@ const handleUpdate = async (row?: UserForm) => {
|
||||
dialog.title = '修改客户';
|
||||
try {
|
||||
if (row) {
|
||||
// 从行内按钮调用,直接使用行数据
|
||||
Object.assign(form.value, row);
|
||||
} else {
|
||||
const customerId = ids.value[0];
|
||||
Object.assign(form.value, customerId);
|
||||
const selectedId = ids.value[0];
|
||||
Object.assign(form.value, selectedId);
|
||||
}
|
||||
} catch (error) {
|
||||
dialog.visible = false;
|
||||
@ -304,15 +335,17 @@ const handleUpdate = async (row?: UserForm) => {
|
||||
|
||||
/** 提交按钮 */
|
||||
const submitForm = () => {
|
||||
|
||||
userFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
loadingIng.value = true
|
||||
form.value.customerId ? await api.updateCustomer(form.value) : await api.addCustomer(form.value);
|
||||
proxy?.$modal.msgSuccess('操作成功');
|
||||
dialog.visible = false;
|
||||
await getList();
|
||||
loadingIng.value = false
|
||||
loadingIng.value = true;
|
||||
try {
|
||||
form.value.customerId ? await api.updateCustomer(form.value) : await api.addCustomer(form.value);
|
||||
proxy?.$modal.msgSuccess('操作成功');
|
||||
dialog.visible = false;
|
||||
await getList();
|
||||
} finally {
|
||||
loadingIng.value = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -331,11 +364,10 @@ const closeDialog = () => {
|
||||
const resetForm = () => {
|
||||
userFormRef.value?.resetFields();
|
||||
userFormRef.value?.clearValidate();
|
||||
form.value.customerId = undefined;
|
||||
form.value.customerId = '';
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getList(); // 初始化列表数据
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user