wangxin 1 жил өмнө
parent
commit
f14a93f343

+ 13 - 1
src/api/business/outsourcedOrder.js

@@ -1,5 +1,5 @@
 import request from '@/utils/request'
-
+import { download } from '@/utils/request'
 const baseUrl = import.meta.env.VITE_APP_PRODUCTION_API
 
 // 查询外协单
@@ -46,6 +46,18 @@ export function processesForOutsource(data) {
 	})
 }
 
+// 导出
+export function exportOutsource(data) {
+  download(
+    baseUrl+"/business/outsource/export",
+    {
+      ...data,
+    },
+    `外协发出单_${new Date().getTime()}.xlsx`
+  )
+}
+
+
 
 
 // 修改外协单

+ 3 - 3
src/views/business/outsource/DialogProcesses.vue

@@ -16,7 +16,7 @@
     >
       <el-form-item label="工序名称:" prop="processAlias" label-width="104">
         <el-input
-          v-model.trim="queryParams.processAlias"
+          v-model.trim="queryParams.keyword"
           type="text"
           @keydown.enter.prevent
           style="width: 160px"
@@ -46,13 +46,13 @@
       <el-table-column label="工序名称" align="center" prop="processAlias" />
     </el-table>
     <!-- 分页 -->
-    <pagination
+    <!-- <pagination
       v-show="total > 0"
       :total="total"
       v-model:page="queryParams.pageNum"
       v-model:limit="queryParams.pageSize"
       @pagination="getList"
-    />
+    /> -->
     <template #footer>
       <div class="dialog-footer">
         <el-button

+ 3 - 3
src/views/business/outsource/DialogProducts.vue

@@ -15,16 +15,16 @@
       style="padding-top: 16px"
     >
       <el-form-item
-        label="产品描述:"
+        label="关键字:"
         prop="productDescription"
         label-width="104"
       >
         <el-input
-          v-model.trim="queryParams.productDescription"
+          v-model.trim="queryParams.keyword"
           type="text"
           @keydown.enter.prevent
           style="width: 160px"
-          placeholder="请输入关键字"
+          placeholder="请输入批号或产品描述"
           :clearable="true"
           @keyup.enter="handleSearch"
         />

+ 167 - 46
src/views/business/outsource/form.vue

@@ -15,12 +15,21 @@
 
         <el-button
           v-if="editStatus"
-          type="primary"
+          type="success"
           icon="check"
           @click="saveFrom"
         >
-          
+          
         </el-button>
+
+        <el-button
+          v-if="!editStatus"
+          type="primary"
+          icon="Download"
+          @click="handleExport"
+          v-hasPermi="['business:outsource:export']"
+          >导出</el-button
+        >
         <el-button
           v-if="editStatus"
           type="primary"
@@ -28,15 +37,6 @@
           @click="submitFrom"
           >保存并提交</el-button
         >
-        <!-- <el-button
-          v-if="form.id && editStatus"
-          type="info"
-          icon="Close"
-          @click="editStatus = false"
-        >
-          取消编辑
-        </el-button> -->
-
         <div class="close-btn" @click="cancel">
           <i class="fa fa-times" aria-hidden="true" />
           <!-- <span>关闭</span> -->
@@ -224,6 +224,18 @@
               prop="productDescription"
               width="320"
             />
+            <el-table-column label="产品数" align="center" prop="productNum">
+              <template #default="scope">
+                <el-input-number
+                  v-if="editStatus"
+                  :min="0"
+                  v-model="scope.row.productNum"
+                  placeholder="产品数"
+                />
+                <span v-else>{{ scope.row.productNum }}</span>
+              </template>
+            </el-table-column>
+
             <el-table-column
               :label="form.packagingMethod === '0' ? '箱号' : '原箱号'"
               align="center"
@@ -231,14 +243,37 @@
               width="320"
             />
             <el-table-column
-              v-if="form.packagingMethod === '1'"
               label="新箱号"
               align="center"
               prop="newCarrier"
               width="320"
             >
               <template #default="scope">
-                <el-input
+                <el-select
+                  v-if="editStatus"
+                  v-model="scope.row.carrierIds"
+                  multiple
+                  filterable
+                  remote
+                  reserve-keyword
+                  placeholder="请选择箱号"
+                  collapse-tags-tooltip
+                  collapse-tags
+                  :remote-method="
+                    (arg) => remoteCarriers(arg, scope.row.newCarriers)
+                  "
+                  :loading="loadingCarrier"
+                  @change="(arg) => handleCarrierChange(arg, scope.row)"
+                >
+                  <el-option
+                    v-for="item in carriers"
+                    :key="item.value"
+                    :label="item.label"
+                    :value="item.value"
+                  />
+                </el-select>
+                <span v-else>{{ scope.row.newCarrier }}</span>
+                <!-- <el-input
                   v-if="editStatus"
                   v-model="scope.row.newCarrier"
                   readonly
@@ -251,7 +286,7 @@
                     />
                   </template>
                 </el-input>
-                <span v-else>{{ scope.row.newCarrier }}</span>
+                <span v-else>{{ scope.row.newCarrier }}</span>-->
               </template>
             </el-table-column>
             <el-table-column
@@ -335,7 +370,9 @@
 import {
   getOrder,
   saveOrder,
+  carrierForOutsource,
   submitOrder,
+  exportOutsource,
 } from "@/api/business/outsourcedOrder";
 import dialogCarrier from "./DialogCarrier";
 import dialogSuppliers from "./DialogSuppliers";
@@ -371,6 +408,8 @@ const multiple = ref(true);
 const visible = ref(false);
 const editStatus = ref(true);
 const isFullscreen = ref(false);
+const loadingCarrier = ref(false);
+const carriers = ref([]);
 const webHost = import.meta.env.VITE_APP_BASE_API;
 const form = ref({});
 // const formatDetails = ref([])
@@ -382,6 +421,11 @@ const rules = {
 };
 
 /***********************  方法区  ****************************/
+/** 导出按钮操作 */
+function handleExport() {
+  exportOutsource({ id: form.value.id });
+}
+
 /** 打开抽屉 */
 function open(id) {
   reset();
@@ -404,12 +448,6 @@ function getForm() {
   });
 }
 
-/** 查询表单信息  */
-// function selectProceseName(row) {
-//   row.processNames = row.processes.map((item) => item.processAlias).join(",");
-//   return row.processNames;
-// }
-
 function selectText(value, data) {
   if (value) {
     return data.filter((item) => item.value == value)[0].label;
@@ -450,6 +488,7 @@ function saveFrom() {
     proxy.$modal.msgError("请添加产品明细");
     return;
   }
+
   proxy.$refs["formRef"].validate((valid) => {
     for (const item of form.value.details) {
       if (!item.processNames) {
@@ -457,6 +496,16 @@ function saveFrom() {
         return;
       }
     }
+
+    if (form.value.packagingMethod == 1) {
+      console.log("form.value.details", form.value.details);
+      for (const item of form.value.details) {
+        if (item.newCarriers.length == 0) {
+          proxy.$modal.msgError("请选择" + item.lotCode + "批次的新箱号");
+          return;
+        }
+      }
+    }
     if (valid) {
       saveOrder(form.value).then((response) => {
         if (response.code == 200) {
@@ -469,34 +518,46 @@ function saveFrom() {
   });
 }
 
-function save() {}
-
 /** 保存并提交 */
 function submitFrom() {
-  proxy.$modal.confirm("是否确定提交吗,提交后不可修改").then(function () {
-    return;
-  });
-
-  if (!form.value.details || form.value.details.length == 0) {
-    proxy.$modal.msgError("请添加产品明细");
-    return;
-  }
+  console.log("from", form.value);
+  proxy.$modal
+    .confirm("是否确定提交,提交后不可修改,删除")
+    .then(function () {
+      return;
+    })
+    .then(() => {
+      if (!form.value.details || form.value.details.length == 0) {
+        proxy.$modal.msgError("请添加产品明细");
+        return;
+      }
 
-  proxy.$refs["formRef"].validate((valid) => {
-    if (valid) {
-      for (const item of form.value.details) {
-        if (!item.processNames) {
-          proxy.$modal.msgError("请选择" + item.lotCode + "批次的工序");
-          return;
+      proxy.$refs["formRef"].validate((valid) => {
+        for (const item of form.value.details) {
+          if (!item.processNames) {
+            proxy.$modal.msgError("请选择" + item.lotCode + "批次的工序");
+            return;
+          }
+        }
+        if (form.value.packagingMethod == 1) {
+          console.log("form.value.details", form.value.details);
+          for (const item of form.value.details) {
+            if (item.newCarriers.length == 0) {
+              proxy.$modal.msgError("请选择" + item.lotCode + "批次的新箱号");
+              return;
+            }
+          }
+        }
+        if (valid) {
+          submitOrder(form.value).then((response) => {
+            proxy.$modal.msgSuccess("提交成功");
+            visible.value = false;
+            getList.value();
+          });
         }
-      }
-      submitOrder(form.value).then((response) => {
-        proxy.$modal.msgSuccess("提交成功");
-        visible.value = false;
-        getList.value();
       });
-    }
-  });
+    })
+    .catch(() => {});
 }
 
 /***************************** 外协商对话框相关 *****************************/
@@ -538,6 +599,7 @@ const handleMultipleSelectedProducts = (selection) => {
       productCode: item.productCode,
       newCarrier: "",
       newCarrierCount: 0,
+      newCarriers: [],
       processNames: "",
       remark: item.remark,
       processes: [],
@@ -549,10 +611,69 @@ const handleMultipleSelectedProducts = (selection) => {
 
 /***************************** 外协箱子对话框相关 *****************************/
 // 打开外协箱子选择对话框
-const handleShowDialogOutsourceCarriers = (row) => {
+const handleShowDialogOutsourceCarriers = (row) => {};
+
+function remoteCarriers(code, row) {
+  loadingCarrier.value = true;
   console.log("row", row);
-  proxy.$refs.dialogCarrierRef.open(row.lotId);
-};
+  let categoryId;
+  if (form.value.packagingMethod == 1) {
+    categoryId = "1783783697558847489";
+  } else {
+    categoryId = "2";
+  }
+  if (code == "") {
+    return;
+  }
+  carrierForOutsource({
+    categoryId: categoryId,
+    code: code,
+  }).then((res) => {
+    if (res.code === 200) {
+      carriers.value = res.rows.map((v) => ({ value: v.id, label: v.code }));
+      if (Array.isArray(row)) {
+        // 安全地更新 carriers
+        carriers.value.push(
+          ...row
+            .filter((v) => !carriers.value.map((e) => e.value).includes(v.id))
+            .map((v) => ({ value: v.id, label: v.code }))
+        );
+      }
+    } else {
+      carriers.value = [];
+      carriers.value.push(...row);
+    }
+    loadingCarrier.value = false;
+  });
+}
+
+function handleCarrierChange(arg, item) {
+  item.newCarriers = carriers.value
+    .filter((v) => arg.includes(v.value))
+    .map((v) => ({ id: v.value, code: v.label }));
+  console.log("item", item);
+  console.log("form", form.value);
+}
+
+/** 使用新方式 */
+// const handleShowDialogOutsourceCarriers = (row) => {
+//   // 确保 form.details 存在且不是 undefined
+//   let allNewCarriers;
+//   if (form.value && form.value.details && Array.isArray(form.value.details)) {
+//     allNewCarriers = form.value.details
+//       .flatMap((detail) =>
+//         detail.newCarriers ? detail.newCarriers.filter((item) => item) : []
+//       )
+//       .filter(Boolean);
+
+//     // 现在 allNewCarriers 包含了所有非空的 newCarriers 数组的元素
+//   }
+//   // form.value.details.newCarriers
+//   // const allNewCarriers = form.details.flatMap((detail) => detail.newCarriers);
+//   console.log("allNewCarriers", allNewCarriers);
+//   proxy.$refs.dialogCarrierRef.open(row.lotId, from.value.deliveryMethod);
+// };
+
 // 箱子选择带回
 const handleMultipleSelectedOutsourceCarriers = (selection, lotId) => {
   const carrierNames = selection.map((item) => item.code);

+ 18 - 11
src/views/business/outsource/index.vue

@@ -203,6 +203,7 @@
                 查看
               </el-button>
               <el-button
+                v-if="scope.row.isSubmit == 0"
                 link
                 type="danger"
                 icon="Delete"
@@ -248,6 +249,7 @@ const { packaging_method } = proxy.useDict("packaging_method");
 
 const orderList = ref([]);
 const loading = ref(true);
+const del = ref(true); //选中数据是否可以删除
 const ids = ref([]);
 const single = ref(true);
 const multiple = ref(true);
@@ -272,7 +274,6 @@ const queryParams = ref({
 function getList() {
   loading.value = true;
   listOrder(queryParams.value).then((response) => {
-    console.log("response", response);
     orderList.value = response.rows;
     total.value = response.total;
     loading.value = false;
@@ -294,6 +295,7 @@ function resetQuery() {
 // 多选框选中数据
 function handleSelectionChange(selection) {
   ids.value = selection.map((item) => item.id);
+  del.value = !selection.some((item) => item.isSubmit == 1);
   single.value = selection.length != 1;
   multiple.value = !selection.length;
 }
@@ -312,16 +314,21 @@ function handleUpdate(row) {
 /** 删除按钮操作 */
 function handleDelete(row) {
   const _ids = row.id || ids.value;
-  proxy.$modal
-    .confirm("是否确认删除选中的数据项?")
-    .then(function () {
-      return delOrder(_ids);
-    })
-    .then(() => {
-      getList();
-      proxy.$modal.msgSuccess("删除成功!");
-    })
-    .catch(() => {});
+
+  if (del.value) {
+    proxy.$modal
+      .confirm("是否确认删除选中的数据项?")
+      .then(function () {
+        return delOrder(_ids);
+      })
+      .then(() => {
+        getList();
+        proxy.$modal.msgSuccess("删除成功!");
+      })
+      .catch(() => {});
+  } else {
+    proxy.$modal.msgError("已提交单据,不能删除!");
+  }
 }
 
 /** 导出按钮操作 */