LODOP Web端打印,并选择打印机

2021-03-23  本文已影响0人  前端小飞象
export function needCLodop() {......}
export function loadCLodop() {......}
export function getLodop() {......}
<template>
  <div class="demo">
    <el-button @click="printPdf" >打印</el-button>
    <el-select v-model="printValue" placeholder="请选择">
                    <el-option v-for="item in printOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"></el-option>
     </el-select>
  </div>
</template>

<script>
  var LODOP;
  import {getLodop} from '../common/LodopFuncs'

  export default {
    name: "demo",
    data() {
      return {
          printOptions: [],
          printValue: '-1'
        }
    },
    methods: {
    //选择打印机
     getLodopData () {
      LODOP = getLodop();
      let arr = []
      let iPrinterCount = LODOP.GET_PRINTER_COUNT();
      for (let i = 0; i < iPrinterCount; i++) {
        arr.push({
          label: LODOP.GET_PRINTER_NAME(i),
          value: i
        })
      }
      let defaultName = LODOP.GET_PRINTER_NAME('-1')  //GET_PRINTER_NAME(intPrinterIndex);用序号获得打印机名,一般序号从0开始,-1特指默认打印机;
      arr.forEach(item => {
        if (item.label === defaultName) {
          item.value = '-1'
          item.label += '-默认打印机'
        }
      })
      console.log(defaultName)
      this.printOptions = arr
    },
      // 查询数据
     printPdf() {
      LODOP = getLodop();
      LODOP.SET_PRINTER_INDEX(this.printValue)//设置打印机
      let he = "<p style=\"font-size:12px;\">"
      LODOP.PRINT_INIT("打印小票"); //首先一个初始化语句
      LODOP.SET_PRINT_PAGESIZE(1, '70mm', '110mm', ''); //设置纸张高度(仅仅只是用来调整高度的--也就是长度)
      LODOP.ADD_PRINT_HTM(i, 0, 300, 140, '<p style="font-size:20px;text-align: center;">xxxxx有限公司');
      LODOP.ADD_PRINT_HTM(i += 40, 0, 300, 140, he + '地址:' "</div>");
      // LODOP.ADD_PRINT_HTM(i+=20, 0, 300, 140, '东荔商业大厦601');
      LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + '電話:' );
      LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + 'FAX:' );
      LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "Time:" );
      LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "Staff-Staff:" ); //员工
      LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "ID:");
      LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "SN:");
      LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "----CloseReceipt----");
      LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he +
        "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
      LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, "&thinsp; &thinsp; &thinsp; &thinsp; &thinsp; &thinsp; &thinsp;" +
        sale.cntAmount);
      LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he +
        "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
      LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "**************************************");
      LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "Welcome");
      LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "**************************************");
      // LODOP.PRINT();   //静默打印
      LODOP.PREVIEW(); //预览
     },
    }
  }
</script>
上一篇下一篇

猜你喜欢

热点阅读