lxf 1 jaar geleden
bovenliggende
commit
4d80e22d8b
1 gewijzigde bestanden met toevoegingen van 149 en 49 verwijderingen
  1. 149 49
      src/views/production/operation/batching/quick.vue

+ 149 - 49
src/views/production/operation/batching/quick.vue

@@ -1,7 +1,7 @@
 <template>
   <div>
     <el-card class="box-card" v-loading="loading">
-      <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" ref="submit">
+      <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="submit">
         <template #inOutStorageBomList>
           <div style="width: 100%; padding: 0 20px">
             <el-table :data="formData.data.inOutStorageBomList" :row-style="{ height: '35px' }" header-row-class-name="tableHeader">
@@ -29,9 +29,28 @@
               </el-table-column>
               <el-table-column label="品号" prop="bomSpecCode" width="180" />
               <el-table-column label="品名" prop="bomSpecName" min-width="220" />
+              <el-table-column label="仓库" width="160">
+                <template #default="{ row, $index }">
+                  <el-form-item :prop="'inOutStorageBomList.' + $index + '.warehouseId'" :rules="rules.warehouseId" :inline-message="true" style="width: 100%">
+                    <el-select
+                      v-model="row.warehouseId"
+                      placeholder="请选择仓库"
+                      clearable
+                      style="width: 100%"
+                      @change="
+                        (val) => {
+                          return changeWarehouse(val, row, $index);
+                        }
+                      ">
+                      <el-option v-for="item in warehouseList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
+                    </el-select>
+                  </el-form-item>
+                </template>
+              </el-table-column>
+              <el-table-column label="剩余库存" prop="surplusStock" width="120" />
               <el-table-column label="出库数量" width="140">
                 <template #default="{ row }">
-                  <span>{{ row.quantity }}</span>
+                  <span :style="row.surplusStock && row.surplusStock > row.quantity ? '' : 'color: red'">{{ row.quantity }}</span>
                 </template>
               </el-table-column>
             </el-table>
@@ -55,6 +74,7 @@ const departmentList = ref([{ dictKey: "0", dictValue: "胜德体育" }]);
 const props = defineProps({
   selectData: Array,
 });
+const warehouseList = ref([]);
 const submit = ref(null);
 const formOption = reactive({
   inline: true,
@@ -82,6 +102,9 @@ const formConfig = computed(() => {
     },
   ];
 });
+const rules = ref({
+  warehouseId: [{ required: true, message: "请选择仓库", trigger: "change" }],
+});
 const getDemandData = () => {
   proxy.post("/department/page", { pageNum: 1, pageSize: 999 }).then((res) => {
     if (res.rows && res.rows.length > 0) {
@@ -106,6 +129,11 @@ const loading = ref(false);
 const submitForm = () => {
   submit.value.handleSubmit(() => {
     if (formData.data.inOutStorageBomList && formData.data.inOutStorageBomList.length > 0) {
+      for (let i = 0; i < formData.data.inOutStorageBomList.length; i++) {
+        if (Number(formData.data.inOutStorageBomList[i].surplusStock) < Number(formData.data.inOutStorageBomList[i].quantity)) {
+          return ElMessage("出库数量大于剩余库存数量");
+        }
+      }
       loading.value = true;
       let orderList = [];
       for (let j = 0; j < formData.data.inOutStorageBomList.length; j++) {
@@ -145,60 +173,132 @@ const delSomeObjValue = (arr, keyName, valueName) => {
   }
   return resultArr;
 };
+const getWarehouse = () => {
+  return proxy.post("/warehouse/page", { pageNum: 1, pageSize: 999 }).then((res) => {
+    if (res.rows && res.rows.length > 0) {
+      warehouseList.value = res.rows
+        .filter((item) => ["2", "3"].includes(item.type))
+        .map((item) => {
+          return {
+            dictKey: item.id,
+            dictValue: item.name,
+          };
+        });
+    }
+  });
+};
 onMounted(() => {
-  if (props.selectData && props.selectData.length > 0) {
-    formData.data.inOutStorageBomList = delSomeObjValue(
-      props.selectData.map((item) => {
-        let num = 0;
-        if (item.quantity) {
-          num = Number(item.quantity);
-        }
+  Promise.all([getWarehouse()]).then(async () => {
+    if (props.selectData && props.selectData.length > 0) {
+      formData.data.inOutStorageBomList = delSomeObjValue(
+        props.selectData.map((item) => {
+          let num = 0;
+          if (item.quantity) {
+            num = Number(item.quantity);
+          }
+          return {
+            bomSpecId: item.bomSpecId,
+            quantity: num,
+            bomSpecName: item.bomSpecName,
+            bomSpecCode: item.bomSpecCode,
+            warehouseId: "",
+            surplusStock: 0,
+          };
+        }),
+        "bomSpecId",
+        "quantity"
+      ).map((item) => {
         return {
-          bomSpecId: item.bomSpecId,
-          quantity: num,
-          bomSpecName: item.bomSpecName,
-          bomSpecCode: item.bomSpecCode,
-          warehouseId: "",
-          surplusStock: 0,
+          ...item,
+          orderList: props.selectData
+            .map((item) => {
+              let num = 0;
+              if (item.quantity) {
+                num = Number(item.quantity);
+              }
+              return {
+                bomSpecId: item.bomSpecId,
+                quantity: num,
+                orderSkuId: item.orderSkuId,
+                orderCode: item.orderCode,
+                orderWlnCode: item.orderWlnCode,
+                skuSpecCode: item.skuSpecCode,
+                skuSpecName: item.skuSpecName,
+              };
+            })
+            .filter((itemSelect) => itemSelect.bomSpecId === item.bomSpecId),
         };
-      }),
-      "bomSpecId",
-      "quantity"
-    ).map((item) => {
-      return {
-        ...item,
-        orderList: props.selectData
-          .map((item) => {
-            let num = 0;
-            if (item.quantity) {
-              num = Number(item.quantity);
-            }
-            return {
-              bomSpecId: item.bomSpecId,
-              quantity: num,
-              orderSkuId: item.orderSkuId,
-              orderCode: item.orderCode,
-              orderWlnCode: item.orderWlnCode,
-              skuSpecCode: item.skuSpecCode,
-              skuSpecName: item.skuSpecName,
-            };
+      });
+      let orderList = [];
+      for (let j = 0; j < formData.data.inOutStorageBomList.length; j++) {
+        if (formData.data.inOutStorageBomList[j].orderList && formData.data.inOutStorageBomList[j].orderList.length > 0) {
+          orderList = orderList.concat(formData.data.inOutStorageBomList[j].orderList.map((itemOrder) => itemOrder.orderSkuId));
+        }
+      }
+      const a = await proxy.post("/stockPreparation/getPackageBomList", orderList).then((res) => {
+        if (res && res.length > 0) {
+          formData.data.inOutStorageBomList = formData.data.inOutStorageBomList.concat(res);
+        }
+      });
+      if (formData.data.inOutStorageBomList && formData.data.inOutStorageBomList.length > 0) {
+        let bomSpecIdList = [];
+        bomSpecIdList = formData.data.inOutStorageBomList.map((item) => item.bomSpecId);
+        proxy
+          .post("/inventory/getQuantity", {
+            departmentId: "0",
+            warehouseId: warehouseList.value[0].dictKey,
+            bomSpecIdList: bomSpecIdList,
           })
-          .filter((itemSelect) => itemSelect.bomSpecId === item.bomSpecId),
-      };
-    });
-    let orderList = [];
-    for (let j = 0; j < formData.data.inOutStorageBomList.length; j++) {
-      if (formData.data.inOutStorageBomList[j].orderList && formData.data.inOutStorageBomList[j].orderList.length > 0) {
-        orderList = orderList.concat(formData.data.inOutStorageBomList[j].orderList.map((itemOrder) => itemOrder.orderSkuId));
+          .then((resInventory) => {
+            let bomSpecIdTwoList = [];
+            for (let i = 0; i < formData.data.inOutStorageBomList.length; i++) {
+              if (resInventory[formData.data.inOutStorageBomList[i].bomSpecId]) {
+                formData.data.inOutStorageBomList[i].warehouseId = warehouseList.value[0].dictKey;
+                formData.data.inOutStorageBomList[i].surplusStock = resInventory[formData.data.inOutStorageBomList[i].bomSpecId];
+              } else {
+                bomSpecIdTwoList.push(formData.data.inOutStorageBomList[i].bomSpecId);
+              }
+            }
+            if (bomSpecIdTwoList && bomSpecIdTwoList.length > 0) {
+              proxy
+                .post("/inventory/getQuantity", {
+                  departmentId: "0",
+                  warehouseId: warehouseList.value[1].dictKey,
+                  bomSpecIdList: bomSpecIdTwoList,
+                })
+                .then((inventoryTwo) => {
+                  for (let i = 0; i < formData.data.inOutStorageBomList.length; i++) {
+                    if (inventoryTwo[formData.data.inOutStorageBomList[i].bomSpecId]) {
+                      formData.data.inOutStorageBomList[i].warehouseId = warehouseList.value[0].dictKey;
+                      formData.data.inOutStorageBomList[i].surplusStock = inventoryTwo[formData.data.inOutStorageBomList[i].bomSpecId];
+                    }
+                  }
+                });
+            }
+          });
       }
     }
-    proxy.post("/stockPreparation/getPackageBomList", orderList).then((res) => {
-      if (res && res.length > 0) {
-        formData.data.inOutStorageBomList = formData.data.inOutStorageBomList.concat(res);
-      }
-    });
-  }
+  });
 });
+const changeWarehouse = (val, item, index) => {
+  if (val) {
+    proxy
+      .post("/inventory/getQuantity", {
+        departmentId: "0",
+        warehouseId: val,
+        bomSpecIdList: [item.bomSpecId],
+      })
+      .then((res) => {
+        if (res[item.bomSpecId]) {
+          formData.data.inOutStorageBomList[index].surplusStock = res[item.bomSpecId];
+        } else {
+          formData.data.inOutStorageBomList[index].surplusStock = 0;
+        }
+      });
+  } else {
+    formData.data.inOutStorageBomList[index].surplusStock = 0;
+  }
+};
 </script>
 
 <style lang="scss" scoped>