123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <template>
- <div>
- <el-card>
- <span class="title">监控ASIN每月平均评分</span>
- <div style="display: flex; align-items: baseline; justify-content: space-between">
- <div style="display: flex; gap: 25px; margin-bottom: 10px">
- <div>
- <span style="font-size: 14px; padding-right: 4px; color: #95969a">ASIN:</span>
- <el-input v-model="searchAsin" clearable style="width: 180px" @change="fetchData"></el-input>
- </div>
- <div>
- <span style="font-size: 14px; padding-right: 4px; color: #95969a">SKU:</span>
- <el-input v-model="searchSku" clearable style="width: 180px" @change="fetchData"></el-input>
- </div>
- <div>
- <span style="font-size: 14px; color: #95969a">时间选择:</span>
- <el-date-picker
- v-model="asinMonthDate"
- :clearable="false"
- :disabled-date="disabledDate"
- placeholder="选择月"
- style="width: 170px"
- type="month"
- >
- </el-date-picker>
- </div>
- </div>
- <div>
- <el-button circle :icon="Download" plain @click="handleDownload"></el-button>
- </div>
- </div>
- <el-card body-style="padding: 0" shadow="never">
- <vxe-grid :cell-style="cellStyle" :header-cell-style="headerStyle" v-bind="gridOptions" v-on="gridEvents" show-overflow="tooltip"></vxe-grid>
- </el-card>
- </el-card>
- </div>
- </template>
- <script lang="ts" setup>
- import { getTableData, getTableDownloadData } from '/src/views/score-statistics/api';
- import { Download } from '@element-plus/icons-vue';
- import { scoreStatisticsColumns } from '/src/views/score-statistics/Columns';
- const gridOptions = reactive({
- border: 'inner',
- loading: false,
- height: 700,
- pagerConfig: {
- enabled: true,
- total: 20,
- currentPage: 1,
- pageSize: 20,
- pageSizes: [10, 20, 30],
- },
- rowConfig: {
- height: 38,
- },
- columns: scoreStatisticsColumns,
- data: [],
- });
- const asinMonthDate = ref(dayjs().subtract(1, 'month').startOf('month').format('YYYY-MM-DD'))
- const disabledDate = (time: Date) => {
- // 禁用当前月和当前月之后的日期
- const today = new Date(); // 获取当前日期
- const currentYear = today.getFullYear();
- const currentMonth = today.getMonth() + 1; // 获取月份,注意要 +1
- // 通过比较年份和月份来禁用
- return time.getFullYear() > currentYear || (time.getFullYear() === currentYear && time.getMonth() + 2 > currentMonth);
- };
- const searchAsin = ref('');
- const searchSku = ref('');
- const averageData = ref([]);
- const gridEvents = {
- pageChange({ pageSize, currentPage }) {
- gridOptions.pagerConfig.currentPage = currentPage;
- gridOptions.pagerConfig.pageSize = pageSize;
- fetchData();
- },
- };
- async function fetchData() {
- gridOptions.loading = true; // 显示加载状态
- try {
- const params = {
- limit: gridOptions.pagerConfig.pageSize,
- page: gridOptions.pagerConfig.currentPage,
- review_date: asinMonthDate.value,
- asin : searchAsin.value,
- sku : searchSku.value,
- };
- const resp = await getTableData(params);
- gridOptions.data = resp.data;
- console.log("=>(monthlyRating.vue:121) gridOptions.data", gridOptions.data);
- gridOptions.pagerConfig.total = resp.total;
- } catch (error) {
- console.log(error);
- } finally {
- gridOptions.loading = false;
- }
- }
- async function handleDownload() {
- gridOptions.loading = true; // 显示加载状态
- try {
- const params = {
- review_date: asinMonthDate.value,
- asin : searchAsin.value,
- sku : searchSku.value,
- };
- const resp = await getTableDownloadData(params);
- const url = window.URL.createObjectURL(resp.data);
- const link = document.createElement('a');
- link.href = url;
- link.setAttribute('download', asinMonthDate.slice(0, 7) + '平均评分.xlsx');
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- window.URL.revokeObjectURL(url);
- gridOptions.loading = false;
- ElMessage.success('下载成功!');
- } catch (error) {
- ElMessage.error('下载失败!');
- } finally {
- gridOptions.loading = false;
- }
- }
- function cellStyle() {
- return {
- fontSize: '13px',
- fontWeight: '500',
- };
- }
- function headerStyle() {
- return {
- fontSize: '13px',
- backgroundColor: '#f0f1f3',
- height: 10,
- //color: '#b4b6ba',
- //fontWeight: '500',
- };
- }
- watch(asinMonthDate, (newVal) => {
- const date = dayjs(newVal).startOf('month').format('YYYY-MM-DD');
- console.log("=>(monthlyRating.vue:180) date", date);
- if (date !== asinMonthDate.value) {
- asinMonthDate.value = date;
- console.log("=>(monthlyRating.vue:183) asinMonthDate.value", asinMonthDate.value);
- fetchData();
- }
- }
- );
- onMounted(() => {
- fetchData();
- });
- </script>
- <style scoped>
- .tool {
- padding-right: 25px;
- }
- .title {
- display: flex;
- align-items: center; /* 垂直居中对齐 */
- /* justify-content: space-between; !* 水平居中对齐 *! */
- font-size: 16px;
- font-weight: 500;
- margin-bottom: 20px;
- }
- </style>
|