Browse Source

申购采购作废接口更换,盘点excel导入

cz 1 year ago
parent
commit
ddff0bf5f1

BIN
public/static/InventoryImportTemplate.xlsx


+ 51 - 25
src/components/product/SelectGoods.vue

@@ -9,8 +9,8 @@
     <div>
       <div>已选择货品</div>
       <div style="margin: 10px 0px">
-        <el-tag style="margin-right: 10px" type="info" closable v-for="(good, index) in goodList" :key="good.id"
-                @close="handleRemove(index)">{{ good.name }}</el-tag>
+        <el-tag style="margin-right: 10px" type="info" :closable="false" v-for="(good, index) in goodList" :key="good.id">{{ good.name }}</el-tag>
+        <!-- @close="handleRemove(index)" -->
       </div>
       <div style="text-align: center">
         <el-button @click="handleCancel" size="large">取消</el-button>
@@ -29,6 +29,17 @@ import byTable from "@/components/byTable/index";
 import byForm from "@/components/byForm/index";
 import treeList from "@/components/product/treeList";
 import { computed, defineComponent, ref, watch } from "vue";
+const props = defineProps({
+  isInventory: {
+    type: Boolean,
+    default: false,
+  },
+  warehouseId: {
+    type: String,
+    default: "",
+  },
+  selectList: Array,
+});
 const loading = ref(false);
 const submitLoading = ref(false);
 const sourceList = ref({
@@ -123,6 +134,14 @@ const config = computed(() => {
         return proxy.dictValueLabel(unit, productUnit.value);
       },
     },
+    props.isInventory
+      ? {
+          attrs: {
+            label: "库存数量",
+            prop: "stockQuantity",
+          },
+        }
+      : {},
     {
       attrs: {
         label: "操作",
@@ -244,32 +263,36 @@ const getList = async (req = {}) => {
     ...req,
   };
   loading.value = true;
-  proxy
-    .post("/productInfo/page", sourceList.value.pagination)
-    .then((message) => {
-      sourceList.value.data = message.rows.map((x) => ({ ...x, fileList: [] }));
-      sourceList.value.pagination.total = message.total;
-      setTimeout(() => {
-        loading.value = false;
-      }, 200);
+  let requestUrl =
+    props.isInventory == false
+      ? "/productInfo/page"
+      : "/stockCheck/productPage";
+  sourceList.value.pagination.warehouseId =
+    props.isInventory == true ? props.warehouseId : "";
+  proxy.post(requestUrl, sourceList.value.pagination).then((message) => {
+    sourceList.value.data = message.rows.map((x) => ({ ...x, fileList: [] }));
+    sourceList.value.pagination.total = message.total;
+    setTimeout(() => {
+      loading.value = false;
+    }, 200);
 
-      const productIdList = message.rows.map((x) => x.id);
-      // 请求文件数据并回显
-      if (productIdList.length > 0) {
-        proxy
-          .post("/fileInfo/getList", { businessIdList: productIdList })
-          .then((fileObj) => {
-            for (let i = 0; i < sourceList.value.data.length; i++) {
-              const e = sourceList.value.data[i];
-              for (const key in fileObj) {
-                if (e.id === key) {
-                  e.fileList = fileObj[key];
-                }
+    const productIdList = message.rows.map((x) => x.id);
+    // 请求文件数据并回显
+    if (productIdList.length > 0) {
+      proxy
+        .post("/fileInfo/getList", { businessIdList: productIdList })
+        .then((fileObj) => {
+          for (let i = 0; i < sourceList.value.data.length; i++) {
+            const e = sourceList.value.data[i];
+            for (const key in fileObj) {
+              if (e.id === key) {
+                e.fileList = fileObj[key];
               }
             }
-          });
-      }
-    });
+          }
+        });
+    }
+  });
 };
 
 const getTreeList = () => {
@@ -288,6 +311,9 @@ const getTreeList = () => {
 };
 
 const goodList = ref([]);
+onMounted(() => {
+  goodList.value = proxy.deepClone(props.selectList);
+});
 const handleSelect = (row) => {
   const flag = goodList.value.some((x) => x.id === row.id);
   if (flag)

+ 1 - 1
src/views/WDLY/outInBound/waitOutBound/index.vue

@@ -93,7 +93,7 @@
       </template>
     </el-dialog>
 
-    <el-dialog v-model="openExcel" title="excel导入" width="30%" append-to-body>
+    <el-dialog v-model="openExcel" title="Excel导入" width="30%" append-to-body>
       <div v-loading="excelLoading">
         <div style="margin: 15px 0">
           <el-button @click="downloadTemplate" type="primary">Excel模板下载</el-button>

+ 19 - 1
src/views/WDLY/purchaseManage/alreadyPurchase/index.vue

@@ -43,7 +43,7 @@
             <el-button type="primary" link v-if="
                 item.purchaseStatus == 10 ||
                 (item.purchaseStatus == 30 && item.arrivalStatus == 0)
-              " @click="handleEdit(item, 88)">作废</el-button>
+              " @click="handleEditOne(item)">作废</el-button>
             <el-button type="primary" link v-if="item.purchaseStatus == 30" @click="handleEdit(item, 99)">结束</el-button>
           </div>
         </template>
@@ -1104,6 +1104,24 @@ const handleEdit = (row, status) => {
   });
 };
 
+const handleEditOne = (row) => {
+  // 弹窗提示是否删除
+  ElMessageBox.confirm(`此操作将作废该数据, 是否继续?`, "提示", {
+    confirmButtonText: "确定",
+    cancelButtonText: "取消",
+    type: "warning",
+  }).then(() => {
+    // 删除
+    proxy.post("/purchase/cancellation", { id: row.id }).then((res) => {
+      ElMessage({
+        message: `作废成功`,
+        type: "success",
+      });
+      getList();
+    });
+  });
+};
+
 const handleArrival = (row, type) => {
   modalType.value = type;
   if (type === "add") {

+ 2 - 2
src/views/WDLY/purchaseManage/subscribe/index.vue

@@ -171,7 +171,7 @@ const config = computed(() => {
         width: 80,
       },
       render(status) {
-        return statusData.value.find((x) => x.value == status).label;
+        return proxy.dictValueLabel(status, statusData.value);
       },
     },
     {
@@ -205,7 +205,7 @@ const config = computed(() => {
                   ).then(() => {
                     // 删除
                     proxy
-                      .post("/subscribeDetail/edit", {
+                      .post("/subscribeDetail/cancellation", {
                         ...row,
                         status: 99,
                       })

+ 13 - 57
src/views/purchaseManage/purchaseManage/subscribe/index.vue

@@ -2,48 +2,25 @@
   <div class="tenant">
     <!-- <Banner /> -->
     <div class="content">
-      <byTable
-        :source="sourceList.data"
-        :pagination="sourceList.pagination"
-        :config="config"
-        :loading="loading"
-        highlight-current-row
-        :selectConfig="selectConfig"
-        :table-events="{
+      <byTable :source="sourceList.data" :pagination="sourceList.pagination" :config="config" :loading="loading" highlight-current-row
+               :selectConfig="selectConfig" :table-events="{
           //element talbe事件都能传
           select: select,
-        }"
-        :action-list="[
+        }" :action-list="[
           {
             text: '发起申购',
             action: () => openModal(),
           },
-        ]"
-        @get-list="getList"
-      >
+        ]" @get-list="getList">
         <template #fileSlot="{ item }">
-          <div
-            style="cursor: pointer; color: #409eff"
-            @click="handleClickFile(item)"
-          >
+          <div style="cursor: pointer; color: #409eff" @click="handleClickFile(item)">
             {{ item.fileName }}
           </div>
         </template>
       </byTable>
     </div>
-    <el-dialog
-      :title="modalType == 'add' ? '添加供应商' : '编辑供应商'"
-      v-model="dialogVisible"
-      width="800"
-      v-loading="loading"
-    >
-      <byForm
-        :formConfig="formConfig"
-        :formOption="formOption"
-        v-model="formData.data"
-        :rules="rules"
-        ref="byform"
-      >
+    <el-dialog :title="modalType == 'add' ? '添加供应商' : '编辑供应商'" v-model="dialogVisible" width="800" v-loading="loading">
+      <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="byform">
         <template #address>
           <el-row :gutter="10" style="width: 100%">
             <el-col :span="8">
@@ -87,31 +64,15 @@
 
         <template #fileSlot>
           <div>
-            <el-upload
-              v-model:fileList="fileList"
-              class="upload-demo"
-              action="https://winfaster.obs.cn-south-1.myhuaweicloud.com"
-              :limit="3"
-              :data="uploadData"
-              :on-preview="handlePreview"
-              :on-remove="handleRemove"
-              :on-success="handleSuccess"
-              :before-upload="handleBeforeUpload"
-              accept=".pdf"
-            >
+            <el-upload v-model:fileList="fileList" class="upload-demo" action="https://winfaster.obs.cn-south-1.myhuaweicloud.com" :limit="3"
+                       :data="uploadData" :on-preview="handlePreview" :on-remove="handleRemove" :on-success="handleSuccess"
+                       :before-upload="handleBeforeUpload" accept=".pdf">
               <el-button type="primary">选择</el-button>
               <template #file>
                 <div>
                   <div style="margin-top: 15px">
-                    <el-tag
-                      class="ml-2"
-                      type="info"
-                      v-for="(item, index) in fileList"
-                      :key="index"
-                      closable
-                      @close="handleClose(index)"
-                      >{{ item.fileName }}</el-tag
-                    >
+                    <el-tag class="ml-2" type="info" v-for="(item, index) in fileList" :key="index" closable
+                            @close="handleClose(index)">{{ item.fileName }}</el-tag>
                   </div>
                 </div>
               </template>
@@ -121,12 +82,7 @@
       </byForm>
       <template #footer>
         <el-button @click="dialogVisible = false" size="large">取 消</el-button>
-        <el-button
-          type="primary"
-          @click="submitForm('byform')"
-          size="large"
-          :loading="submitLoading"
-        >
+        <el-button type="primary" @click="submitForm('byform')" size="large" :loading="submitLoading">
           确 定
         </el-button>
       </template>

+ 219 - 139
src/views/purchaseSales/stockManage/inventory/index.vue

@@ -2,108 +2,54 @@
   <div class="tenant">
     <!-- <Banner /> -->
     <div class="content">
-      <byTable
-        :source="sourceList.data"
-        :pagination="sourceList.pagination"
-        :config="config"
-        :loading="loading"
-        highlight-current-row
-        :selectConfig="selectConfig"
-        :table-events="{
+      <byTable :source="sourceList.data" :pagination="sourceList.pagination" :config="config" :loading="loading" highlight-current-row
+               :selectConfig="selectConfig" :table-events="{
           //element talbe事件都能传
           select: select,
-        }"
-        :action-list="[
+        }" :action-list="[
           {
             text: '发起盘点',
             action: () => openModal('add'),
           },
-        ]"
-        @get-list="getList"
-      >
+        ]" @get-list="getList">
         <template #code="{ item }">
-          <div
-            style="cursor: pointer; color: #409eff"
-            @click="handleClickCode(item)"
-          >
+          <div style="cursor: pointer; color: #409eff" @click="handleClickCode(item)">
             {{ item.code }}
           </div>
         </template>
       </byTable>
     </div>
-    <el-dialog
-      :title="modalType == 'add' ? '发起盘点' : '盘点详情'"
-      v-model="dialogVisible"
-      width="800"
-      v-loading="loading"
-      destroy-on-close
-    >
-      <byForm
-        :formConfig="formConfig"
-        :formOption="formOption"
-        v-model="formData.data"
-        :rules="rules"
-        ref="byform"
-      >
+    <el-dialog :title="modalType == 'add' ? '发起盘点' : '盘点详情'" v-model="dialogVisible" width="70%" v-loading="loading" destroy-on-close>
+      <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="byform">
         <template #products>
           <div style="width: 100%">
-            <el-button
-              type="primary"
-              @click="openProduct = true"
-              style="margin-bottom: 10px"
-              v-if="modalType == 'add'"
-              :disabled="!formData.data.warehouseId"
-            >
+            <el-button type="primary" @click="openProduct = true" style="margin-bottom: 10px" v-if="modalType == 'add'"
+                       :disabled="!formData.data.warehouseId">
               添加物品
             </el-button>
-            <el-table
-              :data="formData.data.list"
-              :row-class-name="changeClass"
-              show-summary
-              :summary-method="getSummaries"
-            >
+            <el-button type="primary" @click="excelImport()" plain style="margin-bottom: 10px" v-if="modalType == 'add'"
+                       :disabled="!formData.data.warehouseId">
+              Excel导入
+            </el-button>
+
+            <el-table :data="formData.data.list" :row-class-name="changeClass" show-summary :summary-method="getSummaries">
               <el-table-column prop="productCode" label="物品编码" />
               <el-table-column prop="productName" label="物品名称" />
-              <el-table-column
-                prop="productUnit"
-                label="单位"
-                :formatter="
+              <el-table-column prop="productUnit" label="单位" :formatter="
                   (row) => dictValueLabel(row.productUnit, productUnit)
-                "
-              />
+                " />
               <el-table-column prop="quantity" label="库存数量" />
-              <el-table-column
-                prop="checkQuantity"
-                label="盘点数量"
-                min-width="150"
-              >
+              <el-table-column prop="checkQuantity" label="盘点数量" min-width="150">
                 <template #default="{ row, $index }">
-                  <el-form-item
-                    :prop="'list.' + $index + '.checkQuantity'"
-                    :rules="rules.checkQuantity"
-                    :inline-message="true"
-                  >
-                    <el-input-number
-                      v-model="row.checkQuantity"
-                      :precision="4"
-                      :controls="false"
-                      :min="0"
-                      @change="() => handleChange($index)"
-                    />
+                  <el-form-item :prop="'list.' + $index + '.checkQuantity'" :rules="rules.checkQuantity" :inline-message="true">
+                    <el-input-number v-model="row.checkQuantity" :precision="4" :controls="false" :min="0" @change="handleChange" />
                   </el-form-item>
                 </template>
               </el-table-column>
               <el-table-column prop="result" label="盘点结果" />
-              <el-table-column
-                prop="zip"
-                label="操作"
-                width="100"
-                v-if="modalType == 'add'"
-              >
+              <el-table-column prop="zip" label="操作" width="100" v-if="modalType == 'add'">
                 <template #default="{ $index }">
-                  <el-button type="primary" link @click="handleRemove($index)"
-                    >删除</el-button
-                  >
+                  <el-button type="primary" link @click="handleRemove($index)">删除</el-button>
                 </template>
               </el-table-column>
             </el-table>
@@ -112,26 +58,30 @@
       </byForm>
       <template #footer v-if="modalType == 'add'">
         <el-button @click="dialogVisible = false" size="large">取 消</el-button>
-        <el-button
-          type="primary"
-          @click="submitForm('byform')"
-          size="large"
-          :loading="submitLoading"
-        >
+        <el-button type="primary" @click="submitForm('byform')" size="large" :loading="submitLoading">
           确 定
         </el-button>
       </template>
     </el-dialog>
-    <el-dialog
-      v-model="openProduct"
-      title="选择物品"
-      width="70%"
-      append-to-body
-    >
-      <SelectGoods
-        @cancel="openProduct = false"
-        @pushGoods="pushGoods"
-      ></SelectGoods>
+    <el-dialog v-model="openProduct" title="选择物品" width="70%" append-to-body destroy-on-close>
+      <SelectGoods @cancel="openProduct = false" @pushGoods="pushGoods" :selectList="acquireSelectList()" :isInventory="true"
+                   :warehouseId="formData.data.warehouseId"></SelectGoods>
+    </el-dialog>
+
+    <el-dialog v-model="openExcel" title="Excel导入" width="30%" append-to-body>
+      <div v-loading="excelLoading">
+        <div style="margin: 15px 0">
+          <el-button @click="downloadTemplate" type="primary">Excel模板下载</el-button>
+        </div>
+        <el-upload :action="actionUrl + '/stockCheck/excelImport'" :data="importData" :headers="headers"
+                   :before-upload="useImportExcelStore().updateRequestHeaders" :on-success="handleSuccess" :on-progress="handleProgress"
+                   :show-file-list="false" :on-error="handleError" accept=".xls, .xlsx">
+          <el-button type="primary" plain>点击导入</el-button>
+        </el-upload>
+      </div>
+      <template #footer>
+        <el-button @click="openExcel = false" size="large">取 消</el-button>
+      </template>
     </el-dialog>
   </div>
 </template>
@@ -144,7 +94,9 @@ import byForm from "@/components/byForm/index";
 import { computed, defineComponent, ref } from "vue";
 import useUserStore from "@/store/modules/user";
 import SelectGoods from "@/components/product/SelectGoods";
-
+const actionUrl = import.meta.env.VITE_APP_BASE_API;
+import useImportExcelStore from "@/store/modules/importExcel";
+const headers = computed(() => useImportExcelStore().requestHeaders);
 const loading = ref(false);
 const submitLoading = ref(false);
 const sourceList = ref({
@@ -410,41 +362,93 @@ const handleSelect = (row) => {
   });
 };
 
+const acquireSelectList = () => {
+  let data = [];
+  if (formData.data.list && formData.data.list.length > 0) {
+    data = formData.data.list.map((item) => {
+      return {
+        id: item.productId,
+        name: item.productName,
+      };
+    });
+  }
+  return data;
+};
+
 const pushGoods = (goods) => {
-  const arr = goods.map((x) => ({
-    productId: x.id,
-    quantity: "",
-    checkQuantity: "",
-    productName: x.name,
-    productCode: x.code,
-    productUnit: x.unit,
-  }));
-  const ids = arr.map((x) => x.productId);
-  if (formData.data.warehouseId) {
-    proxy
-      .post("/stock/pageByWarehouse", {
-        id: formData.data.warehouseId,
-        productIds: ids,
-      })
-      .then((res) => {
-        const productList = res.rows;
-        for (let i = 0; i < productList.length; i++) {
-          const e = productList[i];
-          for (let j = 0; j < arr.length; j++) {
-            const jele = arr[j];
-            if (e.productId === jele.productId) {
-              formData.data.list.push({ ...jele, quantity: e.quantity });
-            }
-          }
+  if (goods && goods.length > 0) {
+    let afterFiltering = [];
+    if (formData.data.list && formData.data.list.length > 0) {
+      afterFiltering = goods.filter((item) => {
+        let data = formData.data.list.filter(
+          (itemProduct) => itemProduct.productId === item.id
+        );
+        if (data && data.length > 0) {
+          return false;
         }
+        return true;
       });
+    } else {
+      afterFiltering = goods;
+    }
+    formData.data.list = formData.data.list.concat(
+      afterFiltering.map((x) => {
+        return {
+          productId: x.id,
+          quantity: x.stockQuantity || 0,
+          checkQuantity: null,
+          productName: x.name,
+          productCode: x.code,
+          productUnit: x.unit,
+        };
+      })
+    );
+
+    ElMessage({
+      message: "添加成功!",
+      type: "success",
+    });
+    openProduct.value = false;
+  } else {
+    ElMessage("请选择至少一件商品");
   }
-  return ElMessage({
-    message: "添加成功,已为你自动过滤库存数量为0的数据 !",
-    type: "success",
-  });
 };
 
+// const pushGoods = (goods) => {
+//   const arr = goods.map((x) => ({
+//     productId: x.id,
+//     quantity: "",
+//     checkQuantity: "",
+//     productName: x.name,
+//     productCode: x.code,
+//     productUnit: x.unit,
+//   }));
+//   const ids = arr.map((x) => x.productId);
+//   if (formData.data.warehouseId) {
+//     proxy
+//       .post("/stock/pageByWarehouse", {
+//         id: formData.data.warehouseId,
+//         productIds: ids,
+//       })
+//       .then((res) => {
+//         const productList = res.rows;
+//         for (let i = 0; i < productList.length; i++) {
+//           const e = productList[i];
+//           for (let j = 0; j < arr.length; j++) {
+//             const jele = arr[j];
+//             if (e.productId === jele.productId) {
+//               formData.data.list.push({ ...jele, quantity: e.quantity });
+//             }
+//           }
+//         }
+//       });
+//   }
+//   return ElMessage({
+//     message: "添加成功,已为你自动过滤库存数量为0的数据 !",
+//     type: "success",
+//   });
+// };
+
 const handleRemove = (index) => {
   formData.data.list.splice(index, 1);
   return ElMessage({
@@ -481,23 +485,36 @@ const handleRemove = (index) => {
 //   }
 // });
 
-const handleChange = (index) => {
-  if (!formData.data.list[index].quantity) return;
-  if (
-    formData.data.list[index].quantity > formData.data.list[index].checkQuantity
-  ) {
-    formData.data.list[index].result = "盘亏";
-  }
-  if (
-    formData.data.list[index].quantity ==
-    formData.data.list[index].checkQuantity
-  ) {
-    formData.data.list[index].result = "正常";
-  }
-  if (
-    formData.data.list[index].quantity < formData.data.list[index].checkQuantity
-  ) {
-    formData.data.list[index].result = "盘盈";
+// const handleChange = (index) => {
+//   if (!formData.data.list[index].quantity) return;
+//   if (
+//     formData.data.list[index].quantity > formData.data.list[index].checkQuantity
+//   ) {
+//     formData.data.list[index].result = "盘亏";
+//   }
+//   if (
+//     formData.data.list[index].quantity ==
+//     formData.data.list[index].checkQuantity
+//   ) {
+//     formData.data.list[index].result = "正常";
+//   }
+//   if (
+//     formData.data.list[index].quantity < formData.data.list[index].checkQuantity
+//   ) {
+//     formData.data.list[index].result = "盘盈";
+//   }
+// };
+
+const handleChange = () => {
+  for (let i = 0; i < formData.data.list.length; i++) {
+    const ele = formData.data.list[i];
+    if (Number(ele.quantity) > Number(ele.checkQuantity)) {
+      formData.data.list[i].result = "盘亏";
+    } else if (Number(ele.quantity) == Number(ele.checkQuantity)) {
+      formData.data.list[i].result = "正常";
+    } else if (Number(ele.quantity) < Number(ele.checkQuantity)) {
+      formData.data.list[i].result = "盘盈";
+    }
   }
 };
 
@@ -555,6 +572,69 @@ const getSummaries = (param) => {
   });
   return sums;
 };
+const importData = ref({});
+const excelImport = () => {
+  openExcel.value = true;
+  importData.value = {
+    warehouseId: formData.data.warehouseId,
+  };
+};
+const excelLoading = ref(false);
+const openExcel = ref(false);
+const downloadTemplate = () => {
+  fetch("/static/InventoryImportTemplate.xlsx")
+    .then((res) => res.blob())
+    .then((res) => {
+      const url = window.URL.createObjectURL(res);
+      let filename = "库存盘点导入模板.xlsx";
+      const link = document.createElement("a");
+      link.style.display = "none";
+      link.href = url;
+      link.setAttribute("download", filename);
+      document.body.appendChild(link);
+      link.click();
+    });
+};
+
+const handleProgress = () => {
+  excelLoading.value = true;
+};
+const handleSuccess = (res) => {
+  if (res.code != 200) {
+    excelLoading.value = false;
+    return ElMessage({
+      message: `${res.msg},请重试!`,
+      type: "info",
+    });
+  } else {
+    ElMessage({
+      message: "导入成功!",
+      type: "success",
+    });
+    if (res && res.data && res.data.length > 0) {
+      formData.data.list = res.data.map((x) => ({
+        productId: x.productId,
+        quantity: Number(x.stockCount) || 0,
+        checkQuantity: Number(x.count) || 0,
+        productName: x.productName,
+        productCode: x.productCustomCode,
+        productUnit: x.productUnit,
+      }));
+      handleChange();
+    }
+    openExcel.value = false;
+    excelLoading.value = false;
+  }
+};
+
+const handleError = (err) => {
+  ElMessage({
+    message: `${err},请重试!`,
+    type: "info",
+  });
+  openExcel.value = false;
+  excelLoading.value = false;
+};
 </script>
   
 <style lang="scss" scoped>