Sfoglia il codice sorgente

Finish Hotfix-zh-171

Howie 3 anni fa
parent
commit
453f05c1b4

+ 10 - 1
package.json

@@ -16,17 +16,23 @@
   "dependencies": {
     "axios": "0.18.1",
     "clipboard": "^2.0.8",
+    "concurrent-tasks": "^1.0.7",
     "core-js": "3.6.5",
     "echarts": "^5.1.1",
     "element-ui": "2.13.2",
     "file-saver": "^2.0.5",
+    "html2canvas": "^1.4.1",
     "js-cookie": "2.2.0",
+    "jspdf": "^2.5.1",
     "normalize.css": "7.0.0",
     "nprogress": "0.2.0",
     "path-to-regexp": "2.4.0",
+    "print-js": "^1.6.0",
     "screenfull": "^4.2.0",
     "vue": "2.6.10",
+    "vue-ls": "^4.0.0",
     "vue-pdf": "^4.3.0",
+    "vue-plugin-hiprint": "^0.0.17",
     "vue-print-nb": "^1.7.5",
     "vue-quill-editor": "^3.0.6",
     "vue-router": "3.0.6",
@@ -48,6 +54,7 @@
     "eslint": "^6.7.2",
     "eslint-plugin-vue": "6.2.2",
     "html-webpack-plugin": "3.2.0",
+    "less-loader": "^6.1.1",
     "mockjs": "1.0.1-beta3",
     "runjs": "4.3.2",
     "sass": "1.26.8",
@@ -56,7 +63,9 @@
     "serve-static": "1.13.2",
     "svg-sprite-loader": "4.1.3",
     "svgo": "1.2.2",
-    "vue-template-compiler": "2.6.10"
+    "uglifyjs-webpack-plugin": "^2.2.0",
+    "vue-template-compiler": "2.6.10",
+    "webpack-cli": "^4.9.1"
   },
   "browserslist": [
     "> 1%",

+ 4 - 3
src/main.js

@@ -1,14 +1,14 @@
 import Vue from 'vue'
 
 import 'normalize.css/normalize.css' // A modern alternative to CSS resets
-
+// import './plugins/jquery.hiwprint.js'
 import ElementUI from 'element-ui'
 import 'element-ui/lib/theme-chalk/index.css'
 // import locale from 'element-ui/lib/locale/lang/en' // lang i18n
-
+import print from '@/utils/print'
 import * as echarts from 'echarts'
 Vue.prototype.$echarts = echarts
-
+Vue.use(print)
 import '@/styles/index.scss' // global css
 
 import App from './App'
@@ -20,6 +20,7 @@ import '@/permission' // permission control
 
 import * as filters from './filters' // global filters
 
+
 // 成功/错误提示
 import {successMsg, errorMsg, warningNotify, checkBtnRole, getSummaries, numToFixed} from '@/utils/common.js'
 Vue.prototype.$successMsg = successMsg;

+ 100 - 0
src/utils/pdf.js

@@ -0,0 +1,100 @@
+import html2canvas from "html2canvas";
+
+import jsPDF from "jspdf";
+
+export const downloadPDF = page => {
+    html2canvas(page).then(function (canvas) {
+        canvas2PDF(canvas);
+
+    });
+
+};
+
+const canvas2PDF = canvas => {
+    let contentWidth = canvas.width;
+
+    let contentHeight = canvas.height;
+
+    //a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高
+
+    let imgWidth = 595.28;
+
+    let imgHeight = 592.28 / contentWidth * contentHeight;
+
+    //let imgHeight = 700/contentWidth * contentHeight;
+
+    //一页pdf显示html页面生成的canvas高度;
+
+    var pageHeight = contentWidth / 592.28 * 841.89;
+
+    let totalHeight = contentHeight;
+
+    // 第一个参数: l:横向  p:纵向
+
+    // 第二个参数:测量单位("pt","mm", "cm", "m", "in" or "px")
+
+    let pdf = new jsPDF("p", "pt");
+
+    let position = 0;
+
+    //   pdf.addImage(
+
+    //     canvas.toDataURL("image/jpeg", 1.0),
+
+    //     "JPEG",
+
+    //     0,
+
+    //     0,
+
+    //     imgWidth,
+
+    //     imgHeight
+
+    //   );
+
+    if (totalHeight < pageHeight) {
+        pdf.addImage( canvas.toDataURL("image/jpeg", 1.0), 'JPEG', 0, 0, imgWidth, imgHeight);
+
+    } else {    
+
+        while (totalHeight > 0) {
+            pdf.addImage( canvas.toDataURL("image/jpeg", 1.0), 'JPEG', 0, position, imgWidth, imgHeight)
+
+            totalHeight -= pageHeight;
+
+            position -= 841.89;
+
+            //避免添加空白页
+
+            if (totalHeight > 0) {
+                pdf.addPage();
+
+            }
+
+        }
+
+    }
+
+    // pdf.addImage(
+
+    //     canvas.toDataURL("image/jpeg", 1.0),
+
+    //     "JPEG",
+
+    //     0,
+
+    //     position,
+
+    //     imgWidth,
+
+    //     imgHeight
+
+    // );
+
+
+ 
+
+    pdf.save("导出.pdf");
+
+};

+ 163 - 0
src/utils/print.js

@@ -0,0 +1,163 @@
+// 打印类属性、方法定义
+/* eslint-disable */
+const Print = function (dom, options) {
+    if (!(this instanceof Print)) return new Print(dom, options);
+  
+    this.options = this.extend({
+      'noPrint': '.no-print'
+    }, options);
+  
+    if ((typeof dom) === "string") {
+      this.dom = document.querySelector(dom);
+    } else {
+      this.isDOM(dom)
+      this.dom = this.isDOM(dom) ? dom : dom.$el;
+    }
+  
+    this.init();
+  };
+  Print.prototype = {
+    init: function () {
+      var content = this.getStyle() + this.getHtml();
+      this.writeIframe(content);
+    },
+    extend: function (obj, obj2) {
+      for (var k in obj2) {
+        obj[k] = obj2[k];
+      }
+      return obj;
+    },
+  
+    getStyle: function () {
+      var str = "",
+        styles = document.querySelectorAll('style,link');
+      for (var i = 0; i < styles.length; i++) {
+        str += styles[i].outerHTML;
+      }
+      str += "<style>" + (this.options.noPrint ? this.options.noPrint : '.no-print') + "{display:none;}</style>";
+  
+      return str;
+    },
+  
+    getHtml: function () {
+      var inputs = document.querySelectorAll('input');
+      var textareas = document.querySelectorAll('textarea');
+      var selects = document.querySelectorAll('select');
+  
+      for (var k = 0; k < inputs.length; k++) {
+        if (inputs[k].type == "checkbox" || inputs[k].type == "radio") {
+          if (inputs[k].checked == true) {
+            inputs[k].setAttribute('checked', "checked")
+          } else {
+            inputs[k].removeAttribute('checked')
+          }
+        } else if (inputs[k].type == "text") {
+          inputs[k].setAttribute('value', inputs[k].value)
+        } else {
+          inputs[k].setAttribute('value', inputs[k].value)
+        }
+      }
+  
+      for (var k2 = 0; k2 < textareas.length; k2++) {
+        if (textareas[k2].type == 'textarea') {
+          textareas[k2].innerHTML = textareas[k2].value
+        }
+      }
+  
+      for (var k3 = 0; k3 < selects.length; k3++) {
+        if (selects[k3].type == 'select-one') {
+          var child = selects[k3].children;
+          for (var i in child) {
+            if (child[i].tagName == 'OPTION') {
+              if (child[i].selected == true) {
+                child[i].setAttribute('selected', "selected")
+              } else {
+                child[i].removeAttribute('selected')
+              }
+            }
+          }
+        }
+      }
+      // 包裹要打印的元素
+      // fix: https://github.com/xyl66/vuePlugs_printjs/issues/36
+      let outerHTML = this.wrapperRefDom(this.dom).outerHTML
+      return outerHTML;
+    },
+    // 向父级元素循环,包裹当前需要打印的元素
+    // 防止根级别开头的 css 选择器不生效
+    wrapperRefDom: function (refDom) {
+      let prevDom = null
+      let currDom = refDom
+      // 判断当前元素是否在 body 中,不在文档中则直接返回该节点
+      if (!this.isInBody(currDom)) return currDom
+  
+      while (currDom) {
+        if (prevDom) {
+          let element = currDom.cloneNode(false)
+          element.appendChild(prevDom)
+          prevDom = element
+        } else {
+          prevDom = currDom.cloneNode(true)
+        }
+  
+        currDom = currDom.parentElement
+      }
+  
+      return prevDom
+    },
+  
+    writeIframe: function (content) {
+      var w, doc, iframe = document.createElement('iframe'),
+        f = document.body.appendChild(iframe);
+      iframe.id = "myIframe";
+      //iframe.style = "position:absolute;width:0;height:0;top:-10px;left:-10px;";
+      iframe.setAttribute('style', 'position:absolute;width:0;height:0;top:-10px;left:-10px;');
+      w = f.contentWindow || f.contentDocument;
+      doc = f.contentDocument || f.contentWindow.document;
+      doc.open();
+      doc.write(content);
+      doc.close();
+      var _this = this
+      iframe.onload = function(){
+        _this.toPrint(w);
+        setTimeout(function () {
+          document.body.removeChild(iframe)
+        }, 100)
+      }
+    },
+  
+    toPrint: function (frameWindow) {
+      try {
+        setTimeout(function () {
+          frameWindow.focus();
+          try {
+            if (!frameWindow.document.execCommand('print', false, null)) {
+              frameWindow.print();
+            }
+          } catch (e) {
+            frameWindow.print();
+          }
+          frameWindow.close();
+        }, 10);
+      } catch (err) {
+        console.log('err', err);
+      }
+    },
+    // 检查一个元素是否是 body 元素的后代元素且非 body 元素本身
+    isInBody: function (node) {
+      return (node === document.body) ? false : document.body.contains(node);
+    },
+    isDOM: (typeof HTMLElement === 'object') ?
+      function (obj) {
+        return obj instanceof HTMLElement;
+      } :
+      function (obj) {
+        return obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';
+      }
+  };
+  const MyPlugin = {}
+  MyPlugin.install = function (Vue, options) {
+    // 4. 添加实例方法
+    Vue.prototype.$print = Print
+  }
+  export default MyPlugin

+ 81 - 0
src/views/supply/deliver/components/design/index.vue

@@ -0,0 +1,81 @@
+<template>
+  <div>
+      <a-button type="primary" icon="eye" @click="preView">
+        预览
+      </a-button>
+    <print-preview ref="preView"/>
+  </div>
+</template>
+
+<script>
+import {disAutoConnect, hiprint, defaultElementTypeProvider} from 'vue-plugin-hiprint'
+// disAutoConnect();
+
+let hiprintTemplate;
+import panel from './panel'
+import printData from './print-data'
+import printPreview from './preview'
+
+export default {
+  name: "printDesign",
+  components: {},
+  data() {
+    return {
+      
+    }
+  },
+
+  methods: {
+    preView() {
+     
+    },
+   
+  }
+}
+</script>
+
+<style  scoped>
+  td {
+    border:none !important;
+  }
+.drag_item_box {
+  height: 100%;
+  padding: 6px;
+}
+
+.drag_item_box > div {
+  height: 100%;
+  width: 100%;
+  background-color: #fff;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+}
+
+.drag_item_box > div > a {
+  text-align: center;
+  text-decoration-line: none;
+}
+
+.drag_item_box > div > a > span {
+  font-size: 28px;
+}
+
+.drag_item_box > div > a > p {
+  margin: 0;
+}
+
+.drag_item_title {
+  font-size: 16px;
+  padding: 12px 6px 0 6px;
+  font-weight: bold;
+}
+
+
+.card-design {
+  overflow: hidden;
+  overflow-x: auto;
+  overflow-y: auto;
+}
+
+</style>

+ 310 - 0
src/views/supply/deliver/components/design/panel.js

@@ -0,0 +1,310 @@
+
+export default {
+  "panels": [{
+    "index": 0,
+    "height": 140,
+    "width": 241,
+    "printElements": [{
+      "options": {
+        "left": 0,
+        "top": 20,
+        "height": 27,
+        "width": 656,
+        "field": "company",
+        "fontSize": 19,
+        "fontWeight": "600",
+        "fontFamily": '黑体',
+        "textAlign": "center",
+        "lineHeight": 26
+      }, "printElementType": { "title": "", "type": "text" }
+    }, {
+      "options": {
+        "left": 40,
+        "top": 50,
+        "height": 13,
+        "width": 328,
+        "fontSize": 13,
+        "title": "经销商编码",
+        "fontFamily": '黑体',
+        "field": "customerNumber",
+        "color": "#000",
+        "textAlign": "left"
+      }, "printElementType": { "title": "", "type": "text" }
+    }, {
+      "options": {
+        "left": 348,
+        "top": 50,
+        "height": 13,
+        "width": 328,
+        "fontSize": 13,
+        "title": "打印日期",
+        "fontFamily": '黑体',
+        "field": "nowDate",
+        "testData": "",
+        "color": "#000",
+
+        "textAlign": "left"
+      }, "printElementType": { "title": "", "type": "text" }
+    },
+      , {
+      "options": {
+        "left": 40,
+        "top": 70,
+        "height": 13,
+        "width": 328,
+        "fontSize": 13,
+        "title": "经销商",
+        "fontFamily": '黑体',
+        "field": "customerName",
+        "color": "#000",
+        "textAlign": "left"
+      }, "printElementType": { "title": "", "type": "text" }
+    }, {
+      "options": {
+        "left": 348,
+        "top": 70,
+        "height": 13,
+        "width": 328,
+        "fontSize": 13,
+        "title": "仓库",
+        "fontFamily": '黑体',
+        "field": "correspondName",
+        "testData": "",
+        "color": "#000",
+        "textAlign": "left"
+      }, "printElementType": { "title": "", "type": "text" }
+    },
+    , {
+      "options": {
+        "left": 40,
+        "top": 90,
+        "height": 13,
+        "width": 328,
+        "fontSize": 13,
+        "title": "备注",
+        "fontFamily": '黑体',
+        "field": "headerRemark",
+        "testData": "",
+        "color": "#000",
+        "textAlign": "left"
+      }, "printElementType": { "title": "", "type": "text" }
+    },
+    {
+      "options": {
+        "left": 15,
+        "top": 115,
+        "height": 381,
+        "width": 656,
+        "fontSize": 13,
+        "field": "table",
+        "fontFamily": '黑体',
+        "lineHeight": 16,
+        "tableFooterRepeat": "",
+        "columns": [[
+          {
+            "title": "出库单号",
+            "field": "salesId",
+            "width": 40,
+            "align": "left",
+            "colspan": 1,
+            "rowspan": 1,
+            "fontSize": 13,
+
+          }, {
+            "title": "发货单号",
+            "field": "invoiceId",
+            "width": 45,
+            "align": "left",
+            "colspan": 1,
+            "rowspan": 1,
+            "fontSize": 13,
+            
+
+          }
+          , {
+            "title": "发货日期",
+            "field": "createTime",
+            "width": 50,
+            "align": "left",
+            "colspan": 1,
+            "rowspan": 1,
+            "fontSize": 13,
+           
+
+          }
+          , {
+            "title": "订单号",
+            "field": "enginOrderType",
+            "width": 40,
+            "align": "left",
+            "colspan": 1,
+            "rowspan": 1,
+            "fontSize": 13,
+            
+          }
+          , {
+            "title": "存货名称",
+            "field": "materialName",
+            "width": 40,
+            "align": "left",
+            "colspan": 1,
+            "rowspan": 1,
+            "fontSize": 13,
+
+
+          }, {
+            "title": "规格型号",
+            "field": "specification",
+            "width": 100,
+            "align": "left",
+            "colspan": 1,
+            "rowspan": 1,
+            "fontSize": 13,
+
+
+          }
+          , {
+            "title": "数量",
+            "field": "refundableQty",
+            "width": 23,
+            "align": "right",
+            "colspan": 1,
+            "rowspan": 1,
+            "fontSize": 13,
+
+          }
+          // , {
+          //   "title": "订单备注",
+          //   "field": "headerRemark",
+          //   "width": 40,
+          //   "align": "center",
+          //   "colspan": 1,
+          //   "rowspan": 1,
+          //   "fontSize": 13,
+          // }
+          
+          , 
+          
+          {
+            "title": "备注说明",
+            "field": "pjxh1Text",
+            "width": 60,
+            "align": "left",
+            "colspan": 2,
+            "rowspan": 1,
+            "fontSize": 13,
+          }]]
+      }, "printElementType": {
+        "title": "表格", "type": "table",
+        editable: true,
+        columnDisplayEditable: true,//列显示是否能编辑
+        columnDisplayIndexEditable: true,//列顺序显示是否能编辑
+        columnTitleEditable: true,//列标题是否能编辑
+        columnResizable: true, //列宽是否能调整
+        columnAlignEditable: true,//列对齐是否调整
+        isEnableEditField: true, //编辑字段
+        isEnableContextMenu: true, //开启右键菜单 默认true
+        isEnableInsertRow: true, //插入行
+        isEnableDeleteRow: true, //删除行
+        isEnableInsertColumn: true, //插入列
+        isEnableDeleteColumn: true, //删除列
+        isEnableMergeCell: true, //合并单元格
+      }
+
+    },
+      , {
+      "options": {
+        "left": 40,
+        "top": 343,
+        "height": 13,
+        "width": 218,
+        "fontSize": 13,
+        "title": "",
+        "fontFamily": '黑体',
+        "field": "tiTui",
+        "testData": "",
+        "color": "#000",
+        "textAlign": "left"
+      }, "printElementType": { "title": "", "type": "text" }
+    },
+    {
+      "options": {
+        
+        "left": 40,
+        "top": 365,
+        "height": 13,
+        "width": 218,
+        "fontSize": 13,
+        "title": "打单",
+        "fontFamily": '黑体',
+        "field": "createBy",
+        "testData": "",
+        "color": "#000",
+        "textAlign": "left"
+      }, "printElementType": { "title": "", "type": "text" }
+    },
+    {
+      "options": {
+        "left": 238,
+        "top": 365,
+        "height": 13,
+        "width": 218,
+        "fontSize": 13,
+        "title": "提单",
+        "fontFamily": '黑体',
+        "field": "",
+        "testData": "",
+        "color": "#000",
+        "textAlign": "left"
+      }, "printElementType": { "title": "", "type": "text" }
+    },
+    {
+      "options": {
+        "left": 238,
+        "top": 343,
+        "height": 13,
+        "width": 218,
+        "fontSize": 13,
+        "title": "联系方式",
+        "fontFamily": '黑体',
+        "field": "",
+        "testData": "",
+        "color": "#000",
+        "textAlign": "left"
+      }, "printElementType": { "title": "", "type": "text" }
+    },
+    {
+      "options": {
+        "left": 463,
+        "top": 343,
+        "height": 13,
+        "width": 218,
+        "fontSize": 13,
+        "title": "车辆",
+        "fontFamily": '黑体',
+        "field": "",
+        "testData": "",
+        "color": "#000",
+        "textAlign": "left"
+      }, "printElementType": { "title": "", "type": "text" }
+    },
+    {
+      "options": {
+        "left": 463,
+        "top": 365,
+        "height": 13,
+        "width": 218,
+        "fontSize": 13,
+        "title": "仓库",
+        "fontFamily": '黑体',
+        "field": "",
+        "testData": "",
+        "color": "#000",
+        "textAlign": "left"
+      }, "printElementType": { "title": "", "type": "text" }
+    }],
+
+    "paperNumberLeft": 0,
+    "paperNumberTop": 0
+  }]
+}

+ 224 - 0
src/views/supply/deliver/components/design/preview.vue

@@ -0,0 +1,224 @@
+<template>
+  <el-dialog :visible.sync="visible" :show-close="false" :maskClosable="false" :close-on-click-modal="false"
+    @cancel="hideModal" :width="350 + 'mm'">
+    <div :spinning="spinning" style="min-height: 100px">
+      <div id="preview_content" ref="printDom">
+
+      </div>
+    </div>
+    <template slot="title">
+      <div>
+        <!-- <div style="margin-right: 20px">打印预览</div> -->
+        <el-button :loading="waitShowPrinter" type="primary" icon="printer" @click.stop="print">打印</el-button>
+        <!-- <el-button type="primary" icon="printer" @click.stop="toPdf">pdf</el-button> -->
+      </div>
+    </template>
+    <template slot="footer">
+      <el-button key="close" type="info" @click="hideModal">
+        关闭
+      </el-button>
+    </template>
+  </el-dialog>
+</template>
+
+<script>
+// import { downloadPDF } from '@/utils/pdf'
+import { addPrint } from './print-data'
+import { detailArr } from './print-data'
+export default {
+  name: "printPreview",
+  props: {},
+  data() {
+    return {
+      visible: false,
+      spinning: true,
+      waitShowPrinter: false,
+      // 纸张宽 mm
+      width: 0,
+      // 模板
+      hiprintTemplate: {},
+      // 数据
+      printData: {}
+    }
+  },
+  computed: {},
+  watch: {},
+  created() {
+  },
+  mounted() {
+  },
+  methods: {
+    // handleExport() {
+    //   downloadPDF(this.$refs.printDom);
+    // },
+    hideModal() {
+      this.visible = false
+      this.waitShowPrinter = false
+      this.$parent.initPrint()
+      // console.log(this.$parent);
+    },
+    show(hiprintTemplate, printData, width = '210') {
+      this.visible = true
+      this.spinning = true
+      this.width = width
+      this.hiprintTemplate = hiprintTemplate
+      this.printData = printData
+      setTimeout(() => {
+        // eslint-disable-next-line no-undef
+        $('#preview_content').html(hiprintTemplate.getHtml(printData))
+        this.spinning = false
+      }, 500)
+    },
+    print() {
+       
+      this.hiprintTemplate.print(this.printData, {}, {
+        callback: () => {
+          addPrint()
+          this.hiprintTemplate = {}
+          this.$parent.getList()
+          this.$parent.tableSelection =[]
+        }
+      })
+      // this.hiprintTemplate.on('printSuccess', function (data) {
+      //   console.log('打印完成')
+      //      addPrint()
+      //     this.hiprintTemplate = {}
+      //     this.$parent.getList()
+      //     this.$parent.tableSelection =[]
+      // })
+      // this.hiprintTemplate.on('printError', function (data) {
+      //   console.log('打印失败')
+      //   this.hiprintTemplate = {}
+      //     this.$parent.getList()
+      //     this.$parent.tableSelection =[]
+      // })
+      setTimeout(()=>{
+        this.hideModal()
+      },2000)
+    },
+    // toPdf() {
+    //   downloadPDF(this.$refs.printDom);
+    //   this.hiprintTemplate.toPdf({}, '打印预览');
+    // },
+  }
+}
+
+</script>
+<style scoped>
+::v-deep .el-dialog__body {
+  padding: 0;
+}
+
+::v-deep table {
+  /* height: 240px !important; */
+}
+
+::v-deep tr {
+  height: 40px !important;
+}
+
+::v-deep .hiprint-printPaper {
+  margin: 0 auto;
+}
+
+::v-deep tr td {
+  border: 0 !important;
+  /* width: 911px !important;
+    height: 529px !important; */
+}
+
+::v-deep .hiprint-paperNumber {
+  display: none;
+}
+
+.ant-modal-body {
+  padding: 0px;
+}
+
+.ant-modal-content {
+  margin-bottom: 24px;
+
+}
+
+@media print {
+
+  td {
+    border: none !important;
+  }
+
+  .drag_item_box {
+    height: 100%;
+    padding: 6px;
+  }
+
+  .drag_item_box>div {
+    height: 100%;
+    width: 100%;
+    background-color: #fff;
+    display: flex;
+    justify-content: center;
+    align-items: center;
+  }
+
+  .drag_item_box>div>a {
+    text-align: center;
+    text-decoration-line: none;
+  }
+
+  .drag_item_box>div>a>span {
+    font-size: 28px;
+  }
+
+  .drag_item_box>div>a>p {
+    margin: 0;
+  }
+
+  .drag_item_title {
+    font-size: 16px;
+    padding: 12px 6px 0 6px;
+    font-weight: bold;
+  }
+
+
+  .card-design {
+    overflow: hidden;
+    overflow-x: auto;
+    overflow-y: auto;
+  }
+
+  ::v-deep .el-dialog__body {
+    padding: 0;
+  }
+
+  ::v-deep table {
+    height: 240px !important;
+  }
+
+  ::v-deep tr {
+    height: 40px !important;
+  }
+
+  ::v-deep .hiprint-printPaper {
+    margin: 0 auto;
+  }
+
+  ::v-deep tr td {
+    border: 0 !important;
+    /* width: 911px !important;
+    height: 529px !important; */
+  }
+
+  ::v-deep .hiprint-paperNumber {
+    display: none;
+  }
+
+  .ant-modal-body {
+    padding: 0px;
+  }
+
+  .ant-modal-content {
+    margin-bottom: 24px;
+
+  }
+}
+</style>

+ 120 - 0
src/views/supply/deliver/components/design/print-data.js

@@ -0,0 +1,120 @@
+import { getDeliverDetail } from '@/api/supply/deliver'
+import { addPrints } from '@/api/supply/pickup'
+import { getCompanyList } from '@/api/user'
+
+let detailArr = []
+let detailData = []
+let company = ''
+// 获取详情
+getCompanyLists()
+function getDetail(ids) {
+
+  detailArr = []
+  // detailData = ids 
+  let newIds = []
+  newIds = ids
+  for (let i = 0; i < newIds.length; i++) {
+    getDeliverDetail({ id: newIds[i].id }).then(res => {
+      const item = res.data
+      detailData.push(item)
+      const table = []
+      item.invoicePickBeans.length = 5
+      item.invoicePickBeans.forEach(e => {
+        table.push({
+          salesId: e.salesOrderId,
+          invoiceId: e.invoiceId,
+          id: e.id,
+          createTime: e.id ? dateToDayFilter(item.createTime) : '',
+          enginOrderType: e.enginOrderType == 'HOME' || e.enginOrderType == 'TRADE' ? e.enginOrderNo : e.mainOrderId,
+          materialName: e.materialName || '',
+          specification: e.specification || '',
+          refundableQty: 100,
+          // headerRemark:e.headerRemark,
+          pjxh1Text: e.pjxh1Text || ''
+        })
+      });
+
+      console.log(company);
+      detailArr.push({
+        type: item.type,
+        tiTui:item.type === 2 ? `退货人` : `提货人`,
+        headerRemark:item.remark,
+        total_num: item.total_num,
+        company: item.type === 2 ? `${company}销售退货单` : `${company}销售发货单`,
+        pickOrderWater: item.pickOrderWater,
+        customerNumber: item.customerNumber,
+        nowDate: nowDate(),
+        customerName: item.customerName || '',
+        correspondName: item.correspondName || '',
+        createBy: item.createBy,
+        table
+      })
+    })
+  }
+}
+
+function nowDate() {
+  var date = new Date();
+  var seperator1 = "-";
+  var year = date.getFullYear();
+  var month = date.getMonth() + 1;
+  var strDate = date.getDate();
+  if (month >= 1 && month <= 9) {
+    month = "0" + month;
+  }
+  if (strDate >= 0 && strDate <= 9) {
+    strDate = "0" + strDate;
+  }
+  var currentdate = year + seperator1 + month + seperator1 + strDate;
+  console.log(currentdate);
+  return currentdate;
+}
+
+function dateToDayFilter(date) {
+  if (!date) { return '' }
+  return date.slice(0, 10)
+}
+
+function getCompanyLists() {
+  getCompanyList().then(res => {
+    company = res.data ? res.data[0].companyName : ''
+  })
+  return company
+}
+
+// 添加次数
+function addPrint() {
+        // console.log(detailData);
+  let ids = detailData.map(item => {
+    console.log(item.invoicePickBeans);
+    if (item.invoicePickBeans && item.invoicePickBeans.length) {
+      for (let index = 0; index < item.invoicePickBeans.length; index++) {
+        const element = item.invoicePickBeans[index];
+            // console.log(element.id ,'element.id ');
+        return  element.id 
+      }
+    } else {
+      // console.log(item.invoiceOrderId ,'item.invoiceOrderId ');
+      return item.invoiceOrderId || item.id
+    }
+  
+  })
+    ids = [...new Set(ids)]
+  // console.log(document.execCommand('print'),'4545');
+  addPrints({ ids: ids.join(',') }).then(res => {
+      console.log('chenggong ');
+    // this.$successMsg('提交成功');
+    // this.$parent.getList()
+ 
+  })
+}
+
+
+
+
+
+export {
+  getDetail, getCompanyLists,
+  detailArr,
+  addPrint
+}

+ 161 - 32
src/views/supply/deliver/sum_list.vue

@@ -120,19 +120,22 @@
             highlight-current-row stripe @select="handleSelect" @select-all="handleSelectAll" show-summary
             :summary-method="$getSummaries">
             <el-table-column align="center" type="selection" width="55"></el-table-column>
-            <el-table-column align="right" label="打印次数" prop="printNum" min-width="80" show-overflow-tooltip></el-table-column>
+            <el-table-column align="right" label="打印次数" prop="printNum" min-width="80" show-overflow-tooltip>
+            </el-table-column>
 
             <el-table-column align="left" label="订单类型" prop="orderType" min-width="100" show-overflow-tooltip>
               <template slot-scope="scope">
-                {{ scope.row.orderType | orderTypeFilter }}
+                {{  scope.row.orderType | orderTypeFilter  }}
               </template>
             </el-table-column>
-            <el-table-column align="left" label="制单日期" prop="createTime" min-width="160" show-overflow-tooltip></el-table-column>
-            <el-table-column align="left" label="发货日期" prop="orderTime" min-width="160" show-overflow-tooltip></el-table-column>
+            <el-table-column align="left" label="制单日期" prop="createTime" min-width="160" show-overflow-tooltip>
+            </el-table-column>
+            <el-table-column align="left" label="发货日期" prop="orderTime" min-width="160" show-overflow-tooltip>
+            </el-table-column>
             <el-table-column align="left" label="发货单号" prop="id" min-width="130" show-overflow-tooltip>
               <template slot-scope="scope">
                 <CopyButton :copyText="scope.row.id" />
-                <span>{{ scope.row.id }}</span>
+                <span>{{  scope.row.id  }}</span>
               </template>
             </el-table-column>
             <el-table-column align="left" label="订单号" prop="orderId" min-width="130" show-overflow-tooltip>
@@ -140,23 +143,24 @@
 
                 <CopyButton
                   :copyText="scope.row.enginOrderType == 'HOME' || scope.row.enginOrderType == 'TRADE' ? scope.row.enginOrderNo : scope.row.mainOrderId" />
-                <span>{{ scope.row.enginOrderType == 'HOME' || scope.row.enginOrderType == 'TRADE' ?
-                    scope.row.enginOrderNo
-                    : scope.row.mainOrderId
-                }}</span>
+                <span>{{  scope.row.enginOrderType == 'HOME' || scope.row.enginOrderType == 'TRADE' ?
+                scope.row.enginOrderNo
+                : scope.row.mainOrderId
+
+                  }}</span>
 
               </template>
             </el-table-column>
             <el-table-column align="left" label="经销商编码" prop="customerNumber" min-width="100" show-overflow-tooltip>
               <template slot-scope="scope">
                 <CopyButton :copyText="scope.row.customerNumber" />
-                <span>{{ scope.row.customerNumber }}</span>
+                <span>{{  scope.row.customerNumber  }}</span>
               </template>
             </el-table-column>
             <el-table-column align="left" label="经销商名称" prop="customerName" min-width="250" show-overflow-tooltip>
               <template slot-scope="scope">
                 <CopyButton :copyText="scope.row.customerName" />
-                <span>{{ scope.row.customerName }}</span>
+                <span>{{  scope.row.customerName  }}</span>
               </template>
             </el-table-column>
             <el-table-column align="left" label="销售类型" prop="saleTypeName" min-width="100" show-overflow-tooltip>
@@ -164,25 +168,25 @@
             <el-table-column align="left" label="物料编码" prop="materialCode" min-width="120" show-overflow-tooltip>
               <template slot-scope="scope">
                 <CopyButton :copyText="scope.row.materialCode" />
-                <span>{{ scope.row.materialCode }}</span>
+                <span>{{  scope.row.materialCode  }}</span>
               </template>
             </el-table-column>
             <el-table-column align="left" label="产品编码" prop="materialOldNumber" min-width="140" show-overflow-tooltip>
               <template slot-scope="scope">
                 <CopyButton :copyText="scope.row.materialOldNumber" />
-                <span>{{ scope.row.materialOldNumber }}</span>
+                <span>{{  scope.row.materialOldNumber  }}</span>
               </template>
             </el-table-column>
             <el-table-column align="left" label="产品名称" prop="materialName" min-width="160" show-overflow-tooltip>
               <template slot-scope="scope">
                 <CopyButton :copyText="scope.row.materialName" />
-                <span>{{ scope.row.materialName }}</span>
+                <span>{{  scope.row.materialName  }}</span>
               </template>
             </el-table-column>
             <el-table-column align="left" label="规格型号" prop="specification" min-width="350" show-overflow-tooltip>
               <template slot-scope="scope">
                 <CopyButton :copyText="scope.row.specification" />
-                <span>{{ scope.row.specification }}</span>
+                <span>{{  scope.row.specification  }}</span>
               </template>
             </el-table-column>
             <el-table-column align="left" label="仓库" prop="correspondName" min-width="100" show-overflow-tooltip>
@@ -190,22 +194,22 @@
 
             <el-table-column align="right" label="发货金额" prop="payAmount" min-width="100" show-overflow-tooltip>
               <template slot-scope="scope">
-                {{ scope.row.payAmount | numToFixed }}
+                {{  scope.row.payAmount | numToFixed  }}
               </template>
             </el-table-column>
             <el-table-column align="right" label="发货返利金额" prop="payRebateAmount" min-width="110" show-overflow-tooltip>
               <template slot-scope="scope">
-                {{ scope.row.payRebateAmount | numToFixed }}
+                {{  scope.row.payRebateAmount | numToFixed  }}
               </template>
             </el-table-column>
             <el-table-column align="right" label="发货折扣金额" prop="discAmount" min-width="110" show-overflow-tooltip>
               <template slot-scope="scope">
-                {{ scope.row.totalDiscAmount | numToFixed }}
+                {{  scope.row.totalDiscAmount | numToFixed  }}
               </template>
             </el-table-column>
             <el-table-column align="right" label="折扣额合计" prop="totalDiscAmount" min-width="100" show-overflow-tooltip>
               <template slot-scope="scope">
-                {{ (scope.row.totalDiscAmount + scope.row.payRebateAmount) | numToFixed }}
+                {{  (scope.row.totalDiscAmount + scope.row.payRebateAmount) | numToFixed  }}
               </template>
             </el-table-column>
             <el-table-column align="right" label="发货数量" prop="refundableQty" min-width="100" show-overflow-tooltip>
@@ -213,17 +217,17 @@
 
             <el-table-column align="right" label="含税单价" prop="singlePayPrice" min-width="100" show-overflow-tooltip>
               <template slot-scope="scope">
-                {{ scope.row.singlePayPrice | numToFixed }}
+                {{  scope.row.singlePayPrice | numToFixed  }}
               </template>
             </el-table-column>
             <el-table-column align="right" label="含税总额" prop="singlePayPrice" min-width="100" show-overflow-tooltip>
               <template slot-scope="scope">
-                {{ scope.row.payAmount | numToFixed }}
+                {{  scope.row.payAmount | numToFixed  }}
               </template>
             </el-table-column>
             <el-table-column align="right" label="未出库数量" prop="singlePayPrice" min-width="100" show-overflow-tooltip>
               <template slot-scope="scope">
-                {{ comRefundableQty(scope.row.type, scope.row.salesExamineStatus, scope.row) }}
+                {{  comRefundableQty(scope.row.type, scope.row.salesExamineStatus, scope.row)  }}
               </template>
             </el-table-column>
             <el-table-column align="left" label="表头业务员" prop="k3ServiceName" min-width="100" show-overflow-tooltip>
@@ -276,6 +280,9 @@
       </div>
     </div>
 
+   
+    <print-preview ref="preView" />
+    
     <el-dialog title="密码确认" :visible.sync="isShowDialog" :show-close="false" width="40%" :close-on-click-modal="false">
       <el-form ref="dialogForm" :model="dialogForm" :rules="dialogFormRules" label-position="right" label-width="70px">
         <el-row :gutter="20">
@@ -291,7 +298,8 @@
           </el-col>
           <el-col :xs="24" :sm="12" :lg="12" style="height: 51px;">
             <el-form-item label="操作日期" prop="createDate">
-              <el-date-picker v-model="dialogForm.createDate" readonly type="date" value-format="yyyy-MM-dd" style="width: 100%;" placeholder="选择日期">
+              <el-date-picker v-model="dialogForm.createDate" readonly type="date" value-format="yyyy-MM-dd"
+                style="width: 100%;" placeholder="选择日期">
               </el-date-picker>
             </el-form-item>
           </el-col>
@@ -303,9 +311,7 @@
       </div>
     </el-dialog>
 
-	<!-- <PrintTest v-if="isShowPrint" /> -->
-    <SumPrint :listItem="queryItem" v-if="isShowPrint" @backListFormDetail="backList" />
-
+  
   </div>
 </template>
 
@@ -314,12 +320,19 @@ import { getSumList } from '@/api/supply/deliver'
 import { checkPassword } from "@/api/supply/pickup";
 import { getCategoryList, getSalesmanList } from '@/api/common'
 import SumPrint from '@/views/supply/deliver/components/sum_print'
-import PrintTest from '@/components/Common/print-test'
 
+import { disAutoConnect, hiprint, defaultElementTypeProvider } from 'vue-plugin-hiprint'
+disAutoConnect();
+
+import panel from './components/design/panel'
+import { getDetail, detailArr } from './components/design/print-data'
+
+import printPreview from './components/design/preview.vue'
 export default {
   components: {
     SumPrint,
-    PrintTest
+    printPreview
+
   },
   filters: {
     orderTypeFilter(val) {
@@ -368,7 +381,41 @@ export default {
       tableSelection: [],
       queryItem: {},
       isShowPrint: false,
+      curPaper: {
+        type: 'A5',
+        width: 500,
+        height: 147.6
 
+      },
+      paperTypes: {
+        'A3': {
+          width: 420,
+          height: 296.6
+        },
+        'A4': {
+          width: 210,
+          height: 296.6
+        },
+        'A5': {
+          width: 210,
+          height: 147.6
+        },
+        'B3': {
+          width: 500,
+          height: 352.6
+        },
+        'B4': {
+          width: 250,
+          height: 352.6
+        },
+        'B5': {
+          width: 250,
+          height: 175.6
+        }
+      },
+      scaleValue: 1,
+      scaleMax: 5,
+      scaleMin: 0.5,
       isShowDialog: false,
       dialogForm: {
         password: "",
@@ -378,6 +425,7 @@ export default {
       dialogFormRules: {
         password: [{ required: true, message: "请输入密码", trigger: "blur" }],
       },
+    hiprintTemplate:''
     }
   },
 
@@ -413,6 +461,18 @@ export default {
         }
 
       }
+    },
+    curPaperType() {
+      let type = 'other'
+      let types = this.paperTypes
+      for (const key in types) {
+        let item = types[key]
+        let { width, height } = this.curPaper
+        if (item.width === width && item.height === height) {
+          type = key
+        }
+      }
+      return type
     }
   },
 
@@ -421,8 +481,44 @@ export default {
     this.getCategoryList();
     this.getList();
   },
-
+  activated(){
+    this.initPrint()
+  },
   methods: {
+   initPrint(){
+      hiprint.init({
+      providers: [new defaultElementTypeProvider()]
+    });
+    // 还原配置
+    hiprint.setConfig()
+    // 替换配置
+    hiprint.setConfig({
+      movingDistance: 2.5,
+      text: {
+        supportOptions: [
+          {
+            name: 'styler',
+            hidden: true
+          },
+          {
+            name: 'formatter',
+            hidden: true
+          },
+        ]
+      }
+    })
+    // eslint-disable-next-line no-undef
+    hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item'));
+    this.hiprintTemplate = new hiprint.PrintTemplate({
+      template: panel,
+      settingContainer: '#PrintElementOptionSetting',
+      paginationContainer: '.hiprint-printPagination'
+    });
+    this.hiprintTemplate.design('#hiprint-printTemplate');
+    // 获取当前放大比例, 当zoom时传true 才会有
+    // this.scaleValue = hiprintTemplate.editingPanel.scale || 1;
+    }
+,
     // 获取业务员列表
     getSalesmanList() {
       getSalesmanList({
@@ -447,8 +543,8 @@ export default {
 
     // 查询列表
     getList() {
+      console.log(888);
       this.listLoading = true;
-
       let params = {
         pageNum: this.currentPage,
         pageSize: this.pageSize,
@@ -522,9 +618,19 @@ export default {
 
     // 点击打印
     toPrint() {
+      // this.$refs
+      this.queryItem = this.tableSelection;
+      // console.log(this.tableSelection);
+      // this.isShowPrint = true;
+      // this.$refs.myPdfComponent.print()
+      // console.log(this.hiprintTemplate, detailArr);
+      // getDetail(this.tableSelection)
+      // this.$refs.preView.show(this.hiprintTemplate, detailArr)
       if (!this.tableSelection[0].printNum) {
         this.queryItem = this.tableSelection;
-        this.isShowPrint = true;
+        // this.isShowPrint = true;
+        getDetail(this.tableSelection)
+        this.$refs.preView.show(this.hiprintTemplate, detailArr)
       } else {
         this.queryItem = this.tableSelection;
         this.dialogForm.createMan = JSON.parse(
@@ -551,7 +657,8 @@ export default {
           };
           checkPassword(params).then((res) => {
             this.cancelDialogForm();
-            this.isShowPrint = true;
+            getDetail(this.tableSelection)
+             this.$refs.preView.show(this.hiprintTemplate, detailArr)
           });
         }
       });
@@ -571,6 +678,9 @@ export default {
       }
       var currentdate = year + seperator1 + month + seperator1 + strDate;
       return currentdate;
+
+
+
     },
 
     backList() {
@@ -578,6 +688,25 @@ export default {
       this.isShowPrint = false;
     },
 
+    /**
+      * 设置纸张大小
+      * @param type [A3, A4, A5, B3, B4, B5, other]
+      * @param value {width,height} mm
+      */
+    setPaper(type, value) {
+      try {
+        if (Object.keys(this.paperTypes).includes(type)) {
+          this.curPaper = { type: type, width: value.width, height: value.height }
+          this.hiprintTemplate.setPaper(value.width, value.height)
+        } else {
+          this.curPaper = { type: 'other', width: value.width, height: value.height }
+          this.hiprintTemplate.setPaper(value.width, value.height)
+
+        }
+      } catch (error) {
+        this.$message.error(`操作失败: ${error}`)
+      }
+    },
 
   }
 }

+ 12 - 1
vue.config.js

@@ -1,7 +1,7 @@
 'use strict'
 const path = require('path')
 const defaultSettings = require('./src/settings.js')
-
+let webpack = require('webpack')
 function resolve(dir) {
   return path.join(__dirname, dir)
 }
@@ -51,6 +51,17 @@ module.exports = {
     before: require('./mock/mock-server.js')
   },
   configureWebpack: {
+    plugins: [
+      new webpack.ProvidePlugin({
+      }),
+    ],
+    resolve: {
+      alias: {
+      },
+      extensions: ['*', '.js', '.vue', '.json']
+    },
+  },
+  configureWebpack: {
     // provide the app's title in webpack's name field, so that
     // it can be accessed in index.html to inject the correct title.
     name: name,