浏览代码

提交排序输入框失焦自动排序

hezhanp 8 月之前
父节点
当前提交
23ba20b3bb
共有 1 个文件被更改,包括 15 次插入1 次删除
  1. 15 1
      src/views/inspectionTemplate/AddorUpdate.vue

+ 15 - 1
src/views/inspectionTemplate/AddorUpdate.vue

@@ -172,7 +172,12 @@
             <div> <el-input v-model="row.inspectionName"></el-input></div>
           </template>
           <template v-slot:sort="{ row }">
-            <el-input v-model="row.sort" type="number"></el-input>
+            <el-input
+              v-model="row.sort"
+              type="number"
+              @blur="handleSortBlur"
+              placeholder="输入排序"
+            ></el-input>
           </template>
           <template v-slot:defaultValue="{ row }">
             <div style="width: 100%; display: flex">
@@ -455,6 +460,15 @@ export default {
     };
   },
   methods: {
+      //失去焦点自动排序
+      handleSortBlur() {
+      this.list = this.list.map(item => ({
+        ...item,
+        sort: item.sort === '' || item.sort == null ? 0 : Number(item.sort)
+      }));
+
+      this.list.sort((a, b) => a.sort - b.sort);
+    },
     async getTnspectionPlanType() {
       let res = await getByCode('inspection_plan_type');
       if (res?.code == 0) {