2024-11-11 12:04:24 +08:00
|
|
|
import { addDialog, closeDialog } from '@/components/BaseDialog/index';
|
2024-11-16 20:08:11 +08:00
|
|
|
import BillDialog from '@/views/financial-user/account-bill/bill/bill-dialog.vue';
|
2024-11-14 12:01:08 +08:00
|
|
|
import { useBillUserStore } from '@/store/financialUser/billUser';
|
2024-11-11 12:04:24 +08:00
|
|
|
import { h, ref } from 'vue';
|
|
|
|
import { message, messageBox } from '@/utils/message';
|
2024-11-16 20:08:11 +08:00
|
|
|
import type { FormItemProps } from '@/views/financial-user/account-bill/bill/utils/types';
|
2024-11-11 12:04:24 +08:00
|
|
|
import { $t } from '@/plugins/i18n';
|
|
|
|
import DeleteBatchDialog from '@/components/Table/DeleteBatchDialog.vue';
|
|
|
|
import dayjs from 'dayjs';
|
2024-11-26 23:09:13 +08:00
|
|
|
import ExportBill from '@/views/financial-user/account-bill/bill/export-bill.vue';
|
|
|
|
import { currentMouth } from '@/enums/dateEnums';
|
2024-11-11 12:04:24 +08:00
|
|
|
|
|
|
|
export const formRef = ref();
|
|
|
|
// 删除ids
|
|
|
|
export const deleteIds = ref([]);
|
2024-11-14 12:01:08 +08:00
|
|
|
const billStore = useBillUserStore();
|
2024-11-11 12:04:24 +08:00
|
|
|
|
|
|
|
/** 搜索初始化账单信息 */
|
|
|
|
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: {
|
2024-11-16 19:10:08 +08:00
|
|
|
type: -1,
|
2024-11-11 12:04:24 +08:00
|
|
|
amount: undefined,
|
|
|
|
description: undefined,
|
|
|
|
transactionDate: dayjs(Date.now()).format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
categoryId: undefined,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
draggable: true,
|
|
|
|
fullscreenIcon: true,
|
|
|
|
closeOnClickModal: false,
|
|
|
|
contentRenderer: () => h(BillDialog, { ref: formRef }),
|
|
|
|
footerButtons: [
|
|
|
|
{
|
|
|
|
label: $t('cancel'),
|
|
|
|
text: true,
|
|
|
|
bg: true,
|
2024-11-25 00:43:10 +08:00
|
|
|
btnClick: async ({ dialog: { options, index } }) => {
|
2024-11-11 12:04:24 +08:00
|
|
|
closeDialog(options, index);
|
2024-11-25 00:43:10 +08:00
|
|
|
await onSearch();
|
2024-11-11 12:04:24 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: $t('buttons.pureConfirm'),
|
|
|
|
type: 'primary',
|
|
|
|
text: true,
|
|
|
|
bg: true,
|
|
|
|
btnClick: ({ dialog: { options, index } }) => {
|
|
|
|
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;
|
|
|
|
|
|
|
|
// 添加成功
|
|
|
|
formRef.value.formRef.resetFields();
|
|
|
|
closeDialog(options, index);
|
|
|
|
await onSearch();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: $t('continue_adding'),
|
|
|
|
type: 'success',
|
|
|
|
text: true,
|
|
|
|
bg: true,
|
|
|
|
btnClick: ({ dialog: { 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;
|
|
|
|
|
|
|
|
// 添加成功
|
|
|
|
options.props.formInline.amount = undefined;
|
|
|
|
await onSearch();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 更新账单信息 */
|
|
|
|
export function onUpdate(row: any) {
|
|
|
|
addDialog({
|
|
|
|
title: `${$t('modify')}${$t('bill')}`,
|
|
|
|
width: '30%',
|
|
|
|
props: {
|
|
|
|
formInline: {
|
|
|
|
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' });
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2024-11-26 23:09:13 +08:00
|
|
|
|
|
|
|
/** 导出账单 */
|
|
|
|
export const onExportBill = () => {
|
|
|
|
const formExportBillRef = ref();
|
|
|
|
|
|
|
|
addDialog({
|
|
|
|
title: $t('exportBill'),
|
|
|
|
width: '30%',
|
|
|
|
props: { formInline: { transactionDate: currentMouth } },
|
|
|
|
draggable: true,
|
|
|
|
fullscreenIcon: true,
|
|
|
|
closeOnClickModal: false,
|
|
|
|
contentRenderer: () => h(ExportBill, { ref: formExportBillRef }),
|
|
|
|
beforeSure: (done, { options }) => {
|
|
|
|
formExportBillRef.value.formRef.validate(async (valid: any) => {
|
|
|
|
if (!valid) return;
|
|
|
|
const result = billStore.exportBill(options.props.formInline.transactionDate);
|
|
|
|
if (!result) return;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|