123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <template>
- <a-button type="primary" @click="handleAdd"> 添加 </a-button>
- <BasicTable
- ref="tableRef"
- @register="registerTable"
- rowKey="id"
- :pagination="{
- pageSize: 10,
- defaultPageSize: 10,
- showSizeChanger: false,
- }"
- >
- <template #form-custom> custom-slot </template>
- <template #action="{ record }">
- <TableAction :actions="createActions(record)" stopButtonPropagation />
- </template>
- </BasicTable>
- <Popup @register="addRegister" @saveData="saveData" />
- </template>
- <script lang="ts">
- import { defineComponent, ref, unref } from 'vue';
- import Popup from './popup.vue';
- import { useMessage } from '/@/hooks/web/useMessage';
- import { useModal } from '/@/components/Modal';
- import { getFormConfig, columns } from './data';
- import { getDuesList, addDues } from '/@/api/sys/money';
- import moment from 'moment';
- import {
- BasicTable,
- useTable,
- TableAction,
- ActionItem,
- EditRecordRow,
- TableActionType,
- } from '/@/components/Table';
- export default defineComponent({
- name: 'Dues',
- components: { BasicTable, TableAction, Popup },
- emits: ['select'],
- setup(_, { emit }) {
- const { createMessage } = useMessage();
- const { success /*, error*/ } = createMessage;
- const tableRef = ref<Nullable<TableActionType>>(null);
- const [registerTable] = useTable({
- columns: columns,
- clickToRowSelect: false, // 点击行不勾选
- api: getDuesList,
- useSearchForm: true,
- showTableSetting: true,
- tableSetting: {
- redo: false,
- size: false,
- },
- beforeFetch: beforeFetch,
- afterFetch: afterFetch,
- formConfig: getFormConfig(),
- actionColumn: {
- width: 160,
- title: '操作',
- dataIndex: 'action',
- slots: { customRender: 'action' },
- fixed: undefined,
- },
- maxHeight: 190,
- showIndexColumn: false,
- bordered: true,
- });
- const [addRegister, { openModal: openPopup }] = useModal();
- function getTableAction() {
- // 获取组件
- const tableAction = unref(tableRef);
- if (!tableAction) {
- throw new Error('tableAction is null');
- }
- return tableAction;
- }
- function beforeFetch(params) {
- for (let k in params) {
- if (k !== 'page' && k !== 'pageSize' && k !== 'field' && k !== 'order') {
- if (params[k] === '') {
- delete params[k];
- } else {
- if (!params.filter) {
- params.filter = {};
- }
- if (params.birthday) {
- params.birthday = moment(params.birthday).format('YYYY-MM-DD');
- } else {
- delete params.birthday;
- }
- params.filter[k] = params[k];
- delete params[k];
- }
- }
- }
- params.filter = JSON.stringify(params.filter);
- params.offset = params.page;
- params.limit = params.pageSize;
- delete params.page;
- delete params.pageSize;
- }
- function afterFetch(result) {
- console.log(`result`, result);
- // tableData.result = result;
- }
- function handleAdd() {
- // 开启弹窗
- openPopup(true, { family: [] });
- }
- function handleSelect(record: EditRecordRow) {
- emit('select', record);
- }
- async function saveData(params: any) {
- const data = params.data;
- const closeModel = params.closeModal;
- console.log(`data`, data);
- await addDues(data).then((res) => {
- console.log(res);
- getTableAction().reload();
- closeModel();
- success('创建成功!');
- });
- }
- function createActions(record: EditRecordRow): ActionItem[] {
- return [
- {
- label: '选择',
- icon: 'ant-design:edit-outlined',
- color: 'warning',
- onClick: handleSelect.bind(null, record),
- },
- ];
- }
- return {
- tableRef,
- registerTable,
- handleAdd,
- handleSelect,
- createActions,
- getTableAction,
- addRegister,
- saveData,
- };
- },
- });
- </script>
- <style>
- .ant-calendar-picker {
- width: 100%;
- }
- /* @media (max-width: 639px) {
- .sys-container .vben-basic-table-header__toolbar > * {
- padding: 6px !important;
- margin-right: 3px;
- font-size: 12px !important;
- }
- .sys-container .vben-basic-table .ant-table-wrapper {
- padding: 3px;
- }
- } */
- </style>
|