소스 검색

对账单, 下载excel功能调整

lxf 1 년 전
부모
커밋
79a55bb271

+ 4 - 1
src/main.js

@@ -15,7 +15,7 @@ import useUserStore from "@/store/modules/user";
 
 // 注册指令
 import plugins from "./plugins"; // plugins
-import { download, post, postTwo, get } from "@/utils/request";
+import { download, post, postTwo, get, getFile } from "@/utils/request";
 
 // svg图标
 import "virtual:svg-icons-register";
@@ -47,6 +47,7 @@ import {
   deepClone,
   timeInterval,
   compareTime,
+  downloadFile,
 } from "@/utils/util";
 import '@/utils/table2excel'
 
@@ -67,6 +68,7 @@ app.config.globalProperties.useDict = useDict;
 app.config.globalProperties.get = get;
 app.config.globalProperties.post = post;
 app.config.globalProperties.postTwo = postTwo;
+app.config.globalProperties.getFile = getFile;
 app.config.globalProperties.download = download;
 app.config.globalProperties.parseTime = parseTime;
 app.config.globalProperties.resetForm = resetForm;
@@ -89,6 +91,7 @@ app.config.globalProperties.random = random;
 app.config.globalProperties.deepClone = deepClone;
 app.config.globalProperties.timeInterval = timeInterval;
 app.config.globalProperties.compareTime = compareTime;
+app.config.globalProperties.downloadFile = downloadFile;
 app.config.globalProperties.useUserStore = useUserStore;
 
 // 全局组件挂载

+ 18 - 0
src/utils/request.js

@@ -240,4 +240,22 @@ export function postTwo(url, data = {}, method) {
   });
 }
 
+
+export function getFile(url, data = {}, method) {
+  return new Promise((resolve, reject) => {
+    service({
+      method: method || "get",
+      url: url,
+      params: data,
+      responseType: "blob",
+    })
+      .then((res) => {
+        resolve(res);
+      })
+      .catch((err) => {
+        reject(err);
+      });
+  });
+}
+
 export default service;

+ 15 - 0
src/utils/util.js

@@ -426,3 +426,18 @@ export function NumberToChinese(m) {
   result += result.charAt(result.length - 1) == "元" ? "整" : "";
   return result;
 }
+
+export function downloadFile(fileStream, fileName) {
+  // 创建 Blob 对象
+  const blob = new Blob([fileStream]);
+  // 创建下载链接
+  const url = URL.createObjectURL(blob);
+  // 创建 <a> 元素
+  const a = document.createElement("a");
+  a.href = url;
+  a.download = fileName;
+  // 模拟点击下载
+  a.click();
+  // 释放对象
+  URL.revokeObjectURL(url);
+}

+ 11 - 8
src/views/group/finance/check-bill/printBOM.vue

@@ -39,7 +39,7 @@
 </template>
 
 <script setup>
-import $ from "jquery";
+// import $ from "jquery";
 
 const { proxy } = getCurrentInstance();
 const props = defineProps({
@@ -175,14 +175,17 @@ const clickCancel = () => {
   emit("clickCancel", "");
 };
 const deriveExcel = () => {
-  $("#tableId").table2excel({
-    exclude: ".noExl",
-    sheetName: "BOM对账单",
-    filename: "BOM对账单",
-    exclude_img: false,
-    exclude_links: false,
-    exclude_inputs: true,
+  proxy.getFile("/statementOfAccount/exportDocumentByBom", { id: props.rowData.id }).then((res) => {
+    proxy.downloadFile(res, "BOM对账单.xlsx");
   });
+  // $("#tableId").table2excel({
+  //   exclude: ".noExl",
+  //   sheetName: "BOM对账单",
+  //   filename: "BOM对账单",
+  //   exclude_img: false,
+  //   exclude_links: false,
+  //   exclude_inputs: true,
+  // });
 };
 </script>
 

+ 17 - 16
src/views/group/finance/check-bill/printOrder.vue

@@ -14,9 +14,7 @@
           <el-table-column align="center">
             <template #header>
               <div style="text-align: center; font-size: 30px; padding: 8px">{{ props.rowData.departmentName }}-胜德体育对账单</div>
-              <div style="text-align: center; font-size: 18px; padding-bottom: 8px">
-                ( 对账时间: {{ rowData.timePeriod }} - {{ rowData.timePeriod }} )
-              </div>
+              <div style="text-align: center; font-size: 18px; padding-bottom: 8px">( 对账时间: {{ rowData.timePeriod }} - {{ rowData.timePeriod }} )</div>
             </template>
             <el-table-column label="订单时间" prop="wlnCreateTime" align="center" width="160" />
             <el-table-column label="订单号" prop="code" width="180" />
@@ -56,7 +54,7 @@
 </template>
 
 <script setup>
-import $ from "jquery";
+// import $ from "jquery";
 
 const { proxy } = getCurrentInstance();
 const props = defineProps({
@@ -64,6 +62,7 @@ const props = defineProps({
 });
 const loading = ref(false);
 const tableData = ref([]);
+const total = ref(0);
 onMounted(() => {
   if (props.rowData && props.rowData.id) {
     loading.value = true;
@@ -74,6 +73,9 @@ onMounted(() => {
           for (let i = 0; i < res.length; i++) {
             if (res[i].skuSpecList && res[i].skuSpecList.length > 0) {
               for (let j = 0; j < res[i].skuSpecList.length; j++) {
+                if (res[i].skuSpecList[j].total) {
+                  total.value = Number(Math.round((total.value + res[i].skuSpecList[j].total) * 100) / 100);
+                }
                 if (res[i].skuSpecList[j].bomSpecList && res[i].skuSpecList[j].bomSpecList.length > 0) {
                   for (let x = 0; x < res[i].skuSpecList[j].bomSpecList.length; x++) {
                     list.push({
@@ -190,7 +192,7 @@ const getSummaries = ({ columns, data }) => {
                 padding: "0 12px",
                 height: "35px",
               },
-              innerHTML: getTotal("total"),
+              innerHTML: total.value,
             }),
         h("div", {
           style: {
@@ -236,23 +238,22 @@ const getSummaries = ({ columns, data }) => {
   });
   return sums;
 };
-const getTotal = (label) => {
-  let list = tableData.value.map((item) => item[label]);
-  return Number(Math.round(list.reduce((acc, curr) => acc + curr, 0) * 100) / 100);
-};
 const emit = defineEmits(["clickCancel"]);
 const clickCancel = () => {
   emit("clickCancel", "");
 };
 const deriveExcel = () => {
-  $("#tableId").table2excel({
-    exclude: ".noExl",
-    sheetName: "BOM对账单",
-    filename: "BOM对账单",
-    exclude_img: false,
-    exclude_links: false,
-    exclude_inputs: true,
+  proxy.getFile("/statementOfAccount/exportDocumentByOrder", { id: props.rowData.id }).then((res) => {
+    proxy.downloadFile(res, "订单对账单.xlsx");
   });
+  // $("#tableId").table2excel({
+  //   exclude: ".noExl",
+  //   sheetName: "订单对账单",
+  //   filename: "订单对账单",
+  //   exclude_img: false,
+  //   exclude_links: false,
+  //   exclude_inputs: true,
+  // });
 };
 const objectSpanMethod = ({ rowIndex, columnIndex }) => {
   if ([0, 1, 2, 3, 4, 5, 15, 16, 17].includes(columnIndex)) {

+ 11 - 8
src/views/group/finance/check-bill/printSKU.vue

@@ -34,7 +34,7 @@
 </template>
 
 <script setup>
-import $ from "jquery";
+// import $ from "jquery";
 
 const { proxy } = getCurrentInstance();
 const props = defineProps({
@@ -164,14 +164,17 @@ const clickCancel = () => {
   emit("clickCancel", "");
 };
 const deriveExcel = () => {
-  $("#tableId").table2excel({
-    exclude: ".noExl",
-    sheetName: "SKU对账单",
-    filename: "SKU对账单",
-    exclude_img: false,
-    exclude_links: false,
-    exclude_inputs: true,
+  proxy.getFile("/statementOfAccount/exportDocumentBySku", { id: props.rowData.id }).then((res) => {
+    proxy.downloadFile(res, "SKU对账单.xlsx");
   });
+  // $("#tableId").table2excel({
+  //   exclude: ".noExl",
+  //   sheetName: "SKU对账单",
+  //   filename: "SKU对账单",
+  //   exclude_img: false,
+  //   exclude_links: false,
+  //   exclude_inputs: true,
+  // });
 };
 </script>