Selaa lähdekoodia

【修改】 bug

Howie 3 vuotta sitten
vanhempi
commit
73d9d2914a
5 muutettua tiedostoa jossa 21929 lisäystä ja 36 poistoa
  1. 21432 1
      package-lock.json
  2. 4 0
      package.json
  3. 4 3
      src/main.js
  4. 380 8
      src/views/supply/deliver/components/sum_print.vue
  5. 109 24
      src/views/supply/deliver/sum_list.vue

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 21432 - 1
package-lock.json


+ 4 - 0
package.json

@@ -20,13 +20,17 @@
     "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-pdf": "^4.3.0",
+    "vue-plugin-hiprint": "^0.0.28",
     "vue-print-nb": "^1.7.5",
     "vue-quill-editor": "^3.0.6",
     "vue-router": "3.0.6",

+ 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;

+ 380 - 8
src/views/supply/deliver/components/sum_print.vue

@@ -6,18 +6,20 @@
       </el-radio-group>
     </div> -->
 
-    <div id="printMe">
+    <div id="printMe" ref="printDom">
       <template v-for="(item, i) in detailArr">
         <PrintCommon v-if="currentType === 0" :key="i" :detail-data="item" :company="company" />
-        <PrintFoshan v-if="currentType === 1" :key="i" :detail-data="item" :company="company" />
+        <!-- <PrintFoshan v-if="currentType === 1" :key="i" :detail-data="item" :company="company" />
         <PrintGuangzhou v-if="currentType === 2" :key="i" :detail-data="item" :company="company" />
-        <PrintShaoguan v-if="currentType === 3" :key="i" :detail-data="item" :company="company" />
+        <PrintShaoguan v-if="currentType === 3" :key="i" :detail-data="item" :company="company" /> -->
       </template>
     </div>
 
     <div class="page-footer">
       <div class="footer">
-        <el-button v-print="printObj" type="primary" icon="el-icon-printer">打 印</el-button>
+        <!-- <el-button v-print="printObj" type="primary" icon="el-icon-printer">打 印</el-button> -->
+         <el-button @click="handleExport" type="primary" icon="el-icon-printer">打 印</el-button>
+
         <el-button @click="goBack">关 闭</el-button>
       </div>
     </div>
@@ -27,6 +29,8 @@
 
 <script>
 import print from 'vue-print-nb'
+import html2canvas from "html2canvas"
+import {downloadPDF} from '@/utils/pdf'
 import { getDeliverDetail } from '@/api/supply/deliver'
 import { addPrints } from '@/api/supply/pickup'
 import { getCompanyList } from '@/api/user'
@@ -79,12 +83,50 @@ export default {
   },
 
   methods: {
+    handleExport() {
+      downloadPDF(this.$refs.printDom);
+
+   },
+    toImg() {
+        window.pageYoffset = 0;
+        document.documentElement.scrollTop = 0;
+        document.body.scrollTop = 0;
+        // 先获取你要转换为img的dom节点
+        var node =this.$refs.printDom //传入的id名称
+        var width = node.offsetWidth; //dom宽
+        var height = node.offsetHeight; //dom高
+        var scale = 3; //放大倍数 这个相当于清晰度 调大一点更清晰一点
+        html2canvas(node, {
+          width: width,
+          heigth: height,
+          backgroundColor: "#ffffff", //背景颜色 为null是透明
+          dpi: window.devicePixelRatio * 3, //按屏幕像素比增加像素
+          scale: scale,
+          X: 0,
+          Y: 0,
+          scrollX: -3, //如果左边多个白边 设置该偏移-3 或者更多
+          scrollY: -10,
+          useCORS: true, //是否使用CORS从服务器加载图像 !!!
+          allowTaint: true, //是否允许跨域图像污染画布  !!!
+        }).then((canvas) => {
+          // console.log("canvas", canvas);
+          var url = canvas.toDataURL(); //这里上面不设值cors会报错
+          var a = document.createElement("a"); //创建一个a标签 用来下载
+          a.download = "名"; //设置下载的图片名称
+          var event = new MouseEvent("click"); //增加一个点击事件
+          this.dataURL = url;
+			//如果需要下载的话就加上这两句
+			    a.href = url;//此处的url为base64格式的图片资源
+	        a.dispatchEvent(event); //触发a的单击事件 即可完成下载
+
+        });
+    },
     // 返回列表
     goBack() {
       this.$emit('backListFormDetail')
     },
     changeType() {
-
+        window.print
     },
 
     // 获取详情
@@ -100,7 +142,186 @@ export default {
         this.company = res.data ? res.data[0].companyName : ''
       })
     },
+    toPrint(){
+      // console.log();
+      // window.onload = function(){
+      //   console.log(8888);
+      //   this.$print(this.$refs.printDom) 
+      // }
+    
+      
+//     var iframe = document.createElement('Iframe');
+//     iframe.style.display = 'none';
+//     document.body.appendChild(iframe);
+//     var doc = iframe.contentWindow.document;
+//     doc.write(`<style>
+//       @media print {
+
+// // 1 毫米 [mm] = 3,779 527 559 055 1 像素 [px]
+// //  241mm = ~911px
+// //  140mm = ~529px
+// .detail-container {
+//   width: 911px !important;
+//   height: 529px !important;
+//   margin: auto;
+//   font-size: 16px !important;
+ 
+//   font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif !important;
+//   // font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif !important;
+//   color: #000 !important;
+
+// .top-container {
+//   margin: 20px;
+// }
+
+// }
+// .detail-container {
+//   width: 100%;
+//   height: 100%;
+ 
+// }
+// .print-page {
+//   margin: 20px 0;
+//   // min-height: 1020px;
+//   page-break-after: always;
+// }
+// .print-title {
+//   text-align: center;
+//   .title1 {
+//     font-size: 22px;
+//     margin-bottom: 15px;
+//   }
+// }
+// .print-form-1 {
+//   padding-left: 10px;
+ 
+// }
+// .el-row{
+//   display: flex;
+// }
+// .print-form-1  .item {
+//     display: flex;
+//     padding-right: 10px;
+//     .label {
+//       height: 32px;
+//       display: flex;
+//       align-items: center;
+//       box-sizing: border-box;
+//       font-size: 14.5px;
+//       color: #333333;
+//       flex-shrink: 0;
+//     }
+  
+//   }
+// .print-form-1   .value {
+//       flex: 1;
+//       height: 32px;
+//       display: flex;
+//       align-items: center;
+//       box-sizing: border-box;
+//       font-size: 14.5px;
+//       color: #333333;
+      
+//     }
+// .print-form-1   input {
+//         border: none;
+//         padding: 0;
+//         font-size: 14.5px;
+//       }
+// .print-table-1    .el-row {
+//   font-size: 14.5px;
+//     margin-left: 0 !important;
+//     margin-right: 0 !important;
+//     border: 1px solid #EBEEF5;
+//     border-right: none;
+//   }
+  
+
+//   .head .el-col {
+//       padding-right: 0 !important;
+//       display: flex;
+//       height: 32px;
+//       align-items: center;
+//       font-size: 14.5px;
+//     }
+// .body  .el-col {
+//   font-size: 14.5px;
+//       padding-right: 0 !important;
+//       display: flex;
+//       height: 32px;
+//       align-items: center;
+//       word-break: break-all;
+//     }
+// .foot {
+//     color: #333333;
+    
+//   }
+// .el-row {
+//   font-size: 14.5px;
+//       border-top: none;
+//     }
+    
+// .el-col {
+//       padding: 0;
+//       display: flex;
+//       height: 32px;
+//       align-items: center;
+//       word-break: break-all;
+//     }
+// .print-form-2 {
+//   font-size: 14.5px;
+//   padding-left: 10px;
+ 
+// }
+// .item {
+//   font-size: 14.5px;
+//     display: flex;
+//     padding-right: 10px;
+    
+    
+//   }
+// .label {
+//   font-size: 14.5px;
+//       height: 32px;
+//       display: flex;
+//       align-items: center;
+//       box-sizing: border-box;
+//       font-size: 14.5px;
+//       color: #333333;
+//       flex-shrink: 0;
+//     }
+// .value {
+//   font-size: 14.5px;
+//       flex: 1;
+//       height: 32px;
+//       display: flex;
+//       align-items: center;
+//       box-sizing: border-box;
+//       font-size: 14.5px;
+//       color: #333333;
+      
+//     }
+//         .el-input input {
+//         height: 30px;
+//         border: none;
+//         border-bottom: 1px solid #EBEEF5;
+//         padding: 0 10px;
+//         font-size: 14.5px;
+//       }
+//     }
 
+//       </style>
+// `)
+//     doc.write(this.$refs.printDom.innerHTML);
+//     doc.close();
+//     iframe.contentWindow.print();
+
+
+        // this.$Print.toPrint()
+        
+        // this.$print(this.$refs.printDom, {}); 
+        console.log();
+      },
     // 添加次数
     addPrint() {
       const ids = this.detailArr.map(item => {
@@ -114,7 +335,7 @@ export default {
         }
 
       })
-
+     
       // console.log(document.execCommand('print'),'4545');
       addPrints({ ids: ids.join(',') }).then(res => {
         // this.$successMsg('提交成功');
@@ -134,13 +355,18 @@ body {
 <style scoped lang="scss">
 @media print {
 
+  @page {
+    size:portrait !important;
+  }
+
   // 1 毫米 [mm] = 3,779 527 559 055 1 像素 [px]
   //  241mm = ~911px
   //  140mm = ~529px
   .detail-container {
-    width: 911px !important;
-    height: 529px !important;
+    width: 241mm  !important;
+    height: 140mm !important;
     margin: auto;
+    font-size: 14.5px !important;
     // position: fixed;
     // top: 0;
     // left: 0;
@@ -151,6 +377,152 @@ body {
     color: #000 !important;
   }
 
+  ::v-deep .detail-container {
+    width: 100%;
+    height: 100%;
+
+
+    font-weight: 300;
+  }
+  .print-page {
+    margin: 20px 0;
+    font-family: '微软黑雅';
+    font-weight: bold;
+    font-size: 15px !important;
+    // min-height: 1020px;
+    page-break-after: always;
+  }
+  .print-title {
+    text-align: center;
+    .title1 {
+      font-size: 22px;
+      margin-bottom: 15px;
+    }
+  }
+  .print-form-1 {
+    padding-left: 10px;
+    .item {
+      display: flex;
+      padding-right: 10px;
+      .label {
+        height: 32px;
+        display: flex;
+        align-items: center;
+        box-sizing: border-box;
+        font-size: 13px;
+        color: #333333;
+        flex-shrink: 0;
+      }
+      .value {
+        flex: 1;
+        height: 32px;
+        display: flex;
+        align-items: center;
+        box-sizing: border-box;
+        font-size: 13px;
+        color: #333333;
+        input {
+          border: none;
+          padding: 0;
+        }
+      }
+    }
+  }
+  .print-table-1 {
+    font-size: 12px;
+    margin-top: 10px;
+    margin-bottom: 10px;
+    border-right: 1px solid #EBEEF5;
+    .el-row {
+      margin-left: 0 !important;
+      margin-right: 0 !important;
+      border: 1px solid #EBEEF5;
+      border-right: none;
+    }
+    .div {
+      padding-top: 14px;
+      padding-bottom: 14px;
+      // border-right: 1px solid #EBEEF5;
+    }
+    .head {
+      color: #000;
+      // font-weight: bold; 
+      display: flex;
+      div{
+        margin: 20px;
+      }
+      .div {
+        padding-right: 0 !important;
+        display: flex;
+        height: 32px;
+        align-items: center;
+      }
+    }
+    .body {
+      display: flex;
+      color: #333333;
+      div{
+        margin: 20px;
+      }
+      .el-row {
+        border-top: none;
+      }
+      .div {
+        padding-right: 0 !important;
+        display: flex;
+        height: 32px;
+        align-items: center;
+        word-break: break-all;
+      }
+    }
+    .foot {
+      color: #333333;
+      .el-row {
+        border-top: none;
+      }
+      .div {
+        padding: 0;
+        display: flex;
+        height: 32px;
+        align-items: center;
+        word-break: break-all;
+      }
+    }
+  }
+
+  .print-form-2 {
+    padding-left: 10px;
+    .item {
+      display: flex;
+      padding-right: 10px;
+      .label {
+        height: 32px;
+        display: flex;
+        align-items: center;
+        box-sizing: border-box;
+        font-size: 13px;
+        color: #333333;
+        flex-shrink: 0;
+      }
+      .value {
+        flex: 1;
+        height: 32px;
+        display: flex;
+        align-items: center;
+        box-sizing: border-box;
+        font-size: 13px;
+        color: #333333;
+        ::v-deep .el-input input {
+          height: 30px;
+          border: none;
+          border-bottom: 1px solid #EBEEF5;
+          padding: 0 10px;
+          font-size: 13px;
+        }
+      }
+    }
+  }
+
   .top-container {
     margin: 20px;
   }

+ 109 - 24
src/views/supply/deliver/sum_list.vue

@@ -287,31 +287,18 @@
 import { getSumList } from '@/api/supply/deliver'
 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();
+
+let hiprintTemplate;
+import panel from './components/design/panel'
+import { getDetail ,getCompanyLists,
+    myData} from './components/design/print-data'
+import printPreview from './components/design/preview.vue'
 export default {
   components: {
     SumPrint,
-    PrintTest
-  },
-  filters: {
-    orderTypeFilter(val) {
-      const MAP = {
-        HOME: '家用单',
-        TRADE: '商用单',
-        RETAIL: '零售单',
-        RETAIL_POLICY: '销售政策单',
-        PERMU_HOME: '置换家用单',
-        PERMU_TRADE: '置换商用单',
-        PERMU_RETAIL: '置换零售单',
-        PERMU_RETAIL_POLICY: '置换销售政策单',
-        REQUISITION_HOME: '调拨家用单',
-        REQUISITION_TRADE: '调拨商用单',
-        REQUISITION_RETAIL: '调拨零售单',
-        REQUISITION_RETAIL_POLICY: '调拨销售政策单',
-      }
-      return MAP[val];
-    }
+    printPreview
   },
   data() {
     return {
@@ -341,6 +328,38 @@ export default {
       tableSelection: [],
       queryItem: {},
       isShowPrint: false,
+      curPaper: {
+        type: 'A4',
+        width: 210,
+        height: 296.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
+        }
+      },
+     
     }
   },
 
@@ -377,6 +396,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
     }
   },
 
@@ -385,7 +416,39 @@ export default {
     this.getCategoryList();
     this.getList();
   },
-
+  mounted() {
+    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'));
+    hiprintTemplate = new hiprint.PrintTemplate({
+      template: panel,
+      settingContainer: '#PrintElementOptionSetting',
+      paginationContainer: '.hiprint-printPagination'
+    });
+    hiprintTemplate.design('#hiprint-printTemplate');
+    // 获取当前放大比例, 当zoom时传true 才会有
+    // this.scaleValue = hiprintTemplate.editingPanel.scale || 1;
+  },
   methods: {
     // 获取业务员列表
     getSalesmanList() {
@@ -486,15 +549,37 @@ export default {
 
     // 点击打印
     toPrint() {
+
+
       this.queryItem = this.tableSelection;
+      console.log(this.tableSelection);
+      getDetail(this.tableSelection)
       this.isShowPrint = true;
+      this.$refs.preView.show(hiprintTemplate, myData)
     },
 
     backList() {
       this.queryItem = {};
       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}
+          hiprintTemplate.setPaper(value.width, value.height)
+        } else {
+          this.curPaper = {type: 'other', width: value.width, height: value.height}
+          hiprintTemplate.setPaper(value.width, value.height)
+        }
+      } catch (error) {
+        this.$message.error(`操作失败: ${error}`)
+      }
+    },
 
   }
 }

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä