index.vue 4.6 KB

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