DataTable.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: Table.vue
  4. * @Description: 产品属性表格
  5. * @Author: Cheney
  6. */
  7. import { ElMessage } from 'element-plus';
  8. import { Download, InfoFilled, Refresh, Plus } from '@element-plus/icons-vue';
  9. import { usePagination } from '/@/utils/usePagination';
  10. import { useTableData } from '/@/utils/useTableData';
  11. import { useResponse } from '/@/utils/useResponse';
  12. import { AttributeColumns } from '/@/views/sku-manage/Columns';
  13. import PermissionButton from '/@/components/PermissionButton/index.vue';
  14. import DataTableSlot from './DataTableSlot.vue';
  15. import EditDrawer from './EditDrawer.vue';
  16. import NoticeDialog from '/src/views/product-manage/product-list/component/NoticeDialog.vue';
  17. import * as api from '../api';
  18. import CreateDialog from '/src/views/sku-manage/product-attribute/component/CreateDialog.vue';
  19. interface Parameter {
  20. country: string,
  21. shop: string,
  22. region: string,
  23. delivery: string,
  24. status: string,
  25. asin: string,
  26. sku: string
  27. }
  28. const queryParameter: Parameter | undefined = inject('query-parameter');
  29. const { tableOptions, handlePageChange } = usePagination(fetchList);
  30. const gridRef = ref();
  31. const gridOptions: any = reactive({
  32. id: 'product-attribute-table',
  33. keepSource: true,
  34. size: 'small',
  35. border: false,
  36. round: true,
  37. stripe: true,
  38. currentRowHighLight: true,
  39. height: '100%',
  40. customConfig: {
  41. // mode: 'drawer',
  42. // immediate: true,
  43. storage: true,
  44. },
  45. toolbarConfig: {
  46. size: 'large',
  47. custom: true,
  48. slots: {
  49. tools: 'toolbar_tools',
  50. buttons: 'toolbar_buttons'
  51. }
  52. },
  53. rowConfig: {
  54. isHover: true
  55. },
  56. columnConfig: {
  57. resizable: true
  58. },
  59. pagerConfig: {
  60. total: tableOptions.value.total,
  61. page: tableOptions.value.page,
  62. limit: tableOptions.value.limit
  63. },
  64. loading: false,
  65. loadingConfig: {
  66. icon: 'vxe-icon-indicator roll',
  67. text: '正在拼命加载中...'
  68. },
  69. columns: '',
  70. data: ''
  71. });
  72. const editOpen = ref(false);
  73. const createOpen = ref(false);
  74. const rowData = ref({});
  75. const dialogVisible = ref(false);
  76. onMounted(() => {
  77. fetchList();
  78. });
  79. async function fetchList() {
  80. gridOptions.data = [];
  81. gridOptions.columns = [];
  82. const query = {
  83. asin: queryParameter?.asin,
  84. sku: queryParameter?.sku,
  85. country_code: queryParameter?.country,
  86. shop_id: queryParameter?.shop,
  87. region: queryParameter?.region,
  88. delivery: queryParameter?.delivery,
  89. status: queryParameter?.status
  90. };
  91. await useTableData(api.getTableData, query, gridOptions);
  92. await gridRef.value.loadColumn(AttributeColumns);
  93. gridOptions.showHeader = Boolean(gridOptions.data?.length);
  94. }
  95. function handleRefresh() {
  96. fetchList();
  97. }
  98. function handleEdit(row: any) {
  99. editOpen.value = true;
  100. rowData.value = row;
  101. }
  102. function handleCreate() {
  103. createOpen.value = true;
  104. }
  105. async function singleDelete(row: any) {
  106. const res = await useResponse(api.deleteRow, row);
  107. if (res.code === 2000) {
  108. ElMessage.success({ message: '删除成功', plain: true });
  109. handleRefresh();
  110. }
  111. }
  112. const gridEvents = {
  113. custom ({ type }: any) {
  114. // console.log(`点击 ${type}`)
  115. if (type == 'confirm') {
  116. fetchList();
  117. }
  118. }
  119. }
  120. defineExpose({ fetchList });
  121. </script>
  122. <template>
  123. <vxe-grid ref="gridRef" v-bind="gridOptions" v-on="gridEvents">
  124. <template #toolbar_buttons>
  125. <PermissionButton type="primary" :icon="Plus" plain round @click="handleCreate">新 增</PermissionButton>
  126. </template>
  127. <!-- 工具栏右侧 -->
  128. <template #toolbar_tools>
  129. <el-button circle class="toolbar-btn mr-3" @click="handleRefresh">
  130. <el-icon>
  131. <Refresh />
  132. </el-icon>
  133. </el-button>
  134. </template>
  135. <template #pager>
  136. <vxe-pager
  137. v-model:currentPage="gridOptions.pagerConfig.page"
  138. v-model:pageSize="gridOptions.pagerConfig.limit"
  139. :total="gridOptions.pagerConfig.total"
  140. class="mt-1.5"
  141. @page-change="handlePageChange"
  142. />
  143. </template>
  144. <!-- 自定义列插槽 -->
  145. <template v-for="col in AttributeColumns" #[`${col.field}`]="{ row }">
  146. <DataTableSlot :key="row.id" :field="col.field" :row="row" @edit-row="handleEdit" @handle-delete="singleDelete" />
  147. </template>
  148. </vxe-grid>
  149. <EditDrawer v-if="editOpen" v-model="editOpen" :row-data="rowData" @refresh="handleRefresh" />
  150. <NoticeDialog v-if="dialogVisible" v-model="dialogVisible" :row-data="rowData" />
  151. <CreateDialog v-if="createOpen" v-model="createOpen" @refresh="fetchList" />
  152. </template>
  153. <style scoped>
  154. .toolbar-btn {
  155. width: 34px;
  156. height: 34px;
  157. font-size: 18px
  158. }
  159. :deep(.custom-el-input .el-select__wrapper) {
  160. border-radius: 20px;
  161. }
  162. </style>