123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <script lang="ts" setup>
- /**
- * @Name: Table.vue
- * @Description: 市场店铺表格
- * @Author: Cheney
- */
- import { Download, InfoFilled, Refresh } from '@element-plus/icons-vue';
- import { usePagination } from '/@/utils/usePagination';
- import { useTableData } from '/@/utils/useTableData';
- import { OnlineMerchandiseColumns } from '/@/views/store-manage/Columns';
- import DataTableSlot from './DataTableSlot.vue';
- import * as api from '../api';
- import { ElMessage } from 'element-plus';
- import { uesDownloadFile } from '/@/utils/useDownload';
- interface Parameter {
- country: string,
- shop: string,
- region: string,
- delivery: string,
- status: string,
- asin: string,
- sku: string,
- platformId: string,
- }
- const queryParameter: Parameter | undefined = inject('query-parameter');
- const { tableOptions, handlePageChange } = usePagination(fetchList);
- const gridRef = ref();
- const gridOptions: any = reactive({
- id: 'online-merchandise-table',
- keepSource: true,
- size: 'small',
- border: false,
- round: true,
- stripe: true,
- currentRowHighLight: true,
- height: '100%',
- customConfig: {
- storage: {
- visible: true
- }
- },
- toolbarConfig: {
- size: 'large',
- // custom: true,
- slots: {
- tools: 'toolbar_tools'
- }
- },
- rowConfig: {
- isHover: true
- },
- columnConfig: {
- resizable: true
- },
- pagerConfig: {
- total: tableOptions.value.total,
- page: tableOptions.value.page,
- limit: tableOptions.value.limit
- },
- loading: false,
- loadingConfig: {
- icon: 'vxe-icon-indicator roll',
- text: '正在拼命加载中...'
- },
- columns: '',
- data: ''
- });
- onBeforeMount(() => {
- gridOptions.pagerConfig.limit = 20;
- })
- onMounted(() => {
- fetchList();
- });
- async function fetchList(isQuery = false) {
- if (isQuery) {
- gridOptions.pagerConfig.page = 1;
- }
- gridOptions.data = [];
- gridOptions.columns = [];
- const query = {
- asin: queryParameter?.asin,
- sku: queryParameter?.sku,
- country_code: queryParameter?.country,
- shop_id: queryParameter?.shop,
- region: queryParameter?.region,
- delivery: queryParameter?.delivery,
- status: queryParameter?.status,
- platform_number: queryParameter?.platformId,
- };
- await useTableData(api.getTableData, query, gridOptions);
- if (gridOptions && gridOptions.data?.length) await gridRef.value.loadColumn(OnlineMerchandiseColumns);
- gridOptions.showHeader = Boolean(gridOptions.data?.length);
- }
- function handleRefresh() {
- fetchList();
- }
- async function handleDownload() {
- gridOptions.loading = true;
- try {
- await uesDownloadFile({
- apiMethod: api.exportData,
- queryParams: {
- asin: queryParameter?.asin,
- sku: queryParameter?.sku,
- country_code: queryParameter?.country,
- shop_id: queryParameter?.shop,
- region: queryParameter?.region,
- delivery: queryParameter?.delivery,
- status: queryParameter?.status,
- platform_number: queryParameter?.platformId,
- },
- fileName: '在线商品数据.xlsx',
- successMessage: () => ElMessage.success('数据导出成功!'),
- errorMessage: () => ElMessage.error('数据导出失败,请重试!'),
- });
- } finally {
- gridOptions.loading = false;
- }
- }
- defineExpose({ fetchList });
- </script>
- <template>
- <vxe-grid ref="gridRef" v-bind="gridOptions">
- <!-- 工具栏右侧 -->
- <template #toolbar_tools>
- <el-button circle class="toolbar-btn" @click="handleRefresh">
- <el-icon>
- <Refresh />
- </el-icon>
- </el-button>
- <el-button circle class="toolbar-btn" @click="handleDownload">
- <el-icon>
- <Download />
- </el-icon>
- </el-button>
- </template>
- <template #pager>
- <vxe-pager
- v-model:currentPage="gridOptions.pagerConfig.page"
- v-model:pageSize="gridOptions.pagerConfig.limit"
- :total="gridOptions.pagerConfig.total"
- class="mt-1.5"
- @page-change="handlePageChange"
- />
- </template>
- <template #empty>
- <el-empty description="暂无数据" />
- </template>
- <!-- 自定义列插槽 -->
- <template v-for="col in OnlineMerchandiseColumns" #[`${col.field}`]="{ row }">
- <DataTableSlot :key="row.id" :field="col.field" :row="row" />
- </template>
- </vxe-grid>
- </template>
- <style scoped>
- .toolbar-btn {
- width: 34px;
- height: 34px;
- font-size: 18px
- }
- :deep(.custom-el-input .el-select__wrapper) {
- border-radius: 20px;
- }
- </style>
|