Browse Source

fix:选择管号增加区间选择

luoxiao 2 months ago
parent
commit
611e11b807
1 changed files with 71 additions and 20 deletions
  1. 71 20
      src/views/quality/replace/index.vue

+ 71 - 20
src/views/quality/replace/index.vue

@@ -137,18 +137,37 @@
               <el-checkbox v-model="checkAll" @change="handleCheckAll">
                 全选
               </el-checkbox>
+              <span
+                style="
+                  margin: auto 10px auto 10px;
+                  vertical-align: 2px;
+                  font-weight: 200;
+                "
+              >
+                管号总数: {{ options.length }}
+              </span>
               <el-input
-                v-model="toSelectCount"
-                placeholder="请输入选中前面数量"
+                v-model="toSelectStartCount"
+                placeholder="请输入开始区间"
+                class="selectInput"
+                size="small"
+              />
+              <span style="margin: 0 0 0 10px">-</span>
+              <el-input
+                v-model="toSelectEndCount"
+                placeholder="请输入结束区间"
                 class="selectInput"
                 size="small"
               >
-                <template #append>
-                  <el-button type="primary" @click="startToSelectAheads"
-                    >选择</el-button
-                  >
-                </template>
               </el-input>
+              <el-button
+                type="primary"
+                @click="startToSelectAheads"
+                size="small"
+                class="confirmBtn"
+              >
+                确定
+              </el-button>
             </template>
             <el-option
               v-for="item in options"
@@ -219,7 +238,8 @@ const ExDataObj = ref({});
 const workOderShow = ref(false);
 const showProList = ref([]);
 const showSeqList = ref([]);
-const toSelectCount = ref(null);
+const toSelectStartCount = ref(null);
+const toSelectEndCount = ref(null);
 const showSeq = (seqs) => {
   showSeqList.value = seqs;
   dialog2.visible = true;
@@ -261,7 +281,8 @@ const submit = async () => {
       ElMessage.warning("请检查表单选项");
     }
   });
-  toSelectCount.value = null;
+  toSelectStartCount.value = null;
+  toSelectEndCount.value = null;
 };
 const closeShow = () => {
   workOderShow.value = false;
@@ -271,6 +292,8 @@ const resetForm = () => {
   form.value.seqNoList = [];
   form.value.workOrderCode = "";
   form.value.operationId = "";
+  options.value = [];
+  operations.value = [];
 };
 const toAdd = async () => {
   const { code } = await addReplace({ ...form.value });
@@ -351,7 +374,6 @@ const setOperationList = async () => {
   });
 };
 
-const seqListlength = ref(null);
 const setSeqList = async () => {
   form.value.seqNoList = [];
   const { data } = await getSeqList(
@@ -390,25 +412,50 @@ const edit = async (row) => {
 const cancel = () => {
   resetForm();
   dialog.visible = false;
-  toSelectCount.value = null;
+  toSelectStartCount.value = null;
+  toSelectEndCount.value = null;
 };
 
 const startToSelectAheads = () => {
   if (options.value.length === 0) {
     ElMessage.error("请先选择工单和工序");
-    toSelectCount.value = null;
+    toSelectStartCount.value = null;
+    toSelectEndCount.value = null;
+    return;
+  }
+  const start = Number(toSelectStartCount.value);
+  const end = Number(toSelectEndCount.value);
+  const seqNoList = options.value.map((item) => item.value);
+  const seqListlength = seqNoList.length;
+  if (Number.isInteger(start) && start > 0 && end === 0) {
+    form.value.seqNoList = seqNoList.slice(start - 1, seqListlength);
+    isAllChecked(form.value.seqNoList.length, seqNoList.length);
+    return;
+  }
+  if (Number.isInteger(end) && end > 0 && start === 0) {
+    form.value.seqNoList = seqNoList.slice(0, end);
+    isAllChecked(form.value.seqNoList.length, seqNoList.length);
     return;
   }
   if (
-    Number.isInteger(Number(toSelectCount.value)) &&
-    Number(toSelectCount.value) > 0
+    Number.isInteger(start) &&
+    Number.isInteger(end) &&
+    start > 0 &&
+    end > 0
   ) {
-    const count = Number(toSelectCount.value);
-    const seqNoList = options.value.map((item) => item.value);
-    form.value.seqNoList = seqNoList.slice(0, count);
+    form.value.seqNoList = seqNoList.slice(start - 1, end);
+    isAllChecked(form.value.seqNoList.length, seqNoList.length);
+    return;
+  }
+  resetInput();
+  ElMessage.error("请输入正确的数字");
+};
+
+const isAllChecked = (choseLength, seqLength) => {
+  if (choseLength === seqLength) {
+    checkAll.value = true;
   } else {
-    toSelectCount.value = null;
-    ElMessage.error("请输入正确的数字");
+    checkAll.value = false;
   }
 };
 onMounted(() => {
@@ -421,7 +468,11 @@ onMounted(() => {
   margin-bottom: 10px;
 }
 .selectInput {
-  width: 30%;
+  width: 20%;
+  margin: 0 0 8px 10px;
+}
+.confirmBtn {
   margin: 0 0 8px 10px;
+  height: 22px;
 }
 </style>