Переглянути джерело

✨ feat: 普通展示获取表格数据,数据录入更新

xinyan 1 рік тому
батько
коміт
428a871732

+ 7 - 7
package-lock.json

@@ -22,7 +22,7 @@
 				"axios": "^1.2.1",
 				"countup.js": "^2.3.2",
 				"cropperjs": "^2.0.0-beta.4",
-				"dayjs": "^1.11.10",
+				"dayjs": "^1.11.11",
 				"e-icon-picker": "^2.1.1",
 				"echarts": "^5.4.1",
 				"echarts-gl": "^2.0.9",
@@ -5710,9 +5710,9 @@
 			}
 		},
 		"node_modules/dayjs": {
-			"version": "1.11.10",
-			"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz",
-			"integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ=="
+			"version": "1.11.11",
+			"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.11.tgz",
+			"integrity": "sha512-okzr3f11N6WuqYtZSvm+F776mB41wRZMhKP+hc34YdW+KmtYYK9iqvHSwo2k9FEH3fhGXvOPV6yz2IcSrfRUDg=="
 		},
 		"node_modules/debounce": {
 			"version": "1.2.1",
@@ -14772,9 +14772,9 @@
 			"integrity": "sha512-GODcnWq3YGoTnygPfi02ygEiRxqUxpJwuRHjdhJYuxpcZmDq4rjBiXYmbCCzStxo176ixfLT6i4NPwQooRySnw=="
 		},
 		"dayjs": {
-			"version": "1.11.10",
-			"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz",
-			"integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ=="
+			"version": "1.11.11",
+			"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.11.tgz",
+			"integrity": "sha512-okzr3f11N6WuqYtZSvm+F776mB41wRZMhKP+hc34YdW+KmtYYK9iqvHSwo2k9FEH3fhGXvOPV6yz2IcSrfRUDg=="
 		},
 		"debounce": {
 			"version": "1.2.1",

+ 1 - 1
package.json

@@ -22,7 +22,7 @@
 		"axios": "^1.2.1",
 		"countup.js": "^2.3.2",
 		"cropperjs": "^2.0.0-beta.4",
-		"dayjs": "^1.11.10",
+		"dayjs": "^1.11.11",
 		"e-icon-picker": "^2.1.1",
 		"echarts": "^5.4.1",
 		"echarts-gl": "^2.0.9",

+ 38 - 9
src/views/reportManage/dataCenter/api.ts

@@ -38,6 +38,7 @@ export function getLineMonthData(query: UserPageQuery) {
   });
 }
 
+// 任务列表
 export function postCreateTask(body) {
   return request({
     url: '/api/report_manage/summary-tasks/',
@@ -62,14 +63,6 @@ export function postDeleteTask(body) {
   });
 }
 
-export function getOperationSelect(query) {
-  return request({
-    url: '/api/system/user-select/',
-    method: 'GET',
-    params: query,
-  });
-}
-
 export function postUpdateTask(body) {
   return request({
     url: `/api/report_manage/summary-tasks/${body.id}/`,
@@ -78,6 +71,14 @@ export function postUpdateTask(body) {
   });
 }
 
+export function getOperationSelect(query) {
+  return request({
+    url: '/api/system/user-select/',
+    method: 'GET',
+    params: query,
+  });
+}
+
 // 日数据列表展示
 export function getDayData(query) {
   return request({
@@ -94,6 +95,7 @@ export function getWeekData(query) {
     params: query,
   });
 }
+
 export function getMonthData(query) {
   return request({
     url: `/api/report_manage/data-month/`,
@@ -102,6 +104,7 @@ export function getMonthData(query) {
   });
 }
 
+
 //日数据插入
 export function postCreateDayData(body) {
   return request({
@@ -118,6 +121,7 @@ export function postCreateWeekData(body) {
     data: body,
   });
 }
+
 export function postCreateMonthData(body) {
   return request({
     url: `/api/report_manage/data-month/`,
@@ -149,4 +153,29 @@ export function getMonthTaskData(query) {
     method: 'GET',
     params: query,
   });
-}
+}
+
+//日数据更新
+export function postUpdateDayData(body) {
+  return request({
+    url: `/api/report_manage/data-day/${body.id}/`,
+    method: 'POST',
+    params: body,
+  });
+}
+
+export function postUpdateWeekData(body) {
+  return request({
+    url: `/api/report_manage/data-week/${body.id}/`,
+    method: 'POST',
+    params: body,
+  });
+}
+export function postUpdateMonthData(body) {
+  return request({
+    url: `/api/report_manage/data-month/${body.id}/`,
+    method: 'POST',
+    params: body,
+  });
+}
+

+ 228 - 0
src/views/reportManage/dataCenter/components/TableDataDisplay.vue

@@ -0,0 +1,228 @@
+<script setup lang="ts">
+import {ref, reactive, computed, inject, watch, Ref, onMounted} from 'vue'
+import {useRouter} from "vue-router";
+import { getDayData, getMonthData, getWeekData } from '/@/views/reportManage/dataCenter/api';
+import {VxeGridListeners} from "vxe-table";
+
+const router = useRouter()
+
+const dateType = inject<Ref>('dateDimension')
+
+//表格
+const dayColumns = [
+  {field: 'platformNumber', title: '平台编号', slots: {default: 'platformNumber_default'}},
+  {field: 'platformName', title: '平台名称', slots: {default: 'platformName_default'}},
+  {field: 'user_name', title: '运营', slots: {default: 'user_name_default'}},
+  {field: 'country', title: '国家' , slots: {default: 'country_default'}},
+  {field: 'brandName', title: '品牌' ,slots: {default: 'brandName_default'}},
+
+  {field: 'sales', title: '销售额'},
+  {field: 'sales_year_on_year', title: '期末同比变化'},
+  {field: 'sales_monthly_year_on_year', title: '期末环比变化'},
+  {field: 'ad_cost', title: '广告花费'},
+  {field: 'ad_sales', title: '广告销售额'},
+  {field: 'roi', title: '广告ROI'},
+  {field: 'acos', title: '广告ACOS'},
+  {field: 'roas', title: '广告ROAS'},
+]
+const weekColumns = [
+  {field: 'platformNumber', title: '平台编号', slots: {default: 'platformNumber_default'}},
+  {field: 'platformName', title: '平台名称', slots: {default: 'platformName_default'}},
+  {field: 'user_name', title: '运营', slots: {default: 'user_name_default'}},
+  {field: 'country', title: '国家' , slots: {default: 'country_default'}},
+  {field: 'brandName', title: '品牌' ,slots: {default: 'brandName_default'}},
+
+  {field: 'sales', title: '销售额'},
+  {field: 'ad_cost', title: '广告花费'},
+  {field: 'ad_sales', title: '广告销售额'},
+  {field: 'roi', title: '广告ROI'},
+  {field: 'acos', title: '广告ACOS'},
+  {field: 'roas', title: '广告ROAS'},
+  {field: 'impression', title: '广告曝光',},
+  {field: 'ad_click', title: '广告点击',},
+  {field: 'ad_order', title: '广告订单',},
+  {field: 'ad_conversion_rate', title: '广告转化率',},
+  {field: 'money_by_amazon', title: 'Amazon回款金额',},
+  {field: 'money_by_other', title: 'Ebay及其他平台可用余额',},
+  {field: 'currencyCode', title: '回款/余额币种',},
+  {field: 'total_sales_current_monthly', title: '销售额完成情况',},
+  {field: 'sales_year_on_year', title: '环比上周增长率',},
+  {field: 'sales_monthly_year_on_year', title: '环比上月周增长率',},
+  {field: 'sales_weekly_year_on_year', title: '环比上年周增长率',},
+  {field: 'session', title: '流量',},
+  {field: 'ad_order', title: '订单',},
+  {field: 'order', title: '转化',},
+  {field: "availableSalesDay", title: "当前存货可售天",},
+  {field: "intransitInventory", title: "当前在途库存",},
+  {field: "overseasStorage", title: "当前海外仓库存",},
+  {field: "refundRate", title: "最近90天平台退货率",},
+]
+const monthColumns = [
+  {field: 'platformNumber', title: '平台编号', slots: {default: 'platformNumber_default'}},
+  {field: 'platformName', title: '平台名称', slots: {default: 'platformName_default'}},
+  {field: 'user_name', title: '运营', slots: {default: 'user_name_default'}},
+  {field: 'country', title: '国家' , slots: {default: 'country_default'}},
+  {field: 'brandName', title: '品牌' ,slots: {default: 'brandName_default'}},
+
+  {field: 'sales', title: '销售额'},
+  {field: 'ad_cost', title: '广告花费'},
+  {field: 'ad_sales', title: '广告销售额'},
+  {field: 'roi', title: '广告ROI'},
+  {field: 'acos', title: '广告ACOS'},
+  {field: 'roas', title: '广告ROAS'},
+  {field: 'impression', title: '广告曝光',},
+  {field: 'ad_click', title: '广告点击',},
+  {field: 'ad_order', title: '广告订单',},
+  {field: 'ad_conversion_rate', title: '广告转化率',},
+  {field: 'total_sales_current_monthly', title: '销售额完成情况',},
+]
+
+const dayData = []
+const weekData = []
+const monthData = []
+
+const gridOptions = reactive({
+  border: false,
+  height: 600,
+  align: null,
+  round: true,
+  columnConfig: {
+    resizable: true,
+  },
+  pagerConfig: {
+    enabled: true,
+    total: 20,
+    currentPage: 1,
+    pageSize: 10,
+    pageSizes: [10, 20, 30],
+  },
+  toolbarConfig: {
+    slots: {
+      buttons: 'toolbar_buttons',
+    },
+  },
+  day: {
+    columns: dayColumns,
+    data: dayData
+  },
+  week: {
+    columns: weekColumns,
+    data: weekData
+  },
+  month: {
+    columns: monthColumns,
+    data: monthData
+  }
+})
+
+const currentGridOptions = computed(() => {
+  const selectedGridOptions = gridOptions[dateType.value];
+  return {
+    ...gridOptions,
+    ...selectedGridOptions
+  };
+})
+// 分页
+const gridEvents = {
+  pageChange({currentPage, pageSize}) {
+    if (gridOptions.pagerConfig) {
+      gridOptions.pagerConfig.currentPage = currentPage
+      gridOptions.pagerConfig.pageSize = pageSize
+      if (dateType.value === 'day') {
+        fetchDayData();
+      } else if (dateType.value === 'week') {
+        fetchWeekData();
+      } else if (dateType.value === 'month') {
+        fetchMonthData();
+      }
+    }
+  }
+}
+
+async function fetchData(apiFunction) {
+  const resp = await apiFunction({
+    page: gridOptions.pagerConfig.currentPage,
+    limit: gridOptions.pagerConfig.pageSize
+  });
+  gridOptions[dateType.value].data = resp.data;
+  gridOptions.pagerConfig.total = resp.total;
+}
+
+async function fetchDayData() {
+  await fetchData(getDayData);
+}
+
+async function fetchWeekData() {
+  await fetchData(getWeekData);
+}
+
+async function fetchMonthData() {
+  await fetchData(getMonthData);
+}
+
+function fetchCurrentData() {
+  if (dateType.value === 'day') {
+    fetchDayData();
+  } else if (dateType.value === 'week') {
+    fetchWeekData();
+  } else if (dateType.value === 'month') {
+    fetchMonthData();
+  }
+}
+
+const handleImport = () => {
+  router.push({
+    name: 'TableDataEntry',
+    query: {
+      dateType: dateType.value,
+    }
+  })
+}
+
+// const QueryTask = (row: any) => {
+//   router.push({
+//     name: 'TaskManage',
+//   })
+// }
+
+onMounted(() => {
+  fetchCurrentData();
+
+  // 监听 dateType 的变化
+  watch(dateType, () => {
+    fetchCurrentData();
+  });
+});
+</script>
+
+<template>
+  <div>
+    <vxe-grid v-bind="currentGridOptions" v-on="gridEvents">
+      <template #toolbar_buttons>
+        <vxe-button @click="handleImport">数据录入</vxe-button>
+        <!--<vxe-button @click="QueryTask">任务列表</vxe-button>-->
+      </template>
+      <template #platformNumber_default ="{ row }">
+        <div>{{ row.task_info.platformNumber }}</div>
+      </template>
+      <template #platformName_default ="{ row }">
+        <div>{{ row.task_info.platformName }}</div>
+      </template>
+      <template #user_name_default ="{ row }">
+        <div>{{ row.task_info.user_name}}</div>
+      </template>
+      <template #country_default ="{ row }">
+        <div>{{ row.task_info.country }}</div>
+      </template>
+      <template #brandName_default ="{ row }">
+        <div>{{ row.task_info.brandName }}</div>
+      </template>
+    </vxe-grid>
+  </div>
+</template>
+
+<style scoped>
+.vxe-grid {
+  border-radius: 10px;
+}
+</style>

+ 50 - 25
src/views/reportManage/dataCenter/components/TableDataEntry.vue

@@ -8,7 +8,7 @@ import {
   getDayTaskData,
   postCreateDayData,
   postCreateWeekData,
-  postCreateMonthData, getMonthTaskData ,getWeekTaskData
+  postCreateMonthData, getMonthTaskData, getWeekTaskData, postUpdateDayData
 } from '/@/views/reportManage/dataCenter/api';
 
 dayjs.extend(isoWeek);
@@ -25,7 +25,6 @@ const weeklyEntryTime = ref<string | null>(null);
 const weeklySalesTime = ref<string | null>(null);
 const weeklyAdTime = ref<string | null>(null);
 
-
 const entryStartDate = ref<string>('');
 const entryEndDate = ref<string>('');
 const salesStartDate = ref<string>('');
@@ -71,8 +70,7 @@ function handleDayChange(event) {
   }
 }
 
-const handleWeekChange
-    = () => {
+const handleWeekChange = () => {
   if (weeklyEntryTime.value) {
     entryStartDate.value = dayjs(weeklyEntryTime.value).startOf('isoWeek').format('YYYY-MM-DD');
     entryEndDate.value = dayjs(weeklyEntryTime.value).endOf('isoWeek').format('YYYY-MM-DD');
@@ -226,20 +224,23 @@ const gridOptions = reactive({
   }
 });
 
+function fetchCurrentTaskData() {
+  if (dateType === 'day') {
+    fetchDayTaskData();
+  } else if (dateType === 'week') {
+    fetchWeekTaskData();
+  } else if (dateType === 'month') {
+    fetchMonthTaskData();
+  }
+}
+
 const gridEvents = {
   pageChange({currentPage, pageSize}) {
-    console.log(currentPage, pageSize);
     if (gridOptions.pagerConfig) {
       gridOptions.pagerConfig.currentPage = currentPage;
       gridOptions.pagerConfig.pageSize = pageSize;
     }
-    if (dateType === 'day') {
-      fetchDayTaskData();
-    } else if (dateType === 'week') {
-      fetchWeekTaskData();
-    } else if (dateType === 'month') {
-      fetchMonthTaskData();
-    }
+    fetchCurrentTaskData();
   }
 };
 
@@ -251,6 +252,7 @@ async function fetchTaskData(apiFunction) {
       limit: gridOptions.pagerConfig.pageSize,
     });
     gridOptions[dateType].data = resp.data;
+    console.log('resp', resp.data);
     gridOptions.pagerConfig.total = resp.total;
   } catch (error) {
     console.error('Error fetching task data:', error);
@@ -379,10 +381,45 @@ const saveRowEvent = async (row: RowVO) => {
   }
 };
 
+// 更新日数据
+async function updateDayData(row: RowVO) {
+  const $grid = xGrid.value;
+  if ($grid) {
+    const body = {
+    id: row.id,
+    sales: row.sales,
+    ad_sales: row.ad_sales,
+    ad_cost: row.ad_cost,
+    enter_datetime: dailyEntryTime.value,
+    data_datetime: dailyTime.value,
+    task: row.task,
+  };
+    console.log(body);
+  try {
+    const resp = await postUpdateDayData(body);
+    if (resp.code === 2000) {
+      await fetchDayTaskData();
+      await VXETable.modal.message({
+        content: '更新成功',
+        status: 'success',
+      });
+    }
+  } catch (error) {
+    console.log('error:', error);
+  }
+  }
+}
+//更新周数据
+async function updateWeekData(row: RowVO) {
+}
+//更新月数据
+async function updateMonthData(row: RowVO) {
+}
 const editRowEvent = async (row: any) => {
   const $grid = xGrid.value;
   if ($grid) {
     await $grid.clearEdit();
+    await updateDayData(row)
     gridOptions.loading = true;
     // 模拟异步保存
     setTimeout(() => {
@@ -391,12 +428,6 @@ const editRowEvent = async (row: any) => {
   }
 };
 
-const SubmitData = (row: any) => {
-  router.push({
-    name: 'DataCenter',
-  });
-};
-
 const currentGridOptions = computed(() => {
   const selectedGridOptions = gridOptions[dateType] || gridOptions['day'];
   return {
@@ -406,13 +437,7 @@ const currentGridOptions = computed(() => {
 });
 
 onMounted(() => {
-  if (dateType === 'day') {
-    fetchDayTaskData();
-  } else if (dateType === 'week') {
-    fetchWeekTaskData();
-  } else if (dateType === 'month') {
-    fetchMonthTaskData();
-  }
+  fetchCurrentTaskData();
 });
 </script>
 

+ 1 - 0
src/views/reportManage/dataCenter/components/TaskManage.vue

@@ -236,6 +236,7 @@ async function updateRow(row: RowVO) {
       user: [transUser.value],
       currencyCode: row.currencyCode,
     };
+    console.log(updatedRowData);
     try {
       const response = await postUpdateTask(updatedRowData);
       if (response.code === 2000) {