financial-web/src/store/financialUser/billUser.ts

86 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-11-11 12:04:24 +08:00
import { defineStore } from 'pinia';
2024-11-13 13:22:00 +08:00
import { fetchAddBill, fetchDeleteBill, fetchGetBillList, fetchUpdateBill } from '@/api/v1/financialUser/billUser';
2024-11-11 12:04:24 +08:00
import { pageSizes } from '@/enums/baseConstant';
import { storeMessage } from '@/utils/message';
import { storePagination } from '@/store/useStorePagination';
import { getDefaultDateRange } from '@/utils/date';
/**
* Store
*/
export const useBillStore = defineStore('billStore', {
state() {
return {
// 账单信息列表
datalist: [],
// 查询表单
form: {
// 类型1 - 收入,-1 - 支出
type: undefined,
// 描述
description: undefined,
// 开始交易日期
startDate: undefined,
// 结束交易日期
endDate: undefined,
// 交易日期
date: getDefaultDateRange(),
},
// 分页查询结果
pagination: {
currentPage: 1,
pageSize: 30,
total: 1,
pageSizes,
},
// 加载
loading: false,
};
},
getters: {},
actions: {
/** 获取账单信息 */
async getBillList() {
// 将日期格式赋值
if (!this.form.date) {
this.form.startDate = undefined;
this.form.endDate = undefined;
} else {
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);
},
},
});