page: 📄 预算分类完成
This commit is contained in:
parent
a647bfea44
commit
0514b7ade8
|
@ -0,0 +1,22 @@
|
|||
import { http } from '@/api/service/request';
|
||||
import type { BaseResult, ResultTable } from '@/api/service/types';
|
||||
|
||||
/** 账单信息---获取账单信息列表 */
|
||||
export const fetchGetBillList = (data: any) => {
|
||||
return http.request<BaseResult<ResultTable>>('get', `bill/getBillList/${data.currentPage}/${data.pageSize}`, { params: data });
|
||||
};
|
||||
|
||||
/** 账单信息---添加账单信息 */
|
||||
export const fetchAddBill = (data: any) => {
|
||||
return http.request<BaseResult<object>>('post', 'bill/addBill', { data });
|
||||
};
|
||||
|
||||
/** 账单信息---更新账单信息 */
|
||||
export const fetchUpdateBill = (data: any) => {
|
||||
return http.request<BaseResult<object>>('put', 'bill/updateBill', { data });
|
||||
};
|
||||
|
||||
/** 账单信息---删除账单信息 */
|
||||
export const fetchDeleteBill = (data: any) => {
|
||||
return http.request<BaseResult<object>>('delete', 'bill/deleteBill', { data });
|
||||
};
|
|
@ -0,0 +1,82 @@
|
|||
import { defineStore } from 'pinia';
|
||||
import { fetchAddBill, fetchDeleteBill, fetchGetBillList, fetchUpdateBill } from '@/api/v1/financial/bill';
|
||||
import { pageSizes } from '@/enums/baseConstant';
|
||||
import { storeMessage } from '@/utils/message';
|
||||
import { storePagination } from '@/store/useStorePagination';
|
||||
|
||||
/**
|
||||
* 账单信息 Store
|
||||
*/
|
||||
export const useBillStore = defineStore('billStore', {
|
||||
state() {
|
||||
return {
|
||||
// 账单信息列表
|
||||
datalist: [],
|
||||
// 查询表单
|
||||
form: {
|
||||
userId: undefined,
|
||||
// 类型:1 - 收入,-1 - 支出
|
||||
type: undefined,
|
||||
// 描述
|
||||
description: undefined,
|
||||
// 交易日志
|
||||
date: undefined,
|
||||
// 开始交易日期
|
||||
startDate: undefined,
|
||||
// 结束交易日期
|
||||
endDate: undefined,
|
||||
},
|
||||
// 分页查询结果
|
||||
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 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);
|
||||
},
|
||||
},
|
||||
});
|
|
@ -8,7 +8,7 @@ import { getDefaultDateRange } from '@/utils/date';
|
|||
/**
|
||||
* 账单信息 Store
|
||||
*/
|
||||
export const useBillStore = defineStore('billStore', {
|
||||
export const useBillUserStore = defineStore('billUserStore', {
|
||||
state() {
|
||||
return {
|
||||
// 账单信息列表
|
||||
|
|
|
@ -5,7 +5,7 @@ import { rules } from '@/views/financial-user/bill-user/utils/columns';
|
|||
import { FormProps } from '@/views/financial-user/bill-user/utils/types';
|
||||
import { $t } from '@/plugins/i18n';
|
||||
import { incomeOrExpend } from '@/enums/baseConstant';
|
||||
import { useBillStore } from '@/store/financialUser/billUser';
|
||||
import { useBillUserStore } from '@/store/financialUser/billUser';
|
||||
import { onSearch } from '@/views/financial-user/bill-user/utils/hooks';
|
||||
import { useCategoryUserStore } from '@/store/financialUser/categoryUser';
|
||||
|
||||
|
@ -26,7 +26,7 @@ const props = withDefaults(defineProps<FormProps>(), {
|
|||
|
||||
const formRef = ref<FormInstance>();
|
||||
const form = ref(props.formInline);
|
||||
const billStore = useBillStore();
|
||||
const billStore = useBillUserStore();
|
||||
const categoryUserStore = useCategoryUserStore();
|
||||
|
||||
/** 提交表单 */
|
||||
|
@ -63,7 +63,6 @@ defineExpose({ formRef });
|
|||
<el-date-picker
|
||||
v-model="form.transactionDate"
|
||||
:placeholder="$t('input') + $t('transactionDate')"
|
||||
class="w-[100%]"
|
||||
format="YYYY/MM/DD HH:mm:ss"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
|
@ -75,7 +74,6 @@ defineExpose({ formRef });
|
|||
<el-select v-model="form.categoryId" :placeholder="$t('select') + $t('category')" clearable filterable>
|
||||
<el-option v-for="item in categoryUserStore.allCategoryList" :key="item.id" :label="item.categoryName" :navigationBar="false" :value="item.id" />
|
||||
</el-select>
|
||||
<!--<el-input v-model="form.categoryId" :placeholder="$t('input') + $t('categoryId')" autocomplete="off" type="text" />-->
|
||||
</el-form-item>
|
||||
|
||||
<!-- 描述 -->
|
||||
|
|
|
@ -9,7 +9,7 @@ import Delete from '@iconify-icons/ep/delete';
|
|||
import EditPen from '@iconify-icons/ep/edit-pen';
|
||||
import Refresh from '@iconify-icons/ep/refresh';
|
||||
import { $t } from '@/plugins/i18n';
|
||||
import { useBillStore } from '@/store/financialUser/billUser';
|
||||
import { useBillUserStore } from '@/store/financialUser/billUser';
|
||||
import { useRenderIcon } from '@/components/CommonIcon/src/hooks';
|
||||
import { FormInstance } from 'element-plus';
|
||||
import { incomeOrExpend } from '@/enums/baseConstant';
|
||||
|
@ -17,7 +17,7 @@ import { getDefaultDateRange } from '@/utils/date';
|
|||
|
||||
const tableRef = ref();
|
||||
const formRef = ref();
|
||||
const billStore = useBillStore();
|
||||
const billStore = useBillUserStore();
|
||||
|
||||
/** 当前页改变时 */
|
||||
const onCurrentPageChange = async (value: number) => {
|
||||
|
@ -41,6 +41,8 @@ const resetForm = async (formEl: FormInstance | undefined) => {
|
|||
if (!formEl) return;
|
||||
formEl.resetFields();
|
||||
billStore.form.date = getDefaultDateRange();
|
||||
billStore.form.startDate = undefined;
|
||||
billStore.form.endDate = undefined;
|
||||
await onSearch();
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { addDialog, closeDialog } from '@/components/BaseDialog/index';
|
||||
import BillDialog from '@/views/financial-user/bill-user/bill-dialog.vue';
|
||||
import { useBillStore } from '@/store/financialUser/billUser';
|
||||
import { useBillUserStore } from '@/store/financialUser/billUser';
|
||||
import { h, ref } from 'vue';
|
||||
import { message, messageBox } from '@/utils/message';
|
||||
import type { FormItemProps } from '@/views/financial-user/bill-user/utils/types';
|
||||
|
@ -11,7 +11,7 @@ import dayjs from 'dayjs';
|
|||
export const formRef = ref();
|
||||
// 删除ids
|
||||
export const deleteIds = ref([]);
|
||||
const billStore = useBillStore();
|
||||
const billStore = useBillUserStore();
|
||||
|
||||
/** 搜索初始化账单信息 */
|
||||
export async function onSearch() {
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
<script lang="ts" setup>
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { FormInstance } from 'element-plus';
|
||||
import { rules } from '@/views/financial/bill/utils/columns';
|
||||
import { FormProps } from '@/views/financial/bill/utils/types';
|
||||
import { $t } from '@/plugins/i18n';
|
||||
import { incomeOrExpend } from '@/enums/baseConstant';
|
||||
import { useCategoryUserStore } from '@/store/financialUser/categoryUser';
|
||||
import { onSearch } from '@/views/financial/bill/utils/hooks';
|
||||
import { useBillStore } from '@/store/financial/bill';
|
||||
import { useAdminUserStore } from '@/store/system/adminUser';
|
||||
import LoadingSvg from '@/assets/svg/loading.svg';
|
||||
|
||||
const props = withDefaults(defineProps<FormProps>(), {
|
||||
formInline: () => ({
|
||||
// 绑定的用户id
|
||||
userId: undefined,
|
||||
// 类型:1 - 收入,-1 - 支出
|
||||
type: undefined,
|
||||
// 金额
|
||||
amount: undefined,
|
||||
// 描述
|
||||
description: undefined,
|
||||
// 交易日期
|
||||
transactionDate: undefined,
|
||||
// 类别id
|
||||
categoryId: undefined,
|
||||
}),
|
||||
});
|
||||
|
||||
const formRef = ref<FormInstance>();
|
||||
const form = ref(props.formInline);
|
||||
// 用户信息列表
|
||||
const userDataList = ref();
|
||||
// 搜索用户加载
|
||||
const loading = ref(false);
|
||||
const billStore = useBillStore();
|
||||
const categoryUserStore = useCategoryUserStore();
|
||||
const adminUserStore = useAdminUserStore();
|
||||
|
||||
/** 搜索 */
|
||||
const onSearchUserinfo = async (keyword: string) => {
|
||||
loading.value = true;
|
||||
userDataList.value = await adminUserStore.queryUser({ keyword });
|
||||
loading.value = false;
|
||||
};
|
||||
|
||||
/** 提交表单 */
|
||||
const onSubmit = () => {
|
||||
formRef.value.validate(async (valid: any) => {
|
||||
if (!valid) return;
|
||||
|
||||
const result = await billStore.addBill(form.value);
|
||||
if (!result) return;
|
||||
|
||||
// 添加成功
|
||||
form.value.amount = undefined;
|
||||
await onSearch();
|
||||
});
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
onSearchUserinfo();
|
||||
categoryUserStore.getCategoryUserAllList();
|
||||
});
|
||||
|
||||
defineExpose({ formRef });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="auto">
|
||||
<!-- 类型:1 - 收入,-1 - 支出 -->
|
||||
<el-form-item :label="$t('type')" prop="type">
|
||||
<el-select v-model="form.type" :placeholder="$t('select') + $t('type')" clearable filterable>
|
||||
<el-option v-for="(item, index) in incomeOrExpend" :key="index" :label="item.label" :navigationBar="false" :value="item.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 绑定的用户id -->
|
||||
<el-form-item :label="$t('user')" prop="userId">
|
||||
<el-select
|
||||
v-model="form.userId"
|
||||
:loading="loading"
|
||||
:placeholder="$t('user')"
|
||||
:remote-method="onSearchUserinfo"
|
||||
clearable
|
||||
filterable
|
||||
remote
|
||||
remote-show-suffix
|
||||
>
|
||||
<el-option v-for="item in userDataList" :key="item.id" :label="item.username" :value="item.id" />
|
||||
<template #loading>
|
||||
<el-icon class="is-loading">
|
||||
<LoadingSvg />
|
||||
</el-icon>
|
||||
</template>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 交易日期 -->
|
||||
<el-form-item :label="$t('transactionDate')" prop="transactionDate">
|
||||
<el-date-picker
|
||||
v-model="form.transactionDate"
|
||||
:placeholder="$t('input') + $t('transactionDate')"
|
||||
format="YYYY/MM/DD HH:mm:ss"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 类别id -->
|
||||
<el-form-item :label="$t('category')" prop="categoryId">
|
||||
<el-select v-model="form.categoryId" :placeholder="$t('select') + $t('category')" clearable filterable>
|
||||
<el-option v-for="item in categoryUserStore.allCategoryList" :key="item.id" :label="item.categoryName" :navigationBar="false" :value="item.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 描述 -->
|
||||
<el-form-item :label="$t('description')" prop="description">
|
||||
<el-input
|
||||
v-model="form.description"
|
||||
:autosize="{ minRows: 2, maxRows: 4 }"
|
||||
:placeholder="$t('input') + $t('description')"
|
||||
autocomplete="off"
|
||||
maxlength="256"
|
||||
show-word-limit
|
||||
type="textarea"
|
||||
@keydown.enter="onSubmit"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 金额 -->
|
||||
<el-form-item :label="$t('amount')" prop="amount">
|
||||
<el-input v-model="form.amount" :min="0" :placeholder="$t('input') + $t('amount')" :step="0.01" autocomplete="off" type="number" @keydown.enter="onSubmit" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</template>
|
|
@ -0,0 +1,187 @@
|
|||
<script lang="ts" setup>
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { columns } from '@/views/financial/bill/utils/columns';
|
||||
import PureTableBar from '@/components/TableBar/src/bar';
|
||||
import AddFill from '@iconify-icons/ri/add-circle-line';
|
||||
import PureTable from '@pureadmin/table';
|
||||
import { deleteIds, onAdd, onDelete, onDeleteBatch, onSearch, onUpdate } from '@/views/financial/bill/utils/hooks';
|
||||
import Delete from '@iconify-icons/ep/delete';
|
||||
import EditPen from '@iconify-icons/ep/edit-pen';
|
||||
import Refresh from '@iconify-icons/ep/refresh';
|
||||
import { $t } from '@/plugins/i18n';
|
||||
import { useBillStore } from '@/store/financial/bill';
|
||||
import { useRenderIcon } from '@/components/CommonIcon/src/hooks';
|
||||
import { FormInstance } from 'element-plus';
|
||||
import { incomeOrExpend } from '@/enums/baseConstant';
|
||||
import { selectUserinfo } from '@/components/Table/Userinfo/columns';
|
||||
import LoadingSvg from '@/assets/svg/loading.svg';
|
||||
import { useAdminUserStore } from '@/store/system/adminUser';
|
||||
|
||||
const tableRef = ref();
|
||||
const formRef = ref();
|
||||
// 用户信息列表
|
||||
const userDataList = ref();
|
||||
// 搜索用户加载
|
||||
const loading = ref(false);
|
||||
const adminUserStore = useAdminUserStore();
|
||||
const billStore = useBillStore();
|
||||
|
||||
/** 当前页改变时 */
|
||||
const onCurrentPageChange = async (value: number) => {
|
||||
billStore.pagination.currentPage = value;
|
||||
await onSearch();
|
||||
};
|
||||
|
||||
/** 当分页发生变化 */
|
||||
const onPageSizeChange = async (value: number) => {
|
||||
billStore.pagination.pageSize = value;
|
||||
await onSearch();
|
||||
};
|
||||
|
||||
/** 选择多行 */
|
||||
const onSelectionChange = (rows: Array<any>) => {
|
||||
deleteIds.value = rows.map((row: any) => row.id);
|
||||
};
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = async (formEl: FormInstance | undefined) => {
|
||||
if (!formEl) return;
|
||||
formEl.resetFields();
|
||||
billStore.form.date = undefined;
|
||||
billStore.form.startDate = undefined;
|
||||
billStore.form.endDate = undefined;
|
||||
await onSearch();
|
||||
};
|
||||
|
||||
/** 搜索 */
|
||||
const onSearchUserinfo = async (keyword: string) => {
|
||||
loading.value = true;
|
||||
userDataList.value = await adminUserStore.queryUser({ keyword });
|
||||
loading.value = false;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
onSearch();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="main">
|
||||
<el-form ref="formRef" :inline="true" :model="billStore.form" class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px] overflow-auto">
|
||||
<!-- 绑定的用户id -->
|
||||
<el-form-item :label="$t('user')" prop="userId">
|
||||
<el-select
|
||||
v-model="billStore.form.userId"
|
||||
:loading="loading"
|
||||
:placeholder="$t('user')"
|
||||
:remote-method="onSearchUserinfo"
|
||||
class="!w-[180px]"
|
||||
clearable
|
||||
filterable
|
||||
remote
|
||||
remote-show-suffix
|
||||
>
|
||||
<el-option v-for="item in userDataList" :key="item.id" :label="item.username" :value="item.id" />
|
||||
<template #loading>
|
||||
<el-icon class="is-loading">
|
||||
<LoadingSvg />
|
||||
</el-icon>
|
||||
</template>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 类型:1 - 收入,-1 - 支出 -->
|
||||
<el-form-item :label="$t('type')" prop="type">
|
||||
<el-select v-model="billStore.form.type" :placeholder="$t('select') + $t('type')" class="!w-[180px]" clearable filterable>
|
||||
<el-option v-for="(item, index) in incomeOrExpend" :key="index" :label="item.label" :navigationBar="false" :value="item.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 描述 -->
|
||||
<el-form-item :label="$t('description')" prop="description">
|
||||
<el-input v-model="billStore.form.description" :placeholder="`${$t('input')}${$t('description')}`" class="!w-[180px]" clearable />
|
||||
</el-form-item>
|
||||
|
||||
<!-- 开始交易日期 -->
|
||||
<el-form-item :label="$t('startDate')" prop="startDate">
|
||||
<el-date-picker
|
||||
v-model="billStore.form.date"
|
||||
:end-placeholder="$t('endDate')"
|
||||
:start-placeholder="$t('startDate')"
|
||||
clearable
|
||||
type="daterange"
|
||||
value-format="YYYY-MM-DD"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 搜索 -->
|
||||
<el-form-item>
|
||||
<el-button :icon="useRenderIcon('ri:search-line')" :loading="billStore.loading" type="primary" @click="onSearch"> {{ $t('search') }} </el-button>
|
||||
<el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)"> {{ $t('buttons.reset') }}</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<PureTableBar :columns="columns" title="账单信息" @fullscreen="tableRef.setAdaptive()" @refresh="onSearch">
|
||||
<template #buttons>
|
||||
<el-button :icon="useRenderIcon(AddFill)" type="primary" @click="onAdd"> {{ $t('addNew') }}</el-button>
|
||||
|
||||
<!-- 批量删除按钮 -->
|
||||
<el-button v-show="deleteIds.length > 0" :icon="useRenderIcon(Delete)" type="danger" @click="onDeleteBatch">
|
||||
{{ $t('delete_batches') }}
|
||||
</el-button>
|
||||
</template>
|
||||
|
||||
<template v-slot="{ size, dynamicColumns }">
|
||||
<pure-table
|
||||
ref="tableRef"
|
||||
:adaptiveConfig="{ offsetBottom: 96 }"
|
||||
:columns="dynamicColumns"
|
||||
:data="billStore.datalist"
|
||||
:header-cell-style="{ background: 'var(--el-fill-color-light)', color: 'var(--el-text-color-primary)' }"
|
||||
:loading="billStore.loading"
|
||||
:pagination="billStore.pagination"
|
||||
:size="size"
|
||||
adaptive
|
||||
align-whole="center"
|
||||
border
|
||||
highlight-current-row
|
||||
row-key="id"
|
||||
showOverflowTooltip
|
||||
table-layout="auto"
|
||||
@page-size-change="onPageSizeChange"
|
||||
@selection-change="onSelectionChange"
|
||||
@page-current-change="onCurrentPageChange"
|
||||
>
|
||||
<template #username="{ row }">
|
||||
<el-button v-show="row.username" link type="primary" @click="selectUserinfo(row.userId)">
|
||||
{{ row.username }}
|
||||
</el-button>
|
||||
</template>
|
||||
|
||||
<template #createUser="{ row }">
|
||||
<el-button v-show="row.createUser" link type="primary" @click="selectUserinfo(row.createUser)">
|
||||
{{ row.createUsername }}
|
||||
</el-button>
|
||||
</template>
|
||||
|
||||
<template #updateUser="{ row }">
|
||||
<el-button v-show="row.updateUser" link type="primary" @click="selectUserinfo(row.updateUser)">
|
||||
{{ row.updateUsername }}
|
||||
</el-button>
|
||||
</template>
|
||||
|
||||
<template #operation="{ row }">
|
||||
<el-button :icon="useRenderIcon(EditPen)" :size="size" class="reset-margin" link type="primary" @click="onUpdate(row)"> {{ $t('modify') }} </el-button>
|
||||
<el-popconfirm :title="`${$t('delete')}${row.description}?`" @confirm="onDelete(row)">
|
||||
<template #reference>
|
||||
<el-button :icon="useRenderIcon(Delete)" :size="size" class="reset-margin" link type="primary">
|
||||
{{ $t('delete') }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-popconfirm>
|
||||
</template>
|
||||
</pure-table>
|
||||
</template>
|
||||
</PureTableBar>
|
||||
</div>
|
||||
</template>
|
|
@ -0,0 +1,61 @@
|
|||
import { reactive } from 'vue';
|
||||
import { $t } from '@/plugins/i18n';
|
||||
import { ElTag, ElText, type FormRules } from 'element-plus';
|
||||
|
||||
// 表格列
|
||||
export const columns: TableColumnList = [
|
||||
{ type: 'selection', align: 'left' },
|
||||
{ type: 'index', index: (index: number) => index + 1, label: '序号', width: 60 },
|
||||
// 金额
|
||||
{
|
||||
label: $t('amount'),
|
||||
prop: 'amount',
|
||||
sortable: true,
|
||||
formatter({ type, amount }) {
|
||||
return type === -1 ? (
|
||||
<ElText size={'large'} type={'danger'} style={{ fontWeight: 800 }}>
|
||||
- {amount}¥
|
||||
</ElText>
|
||||
) : (
|
||||
<ElText size={'large'} type={'success'} style={{ fontWeight: 800 }}>
|
||||
+ {amount}¥
|
||||
</ElText>
|
||||
);
|
||||
},
|
||||
width: 200,
|
||||
},
|
||||
// 类别
|
||||
{
|
||||
label: $t('categoryName'),
|
||||
prop: 'categoryName',
|
||||
width: 150,
|
||||
formatter({ categoryName }) {
|
||||
return <ElTag effect={'plain'}>{categoryName}</ElTag>;
|
||||
},
|
||||
},
|
||||
// 交易日期
|
||||
{ label: $t('transactionDate'), prop: 'transactionDate', width: 160 },
|
||||
// 描述
|
||||
{ label: $t('description'), prop: 'description' },
|
||||
// 用户名
|
||||
{ label: $t('username'), prop: 'username', slot: 'username', width: 130 },
|
||||
{ label: $t('table.updateTime'), prop: 'updateTime', sortable: true, width: 160 },
|
||||
{ label: $t('table.createTime'), prop: 'createTime', sortable: true, width: 160 },
|
||||
{ label: $t('table.createUser'), prop: 'createUser', slot: 'createUser', width: 130 },
|
||||
{ label: $t('table.updateUser'), prop: 'updateUser', slot: 'updateUser', width: 130 },
|
||||
{ label: $t('table.operation'), fixed: 'right', width: 210, slot: 'operation' },
|
||||
];
|
||||
|
||||
// 添加规则
|
||||
export const rules = reactive<FormRules>({
|
||||
// 绑定的用户
|
||||
userId: [{ required: true, message: `${$t('input')}${$t('userId')}`, trigger: 'blur' }],
|
||||
// 类型:1 - 收入,-1 - 支出
|
||||
type: [{ required: true, message: `${$t('input')}${$t('type')}`, trigger: 'blur' }],
|
||||
// 金额
|
||||
amount: [{ required: true, message: `${$t('input')}${$t('amount')}`, trigger: 'blur' }],
|
||||
// 交易日期
|
||||
transactionDate: [{ required: true, message: `${$t('input')}${$t('transactionDate')}`, trigger: 'blur' }],
|
||||
// 类别id
|
||||
categoryId: [{ required: true, message: `${$t('input')}${$t('categoryId')}`, trigger: 'blur' }],
|
||||
});
|
|
@ -0,0 +1,134 @@
|
|||
import { addDialog } from '@/components/BaseDialog/index';
|
||||
import BillDialog from '@/views/financial/bill/bill-dialog.vue';
|
||||
import { useBillStore } from '@/store/financial/bill';
|
||||
import { h, ref } from 'vue';
|
||||
import { message, messageBox } from '@/utils/message';
|
||||
import type { FormItemProps } from '@/views/financial/bill/utils/types';
|
||||
import { $t } from '@/plugins/i18n';
|
||||
import DeleteBatchDialog from '@/components/Table/DeleteBatchDialog.vue';
|
||||
|
||||
export const formRef = ref();
|
||||
// 删除ids
|
||||
export const deleteIds = ref([]);
|
||||
const billStore = useBillStore();
|
||||
|
||||
/** 搜索初始化账单信息 */
|
||||
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: {
|
||||
userId: undefined,
|
||||
type: undefined,
|
||||
amount: undefined,
|
||||
description: undefined,
|
||||
transactionDate: undefined,
|
||||
categoryId: undefined,
|
||||
},
|
||||
},
|
||||
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.addBill(form);
|
||||
if (!result) return;
|
||||
done();
|
||||
await onSearch();
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** 更新账单信息 */
|
||||
export function onUpdate(row: any) {
|
||||
addDialog({
|
||||
title: `${$t('modify')}${$t('bill')}`,
|
||||
width: '30%',
|
||||
props: {
|
||||
formInline: {
|
||||
userId: row.userId,
|
||||
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' });
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
|
@ -0,0 +1,20 @@
|
|||
// 添加或者修改表单元素
|
||||
export interface FormItemProps {
|
||||
// 绑定的用户id
|
||||
userId: string;
|
||||
// 类型:1 - 收入,-1 - 支出
|
||||
type: number;
|
||||
// 金额
|
||||
amount: any;
|
||||
// 描述
|
||||
description: string;
|
||||
// 交易日期
|
||||
transactionDate: any;
|
||||
// 类别id
|
||||
categoryId: number;
|
||||
}
|
||||
|
||||
// 添加或修改表单Props
|
||||
export interface FormProps {
|
||||
formInline: FormItemProps;
|
||||
}
|
|
@ -54,6 +54,7 @@ const getAllParentList = async () => {
|
|||
};
|
||||
|
||||
onMounted(() => {
|
||||
onSearchUserinfo();
|
||||
getAllParentList();
|
||||
});
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ const resetForm = async (formEl: FormInstance | undefined) => {
|
|||
formEl.resetFields();
|
||||
budgetCategoryStore.form.period = undefined;
|
||||
budgetCategoryStore.form.startPeriod = undefined;
|
||||
budgetCategoryStore.form.endPeriod == undefined;
|
||||
budgetCategoryStore.form.endPeriod = undefined;
|
||||
await onSearch();
|
||||
};
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ export interface FormItemProps {
|
|||
// 父级id
|
||||
parentId: number;
|
||||
// 绑定的用户id
|
||||
userId: number;
|
||||
userId: string;
|
||||
// 分类名称
|
||||
categoryName: string;
|
||||
// 预算名称
|
||||
|
|
Loading…
Reference in New Issue