Преглед изворни кода

对账单: SKU对账单并导出excel

lxf пре 1 година
родитељ
комит
77c4eb016c

+ 2 - 0
package.json

@@ -37,7 +37,9 @@
     "file-saver": "2.0.5",
     "fuse.js": "6.6.2",
     "html2canvas": "^1.4.1",
+    "jquery": "^3.7.0",
     "js-cookie": "3.0.1",
+    "js-table2excel": "^1.1.2",
     "jsencrypt": "3.3.1",
     "jspdf": "^2.5.1",
     "lossless-json": "^2.0.8",

+ 1 - 0
src/main.js

@@ -48,6 +48,7 @@ import {
   timeInterval,
   compareTime,
 } from "@/utils/util";
+import '@/utils/table2excel'
 
 // 分页组件
 import Pagination from "@/components/Pagination";

+ 186 - 0
src/utils/table2excel.js

@@ -0,0 +1,186 @@
+/*
+ *  jQuery table2excel - v1.0.2
+ *  jQuery plugin to export an .xls file in browser from an HTML table
+ *  https://github.com/rainabba/jquery-table2excel
+ *
+ *  Made by rainabba
+ *  Under MIT License
+ */
+//table2excel.js
+import jQuery from 'jquery'
+;(function ($, window, document, undefined) {
+  var pluginName = 'table2excel',
+    defaults = {
+      exclude: '.noExl',
+      name: 'Table2Excel',
+    }
+
+  // The actual plugin constructor
+  function Plugin(element, options) {
+    this.element = element
+    // jQuery has an extend method which merges the contents of two or
+    // more objects, storing the result in the first object. The first object
+    // is generally empty as we don't want to alter the default options for
+    // future instances of the plugin
+    //
+    this.settings = $.extend({}, defaults, options)
+    this._defaults = defaults
+    this._name = pluginName
+    this.init()
+  }
+
+  Plugin.prototype = {
+    init: function () {
+      var e = this
+
+      e.template = {
+        head: '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta charset="UTF-8"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets>',
+        sheet: {
+          head: '<x:ExcelWorksheet><x:Name>',
+          tail: '</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>',
+        },
+        mid: '</x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><style>td{vnd.ms-excel.numberformat:@}</style></head><body>',
+        table: {
+          head: "<table border='1'>",
+          tail: '</table>',
+        },
+        foot: '</body></html>',
+      }
+
+      e.tableRows = []
+
+      // get contents of table except for exclude
+      $(e.element).each(function (i, o) {
+        var tempRows = ''
+        $(o)
+          .find('tr')
+          .not(e.settings.exclude)
+          .each(function (i, o) {
+            tempRows += "<tr align='center' valign='center'>" + $(o).html() + '</tr>'
+          })
+        e.tableRows.push(tempRows)
+      })
+
+      // exclude img tags
+      if (e.settings.exclude_img) {
+        e.tableRows[0] = exclude_img(e.tableRows[0])
+      }
+
+      // exclude link tags
+      if (e.settings.exclude_links) {
+        e.tableRows[0] = exclude_links(e.tableRows[0])
+      }
+
+      // exclude input tags
+      if (e.settings.exclude_inputs) {
+        e.tableRows[0] = exclude_inputs(e.tableRows[0])
+      }
+
+      e.tableToExcel(e.tableRows, e.settings.name, e.settings.sheetName)
+    },
+
+    tableToExcel: function (table, name, sheetName) {
+      var e = this,
+        fullTemplate = '',
+        i,
+        link,
+        a
+
+      e.uri = 'data:application/vnd.ms-excel;base64,'
+      e.base64 = function (s) {
+        return window.btoa(unescape(encodeURIComponent(s)))
+      }
+      e.format = function (s, c) {
+        return s.replace(/{(\w+)}/g, function (m, p) {
+          return c[p]
+        })
+      }
+      e.ctx = {
+        worksheet: name || 'Worksheet',
+        table: table,
+      }
+
+      fullTemplate = e.template.head
+
+      if ($.isArray(table)) {
+        for (i in table) {
+          //fullTemplate += e.template.sheet.head + "{worksheet" + i + "}" + e.template.sheet.tail;
+          fullTemplate += e.template.sheet.head + sheetName + e.template.sheet.tail
+        }
+      }
+
+      fullTemplate += e.template.mid
+
+      if ($.isArray(table)) {
+        for (i in table) {
+          fullTemplate += e.template.table.head + '{table' + i + '}' + e.template.table.tail
+        }
+      }
+
+      fullTemplate += e.template.foot
+
+      for (i in table) {
+        e.ctx['table' + i] = table[i]
+      }
+      delete e.ctx.table
+
+      if ((typeof msie !== 'undefined' && msie > 0) || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
+        // If Internet Explorer
+        if (typeof Blob !== 'undefined') {
+          //use blobs if we can
+          fullTemplate = [fullTemplate]
+          //convert to array
+          var blob1 = new Blob(fullTemplate, { type: 'text/html' })
+          window.navigator.msSaveBlob(blob1, getFileName(e.settings))
+        } else {
+          //otherwise use the iframe and save
+          //requires a blank iframe on page called txtArea1
+          txtArea1.document.open('text/html', 'replace')
+          txtArea1.document.write(fullTemplate)
+          txtArea1.document.close()
+          txtArea1.focus()
+          sa = txtArea1.document.execCommand('SaveAs', true, getFileName(e.settings))
+        }
+      } else {
+        link = e.uri + e.base64(e.format(fullTemplate, e.ctx))
+        a = document.createElement('a')
+        a.download = getFileName(e.settings)
+        a.href = link
+        a.click()
+      }
+
+      return true
+    },
+  }
+
+  function getFileName(settings) {
+    return (settings.filename ? settings.filename : 'table2excel') + '.xls'
+  }
+
+  // Removes all img tags
+  function exclude_img(string) {
+    return string.replace(/<img[^>]*>/gi, '')
+  }
+
+  // Removes all link tags
+  function exclude_links(string) {
+    return string.replace(/<A[^>]*>|<\/A>/g, '')
+  }
+
+  // Removes input params
+  function exclude_inputs(string) {
+    return string.replace(/<input[^>]*>|<\/input>/gi, '')
+  }
+
+  $.fn[pluginName] = function (options) {
+    var e = this
+    e.each(function () {
+      if (!$.data(e, 'plugin_' + pluginName)) {
+        $.data(e, 'plugin_' + pluginName, new Plugin(this, options))
+      }
+    })
+
+    // chain jQuery functions
+    return e
+  }
+})(jQuery, window, document)

+ 17 - 1
src/views/group/finance/check-bill/index.vue

@@ -116,6 +116,16 @@
         <el-button @click="openOrder = false" size="large">关 闭</el-button>
       </template>
     </el-dialog>
+
+    <el-dialog title="打印" v-if="openPrint" v-model="openPrint" width="94%">
+      <el-tabs v-model="activeName" class="demo-tabs">
+        <el-tab-pane label="SKU对账单" name="sku">
+          <PrintSKU :rowData="rowData" @clickCancel="openPrint = false" v-if="activeName === 'sku'"></PrintSKU>
+        </el-tab-pane>
+        <el-tab-pane label="BOM对账单" name="bom"> </el-tab-pane>
+        <el-tab-pane label="订单对账单" name="order"> </el-tab-pane>
+      </el-tabs>
+    </el-dialog>
   </div>
 </template>
 
@@ -124,6 +134,7 @@ import byTable from "@/components/byTable/index";
 import byForm from "@/components/byForm/index";
 import { ElMessage, ElMessageBox } from "element-plus";
 import SelectOrder from "@/views/group/order/management/index";
+import PrintSKU from "./printSKU.vue";
 
 const { proxy } = getCurrentInstance();
 const departmentList = ref([{ dictKey: "0", dictValue: "胜德体育" }]);
@@ -545,8 +556,13 @@ const submitProofFile = () => {
     getList();
   });
 };
+const openPrint = ref(false);
+const rowData = ref({});
+const activeName = ref("sku");
 const clickPrint = (row) => {
-  console.log(row);
+  activeName.value = "sku";
+  rowData.value = row;
+  openPrint.value = true;
 };
 </script>
 

+ 307 - 0
src/views/group/finance/check-bill/printSKU.vue

@@ -0,0 +1,307 @@
+<template>
+  <div>
+    <el-card style="height: calc(100vh - 168px); overflow-y: auto; overflow-x: hidden" v-loading="loading">
+      <div id="tableId">
+        <el-table :data="tableData" border :row-style="{ height: '35px' }" header-row-class-name="tableHeader" show-summary :summary-method="getSummaries">
+          <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.timePeriodBegin }} - {{ rowData.timePeriodEnd }} )
+              </div>
+            </template>
+            <el-table-column label="SKU品号" prop="skuSpecCode" width="180" />
+            <el-table-column label="SKU品名" prop="skuSpecName" min-width="220" />
+            <el-table-column label="数量(PCS)" align="center" prop="quantity" width="160" />
+            <el-table-column label="SKU单价" align="center" prop="unitPrice" width="160" />
+            <el-table-column label="小计" align="center" width="180">
+              <template #default="{ row }">
+                {{ moneyFormat(row.subtotal) }}
+              </template>
+            </el-table-column>
+            <el-table-column label="合计" align="center" width="180">
+              <template #default="{ row }">
+                {{ moneyFormat(row.total) }}
+              </template>
+            </el-table-column>
+          </el-table-column>
+        </el-table>
+      </div>
+      <div style="padding: 8px; text-align: center">
+        <el-button @click="clickCancel" size="large">关 闭</el-button>
+      </div>
+    </el-card>
+  </div>
+</template>
+
+<script setup>
+import $ from "jquery";
+
+const { proxy } = getCurrentInstance();
+const props = defineProps({
+  rowData: Object,
+});
+const loading = ref(false);
+const tableData = ref([]);
+onMounted(() => {
+  if (props.rowData && props.rowData.id) {
+    loading.value = true;
+    proxy.post("/statementOfAccount/getDocumentBySku", { id: props.rowData.id }).then(
+      (res) => {
+        tableData.value = Object.freeze(res);
+        loading.value = false;
+      },
+      (err) => {
+        console.log(err);
+        loading.value = false;
+      }
+    );
+  }
+});
+const getSummaries = ({ columns, data }) => {
+  const sums = [];
+  columns.forEach((column, index) => {
+    if (index === 0) {
+      sums[index] = h("div", { class: "" }, [
+        h("div", {
+          style: { "text-align": "center", "border-style": "solid", "border-width": "0 1px 1px 0", "border-color": "#ebeef5", padding: "0 12px" },
+          innerHTML: "总计:",
+        }),
+        h("div", {
+          style: { "text-align": "center", "border-style": "solid", "border-width": "0 1px 1px 0", "border-color": "#ebeef5", padding: "0 12px" },
+          innerHTML: "备注:",
+        }),
+        h("div", {
+          style: { "text-align": "center", "border-style": "solid", "border-width": "0 1px 1px 0", "border-color": "#ebeef5", padding: "0 12px" },
+          innerHTML: "交货地点:",
+        }),
+        h("div", { style: { "font-size": "16px", "font-weight": 700, padding: "0 12px" }, innerHTML: "申请人:" }),
+      ]);
+      return;
+    }
+    if (index === 1) {
+      sums[index] = h("div", { class: "" }, [
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 1px 1px 0",
+            "border-color": "#ebeef5",
+            color: "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: ".",
+        }),
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 0 1px 0",
+            "border-color": "#ebeef5",
+            color: "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: ".",
+        }),
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 0 1px 0",
+            "border-color": "#ebeef5",
+            color: "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: ".",
+        }),
+        h("div", { style: { "font-size": "16px", "font-weight": 700, padding: "0 12px" }, innerHTML: "胜德体育总经理:" }),
+      ]);
+      return;
+    }
+    if (index === 2) {
+      sums[index] = h("div", { class: "" }, [
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 1px 1px 0",
+            "border-color": "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: getTotal("quantity"),
+        }),
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 0 1px 0",
+            "border-color": "#ebeef5",
+            color: "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: ".",
+        }),
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 0 1px 0",
+            "border-color": "#ebeef5",
+            color: "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: ".",
+        }),
+        h("div", { style: { "font-size": "16px", "font-weight": 700, padding: "0 12px", "text-align": "left" }, innerHTML: "申请日期:" }),
+      ]);
+      return;
+    }
+    if ([1, 3, 4].includes(index)) {
+      sums[index] = h("div", { class: "" }, [
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 1px 1px 0",
+            "border-color": "#ebeef5",
+            color: "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: ".",
+        }),
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 0 1px 0",
+            "border-color": "#ebeef5",
+            color: "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: ".",
+        }),
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 0 1px 0",
+            "border-color": "#ebeef5",
+            color: "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: ".",
+        }),
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 0 1px 0",
+            "border-color": "#ebeef5",
+            color: "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: ".",
+        }),
+      ]);
+      return;
+    }
+    if (index === 5) {
+      sums[index] = h("div", { class: "" }, [
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 1px 1px 0",
+            "border-color": "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: getTotal("total"),
+        }),
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 0 1px 0",
+            "border-color": "#ebeef5",
+            color: "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: ".",
+        }),
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 0 1px 0",
+            "border-color": "#ebeef5",
+            color: "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: ".",
+        }),
+        h("div", {
+          style: {
+            "text-align": "center",
+            "border-style": "solid",
+            "border-width": "0 0 1px 0",
+            "border-color": "#ebeef5",
+            color: "#ebeef5",
+            padding: "0 12px",
+            height: "35px",
+          },
+          innerHTML: ".",
+        }),
+      ]);
+      return;
+    }
+  });
+  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 = () => {
+  $("#tableId").table2excel({
+    exclude: ".noExl",
+    sheetName: "SKU对账单",
+    filename: "SKU对账单",
+    exclude_img: false,
+    exclude_links: false,
+    exclude_inputs: true,
+  });
+  //   emit("clickCancel", "");
+};
+</script>
+
+<style lang="scss" scoped>
+::v-deep(.el-table thead.is-group th.el-table__cell) {
+  background-color: white !important;
+}
+::v-deep(.el-table__footer-wrapper tbody td.el-table__cell) {
+  background-color: white !important;
+}
+::v-deep(.el-table .el-table__cell) {
+  padding: 0;
+}
+::v-deep(.el-table__footer .cell) {
+  padding: 0;
+}
+::v-deep(.el-table__footer .el-table__cell) {
+  border-right: 0px;
+}
+</style>

+ 0 - 1
src/views/process/processConfig/vueFlow.vue

@@ -46,7 +46,6 @@ import handleBtn from "./handleBtn.vue";
 import branchBtn from "./branchBtn.vue";
 import { MiniMap } from "@antv/x6-plugin-minimap";
 import useTagsViewStore from "@/store/modules/tagsView";
-import { rectToBox } from "@vue-flow/core/dist/utils/graph";
 
 defineProps({
   title: {