Ver código fonte

[新增】 打印

Howie 3 anos atrás
pai
commit
59abe94080

+ 81 - 0
src/views/finance/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>

+ 149 - 0
src/views/finance/components/design/panel.js

@@ -0,0 +1,149 @@
+
+export default {
+  "panels": [{
+    "index": 0,
+    "height": 140,
+    "width": 241,
+    "paperCount": 222,
+    "printElements": [{
+      "options": {
+        "left": 0,
+        "top": 25,
+        "height": 27,
+        "width": 656,
+        "field": "company",
+        "fontSize": 19,
+        "fontWeight": "600",
+        "fontFamily": '黑体',
+        "textAlign": "center",
+        "lineHeight": 26
+      }, "printElementType": { "title": "", "type": "text" }
+    },
+    {
+      "options": {
+        "left": 25,
+        "top": 80,
+        "height": 56,
+        "width": 633,
+        "field": "table",
+        "tableFooterRepeat": "",
+        "tableHeaderRepeat": "none",
+        "rows": [[
+       
+        {
+          "field": "gender",
+          "width": 85.25,
+          "colspan": 1,
+          "rowspan": 1,
+          "checked": false
+        }, {
+
+          "field": "name",
+          "width": 85.25,
+          "align": "center",
+          "colspan": 4,
+          "rowspan": 2,
+         
+        }, {
+
+          "field": "count",
+          "width": 85.25,
+          "align": "center",
+          "colspan": 1,
+          "rowspan": 1,
+       
+        }, {
+          "width": 85.25,
+          "colspan": 1,
+          "rowspan": 1,
+          "checked": true
+        },
+       { "width": 85.25, "colspan": 1, "rowspan": 1, "checked": true }
+      ]]
+      }, "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": 360,
+        "height": 13,
+        "width": 218,
+        "fontSize": 13,
+        "title": "打印",
+        "fontFamily": '黑体',
+        "field": "takerName",
+        "testData": "",
+        "color": "#000",
+        "textAlign": "left"
+      }, "printElementType": { "title": "", "type": "text" }
+    }],
+    "paperNumberDisabled": true
+  }]
+}
+
+
+
+
+// {
+//   "options": {"left": 23, "top": 80, "height": 10, "width": 633},
+//   "printElementType": {"title": "", "type": "hline"}
+// },
+// {
+//   "options": {"left": 23, "top": 80+62.5, "height": 10, "width": 633},
+//   "printElementType": {"title": "", "type": "hline"}
+// },
+// {
+//   "options": {"left": 23, "top": 80+(62.5*2), "height": 10, "width": 633},
+//   "printElementType": {"title": "", "type": "hline"}
+// },
+// {
+//   "options": {"left": 23, "top":80+(62.5*3), "height": 10, "width": 633},
+//   "printElementType": {"title": "", "type": "hline"}
+// },
+// {
+//   "options": {"left": 23, "top": 80, "height": 250, "width": 10},
+//   "printElementType": {"title": "", "type": "vline"}
+// },
+// {
+//   "options": {"left": 23+105.5, "top": 80, "height": 250, "width": 10},
+//   "printElementType": {"title": "", "type": "vline"}
+// },
+// {
+//   "options": {"left": 23+(105.5*2), "top": 80, "height": 250, "width": 10},
+//   "printElementType": {"title": "", "type": "vline"}
+// },
+// {
+//   "options": {"left": 23+(105.5*3), "top": 80, "height": 250, "width": 10},
+//   "printElementType": {"title": "", "type": "vline"}
+// },
+// {
+//   "options": {"left": 23+(105.5*4), "top": 80, "height": 250, "width": 10},
+//   "printElementType": {"title": "", "type": "vline"}
+// },
+// {
+//   "options": {"left": 23+(105.5*5), "top": 80, "height": 250, "width": 10},
+//   "printElementType": {"title": "", "type": "vline"}
+// },
+// {
+//   "options": {"left": 23, "top": 330, "height": 10, "width": 633},
+//   "printElementType": {"title": "", "type": "hline"}
+// },
+// {
+//   "options": {"left": 656, "top": 80, "height": 250, "width": 10},
+//   "printElementType": {"title": "", "type": "vline"}
+// },

+ 219 - 0
src/views/finance/components/design/preview.vue

@@ -0,0 +1,219 @@
+<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 tr {
+  height: 40px !important;
+}
+
+::v-deep .hiprint-printPaper {
+  margin: 0 auto;
+}
+
+/* ::v-deep tr td {
+  border: 0 !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; */
+  }
+
+
+  .ant-modal-body {
+    padding: 0px;
+  }
+
+  .ant-modal-content {
+    margin-bottom: 24px;
+
+  }
+}
+</style>

+ 171 - 0
src/views/finance/components/design/print-data.js

@@ -0,0 +1,171 @@
+import { getK3ReceiptDetail } from "@/api/finance/receipt_list";
+
+import { addPrints } from '@/api/supply/pickup'
+import { getCompanyList } from '@/api/user'
+let detailArr = []
+let detailData = []
+let cids = []
+let company = ''
+// 获取详情
+getCompanyLists()
+function getDetail(ids, nickName) {
+
+  let invoicePickBeans = []
+  let start = 0
+  let end = 5
+  detailArr = []
+  const table = []
+  // detailData = ids 
+  let newIds = []
+  newIds = ids
+  cids = JSON.parse(JSON.stringify(ids))
+  let filterId = []
+  if (newIds instanceof Array) {
+    filterId = newIds.map(k => {
+      return k.id
+    })
+  } else {
+    filterId = [newIds]
+  }
+  filterId = [...new Set(filterId)]
+  for (let i = 0; i < filterId.length; i++) {
+    getK3ReceiptDetail({ id: filterId[i] }).then(res => {
+      const item = res.data
+      console.log(item, '887899');
+
+      table.push({
+        billNo:item.billNo,
+        theTime:item.theTime,
+        walletName:item.walletName,
+        customerName:item.customerName,
+        remark:item.remark,
+        amount:item.amount,
+        nowDate: nowDate(),
+      })
+      detailArr.push({
+        company:`${company}其他收款单`,
+        table: [
+          {id: '1', name: '王小可', gender: '单据编号', count: '120', amount: '9089元'},
+          {id: '2', name: '梦之遥', gender: '付款单位', count: '20', amount: '89元'},
+          {id: '3', name: '梦之遥', gender: '钱包', count: '720', amount: '29089元'},
+          {id: '3', name: '梦之遥', gender: '备注', count: '720', amount: '29089元'},
+        ]
+      })
+
+      return
+      detailData.push(JSON.parse(JSON.stringify(item)))
+      invoicePickBeans = item.invoicePickBeans
+      let len = Math.ceil(invoicePickBeans.length / 5)
+      console.log(len, '长度');
+      for (let index = 0; index < len; index++) {
+        const table = []
+        if (invoicePickBeans.length) {
+          invoicePickBeans.splice(0, 5).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: e.refundableQty || 0,
+              // headerRemark:e.headerRemark,
+              pjxh1Text: e.pjxh1Text || ''
+            })
+
+          });
+        }
+        detailArr.push({
+          pageNumber: `${len}-${index + 1}`,
+          type: item.type,
+          tiTui: item.type === 2 ? `退货人` : `提货人`,
+          takerPhone: item.takerPhone || '',
+          headerRemark: item.remark,
+          total_num: item.total_num,
+          company: item.type === 2 ? `${company}销售退货单` : `${company}销售发货单`,
+          pickOrderWater: item.pickOrderWater,
+          customerNumber: item.customerNumber,
+          takerDa: '',
+          nowDate: nowDate(),
+          takerName: item.type === 2 ? `退货人:${item.takerName || ''}` : `提货人:${item.takerName || ''}`,
+          customerName: item.customerName || '',
+          correspondName: item.correspondName,
+          correspondNames: '',
+          pickCar: item.pickCar || '',
+          createBy: JSON.parse(
+            localStorage.getItem("supply_user")
+          ).nickName,
+          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() {
+  let ids = []
+  detailData.map(item => {
+    console.log(detailData, '3223');
+    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 
+        ids.push(element.id)
+      }
+    } else {
+      // console.log(item.invoiceOrderId ,'item.invoiceOrderId ');
+      return item.invoiceOrderId || item.id
+    }
+
+  })
+
+  // 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
+}