Browse Source

🐛 feat<数据中心>: 合并展示主数据列名显示修复;任务列表币种验证

xinyan 11 months ago
parent
commit
f21844b624

+ 24 - 7
src/views/reportManage/TaskManage/index.vue

@@ -70,7 +70,6 @@ const xGrid = ref<VxeGridInstance<RowVO>>();
 const originalDataMap = new Map();
 let allTasks = []; // 用于存储所有任务数据
 
-
 const gridOptions = reactive<VxeGridProps<RowVO>>({
   border: 'inner',
   keepSource: true,
@@ -181,7 +180,6 @@ async function getTaskList(filters = {}) {
   }
 }
 
-
 function filteredDataChange(newList) {
   if (selectorRef.value) {
     // 重置页码到第一页
@@ -286,6 +284,14 @@ const validateRow = (row) => {
       return;
     }
   }
+  if (!currencyList.value.includes(row.currencyCode)) {
+    ElMessage.error('回款币种格式不正确,请重新选择');
+    return;
+  }
+  if (!currencyList.value.includes(row.currencyCodePlatform)) {
+    ElMessage.error('回款/余额币种格式不正确,请重新选择');
+    return;
+  }
   return true;
 };
 
@@ -305,7 +311,6 @@ async function updateRow(row) {
     //console.log('updatedRowData', updatedRowData);
     try {
       const response = await postUpdateTask(updatedRowData);
-      console.log(response);
       if (response.code === 2000) {
         ElMessage.success('更新成功');
       } else if (response.code == 400) {
@@ -358,21 +363,34 @@ async function createTask() {
   }
 }
 
-const submitForm = async (formEl: FormInstance | undefined) => {
+const submitForm = async (formEl) => {
   if (!formEl) return;
   await formEl.validate(async (valid, fields) => {
     if (valid) {
       const isDuplicate = allTasks.some(task => String(task.platformNumber) === String(taskRuleForm.number));
       if (isDuplicate) {
-        await ElMessage({message: '平台编号已存在,请重新输入', type: 'warning',});
+        await ElMessage({message: '平台编号已存在,请重新输入', type: 'warning'});
+        return;
+      }
+
+      if (!currencyList.value.includes(taskRuleForm.currency)) {
+        await ElMessage({message: '回款币种无效,请重新选择', type: 'warning'});
+        return;
+      }
+
+      if (!currencyList.value.includes(taskRuleForm.currencyCodePlatform)) {
+        await ElMessage({message: '回款/余额币种无效,请重新选择', type: 'warning'});
         return;
       }
+
       await createTask();
       taskRuleFormRef.value.resetFields();
     }
   });
 };
 
+
+
 function handleClose(done: Function) {
   if (taskRuleFormRef.value) taskRuleFormRef.value.resetFields();
   done();
@@ -415,8 +433,7 @@ const handleCurrencyCodePlatformSelect = item => {
 
 function handleRowSelect (item, row){
   row.currencyCode = item;
-};
-
+}
 
 function handelRowCurrencyCodePlatformSelect(item, row) {
   row.currencyCodePlatform = item;

+ 54 - 47
src/views/reportManage/dataCenter/combinedDisplay/components/tableData/mainData.vue

@@ -50,8 +50,8 @@ const gridOptions = reactive({
       tools: 'toolbar_buttons',
     },
   },
-  columns: tableColumns.value,
-  data: []
+  columns: tableColumns,
+  data: tableData,
 });
 
 // 分页
@@ -85,9 +85,57 @@ async function fetchMainData(taskIds, resetPage = false) {
     });
     gridOptions.data = response.data;
     gridOptions.pagerConfig.total = response.total;
-    return response.data;
+
+    if (response.data && response.data.length > 0) {
+      const dynamicColumns = [];
+      const regex1 = /\d{2}-\d{2}/;
+      const regex2 = /\d{4}-\d{2}-\d{2}/;
+      const regex3 = /\d{4}-\d{2}/
+      const middleKeywords = ['~', '截止', '近90天平台退货率', '余额'];
+
+      const allColumns = new Set();
+      response.data.forEach(row => {
+        for (const key in row) {
+          if (regex1.test(key) || middleKeywords.some(kw => key.includes(kw))) {
+            allColumns.add(key);
+          }
+        }
+      });
+
+      const firstColumns = [];
+      const middleColumns = [];
+      const lastColumns = [];
+
+      allColumns.forEach(key => {
+        const column = {
+          field: key,
+          title: key, // 使用字段名作为列标题
+          minWidth: key.includes('~') ? 90 : key.includes('截止')? 90 :regex2.test(key) ? 81 : 70,
+          align: 'center',
+          formatter: formatEmptyCell,
+        };
+        if (middleKeywords.some(kw => key.includes(kw))) {
+          middleColumns.push(column);
+        }
+        else if (regex3.test(key) &&!regex2.test(key)) {
+          lastColumns.push(column);
+        }
+        else if (regex1.test(key)) {
+          firstColumns.push(column);
+        }
+      });
+
+      dynamicColumns.push(...firstColumns, ...middleColumns, ...lastColumns);
+
+      tableColumns.value = [
+        ...universal,
+        ...dynamicColumns,
+      ];
+    }
   } catch (error) {
     console.error('Error fetching task data:', error);
+    // 这里可以添加一个用户友好的错误提示,例如:
+    // showAlert('获取数据失败,请稍后重试。');
   } finally {
     gridOptions.loading = false;
   }
@@ -95,7 +143,7 @@ async function fetchMainData(taskIds, resetPage = false) {
 
 // 监测 taskIds 变化
 watch(() => props.taskIds, (newTaskIds) => {
-  loadData();
+  fetchMainData(newTaskIds, true)
 });
 
 // 监测 dayDate 变化
@@ -105,9 +153,9 @@ watch(() => props.dayDate, (newDayDate) => {
     const {dailyStartDate, dailyTime} = newDayDate;
     dayStartDate.value = dailyStartDate;
     dayEndDate.value = dailyTime;
-    // loadData();
   }
 });
+
 // 监测 weekDate 变化
 watch(() => props.weekDate, (newWeekDate) => {
   if (newWeekDate) {
@@ -115,7 +163,7 @@ watch(() => props.weekDate, (newWeekDate) => {
     const {weekStartDate, weekEndDate} = newWeekDate;
     weekStart.value = weekStartDate;
     weekEnd.value = weekEndDate;
-    loadData();
+    fetchMainData(props.taskIds)
   }
 });
 // 监测 monthDate 变化
@@ -125,41 +173,9 @@ watch(() => props.monthDate, (newMonthDate) => {
     const {startDate, endDate} = newMonthDate;
     monthStartDate.value = startDate;
     monthEndDate.value = endDate;
-    // loadData();
   }
 });
 
-const fetchColumnNames = (data) => {
-  if (data && data.length > 0) {
-    const dynamicColumns = [];
-    const allColumns = new Set();
-    // 遍历所有数据行以获取所有列名
-    data.forEach(row => {
-      Object.keys(row).forEach(key => {
-        if (/\d{2}-\d{2}的/.test(key) || key.includes('余额币种') || key.includes('退货率')) {
-          allColumns.add(key);
-        }
-      });
-    });
-    allColumns.forEach(key => {
-      dynamicColumns.push({
-        field: key,
-        title: key, // 使用字段名作为列标题
-        minWidth: key.includes('~') ? 90 : /\d{4}-\d{2}-\d{2}/.test(key) ? 81 : 70,
-        align: 'center',
-        formatter: formatEmptyCell,
-      })
-    });
-    tableColumns.value = [
-      ...universal,
-      ...dynamicColumns
-    ];
-  }else {
-    tableData.value = [];
-    gridOptions.pagerConfig.total = 0;
-  }
-};
-
 const cellStyle = () => {
   return {
     fontSize: '12px',
@@ -184,15 +200,6 @@ const cellStyleHandler = ({column}) => {
   return {fontSize: '12px'};
 };
 
-// 加载数据
-async function loadData() {
-  const data = await fetchMainData(props.taskIds,true);
-  fetchColumnNames(data);
-  tableData.value = data;
-  gridOptions.columns = tableColumns.value;
-  gridOptions.data = tableData.value;
-}
-
 async function handleExport() {
   try {
     gridOptions.loading = true;