Browse Source

✨ feat<任务管理>: 添加计划销售额管理
--创建、修改计划销售额
--筛选功能

xinyan 7 months ago
parent
commit
8f2a0541a3

+ 13 - 13
src/views/reportManage/TaskManage/utils/columns.ts

@@ -296,24 +296,24 @@ export const planColumns = ref([
   { field: 'platformNumber', title: '平台编号', fixed: 'left', width: 81, align: 'center' },
   { field: 'platformName', title: '平台名称', fixed: 'left', width: 142, align: 'center' },
   { field: 'country', title: '国家', fixed: 'left', width: 80, align: 'center' },
-  { field: 'brandName', title: '品牌', fixed: 'left', width: 60 },
+  { field: 'brandName', title: '品牌', fixed: 'left', width: 90 ,align: 'center'},
   { field: 'operater', title: '运营', fixed: 'left', width: 80, align: 'center' },
   // { field: 'status', title: '状态', width: 80, formatter: ({ cellValue }) => cellValue === 1 ? '启用' : '禁用' },
   // { field: 'line', title: '线', width: 80 },
   // { field: 'ipaddress', title: 'IP 地址', width: 150 },
   // { field: 'company', title: '公司', width: 200 },
   // { field: 'platform', title: '平台', width: 100 },
-  { field: '1月.planSales', title: '1月计划销售额', width: 120,editRender: {}, slots: { edit: 'january' }, align: 'center' },
-  { field: '2月.planSales', title: '2月计划销售额', width: 120, editRender: {}, slots: { edit: 'february' }, align: 'center' },
-  { field: '3月.planSales', title: '3月计划销售额', width: 120, editRender: {}, slots: { edit: 'march' }, align: 'center' },
-  { field: '4月.planSales', title: '4月计划销售额', width: 120, editRender: {}, slots: { edit: 'april' }, align: 'center' },
-  { field: '5月.planSales', title: '5月计划销售额', width: 120, editRender: {}, slots: { edit: 'may' }, align: 'center' },
-  { field: '6月.planSales', title: '6月计划销售额', width: 120, editRender: {}, slots: { edit: 'june' }, align: 'center' },
-  { field: '7月.planSales', title: '7月计划销售额', width: 120, editRender: {}, slots: { edit: 'july' }, align: 'center' },
-  { field: '8月.planSales', title: '8月计划销售额', width: 120, editRender: {}, slots: { edit: 'august' }, align: 'center' },
-  { field: '9月.planSales', title: '9月计划销售额', width: 120, editRender: {}, slots: { edit: 'september' }, align: 'center' },
-  { field: '10月.planSales', title: '10月计划销售额', width: 120, editRender: {}, slots: { edit: 'october' }, align: 'center' },
-  { field: '11月.planSales', title: '11月计划销售额', width: 120, editRender: {}, slots: { edit: 'november' }, align: 'center' },
-  { field: '12月.planSales', title: '12月计划销售额', width: 120, editRender: {}, slots: { edit: 'december' }, align: 'center' },
+  { field: '1月', title: '1月计划销售额', width: 120,editRender: {}, slots: { edit: 'january' }, align: 'center' ,formatter: ({ cellValue }) => cellValue?.planSales || '--' },
+  { field: '2月', title: '2月计划销售额', width: 120, editRender: {}, slots: { edit: 'february' }, align: 'center' ,formatter: ({ cellValue }) => cellValue?.planSales || '--'},
+  { field: '3月', title: '3月计划销售额', width: 120, editRender: {}, slots: { edit: 'march' }, align: 'center' ,formatter: ({ cellValue }) => cellValue?.planSales || '--'},
+  { field: '4月', title: '4月计划销售额', width: 120, editRender: {}, slots: { edit: 'april' }, align: 'center' ,formatter: ({ cellValue }) => cellValue?.planSales || '--'},
+  { field: '5月', title: '5月计划销售额', width: 120, editRender: {}, slots: { edit: 'may' }, align: 'center' ,formatter: ({ cellValue }) => cellValue?.planSales || '--'},
+  { field: '6月', title: '6月计划销售额', width: 120, editRender: {}, slots: { edit: 'june' }, align: 'center' ,formatter: ({ cellValue }) => cellValue?.planSales || '--'},
+  { field: '7月', title: '7月计划销售额', width: 120, editRender: {}, slots: { edit: 'july' }, align: 'center' ,formatter: ({ cellValue }) => cellValue?.planSales || '--'},
+  { field: '8月', title: '8月计划销售额', width: 120, editRender: {}, slots: { edit: 'august' }, align: 'center' ,formatter: ({ cellValue }) => cellValue?.planSales || '--'},
+  { field: '9月', title: '9月计划销售额', width: 120, editRender: {}, slots: { edit: 'september' }, align: 'center' ,formatter: ({ cellValue }) => cellValue?.planSales || '--'},
+  { field: '10月', title: '10月计划销售额', width: 120, editRender: {}, slots: { edit: 'october' }, align: 'center' ,formatter: ({ cellValue }) => cellValue?.planSales || '--'},
+  { field: '11月', title: '11月计划销售额', width: 120, editRender: {}, slots: { edit: 'november' }, align: 'center' ,formatter: ({ cellValue }) => cellValue?.planSales || '--'},
+  { field: '12月', title: '12月计划销售额', width: 120, editRender: {}, slots: { edit: 'december' }, align: 'center' ,formatter: ({ cellValue }) => cellValue?.planSales || '--'},
   { title: '操作', width: 120, slots: { default: 'operate' }, align: 'center' , fixed: 'right'},
 ])

+ 53 - 57
src/views/reportManage/dataCenter/normalDisplay/components/PlanningSales.vue

@@ -69,7 +69,6 @@ const formItems = [
   { field: 'november', label: '11月' },
   { field: 'december', label: '12月' }
 ];
-
 // 表格
 const currentRow = ref('');
 const months = [
@@ -77,7 +76,8 @@ const months = [
   '6月', '7月', '8月', '9月', '10月',
   '11月', '12月'
 ];
-const originalDataMap = new Map();
+const originalData = ref([]);
+
 const xGrid = ref<VxeGridInstance>();
 const activeEditRow = ref(null);
 
@@ -93,6 +93,9 @@ const gridOptions = reactive({
     showStatus: true,
     autoClear: false,
   },
+  columnConfig: {
+    resizable: true,
+  },
   pagerConfig: {
     enabled: true,
     total: 20,
@@ -109,9 +112,16 @@ function setDefaultDate() {
 }
 
 const disabledDate = (time: Date) => {
-  return time.getTime() > Date.now();
+  const currentYear = new Date().getFullYear();
+  const selectedYear = time.getFullYear();
+  return selectedYear > currentYear + 1;
 };
 
+async function create(row) {
+  currentRow.value = row;
+  dialogVisible.value = true;
+}
+
 const resetForm = (formEl: FormInstance | undefined) => {
   if (!formEl) return;
   formEl.resetFields();
@@ -145,6 +155,7 @@ async function handleSave() {
   try {
     await postCreatePlanSalesData(body);
     dialogVisible.value = false;
+    await getList();
   } catch (error) {
     console.error('提交数据时出错:', error);
   }
@@ -155,6 +166,7 @@ const submitForm = async (formEl: FormInstance | undefined) => {
   await formEl.validate((valid, fields) => {
     if (valid) {
       handleSave();
+      formEl.resetFields();
       ElMessage.success('创建成功');
     } else {
       ElMessage.error('添加失败,请检查填写数据');
@@ -188,41 +200,51 @@ const clearRowEvent = (row) => {
   activeEditRow.value = false;
   const $grid = xGrid.value;
   if ($grid) {
-    const originalData = originalDataMap.get(row.id);
-    if (originalData) {
-      Object.assign(row, originalData);
-      originalDataMap.delete(row.id);
-    }
     $grid.clearEdit();
   }
 };
 
-const handelEditRow = (row: RowVO) => {
+// 进入编辑模式
+const handelEditRow = (row) => {
   activeEditRow.value = true;
   const $grid = xGrid.value;
   if ($grid) {
-    originalDataMap.set(row.id, { ...row });
+    for (const month in row) {
+      if (row[month] && row[month].id) {
+        originalData.value = JSON.parse(JSON.stringify(row[month]));
+      }
+    }
     $grid.setEditRow(row);
   }
 };
 
-async function create(row) {
-  currentRow.value = row;
-  dialogVisible.value = true;
-}
-
 async function saveRow(row) {
-  try {
-    const body={
-      id: row.id,
-      planSales: row.planSales,
+  const $grid = xGrid.value;
+  if ($grid) {
+    const updatedData = [];
+    for (const month in row) {
+      if (row[month] && row[month].id) {
+        const planSales = parseFloat(row[month].planSales);
+
+        if (!isNaN(planSales)) {
+          updatedData.push({
+            id: row[month].id,
+            planSales: planSales
+          });
+        }
+      }
+    }
+    try {
+      await postUpdatePlanSalesData(updatedData);
+      activeEditRow.value = false;
+      await $grid.clearEdit();
+      await getList();
+      ElMessage.success('更新成功');
+    } catch (error) {
+      ElMessage.error('更新失败,请检查填写数据');
     }
-    // await postUpdatePlanSalesData(body);
-    console.log("=>(PlanningSales.vue:219) body", body);
-  }catch (error){
-    console.error('Error updating plan sales data:', error);
-    ElMessage.error('更新失败,请检查填写数据');
   }
+
 }
 
 async function getList() {
@@ -256,7 +278,6 @@ function updateDataChange(newId) {
 watch(currentYear, (newVal, oldVal) => {
   if (newVal !== oldVal) {
     currentYear.value = dayjs(newVal).format('YYYY');
-    getList();
   }
 });
 
@@ -272,38 +293,10 @@ const headerCellStyle = () => {
     fontSize: '13px',
   };
 };
-function getNestedValue(row, field) {
-  const fields = field.split('.'); // 将字段名按 '.' 分割
-  return fields.reduce((acc, part) => acc && acc[part], row); // 依次访问嵌套属性
-}
 
-function setNestedValue(row, field, value) {
-  const fields = field.split('.');
-  const lastField = fields.pop();
-  const target = fields.reduce((acc, part) => acc && acc[part], row); // 找到最后一个嵌套对象
-  if (target) {
-    target[lastField] = value; // 设置值
-  }
-}
-
-// 函数:解析路径
-function getFieldValue(obj, path) {
-  return path.split('.').reduce((o, key) => (o ? o[key] : ''), obj);
-}
-
-// 函数:设置路径的值
-function setFieldValue(obj, path, value) {
-  const keys = path.split('.');
-  keys.reduce((o, key, index) => {
-    if (index === keys.length - 1) {
-      o[key] = value;
-    }
-    return o[key] || {};
-  }, obj);
-}
 onMounted(() => {
   setDefaultDate();
-  getList();
+  // getList();
 });
 </script>
 
@@ -320,6 +313,7 @@ onMounted(() => {
               placeholder="Pick a year"
               style="width: 150px"
               type="year"
+              @change="getList"
           />
         </div>
       </div>
@@ -334,16 +328,18 @@ onMounted(() => {
           <el-button link size="small" type="warning" @click="saveRow(row)">保存</el-button>
         </template>
         <template v-else>
-          <el-button :disabled="!isMonthIdExist(row)||activeEditRow" link size="small" type="success" @click="handelEditRow(row)">
+          <el-button :disabled="!isMonthIdExist(row)||activeEditRow" link size="small" type="success"
+                     @click="handelEditRow(row)">
             修改
           </el-button>
         </template>
-        <el-button v-if="!hasActiveEditRow(row)" :disabled="isMonthIdExist(row)||activeEditRow" link size="small" type="primary"
+        <el-button v-if="!hasActiveEditRow(row)" :disabled="isMonthIdExist(row)||activeEditRow" link size="small"
+                   type="primary"
                    @click="create(row)">创建
         </el-button>
       </template>
       <template v-for="col in planColumns" #[`${col.slots?.edit}`]="{ row }">
-        <el-input v-model="getFieldValue(row, col.field)" @input="val => setFieldValue(row, col.field, val)" />
+        <el-input v-model="row[col.field].planSales" />
       </template>
     </vxe-grid>
   </el-card>