From 0514b7ade8b733e3ed3bf0cbc2e2118575f7dda5 Mon Sep 17 00:00:00 2001 From: Bunny <1319900154@qq.com> Date: Thu, 14 Nov 2024 12:01:08 +0800 Subject: [PATCH] =?UTF-8?q?page:=20=F0=9F=93=84=20=E9=A2=84=E7=AE=97?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/v1/financial/bill.ts | 22 +++ src/store/financial/bill.ts | 82 ++++++++ src/store/financialUser/billUser.ts | 2 +- .../financial-user/bill-user/bill-dialog.vue | 6 +- src/views/financial-user/bill-user/index.vue | 6 +- .../financial-user/bill-user/utils/hooks.ts | 4 +- src/views/financial/bill/bill-dialog.vue | 137 +++++++++++++ src/views/financial/bill/index.vue | 187 ++++++++++++++++++ src/views/financial/bill/utils/columns.tsx | 61 ++++++ src/views/financial/bill/utils/hooks.ts | 134 +++++++++++++ src/views/financial/bill/utils/types.ts | 20 ++ .../budget-category-dialog.vue | 1 + src/views/financial/budget-category/index.vue | 2 +- .../financial/budget-category/utils/types.ts | 2 +- 14 files changed, 655 insertions(+), 11 deletions(-) create mode 100644 src/api/v1/financial/bill.ts create mode 100644 src/store/financial/bill.ts create mode 100644 src/views/financial/bill/bill-dialog.vue create mode 100644 src/views/financial/bill/index.vue create mode 100644 src/views/financial/bill/utils/columns.tsx create mode 100644 src/views/financial/bill/utils/hooks.ts create mode 100644 src/views/financial/bill/utils/types.ts diff --git a/src/api/v1/financial/bill.ts b/src/api/v1/financial/bill.ts new file mode 100644 index 0000000..ece9d7b --- /dev/null +++ b/src/api/v1/financial/bill.ts @@ -0,0 +1,22 @@ +import { http } from '@/api/service/request'; +import type { BaseResult, ResultTable } from '@/api/service/types'; + +/** 账单信息---获取账单信息列表 */ +export const fetchGetBillList = (data: any) => { + return http.request>('get', `bill/getBillList/${data.currentPage}/${data.pageSize}`, { params: data }); +}; + +/** 账单信息---添加账单信息 */ +export const fetchAddBill = (data: any) => { + return http.request>('post', 'bill/addBill', { data }); +}; + +/** 账单信息---更新账单信息 */ +export const fetchUpdateBill = (data: any) => { + return http.request>('put', 'bill/updateBill', { data }); +}; + +/** 账单信息---删除账单信息 */ +export const fetchDeleteBill = (data: any) => { + return http.request>('delete', 'bill/deleteBill', { data }); +}; diff --git a/src/store/financial/bill.ts b/src/store/financial/bill.ts new file mode 100644 index 0000000..c4eaaf5 --- /dev/null +++ b/src/store/financial/bill.ts @@ -0,0 +1,82 @@ +import { defineStore } from 'pinia'; +import { fetchAddBill, fetchDeleteBill, fetchGetBillList, fetchUpdateBill } from '@/api/v1/financial/bill'; +import { pageSizes } from '@/enums/baseConstant'; +import { storeMessage } from '@/utils/message'; +import { storePagination } from '@/store/useStorePagination'; + +/** + * 账单信息 Store + */ +export const useBillStore = defineStore('billStore', { + state() { + return { + // 账单信息列表 + datalist: [], + // 查询表单 + form: { + userId: undefined, + // 类型:1 - 收入,-1 - 支出 + type: undefined, + // 描述 + description: undefined, + // 交易日志 + date: undefined, + // 开始交易日期 + startDate: undefined, + // 结束交易日期 + endDate: undefined, + }, + // 分页查询结果 + pagination: { + currentPage: 1, + pageSize: 30, + total: 1, + pageSizes, + }, + // 加载 + loading: false, + }; + }, + getters: {}, + actions: { + /** 获取账单信息 */ + async getBillList() { + // 将日期格式赋值 + if (this.form.date) { + this.form.startDate = this.form.date[0]; + this.form.endDate = this.form.date[1]; + } + + // 整理请求参数 + const data = { ...this.pagination, ...this.form }; + delete data.pageSizes; + delete data.total; + delete data.background; + + // 获取账单信息列表 + const result = await fetchGetBillList(data); + + // 公共页面函数hook + const pagination = storePagination.bind(this); + return pagination(result); + }, + + /** 添加账单信息 */ + async addBill(data: any) { + const result = await fetchAddBill(data); + return storeMessage(result); + }, + + /** 修改账单信息 */ + async updateBill(data: any) { + const result = await fetchUpdateBill(data); + return storeMessage(result); + }, + + /** 删除账单信息 */ + async deleteBill(data: any) { + const result = await fetchDeleteBill(data); + return storeMessage(result); + }, + }, +}); diff --git a/src/store/financialUser/billUser.ts b/src/store/financialUser/billUser.ts index 2006a42..dd65bdd 100644 --- a/src/store/financialUser/billUser.ts +++ b/src/store/financialUser/billUser.ts @@ -8,7 +8,7 @@ import { getDefaultDateRange } from '@/utils/date'; /** * 账单信息 Store */ -export const useBillStore = defineStore('billStore', { +export const useBillUserStore = defineStore('billUserStore', { state() { return { // 账单信息列表 diff --git a/src/views/financial-user/bill-user/bill-dialog.vue b/src/views/financial-user/bill-user/bill-dialog.vue index 545fbb9..b86b84e 100644 --- a/src/views/financial-user/bill-user/bill-dialog.vue +++ b/src/views/financial-user/bill-user/bill-dialog.vue @@ -5,7 +5,7 @@ import { rules } from '@/views/financial-user/bill-user/utils/columns'; import { FormProps } from '@/views/financial-user/bill-user/utils/types'; import { $t } from '@/plugins/i18n'; import { incomeOrExpend } from '@/enums/baseConstant'; -import { useBillStore } from '@/store/financialUser/billUser'; +import { useBillUserStore } from '@/store/financialUser/billUser'; import { onSearch } from '@/views/financial-user/bill-user/utils/hooks'; import { useCategoryUserStore } from '@/store/financialUser/categoryUser'; @@ -26,7 +26,7 @@ const props = withDefaults(defineProps(), { const formRef = ref(); const form = ref(props.formInline); -const billStore = useBillStore(); +const billStore = useBillUserStore(); const categoryUserStore = useCategoryUserStore(); /** 提交表单 */ @@ -63,7 +63,6 @@ defineExpose({ formRef }); - diff --git a/src/views/financial-user/bill-user/index.vue b/src/views/financial-user/bill-user/index.vue index e973310..148bc9d 100644 --- a/src/views/financial-user/bill-user/index.vue +++ b/src/views/financial-user/bill-user/index.vue @@ -9,7 +9,7 @@ import Delete from '@iconify-icons/ep/delete'; import EditPen from '@iconify-icons/ep/edit-pen'; import Refresh from '@iconify-icons/ep/refresh'; import { $t } from '@/plugins/i18n'; -import { useBillStore } from '@/store/financialUser/billUser'; +import { useBillUserStore } from '@/store/financialUser/billUser'; import { useRenderIcon } from '@/components/CommonIcon/src/hooks'; import { FormInstance } from 'element-plus'; import { incomeOrExpend } from '@/enums/baseConstant'; @@ -17,7 +17,7 @@ import { getDefaultDateRange } from '@/utils/date'; const tableRef = ref(); const formRef = ref(); -const billStore = useBillStore(); +const billStore = useBillUserStore(); /** 当前页改变时 */ const onCurrentPageChange = async (value: number) => { @@ -41,6 +41,8 @@ const resetForm = async (formEl: FormInstance | undefined) => { if (!formEl) return; formEl.resetFields(); billStore.form.date = getDefaultDateRange(); + billStore.form.startDate = undefined; + billStore.form.endDate = undefined; await onSearch(); }; diff --git a/src/views/financial-user/bill-user/utils/hooks.ts b/src/views/financial-user/bill-user/utils/hooks.ts index fbd5970..5db8d28 100644 --- a/src/views/financial-user/bill-user/utils/hooks.ts +++ b/src/views/financial-user/bill-user/utils/hooks.ts @@ -1,6 +1,6 @@ import { addDialog, closeDialog } from '@/components/BaseDialog/index'; import BillDialog from '@/views/financial-user/bill-user/bill-dialog.vue'; -import { useBillStore } from '@/store/financialUser/billUser'; +import { useBillUserStore } from '@/store/financialUser/billUser'; import { h, ref } from 'vue'; import { message, messageBox } from '@/utils/message'; import type { FormItemProps } from '@/views/financial-user/bill-user/utils/types'; @@ -11,7 +11,7 @@ import dayjs from 'dayjs'; export const formRef = ref(); // 删除ids export const deleteIds = ref([]); -const billStore = useBillStore(); +const billStore = useBillUserStore(); /** 搜索初始化账单信息 */ export async function onSearch() { diff --git a/src/views/financial/bill/bill-dialog.vue b/src/views/financial/bill/bill-dialog.vue new file mode 100644 index 0000000..eb16aa9 --- /dev/null +++ b/src/views/financial/bill/bill-dialog.vue @@ -0,0 +1,137 @@ + + + diff --git a/src/views/financial/bill/index.vue b/src/views/financial/bill/index.vue new file mode 100644 index 0000000..647e89a --- /dev/null +++ b/src/views/financial/bill/index.vue @@ -0,0 +1,187 @@ + + + diff --git a/src/views/financial/bill/utils/columns.tsx b/src/views/financial/bill/utils/columns.tsx new file mode 100644 index 0000000..d6f9604 --- /dev/null +++ b/src/views/financial/bill/utils/columns.tsx @@ -0,0 +1,61 @@ +import { reactive } from 'vue'; +import { $t } from '@/plugins/i18n'; +import { ElTag, ElText, type FormRules } from 'element-plus'; + +// 表格列 +export const columns: TableColumnList = [ + { type: 'selection', align: 'left' }, + { type: 'index', index: (index: number) => index + 1, label: '序号', width: 60 }, + // 金额 + { + label: $t('amount'), + prop: 'amount', + sortable: true, + formatter({ type, amount }) { + return type === -1 ? ( + + - {amount}¥ + + ) : ( + + + {amount}¥ + + ); + }, + width: 200, + }, + // 类别 + { + label: $t('categoryName'), + prop: 'categoryName', + width: 150, + formatter({ categoryName }) { + return {categoryName}; + }, + }, + // 交易日期 + { label: $t('transactionDate'), prop: 'transactionDate', width: 160 }, + // 描述 + { label: $t('description'), prop: 'description' }, + // 用户名 + { label: $t('username'), prop: 'username', slot: 'username', width: 130 }, + { label: $t('table.updateTime'), prop: 'updateTime', sortable: true, width: 160 }, + { label: $t('table.createTime'), prop: 'createTime', sortable: true, width: 160 }, + { 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: 210, slot: 'operation' }, +]; + +// 添加规则 +export const rules = reactive({ + // 绑定的用户 + userId: [{ required: true, message: `${$t('input')}${$t('userId')}`, trigger: 'blur' }], + // 类型:1 - 收入,-1 - 支出 + type: [{ required: true, message: `${$t('input')}${$t('type')}`, trigger: 'blur' }], + // 金额 + amount: [{ required: true, message: `${$t('input')}${$t('amount')}`, trigger: 'blur' }], + // 交易日期 + transactionDate: [{ required: true, message: `${$t('input')}${$t('transactionDate')}`, trigger: 'blur' }], + // 类别id + categoryId: [{ required: true, message: `${$t('input')}${$t('categoryId')}`, trigger: 'blur' }], +}); diff --git a/src/views/financial/bill/utils/hooks.ts b/src/views/financial/bill/utils/hooks.ts new file mode 100644 index 0000000..7441822 --- /dev/null +++ b/src/views/financial/bill/utils/hooks.ts @@ -0,0 +1,134 @@ +import { addDialog } from '@/components/BaseDialog/index'; +import BillDialog from '@/views/financial/bill/bill-dialog.vue'; +import { useBillStore } from '@/store/financial/bill'; +import { h, ref } from 'vue'; +import { message, messageBox } from '@/utils/message'; +import type { FormItemProps } from '@/views/financial/bill/utils/types'; +import { $t } from '@/plugins/i18n'; +import DeleteBatchDialog from '@/components/Table/DeleteBatchDialog.vue'; + +export const formRef = ref(); +// 删除ids +export const deleteIds = ref([]); +const billStore = useBillStore(); + +/** 搜索初始化账单信息 */ +export async function onSearch() { + billStore.loading = true; + await billStore.getBillList(); + billStore.loading = false; +} + +/** 添加账单信息 */ +export function onAdd() { + addDialog({ + title: `${$t('addNew')}${$t('bill')}`, + width: '30%', + props: { + formInline: { + userId: undefined, + type: undefined, + amount: undefined, + description: undefined, + transactionDate: undefined, + categoryId: undefined, + }, + }, + draggable: true, + fullscreenIcon: true, + closeOnClickModal: false, + contentRenderer: () => h(BillDialog, { ref: formRef }), + beforeSure: (done, { options }) => { + const form = options.props.formInline as FormItemProps; + formRef.value.formRef.validate(async (valid: any) => { + if (!valid) return; + + const result = await billStore.addBill(form); + if (!result) return; + done(); + await onSearch(); + }); + }, + }); +} + +/** 更新账单信息 */ +export function onUpdate(row: any) { + addDialog({ + title: `${$t('modify')}${$t('bill')}`, + width: '30%', + props: { + formInline: { + userId: row.userId, + type: row.type, + amount: row.amount, + description: row.description, + transactionDate: row.transactionDate, + categoryId: row.categoryId, + }, + }, + draggable: true, + fullscreenIcon: true, + closeOnClickModal: false, + contentRenderer: () => h(BillDialog, { ref: formRef }), + beforeSure: (done, { options }) => { + const form = options.props.formInline as FormItemProps; + formRef.value.formRef.validate(async (valid: any) => { + if (!valid) return; + + const result = await billStore.updateBill({ ...form, id: row.id }); + if (!result) return; + done(); + await onSearch(); + }); + }, + }); +} + +/** 删除账单信息 */ +export const onDelete = async (row: any) => { + const id = row.id; + + // 是否确认删除 + const result = await messageBox({ + title: $t('confirmDelete'), + showMessage: false, + confirmMessage: undefined, + cancelMessage: $t('cancel_delete'), + }); + if (!result) return; + + // 删除数据 + await billStore.deleteBill([id]); + await onSearch(); +}; + +/** 批量删除 */ +export const onDeleteBatch = async () => { + const ids = deleteIds.value; + const formDeletedBatchRef = ref(); + + addDialog({ + title: $t('deleteBatchTip'), + width: '30%', + props: { formInline: { confirmText: '' } }, + draggable: true, + fullscreenIcon: true, + closeOnClickModal: false, + contentRenderer: () => h(DeleteBatchDialog, { ref: formDeletedBatchRef }), + beforeSure: (done, { options }) => { + formDeletedBatchRef.value.formDeletedBatchRef.validate(async (valid: any) => { + if (!valid) return; + + const text = options.props.formInline.confirmText.toLowerCase(); + if (text === 'yes' || text === 'y') { + // 删除数据 + await billStore.deleteBill(ids); + await onSearch(); + + done(); + } else message($t('deleteBatchTip'), { type: 'warning' }); + }); + }, + }); +}; diff --git a/src/views/financial/bill/utils/types.ts b/src/views/financial/bill/utils/types.ts new file mode 100644 index 0000000..5c83872 --- /dev/null +++ b/src/views/financial/bill/utils/types.ts @@ -0,0 +1,20 @@ +// 添加或者修改表单元素 +export interface FormItemProps { + // 绑定的用户id + userId: string; + // 类型:1 - 收入,-1 - 支出 + type: number; + // 金额 + amount: any; + // 描述 + description: string; + // 交易日期 + transactionDate: any; + // 类别id + categoryId: number; +} + +// 添加或修改表单Props +export interface FormProps { + formInline: FormItemProps; +} diff --git a/src/views/financial/budget-category/budget-category-dialog.vue b/src/views/financial/budget-category/budget-category-dialog.vue index 5eabbb8..aa86c6c 100644 --- a/src/views/financial/budget-category/budget-category-dialog.vue +++ b/src/views/financial/budget-category/budget-category-dialog.vue @@ -54,6 +54,7 @@ const getAllParentList = async () => { }; onMounted(() => { + onSearchUserinfo(); getAllParentList(); }); diff --git a/src/views/financial/budget-category/index.vue b/src/views/financial/budget-category/index.vue index a39536f..385cb98 100644 --- a/src/views/financial/budget-category/index.vue +++ b/src/views/financial/budget-category/index.vue @@ -51,7 +51,7 @@ const resetForm = async (formEl: FormInstance | undefined) => { formEl.resetFields(); budgetCategoryStore.form.period = undefined; budgetCategoryStore.form.startPeriod = undefined; - budgetCategoryStore.form.endPeriod == undefined; + budgetCategoryStore.form.endPeriod = undefined; await onSearch(); }; diff --git a/src/views/financial/budget-category/utils/types.ts b/src/views/financial/budget-category/utils/types.ts index 5b2b5c8..b9a48ac 100644 --- a/src/views/financial/budget-category/utils/types.ts +++ b/src/views/financial/budget-category/utils/types.ts @@ -3,7 +3,7 @@ export interface FormItemProps { // 父级id parentId: number; // 绑定的用户id - userId: number; + userId: string; // 分类名称 categoryName: string; // 预算名称