|
@@ -6,98 +6,100 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
import { Download, Refresh, Search } from '@element-plus/icons-vue';
|
|
import { Download, Refresh, Search } from '@element-plus/icons-vue';
|
|
-import enLocale from 'element-plus/es/locale/lang/en';
|
|
|
|
-import { usePagination } from '/@/utils/usePagination';
|
|
|
|
-import { nextTick, ref } from 'vue';
|
|
|
|
-import { marketplaceIdEnum } from '/@/utils/marketplaceIdEnum';
|
|
|
|
|
|
+import { nextTick, onBeforeMount, reactive, ref, watch } from 'vue';
|
|
import dayjs from 'dayjs';
|
|
import dayjs from 'dayjs';
|
|
-import { getTopSearchTermTable, postDownload } from '/@/views/searchTerm/topSearchTermTable/api';
|
|
|
|
|
|
+import { getTableData, postDownload } from './api';
|
|
import { ElMessage } from 'element-plus';
|
|
import { ElMessage } from 'element-plus';
|
|
|
|
+import { asinColumns } from './useColumns';
|
|
|
|
+import { brandColumns } from '/@/views/searchTerm/brandView/useColumns';
|
|
|
|
|
|
-const { tableData, total, currentPage, pageSize, handlePageChange } = usePagination(fetchTableData);
|
|
|
|
-const marketplaceSelect = ref(marketplaceIdEnum[0].value); // 当前只有美国区 默认第一个为美国
|
|
|
|
-const marketplaceOptions = marketplaceIdEnum;
|
|
|
|
-const reportTypeSelect = ref('weekly');
|
|
|
|
|
|
+const reportTypeSelect = ref('monthly');
|
|
const searchTermInp = ref('');
|
|
const searchTermInp = ref('');
|
|
-const asinInp = ref('');
|
|
|
|
|
|
+const asinInp = ref('B0');
|
|
const tableLoading = ref(false);
|
|
const tableLoading = ref(false);
|
|
const downloadLoading = ref(false);
|
|
const downloadLoading = ref(false);
|
|
-const date = ref(calculateLastWeek()); // 设置默认日期为上周的周日到周六
|
|
|
|
-const dateDimension = ref(date.value[0]);
|
|
|
|
|
|
+const date = ref(calculateLastWeek());
|
|
|
|
|
|
-/**
|
|
|
|
- * 判断当前时间维度 并 计算起始和结束日期
|
|
|
|
- */
|
|
|
|
-function calculateDate() {
|
|
|
|
- if (reportTypeSelect.value === 'weekly') {
|
|
|
|
- date.value[0] = dateDimension.value;
|
|
|
|
- date.value[1] = calculateEndDate(dateDimension.value);
|
|
|
|
- } else if (reportTypeSelect.value === 'monthly') {
|
|
|
|
- const selectedMonth = dayjs(dateDimension.value);
|
|
|
|
- date.value[0] = selectedMonth.startOf('month').format('YYYY-MM-DD');
|
|
|
|
- date.value[1] = selectedMonth.endOf('month').format('YYYY-MM-DD');
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+const gridOptions: any = reactive({
|
|
|
|
+ height: 'auto',
|
|
|
|
+ border: false,
|
|
|
|
+ round: true,
|
|
|
|
+ columnConfig: {
|
|
|
|
+ resizable: true,
|
|
|
|
+ },
|
|
|
|
+ toolbarConfig: {
|
|
|
|
+ custom: true,
|
|
|
|
+ slots: {
|
|
|
|
+ buttons: 'toolbar_buttons',
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ columns: asinColumns,
|
|
|
|
+ data: [],
|
|
|
|
+});
|
|
|
|
|
|
-/**
|
|
|
|
- * 计算上周的周日到周六的日期范围
|
|
|
|
- */
|
|
|
|
-function calculateLastWeek() {
|
|
|
|
- const today = dayjs();
|
|
|
|
- const lastSaturday = today.subtract(today.day() + 1, 'day'); // 上周六
|
|
|
|
- const lastSunday = lastSaturday.subtract(6, 'day'); // 上周日
|
|
|
|
- return [lastSunday.format('YYYY-MM-DD'), lastSaturday.format('YYYY-MM-DD')];
|
|
|
|
|
|
+const tablePage = reactive({
|
|
|
|
+ total: 0,
|
|
|
|
+ currentPage: 1,
|
|
|
|
+ pageSize: 20,
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+onBeforeMount(() => {
|
|
|
|
+ fetchTableData();
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+watch(date, () => {
|
|
|
|
+ fetchTableData();
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+async function handlePageChange({ currentPage, pageSize }) {
|
|
|
|
+ tablePage.currentPage = currentPage;
|
|
|
|
+ tablePage.pageSize = pageSize;
|
|
|
|
+ await fetchTableData();
|
|
}
|
|
}
|
|
|
|
|
|
-/**
|
|
|
|
- * 计算结束日期
|
|
|
|
- * @param startDate el-date-picker组件的value
|
|
|
|
- */
|
|
|
|
-function calculateEndDate(startDate: string) {
|
|
|
|
- return dayjs(startDate).add(6, 'day').format('YYYY-MM-DD');
|
|
|
|
|
|
+async function handleSelectChange() {
|
|
|
|
+ if (!asinInp.value) {
|
|
|
|
+ ElMessage.warning({ message: '请输入ASIN', plain: true });
|
|
|
|
+ return;
|
|
|
|
+ } else {
|
|
|
|
+ await fetchTableData();
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
async function refreshTable() {
|
|
async function refreshTable() {
|
|
- currentPage.value = 1;
|
|
|
|
- pageSize.value = 20;
|
|
|
|
|
|
+ tablePage.currentPage = 1;
|
|
|
|
+ tablePage.pageSize = 20;
|
|
asinInp.value = '';
|
|
asinInp.value = '';
|
|
searchTermInp.value = '';
|
|
searchTermInp.value = '';
|
|
reportTypeSelect.value = 'weekly';
|
|
reportTypeSelect.value = 'weekly';
|
|
- marketplaceSelect.value = marketplaceIdEnum[0].value;
|
|
|
|
|
|
+ // marketplaceSelect.value = marketplaceIdEnum[0].value;
|
|
await fetchTableData();
|
|
await fetchTableData();
|
|
}
|
|
}
|
|
|
|
|
|
async function fetchTableData() {
|
|
async function fetchTableData() {
|
|
tableLoading.value = true;
|
|
tableLoading.value = true;
|
|
const query = {
|
|
const query = {
|
|
- page: currentPage.value,
|
|
|
|
- limit: pageSize.value,
|
|
|
|
|
|
+ page: tablePage.currentPage,
|
|
|
|
+ limit: tablePage.pageSize,
|
|
asin: asinInp.value,
|
|
asin: asinInp.value,
|
|
search_term: searchTermInp.value,
|
|
search_term: searchTermInp.value,
|
|
report_type: reportTypeSelect.value,
|
|
report_type: reportTypeSelect.value,
|
|
- marketplace_Ids: marketplaceSelect.value,
|
|
|
|
|
|
+ // marketplace_Ids: marketplaceSelect.value,
|
|
date_start: date.value[0],
|
|
date_start: date.value[0],
|
|
date_end: date.value[1],
|
|
date_end: date.value[1],
|
|
};
|
|
};
|
|
try {
|
|
try {
|
|
- const response = await getTopSearchTermTable(query);
|
|
|
|
- total.value = response.total;
|
|
|
|
- tableData.value = response.data;
|
|
|
|
|
|
+ const response = await getTableData(query);
|
|
|
|
+ tablePage.total = response.total;
|
|
|
|
+ gridOptions.data = response.data;
|
|
} catch (error) {
|
|
} catch (error) {
|
|
console.error('==Error==:', error);
|
|
console.error('==Error==:', error);
|
|
} finally {
|
|
} finally {
|
|
tableLoading.value = false;
|
|
tableLoading.value = false;
|
|
- await nextTick();
|
|
|
|
- // 触发窗口 resize 事件
|
|
|
|
- window.dispatchEvent(new Event('resize'));
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-async function handleSelectChange() {
|
|
|
|
- calculateDate();
|
|
|
|
- await fetchTableData();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 输入框按下回车后触发
|
|
* 输入框按下回车后触发
|
|
*/
|
|
*/
|
|
@@ -135,56 +137,66 @@ function validateAsinInput(input: string) {
|
|
return regex.test(input);
|
|
return regex.test(input);
|
|
}
|
|
}
|
|
|
|
|
|
-async function handleDownload() {
|
|
|
|
- downloadLoading.value = true;
|
|
|
|
- try {
|
|
|
|
- const body = {
|
|
|
|
- asin: asinInp.value,
|
|
|
|
- date_start: date.value[0],
|
|
|
|
- date_end: date.value[1],
|
|
|
|
- search_term: searchTermInp.value,
|
|
|
|
- marketplace_Ids: marketplaceSelect.value,
|
|
|
|
- report_type: reportTypeSelect.value,
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- const response = await postDownload(body);
|
|
|
|
-
|
|
|
|
- const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
|
|
|
-
|
|
|
|
- // 创建一个临时 URL
|
|
|
|
- const url = window.URL.createObjectURL(blob);
|
|
|
|
-
|
|
|
|
- // 创建一个临时的 <a> 元素并触发下载
|
|
|
|
- const link = document.createElement('a');
|
|
|
|
- link.href = url;
|
|
|
|
-
|
|
|
|
- // 设置文件名
|
|
|
|
- const currentTime = dayjs().format('YYYY-MM-DD_HH_mm_ss');
|
|
|
|
- const filename = `TopSearchTerm_${currentTime}.xlsx`;
|
|
|
|
-
|
|
|
|
- link.setAttribute('download', filename);
|
|
|
|
-
|
|
|
|
- // 添加到 body, 触发点击, 然后移除
|
|
|
|
- document.body.appendChild(link);
|
|
|
|
- link.click();
|
|
|
|
- document.body.removeChild(link);
|
|
|
|
-
|
|
|
|
- // 释放 URL 对象
|
|
|
|
- window.URL.revokeObjectURL(url);
|
|
|
|
-
|
|
|
|
- ElMessage.success('文件下载成功');
|
|
|
|
- } catch (error) {
|
|
|
|
- console.error('==Error==:', error);
|
|
|
|
- ElMessage.error('文件下载失败,请重试');
|
|
|
|
- } finally {
|
|
|
|
- downloadLoading.value = false;
|
|
|
|
- }
|
|
|
|
|
|
+/**
|
|
|
|
+ * 计算上周的周日到周六的日期范围
|
|
|
|
+ */
|
|
|
|
+function calculateLastWeek() {
|
|
|
|
+ const today = dayjs();
|
|
|
|
+ const lastDay = today.subtract(1, 'day'); // 昨天
|
|
|
|
+ const firstDay = lastDay.subtract(6, 'day'); // 一周前
|
|
|
|
+ return [firstDay.format('YYYY-MM-DD'), lastDay.format('YYYY-MM-DD')];
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// async function handleDownload() {
|
|
|
|
+// downloadLoading.value = true;
|
|
|
|
+// try {
|
|
|
|
+// const body = {
|
|
|
|
+// asin: asinInp.value,
|
|
|
|
+// date_start: date.value[0],
|
|
|
|
+// date_end: date.value[1],
|
|
|
|
+// search_term: searchTermInp.value,
|
|
|
|
+// marketplace_Ids: marketplaceSelect.value,
|
|
|
|
+// report_type: reportTypeSelect.value,
|
|
|
|
+// };
|
|
|
|
+//
|
|
|
|
+// const response = await postDownload(body);
|
|
|
|
+//
|
|
|
|
+// const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
|
|
|
+//
|
|
|
|
+// // 创建一个临时 URL
|
|
|
|
+// const url = window.URL.createObjectURL(blob);
|
|
|
|
+//
|
|
|
|
+// // 创建一个临时的 <a> 元素并触发下载
|
|
|
|
+// const link = document.createElement('a');
|
|
|
|
+// link.href = url;
|
|
|
|
+//
|
|
|
|
+// // 设置文件名
|
|
|
|
+// const currentTime = dayjs().format('YYYY-MM-DD_HH_mm_ss');
|
|
|
|
+// const filename = `TopSearchTerm_${currentTime}.xlsx`;
|
|
|
|
+//
|
|
|
|
+// link.setAttribute('download', filename);
|
|
|
|
+//
|
|
|
|
+// // 添加到 body, 触发点击, 然后移除
|
|
|
|
+// document.body.appendChild(link);
|
|
|
|
+// link.click();
|
|
|
|
+// document.body.removeChild(link);
|
|
|
|
+//
|
|
|
|
+// // 释放 URL 对象
|
|
|
|
+// window.URL.revokeObjectURL(url);
|
|
|
|
+//
|
|
|
|
+// ElMessage.success('文件下载成功');
|
|
|
|
+// } catch (error) {
|
|
|
|
+// console.error('==Error==:', error);
|
|
|
|
+// ElMessage.error('文件下载失败,请重试');
|
|
|
|
+// } finally {
|
|
|
|
+// downloadLoading.value = false;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<template>
|
|
<template>
|
|
- <div class="py-2 px-2.5">
|
|
|
|
- <el-card class="mb-2.5">
|
|
|
|
|
|
+ <div class="py-2 px-2.5" style="background-color: #f7f7f7">
|
|
|
|
+ <el-card shadow="hover" class="mb-2.5" style="border: none; margin-bottom: 10px">
|
|
<div class="flex justify-between">
|
|
<div class="flex justify-between">
|
|
<div class="flex gap-5 flex-wrap">
|
|
<div class="flex gap-5 flex-wrap">
|
|
<div>
|
|
<div>
|
|
@@ -218,49 +230,66 @@ async function handleDownload() {
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div>
|
|
<span class="font-medium mr-0.5">报告日期 </span>
|
|
<span class="font-medium mr-0.5">报告日期 </span>
|
|
- <el-config-provider :locale="enLocale">
|
|
|
|
- <el-date-picker
|
|
|
|
- v-if="reportTypeSelect === 'weekly'"
|
|
|
|
- v-model="dateDimension"
|
|
|
|
- type="week"
|
|
|
|
- value-format="YYYY-MM-DD"
|
|
|
|
- :format="`${date[0]} To ${date[1]}`"
|
|
|
|
- :popper-options="{ placement: 'bottom-end' }"
|
|
|
|
- :disabled-date="(time: Date) => time > new Date()"
|
|
|
|
- :clearable="false" />
|
|
|
|
- <el-date-picker
|
|
|
|
- v-else
|
|
|
|
- v-model="dateDimension"
|
|
|
|
- type="month"
|
|
|
|
- value-format="YYYY-MM"
|
|
|
|
- :format="`${date[0]} To ${date[1]}`"
|
|
|
|
- :popper-options="{ placement: 'bottom-end' }"
|
|
|
|
- :disabled-date="(time: Date) => time > new Date()"
|
|
|
|
- :clearable="false">
|
|
|
|
- <template #default> 123</template>
|
|
|
|
- </el-date-picker>
|
|
|
|
- </el-config-provider>
|
|
|
|
|
|
+ <el-date-picker
|
|
|
|
+ v-model="date"
|
|
|
|
+ type="daterange"
|
|
|
|
+ value-format="YYYY-MM-DD"
|
|
|
|
+ range-separator="To"
|
|
|
|
+ :disabled-date="(time: Date) => time > new Date()"
|
|
|
|
+ :popper-options="{ placement: 'bottom-end' }"
|
|
|
|
+ :clearable="false" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="flex">
|
|
<div class="flex">
|
|
- <el-button
|
|
|
|
- type="success"
|
|
|
|
- plain
|
|
|
|
- @click="handleDownload"
|
|
|
|
- :icon="Download"
|
|
|
|
- round
|
|
|
|
- :loading="downloadLoading"
|
|
|
|
- :disabled="!tableData.length"
|
|
|
|
- >下载表格
|
|
|
|
- </el-button>
|
|
|
|
|
|
+ <!--<el-button-->
|
|
|
|
+ <!-- type="success"-->
|
|
|
|
+ <!-- plain-->
|
|
|
|
+ <!-- @click="handleDownload"-->
|
|
|
|
+ <!-- :icon="Download"-->
|
|
|
|
+ <!-- round-->
|
|
|
|
+ <!-- :loading="downloadLoading"-->
|
|
|
|
+ <!-- :disabled="!tableData.length"-->
|
|
|
|
+ <!-- >下载表格-->
|
|
|
|
+ <!--</el-button>-->
|
|
<el-button @click="refreshTable" :icon="Refresh" circle></el-button>
|
|
<el-button @click="refreshTable" :icon="Refresh" circle></el-button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</el-card>
|
|
</el-card>
|
|
- <el-card>
|
|
|
|
- <el-table></el-table>
|
|
|
|
|
|
+ <el-card shadow="hover" style="border: none">
|
|
|
|
+ <div style="overflow: hidden; width: 100%; height: 950px" v-loading="tableLoading">
|
|
|
|
+ <vxe-grid v-bind="gridOptions">
|
|
|
|
+ <template #toolbar_buttons></template>
|
|
|
|
+ <template v-for="col in asinColumns" #[`${col.field}_default`]="{ row }">
|
|
|
|
+ <div v-if="col.field === 'clickedItemName'">
|
|
|
|
+ <el-tooltip effect="dark" :content="row.clickedItemName" placement="top" :show-after="300" >
|
|
|
|
+ <div class="line-text font-medium">
|
|
|
|
+ {{ row.clickedItemName }}
|
|
|
|
+ </div>
|
|
|
|
+ </el-tooltip>
|
|
|
|
+ </div>
|
|
|
|
+ <div v-else class="font-medium">
|
|
|
|
+ {{ row[col.field] ? row[col.field] : '-' }}
|
|
|
|
+ </div>
|
|
|
|
+ </template>
|
|
|
|
+ <template #pager>
|
|
|
|
+ <vxe-pager
|
|
|
|
+ :layouts="['Sizes', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'FullJump', 'Total']"
|
|
|
|
+ v-model:current-page="tablePage.currentPage"
|
|
|
|
+ v-model:page-size="tablePage.pageSize"
|
|
|
|
+ :total="tablePage.total"
|
|
|
|
+ @page-change="handlePageChange">
|
|
|
|
+ </vxe-pager>
|
|
|
|
+ </template>
|
|
|
|
+ </vxe-grid>
|
|
|
|
+ </div>
|
|
</el-card>
|
|
</el-card>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
-<style scoped></style>
|
|
|
|
|
|
+<style scoped>
|
|
|
|
+.line-text {
|
|
|
|
+ white-space: nowrap;
|
|
|
|
+ overflow: hidden;
|
|
|
|
+ text-overflow: ellipsis;
|
|
|
|
+}
|
|
|
|
+</style>
|