Browse Source

fix: 时间段序号bug

zhangjie 1 year ago
parent
commit
fe4821e3e1
1 changed files with 33 additions and 8 deletions
  1. 33 8
      src/views/order/task-manage/timeForm.vue

+ 33 - 8
src/views/order/task-manage/timeForm.vue

@@ -15,11 +15,11 @@
         :data="formData.times"
         :bordered="false"
       >
-        <template #item="{ item, index }">
+        <template #item="{ item }">
           <a-form-item
-            :field="`times[${index}].startTime`"
+            :field="`times[${item.no - 1}].startTime`"
             :rules="rules"
-            :label="index + 1 + ''"
+            :label="item.no + ''"
           >
             <select-range-datetime
               v-model:startTime="item.startTime"
@@ -27,7 +27,11 @@
               popup-container=".modify-task"
             >
             </select-range-datetime>
-            <a-button class="ml-10" status="danger" @click="toDelete(index)">
+            <a-button
+              class="ml-10"
+              status="danger"
+              @click="toDelete(item.no - 1)"
+            >
               <template #icon>
                 <svg-icon name="icon-delete"></svg-icon>
               </template>
@@ -55,7 +59,6 @@
   import { updateTaskTime, deleteTaskTime } from '@/api/order';
   import useLoading from '@/hooks/loading';
   import type { FormInstance, FieldRule } from '@arco-design/web-vue/es/form';
-  import { deepCopy } from '@/utils/utils';
   import { TaskItemDetail } from '@/api/types/order';
   import { modalConfirm } from '@/utils/arco';
 
@@ -71,7 +74,12 @@
 
   interface FormDataType {
     id: number;
-    times: TaskItemDetail['timeList'];
+    times: Array<{
+      id: number | null;
+      startTime: number | undefined;
+      endTime: number | undefined;
+      no: number;
+    }>;
   }
 
   const defaultFormData = {
@@ -99,7 +107,12 @@
   }
 
   function timeSelected(times: TaskItemDetail['timeList']) {
-    formData.times.push(...times);
+    formData.times.push(
+      ...times.map((item) => {
+        return { ...item, no: 0 };
+      })
+    );
+    updateTimeIndex();
   }
 
   async function toDelete(index: number) {
@@ -113,9 +126,16 @@
       await deleteTaskTime(formData.times[index].id as number);
     }
     formData.times.splice(index, 1);
+    updateTimeIndex();
     await formRef.value?.validate();
   }
 
+  function updateTimeIndex() {
+    formData.times.forEach((item, index) => {
+      item.no = index + 1;
+    });
+  }
+
   /* confirm */
   const { loading, setLoading } = useLoading();
   async function confirm() {
@@ -138,7 +158,12 @@
   }
   /* init */
   function initData() {
-    formData.times = deepCopy(props.rowData.timeList);
+    formData.times = props.rowData.timeList.map((item, index) => {
+      return {
+        no: index + 1,
+        ...item,
+      };
+    });
     formData.id = props.rowData.id;
   }
   onMounted(() => {