Browse Source

研发工时优化

ljb 10 months ago
parent
commit
b3e2295fa3

+ 23 - 3
src/views/yf-cost-manage/basic-data-setting/working-hours-records.vue

@@ -92,6 +92,8 @@ export default window.$crudCommon({
       },
       defaultColumns: [],
 
+      oldMonthData: [],
+
       wideTableColumns: [],
       printTitle: "",
     };
@@ -111,6 +113,10 @@ export default window.$crudCommon({
     this.option.column = deepClone(this.defaultColumns);
   },
   methods: {
+    handleBeforeOpen(done, type) {
+      this.oldMonthData = this.form.dailyAttendances || [];
+      done();
+    },
     refreshTableCol(yearAndMonth) {
       let yearMonth = moment(yearAndMonth).format("YYYY-MM").split("-");
       const monthDays = getMonthDatesWithMarkers(Number(yearMonth[0]), Number(yearMonth[1]));
@@ -172,18 +178,32 @@ export default window.$crudCommon({
     getFormData() {
       const newFormData = { ...this.form, yearAndMonth: this.params.yearAndMonth  };
       let dailyAttendances = [];
+      let _oldMonthData = this.oldMonthData;
       Object.keys(this.form).forEach(key => {
         if (key.indexOf(this.params.yearAndMonth) > -1) {
-          if (this.form[key]) {
+          let oldObj = _oldMonthData.find(old => old.workDate == key) || {};
+          if (this.form[key] || oldObj.workHours) {
             dailyAttendances.push({
               workDate: key,
-              workHours: this.form[key]
+              workHours: this.form[key] || ''
             });
           }
           delete newFormData[key];
         }
       });
-      newFormData.dailyAttendances = dailyAttendances;
+
+      // 获取最新修改过的数据
+      let updatedMonthData = [];
+      dailyAttendances.forEach(item => {
+        let oldObj = _oldMonthData.find(old => item.workDate === old.workDate);
+        if (!!oldObj && Number(item.workHours) !== Number(oldObj.workHours)) {
+          updatedMonthData.push(item);
+        } else if (!oldObj) {
+          updatedMonthData.push(item);
+        }
+      })
+
+      newFormData.dailyAttendances = updatedMonthData;
       return newFormData;
     },
     getDelParams(row) {