import { defineStore } from 'pinia'; import { fetchAddBudgetCategory, fetchDeleteBudgetCategory, fetchGetBudgetCategoryList, fetchUpdateBudgetCategory } from '@/api/v1/financial/budgetCategory'; import { pageSizes } from '@/enums/baseConstant'; import { storeMessage } from '@/utils/message'; import { storePagination } from '@/store/useStorePagination'; /** * 预算分类表 Store */ export const useBudgetCategoryStore = defineStore('budgetCategoryStore', { state() { return { // 预算分类表列表 datalist: [], // 查询表单 form: { // 父级id parentId: undefined, // 绑定的用户id userId: undefined, // 分类名称 categoryName: undefined, // 预算名称 budgetName: undefined, // 完成状态 statusType: undefined, // 预算金额 amount: undefined, // 预算周期 period: undefined, }, // 分页查询结果 pagination: { currentPage: 1, pageSize: 30, total: 1, pageSizes, }, // 加载 loading: false, }; }, getters: {}, actions: { /** 获取预算分类表 */ async getBudgetCategoryList() { // 整理请求参数 const data = { ...this.pagination, ...this.form }; delete data.pageSizes; delete data.total; delete data.background; // 获取预算分类表列表 const result = await fetchGetBudgetCategoryList(data); // 公共页面函数hook const pagination = storePagination.bind(this); return pagination(result); }, /** 添加预算分类表 */ async addBudgetCategory(data: any) { const result = await fetchAddBudgetCategory(data); return storeMessage(result); }, /** 修改预算分类表 */ async updateBudgetCategory(data: any) { const result = await fetchUpdateBudgetCategory(data); return storeMessage(result); }, /** 删除预算分类表 */ async deleteBudgetCategory(data: any) { const result = await fetchDeleteBudgetCategory(data); return storeMessage(result); }, }, });