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

83 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineStore } from 'pinia';
import { fetchAddUserBill, fetchDeleteUserBill, fetchGetUserBillList, fetchUpdateUserBill } from '@/api/v1/financialUser/billUser';
import { pageSizes } from '@/enums/baseConstant';
import { storeMessage } from '@/utils/message';
import { storePagination } from '@/store/useStorePagination';
import { getDefaultDateRange } from '@/utils/date';
/**
* 账单信息 Store
*/
export const useBillUserStore = defineStore('billUserStore', {
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 = 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 fetchGetUserBillList(data);
// 公共页面函数hook
const pagination = storePagination.bind(this);
return pagination(result);
},
/** 添加账单信息 */
async addBill(data: any) {
const result = await fetchAddUserBill(data);
return storeMessage(result);
},
/** 修改账单信息 */
async updateBill(data: any) {
const result = await fetchUpdateUserBill(data);
return storeMessage(result);
},
/** 删除账单信息 */
async deleteBill(data: any) {
const result = await fetchDeleteUserBill(data);
return storeMessage(result);
},
},
});