completepage: 🍻 储蓄目标用户页面完成

This commit is contained in:
Bunny 2024-11-16 23:18:30 +08:00
parent 9a0062c0a4
commit e4d81d0357
11 changed files with 146 additions and 108 deletions

View File

@ -0,0 +1,22 @@
import { http } from '@/api/service/request';
import type { BaseResult, ResultTable } from '@/api/service/types';
/** 用户储值---获取用户储值列表 */
export const fetchGetUserSavingGoalList = (data: any) => {
return http.request<BaseResult<ResultTable>>('get', `savingGoal/noManage/getUserSavingGoalList/${data.currentPage}/${data.pageSize}`, { params: data });
};
/** 用户储值---添加用户储值 */
export const fetchAddUserSavingGoal = (data: any) => {
return http.request<BaseResult<object>>('post', 'savingGoal/noManage/adduserSavingGoal', { data });
};
/** 用户储值---更新用户储值 */
export const fetchUpdateUserSavingGoal = (data: any) => {
return http.request<BaseResult<object>>('put', 'savingGoal/noManage/updateUserSavingGoal', { data });
};
/** 用户储值---删除用户储值 */
export const fetchDeleteUserSavingGoal = (data: any) => {
return http.request<BaseResult<object>>('delete', 'savingGoal/noManage/deleteUserSavingGoal', { data });
};

View File

@ -41,11 +41,13 @@ export const useSavingGoalStore = defineStore('savingGoalStore', {
this.form.startDuration = this.form.duration[0]; this.form.startDuration = this.form.duration[0];
this.form.endDuration = this.form.duration[1]; this.form.endDuration = this.form.duration[1];
} }
// 整理请求参数 // 整理请求参数
const data = { ...this.pagination, ...this.form }; const data = { ...this.pagination, ...this.form };
delete data.pageSizes; delete data.pageSizes;
delete data.total; delete data.total;
delete data.background; delete data.background;
delete data.duration;
// 获取用户储值列表 // 获取用户储值列表
const result = await fetchGetSavingGoalList(data); const result = await fetchGetSavingGoalList(data);

View File

@ -13,7 +13,7 @@ import { getDefaultDateRange } from '@/utils/date';
/** /**
* Store * Store
*/ */
export const userBudgetCategoryUser = defineStore('budgetCategoryUserStore', { export const userBudgetCategoryUserStore = defineStore('budgetCategoryUserStore', {
state() { state() {
return { return {
// 预算分类表列表 // 预算分类表列表

View File

@ -0,0 +1,84 @@
import { defineStore } from 'pinia';
import { pageSizes } from '@/enums/baseConstant';
import { storeMessage } from '@/utils/message';
import { storePagination } from '@/store/useStorePagination';
import {
fetchAddUserSavingGoal,
fetchDeleteUserSavingGoal,
fetchGetUserSavingGoalList,
fetchUpdateUserSavingGoal,
} from '@/api/v1/financialUser/savingGoalUser';
import { getDefaultDateRange } from '@/utils/date';
/**
* Store
*/
export const useSavingGoalUserStore = defineStore('savingGoalUserStore', {
state() {
return {
// 用户储值列表
datalist: [],
// 查询表单
form: {
userId: undefined, // 绑定的用户id
statusType: undefined, // 完成状态
savingGoalName: undefined, // 储值目标名称
amount: undefined, // 目标金额
duration: getDefaultDateRange(2, 30), // 目标时长
startDuration: undefined, // 开始目标时长
endDuration: undefined, // 结束目标时长
},
// 分页查询结果
pagination: {
currentPage: 1,
pageSize: 30,
total: 1,
pageSizes,
},
// 加载
loading: false,
};
},
getters: {},
actions: {
/** 获取用户储值 */
async getSavingGoalList() {
if (this.form.duration) {
this.form.startDuration = this.form.duration[0];
this.form.endDuration = this.form.duration[1];
}
// 整理请求参数
const data = { ...this.pagination, ...this.form };
delete data.pageSizes;
delete data.total;
delete data.background;
delete data.duration;
// 获取用户储值列表
const result = await fetchGetUserSavingGoalList(data);
// 公共页面函数hook
const pagination = storePagination.bind(this);
return pagination(result);
},
/** 添加用户储值 */
async addSavingGoal(data: any) {
const result = await fetchAddUserSavingGoal(data);
return storeMessage(result);
},
/** 修改用户储值 */
async updateSavingGoal(data: any) {
const result = await fetchUpdateUserSavingGoal(data);
return storeMessage(result);
},
/** 删除用户储值 */
async deleteSavingGoal(data: any) {
const result = await fetchDeleteUserSavingGoal(data);
return storeMessage(result);
},
},
});

View File

@ -15,7 +15,7 @@ import { FormInstance } from 'element-plus';
import { useAdminUserStore } from '@/store/system/adminUser'; import { useAdminUserStore } from '@/store/system/adminUser';
import { budget } from '@/enums/bill/budget'; import { budget } from '@/enums/bill/budget';
import { handleTree } from '@pureadmin/utils'; import { handleTree } from '@pureadmin/utils';
import { userBudgetCategoryUser } from '@/store/financialUser/budgetCategoryUser'; import { userBudgetCategoryUserStore } from '@/store/financialUser/budgetCategoryUser';
import { getDefaultDateRange } from '@/utils/date'; import { getDefaultDateRange } from '@/utils/date';
const tableRef = ref(); const tableRef = ref();
@ -25,7 +25,7 @@ const userDataList = ref();
// //
const loading = ref(false); const loading = ref(false);
const adminUserStore = useAdminUserStore(); const adminUserStore = useAdminUserStore();
const budgetCategoryStore = userBudgetCategoryUser(); const budgetCategoryStore = userBudgetCategoryUserStore();
const datalist = computed(() => handleTree(budgetCategoryStore.datalist)); const datalist = computed(() => handleTree(budgetCategoryStore.datalist));
/** 当前页改变时 */ /** 当前页改变时 */

View File

@ -5,12 +5,12 @@ import { message, messageBox } from '@/utils/message';
import type { FormItemProps } from '@/views/financial-user/budget-saving/budget-category/utils/types'; import type { FormItemProps } from '@/views/financial-user/budget-saving/budget-category/utils/types';
import { $t } from '@/plugins/i18n'; import { $t } from '@/plugins/i18n';
import DeleteBatchDialog from '@/components/Table/DeleteBatchDialog.vue'; import DeleteBatchDialog from '@/components/Table/DeleteBatchDialog.vue';
import { userBudgetCategoryUser } from '@/store/financialUser/budgetCategoryUser'; import { userBudgetCategoryUserStore } from '@/store/financialUser/budgetCategoryUser';
export const formRef = ref(); export const formRef = ref();
// 删除ids // 删除ids
export const deleteIds = ref([]); export const deleteIds = ref([]);
const budgetCategoryStore = userBudgetCategoryUser(); const budgetCategoryStore = userBudgetCategoryUserStore();
/** 搜索初始化预算分类表 */ /** 搜索初始化预算分类表 */
export async function onSearch() { export async function onSearch() {

View File

@ -1,22 +1,22 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import { columns } from '@/views/financial/budget-saving/saving-goal/utils/columns'; import { columns } from '@/views/financial-user/budget-saving/saving-goal/utils/columns';
import PureTableBar from '@/components/TableBar/src/bar'; import PureTableBar from '@/components/TableBar/src/bar';
import AddFill from '@iconify-icons/ri/add-circle-line'; import AddFill from '@iconify-icons/ri/add-circle-line';
import PureTable from '@pureadmin/table'; import PureTable from '@pureadmin/table';
import { deleteIds, onAdd, onDelete, onDeleteBatch, onSearch, onUpdate } from '@/views/financial/budget-saving/saving-goal/utils/hooks'; import { deleteIds, onAdd, onDelete, onDeleteBatch, onSearch, onUpdate } from '@/views/financial-user/budget-saving/saving-goal/utils/hooks';
import Delete from '@iconify-icons/ep/delete'; import Delete from '@iconify-icons/ep/delete';
import EditPen from '@iconify-icons/ep/edit-pen'; import EditPen from '@iconify-icons/ep/edit-pen';
import Refresh from '@iconify-icons/ep/refresh'; import Refresh from '@iconify-icons/ep/refresh';
import { $t } from '@/plugins/i18n'; import { $t } from '@/plugins/i18n';
import { useSavingGoalStore } from '@/store/financial/savingGoal';
import { useRenderIcon } from '@/components/CommonIcon/src/hooks'; import { useRenderIcon } from '@/components/CommonIcon/src/hooks';
import { FormInstance } from 'element-plus'; import { FormInstance } from 'element-plus';
import { useAdminUserStore } from '@/store/system/adminUser'; import { useAdminUserStore } from '@/store/system/adminUser';
import LoadingSvg from '@/assets/svg/loading.svg';
import { budget } from '@/enums/bill/budget'; import { budget } from '@/enums/bill/budget';
import { selectUserinfo } from '@/components/Table/Userinfo/columns'; import { selectUserinfo } from '@/components/Table/Userinfo/columns';
import { savingGoal } from '@/enums/bill/savingGoal'; import { savingGoal } from '@/enums/bill/savingGoal';
import { useSavingGoalUserStore } from '@/store/financialUser/savingGoalUser';
import { getDefaultDateRange } from '@/utils/date';
const tableRef = ref(); const tableRef = ref();
const formRef = ref(); const formRef = ref();
@ -25,17 +25,17 @@ const userDataList = ref();
// //
const loading = ref(false); const loading = ref(false);
const adminUserStore = useAdminUserStore(); const adminUserStore = useAdminUserStore();
const savingGoalStore = useSavingGoalStore(); const savingGoalUserStore = useSavingGoalUserStore();
/** 当前页改变时 */ /** 当前页改变时 */
const onCurrentPageChange = async (value: number) => { const onCurrentPageChange = async (value: number) => {
savingGoalStore.pagination.currentPage = value; savingGoalUserStore.pagination.currentPage = value;
await onSearch(); await onSearch();
}; };
/** 当分页发生变化 */ /** 当分页发生变化 */
const onPageSizeChange = async (value: number) => { const onPageSizeChange = async (value: number) => {
savingGoalStore.pagination.pageSize = value; savingGoalUserStore.pagination.pageSize = value;
await onSearch(); await onSearch();
}; };
@ -44,20 +44,13 @@ const onSelectionChange = (rows: Array<any>) => {
deleteIds.value = rows.map((row: any) => row.id); deleteIds.value = rows.map((row: any) => row.id);
}; };
/** 搜索 */
const onSearchUserinfo = async (keyword: string) => {
loading.value = true;
userDataList.value = await adminUserStore.queryUser({ keyword });
loading.value = false;
};
/** 重置表单 */ /** 重置表单 */
const resetForm = async (formEl: FormInstance | undefined) => { const resetForm = async (formEl: FormInstance | undefined) => {
if (!formEl) return; if (!formEl) return;
formEl.resetFields(); formEl.resetFields();
savingGoalStore.form.duration = undefined; savingGoalUserStore.form.duration = getDefaultDateRange(2, 30);
savingGoalStore.form.startDuration = undefined; savingGoalUserStore.form.startDuration = undefined;
savingGoalStore.form.endDuration = undefined; savingGoalUserStore.form.endDuration = undefined;
await onSearch(); await onSearch();
}; };
@ -68,50 +61,28 @@ onMounted(() => {
<template> <template>
<div class="main"> <div class="main">
<el-form ref="formRef" :inline="true" :model="savingGoalStore.form" class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px] overflow-auto"> <el-form ref="formRef" :inline="true" :model="savingGoalUserStore.form" class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px] overflow-auto">
<!-- 绑定的用户id -->
<el-form-item :label="$t('user')" prop="userId">
<el-select
v-model="savingGoalStore.form.userId"
:loading="loading"
:placeholder="$t('user')"
:remote-method="onSearchUserinfo"
class="!w-[180px]"
clearable
filterable
remote
remote-show-suffix
>
<el-option v-for="item in userDataList" :key="item.id" :label="item.username" :value="item.id" />
<template #loading>
<el-icon class="is-loading">
<LoadingSvg />
</el-icon>
</template>
</el-select>
</el-form-item>
<!-- 完成状态 --> <!-- 完成状态 -->
<el-form-item :label="$t('statusType')" prop="statusType"> <el-form-item :label="$t('statusType')" prop="statusType">
<el-select v-model="savingGoalStore.form.statusType" :placeholder="$t('statusType')" class="!w-[180px]" clearable filterable remote remote-show-suffix> <el-select v-model="savingGoalUserStore.form.statusType" :placeholder="$t('statusType')" class="!w-[180px]" clearable filterable remote remote-show-suffix>
<el-option v-for="item in savingGoal" :key="item.value" :label="item.label" :value="item.value" /> <el-option v-for="item in savingGoal" :key="item.value" :label="item.label" :value="item.value" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<!-- 储值目标名称 --> <!-- 储值目标名称 -->
<el-form-item :label="$t('savingGoalName')" prop="savingGoalName"> <el-form-item :label="$t('savingGoalName')" prop="savingGoalName">
<el-input v-model="savingGoalStore.form.savingGoalName" :placeholder="`${$t('input')}${$t('savingGoalName')}`" class="!w-[180px]" clearable /> <el-input v-model="savingGoalUserStore.form.savingGoalName" :placeholder="`${$t('input')}${$t('savingGoalName')}`" class="!w-[180px]" clearable />
</el-form-item> </el-form-item>
<!-- 目标金额 --> <!-- 目标金额 -->
<el-form-item :label="$t('amount')" prop="amount"> <el-form-item :label="$t('amount')" prop="amount">
<el-input v-model="savingGoalStore.form.amount" :placeholder="`${$t('input')}${$t('amount')}`" class="!w-[180px]" clearable /> <el-input v-model="savingGoalUserStore.form.amount" :placeholder="`${$t('input')}${$t('amount')}`" class="!w-[180px]" clearable />
</el-form-item> </el-form-item>
<!-- 目标时长 --> <!-- 目标时长 -->
<el-form-item :label="$t('duration')" prop="duration"> <el-form-item :label="$t('duration')" prop="duration">
<el-date-picker <el-date-picker
v-model="savingGoalStore.form.duration" v-model="savingGoalUserStore.form.duration"
:end-placeholder="$t('endTime')" :end-placeholder="$t('endTime')"
:start-placeholder="$t('startTime')" :start-placeholder="$t('startTime')"
class="!w-[210px]" class="!w-[210px]"
@ -123,7 +94,7 @@ onMounted(() => {
<!-- 搜索和重置 --> <!-- 搜索和重置 -->
<el-form-item> <el-form-item>
<el-button :icon="useRenderIcon('ri:search-line')" :loading="savingGoalStore.loading" type="primary" @click="onSearch"> {{ $t('search') }} </el-button> <el-button :icon="useRenderIcon('ri:search-line')" :loading="savingGoalUserStore.loading" type="primary" @click="onSearch"> {{ $t('search') }} </el-button>
<el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)"> {{ $t('buttons.reset') }}</el-button> <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)"> {{ $t('buttons.reset') }}</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -143,10 +114,10 @@ onMounted(() => {
ref="tableRef" ref="tableRef"
:adaptiveConfig="{ offsetBottom: 96 }" :adaptiveConfig="{ offsetBottom: 96 }"
:columns="dynamicColumns" :columns="dynamicColumns"
:data="savingGoalStore.datalist" :data="savingGoalUserStore.datalist"
:header-cell-style="{ background: 'var(--el-fill-color-light)', color: 'var(--el-text-color-primary)' }" :header-cell-style="{ background: 'var(--el-fill-color-light)', color: 'var(--el-text-color-primary)' }"
:loading="savingGoalStore.loading" :loading="savingGoalUserStore.loading"
:pagination="savingGoalStore.pagination" :pagination="savingGoalUserStore.pagination"
:size="size" :size="size"
adaptive adaptive
align-whole="center" align-whole="center"

View File

@ -1,10 +1,9 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, ref } from 'vue'; import { ref } from 'vue';
import { FormInstance } from 'element-plus'; import { FormInstance } from 'element-plus';
import { rules } from '@/views/financial/budget-saving/saving-goal/utils/columns'; import { rules } from '@/views/financial-user/budget-saving/saving-goal/utils/columns';
import { FormProps } from '@/views/financial/budget-saving/saving-goal/utils/types'; import { FormProps } from '@/views/financial-user/budget-saving/saving-goal/utils/types';
import { $t } from '@/plugins/i18n'; import { $t } from '@/plugins/i18n';
import LoadingSvg from '@/assets/svg/loading.svg';
import { useAdminUserStore } from '@/store/system/adminUser'; import { useAdminUserStore } from '@/store/system/adminUser';
import { savingGoal } from '@/enums/bill/savingGoal'; import { savingGoal } from '@/enums/bill/savingGoal';
@ -31,43 +30,11 @@ const userDataList = ref();
const loading = ref(false); const loading = ref(false);
const adminUserStore = useAdminUserStore(); const adminUserStore = useAdminUserStore();
/** 搜索 */
const onSearchUserinfo = async (keyword: string) => {
loading.value = true;
userDataList.value = await adminUserStore.queryUser({ keyword });
loading.value = false;
};
onMounted(() => {
onSearchUserinfo();
});
defineExpose({ formRef }); defineExpose({ formRef });
</script> </script>
<template> <template>
<el-form ref="formRef" :model="form" :rules="rules" label-width="auto"> <el-form ref="formRef" :model="form" :rules="rules" label-width="auto">
<!-- 绑定的用户id -->
<el-form-item :label="$t('user')" prop="userId">
<el-select
v-model="form.userId"
:loading="loading"
:placeholder="$t('user')"
:remote-method="onSearchUserinfo"
clearable
filterable
remote
remote-show-suffix
>
<el-option v-for="item in userDataList" :key="item.id" :label="item.username" :value="item.id" />
<template #loading>
<el-icon class="is-loading">
<LoadingSvg />
</el-icon>
</template>
</el-select>
</el-form-item>
<!-- 完成状态 --> <!-- 完成状态 -->
<el-form-item :label="$t('statusType')" prop="statusType"> <el-form-item :label="$t('statusType')" prop="statusType">
<el-select v-model="form.statusType" :placeholder="$t('select') + $t('statusType')" clearable filterable remote remote-show-suffix> <el-select v-model="form.statusType" :placeholder="$t('select') + $t('statusType')" clearable filterable remote remote-show-suffix>

View File

@ -39,17 +39,11 @@ export const columns: TableColumnList = [
}, },
{ label: $t('table.updateTime'), prop: 'updateTime', sortable: true, width: 160 }, { label: $t('table.updateTime'), prop: 'updateTime', sortable: true, width: 160 },
{ label: $t('table.createTime'), prop: 'createTime', sortable: true, width: 160 }, { label: $t('table.createTime'), prop: 'createTime', sortable: true, width: 160 },
// 绑定的用户id
{ label: $t('username'), prop: 'username', slot: 'username', width: 130 },
{ label: $t('table.createUser'), prop: 'createUser', slot: 'createUser', width: 130 },
{ label: $t('table.updateUser'), prop: 'updateUser', slot: 'updateUser', width: 130 },
{ label: $t('table.operation'), fixed: 'right', width: 160, slot: 'operation' }, { label: $t('table.operation'), fixed: 'right', width: 160, slot: 'operation' },
]; ];
// 添加规则 // 添加规则
export const rules = reactive<FormRules>({ export const rules = reactive<FormRules>({
// 绑定的用户id
userId: [{ required: true, message: `${$t('input')}${$t('userId')}`, trigger: 'blur' }],
// 完成状态 // 完成状态
statusType: [{ required: true, message: `${$t('input')}${$t('statusType')}`, trigger: 'blur' }], statusType: [{ required: true, message: `${$t('input')}${$t('statusType')}`, trigger: 'blur' }],
// 储值目标名称 // 储值目标名称

View File

@ -1,22 +1,22 @@
import { addDialog } from '@/components/BaseDialog/index'; import { addDialog } from '@/components/BaseDialog/index';
import SavingGoalDialog from '@/views/financial/budget-saving/saving-goal/saving-goal-dialog.vue'; import SavingGoalDialog from '@/views/financial-user/budget-saving/saving-goal/saving-goal-dialog.vue';
import { useSavingGoalStore } from '@/store/financial/savingGoal';
import { h, ref } from 'vue'; import { h, ref } from 'vue';
import { message, messageBox } from '@/utils/message'; import { message, messageBox } from '@/utils/message';
import type { FormItemProps } from '@/views/financial/budget-saving/saving-goal/utils/types'; import type { FormItemProps } from '@/views/financial-user/budget-saving/saving-goal/utils/types';
import { $t } from '@/plugins/i18n'; import { $t } from '@/plugins/i18n';
import DeleteBatchDialog from '@/components/Table/DeleteBatchDialog.vue'; import DeleteBatchDialog from '@/components/Table/DeleteBatchDialog.vue';
import { useSavingGoalUserStore } from '@/store/financialUser/savingGoalUser';
export const formRef = ref(); export const formRef = ref();
// 删除ids // 删除ids
export const deleteIds = ref([]); export const deleteIds = ref([]);
const savingGoalStore = useSavingGoalStore(); const savingGoalUserStore = useSavingGoalUserStore();
/** 搜索初始化用户储值 */ /** 搜索初始化用户储值 */
export async function onSearch() { export async function onSearch() {
savingGoalStore.loading = true; savingGoalUserStore.loading = true;
await savingGoalStore.getSavingGoalList(); await savingGoalUserStore.getSavingGoalList();
savingGoalStore.loading = false; savingGoalUserStore.loading = false;
} }
/** 添加用户储值 */ /** 添加用户储值 */
@ -46,7 +46,7 @@ export function onAdd() {
form.startDuration = form.duration[0]; form.startDuration = form.duration[0];
form.endDuration = form.duration[1]; form.endDuration = form.duration[1];
const result = await savingGoalStore.addSavingGoal(form); const result = await savingGoalUserStore.addSavingGoal(form);
if (!result) return; if (!result) return;
done(); done();
await onSearch(); await onSearch();
@ -82,7 +82,7 @@ export function onUpdate(row: any) {
form.startDuration = form.duration[0]; form.startDuration = form.duration[0];
form.endDuration = form.duration[1]; form.endDuration = form.duration[1];
const result = await savingGoalStore.updateSavingGoal({ ...form, id: row.id }); const result = await savingGoalUserStore.updateSavingGoal({ ...form, id: row.id });
if (!result) return; if (!result) return;
done(); done();
await onSearch(); await onSearch();
@ -105,7 +105,7 @@ export const onDelete = async (row: any) => {
if (!result) return; if (!result) return;
// 删除数据 // 删除数据
await savingGoalStore.deleteSavingGoal([id]); await savingGoalUserStore.deleteSavingGoal([id]);
await onSearch(); await onSearch();
}; };
@ -129,7 +129,7 @@ export const onDeleteBatch = async () => {
const text = options.props.formInline.confirmText.toLowerCase(); const text = options.props.formInline.confirmText.toLowerCase();
if (text === 'yes' || text === 'y') { if (text === 'yes' || text === 'y') {
// 删除数据 // 删除数据
await savingGoalStore.deleteSavingGoal(ids); await savingGoalUserStore.deleteSavingGoal(ids);
await onSearch(); await onSearch();
done(); done();

View File

@ -1,7 +1,5 @@
// 添加或者修改表单元素 // 添加或者修改表单元素
export interface FormItemProps { export interface FormItemProps {
// 绑定的用户id
userId: number;
// 完成状态 // 完成状态
statusType: string; statusType: string;
// 储值目标名称 // 储值目标名称