import { defineStore } from 'pinia'; import { fetchAddSavingGoal, fetchDeleteSavingGoal, fetchGetSavingGoalList, fetchUpdateSavingGoal } from '@/api/v1/financial/admin/savingGoal'; import { pageSizes } from '@/enums/baseConstant'; import { storeMessage } from '@/utils/message'; import { storePagination } from '@/store/useStorePagination'; /** * 用户储值 Store */ export const useSavingGoalStore = defineStore('savingGoalStore', { state() { return { // 用户储值列表 datalist: [], // 查询表单 form: { userId: undefined, // 绑定的用户id statusType: undefined, // 完成状态 savingGoalName: undefined, // 储值目标名称 amount: undefined, // 目标金额 amountDeposited: undefined, // 已存入金额 duration: undefined, // 目标时长 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 }; // 获取用户储值列表 const result = await fetchGetSavingGoalList(data); // 公共页面函数hook const pagination = storePagination.bind(this); return pagination(result); }, /** 添加用户储值 */ async addSavingGoal(data: any) { const result = await fetchAddSavingGoal(data); return storeMessage(result); }, /** 修改用户储值 */ async updateSavingGoal(data: any) { const result = await fetchUpdateSavingGoal(data); return storeMessage(result); }, /** 删除用户储值 */ async deleteSavingGoal(data: any) { const result = await fetchDeleteSavingGoal(data); return storeMessage(result); }, }, });