index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <BasicTable
  3. ref="tableRef"
  4. @register="registerTable"
  5. rowKey="id"
  6. :pagination="{
  7. pageSize: 10,
  8. defaultPageSize: 10,
  9. showSizeChanger: false,
  10. }"
  11. >
  12. <template #form-custom> custom-slot </template>
  13. <template #action="{ record }">
  14. <TableAction :actions="createActions(record)" stopButtonPropagation />
  15. </template>
  16. </BasicTable>
  17. <Popup @register="addRegister" @saveData="saveData" />
  18. </template>
  19. <script lang="ts">
  20. import { defineComponent, ref, unref } from 'vue';
  21. import Popup from './popup.vue';
  22. import { useMessage } from '/@/hooks/web/useMessage';
  23. import { useModal } from '/@/components/Modal';
  24. import { getFormConfig, columns } from './data';
  25. import { getDuesList, addDues } from '/@/api/sys/money';
  26. import moment from 'moment';
  27. import {
  28. BasicTable,
  29. useTable,
  30. TableAction,
  31. ActionItem,
  32. EditRecordRow,
  33. TableActionType,
  34. } from '/@/components/Table';
  35. export default defineComponent({
  36. name: 'Dues',
  37. components: { BasicTable, TableAction, Popup },
  38. emits: ['select'],
  39. setup(_, { emit }) {
  40. const { createMessage } = useMessage();
  41. const { success /*, error*/ } = createMessage;
  42. const tableRef = ref<Nullable<TableActionType>>(null);
  43. const [registerTable] = useTable({
  44. columns: columns,
  45. clickToRowSelect: false, // 点击行不勾选
  46. api: getDuesList,
  47. useSearchForm: true,
  48. showTableSetting: true,
  49. tableSetting: {
  50. redo: false,
  51. size: false,
  52. },
  53. beforeFetch: beforeFetch,
  54. afterFetch: afterFetch,
  55. formConfig: getFormConfig(),
  56. actionColumn: {
  57. width: 160,
  58. title: '操作',
  59. dataIndex: 'action',
  60. slots: { customRender: 'action' },
  61. fixed: undefined,
  62. },
  63. maxHeight: 190,
  64. showIndexColumn: false,
  65. bordered: true,
  66. });
  67. const [addRegister, { openModal: openPopup }] = useModal();
  68. function getTableAction() {
  69. // 获取组件
  70. const tableAction = unref(tableRef);
  71. if (!tableAction) {
  72. throw new Error('tableAction is null');
  73. }
  74. return tableAction;
  75. }
  76. function beforeFetch(params) {
  77. for (let k in params) {
  78. if (k !== 'page' && k !== 'pageSize' && k !== 'field' && k !== 'order') {
  79. if (params[k] === '') {
  80. delete params[k];
  81. } else {
  82. if (!params.filter) {
  83. params.filter = {};
  84. }
  85. if (params.birthday) {
  86. params.birthday = moment(params.birthday).format('YYYY-MM-DD');
  87. } else {
  88. delete params.birthday;
  89. }
  90. params.filter[k] = params[k];
  91. delete params[k];
  92. }
  93. }
  94. }
  95. params.filter = JSON.stringify(params.filter);
  96. params.offset = params.page;
  97. params.limit = params.pageSize;
  98. delete params.page;
  99. delete params.pageSize;
  100. }
  101. function afterFetch(result) {
  102. console.log(`result`, result);
  103. // tableData.result = result;
  104. }
  105. function handleAdd() {
  106. // 开启弹窗
  107. openPopup(true, { family: [] });
  108. }
  109. function handleSelect(record: EditRecordRow) {
  110. emit('select', record);
  111. }
  112. async function saveData(params: any) {
  113. const data = params.data;
  114. const closeModel = params.closeModal;
  115. console.log(`data`, data);
  116. await addDues(data).then((res) => {
  117. console.log(res);
  118. getTableAction().reload();
  119. closeModel();
  120. success('创建成功!');
  121. });
  122. }
  123. function createActions(record: EditRecordRow): ActionItem[] {
  124. return [
  125. {
  126. label: '选择',
  127. icon: 'ant-design:edit-outlined',
  128. color: 'warning',
  129. onClick: handleSelect.bind(null, record),
  130. },
  131. ];
  132. }
  133. return {
  134. tableRef,
  135. registerTable,
  136. handleAdd,
  137. handleSelect,
  138. createActions,
  139. getTableAction,
  140. addRegister,
  141. saveData,
  142. };
  143. },
  144. });
  145. </script>
  146. <style>
  147. .ant-calendar-picker {
  148. width: 100%;
  149. }
  150. /* @media (max-width: 639px) {
  151. .sys-container .vben-basic-table-header__toolbar > * {
  152. padding: 6px !important;
  153. margin-right: 3px;
  154. font-size: 12px !important;
  155. }
  156. .sys-container .vben-basic-table .ant-table-wrapper {
  157. padding: 3px;
  158. }
  159. } */
  160. </style>