免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
開發(fā)實現(xiàn)打印功能,1.window.print()實現(xiàn)打印,2.print.js實現(xiàn)打印功能
userphoto

2023.05.13 湖南

關(guān)注

Uxiao7

于 2021-08-20 16:50:00 發(fā)布

331

 收藏

分類專欄: vue js js實現(xiàn)打印 文章標簽: js html vue javascript window

版權(quán)

vue

同時被 3 個專欄收錄

1 篇文章0 訂閱

訂閱專欄

js

15 篇文章0 訂閱

訂閱專欄

js實現(xiàn)打印

1 篇文章0 訂閱

訂閱專欄

1.window.print()

新建一個html直接復(fù)制粘貼,打開項目

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />

  <title>Document</title>

  <style>

    body {

      color: #000;

      font-family: "SimHei";

    }

    .prints {

      background-color: yellow;

      width: 100px;

      height: 50px;

      line-height: 50px;

      text-align: center;

    }

    .printss {

      width: 200px;

      height: 200px;

      line-height: 200px;

      text-align: center;

      border: 10px solid #000;

      margin-top: 30px;

    }

  </style>

</head>

<body>

  <div onclick="printData()" class="prints">打印按鈕</div>

  <script>

    // 打印的方法

    function printData() {

      var bdhtml = window.document.body.innerHTML; // 獲取body里面原本所有的內(nèi)容

      var printHtmls = `<div class="printss">壞女人今天中午吃什么?<div>`; // 想要打印的內(nèi)容,可以是組件、文字等

      window.document.body.innerHTML = printHtmls; // 因為 window.print()默認打印的是body里面所有的內(nèi)容,多以要講想要打印的內(nèi)容進行替換

      window.print(); // 打印

      window.document.body.innerHTML = bdhtml; // 講替換后的打印的內(nèi)容恢復(fù)到頁面本來的內(nèi)容

      window.location.reload(); //  重新加載頁面

    }

  </script>

</body>

</html>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

2.使用Printjs 自定義頁面

1.Printjs官網(wǎng)https://printjs.crabbly.com/

2.使用

1.下載到項目 npm install print-js --save

2.哪個模塊使用就引入import print from “print-js”;

3.訂單打印

   <!--  打印單 -->

    <div class="print-div visible" id="print_area">

      <div class="center bbt">xx商城</div>

      <!-- <div class="center bbt">{{orderDetails.shopName}}</div> -->

      <div class="print-1 bbt">

        <div class="display">

          <span>店員:{{ orderDetails.clerk }}</span>

          <span>機號:{{ orderDetails.MachineNumber }}</span>

          <span>收銀員:{{ orderDetails.cashier }}</span>

        </div>

        <div class="display">

          <span>出單時間:{{ orderDetails.userAddrOrder.createTime }}</span>

          <span>單號:{{ orderDetails.orderNumber }}</span>

        </div>

        <div class="print-table">

          <el-table class="el-table" :data="tableData" style="width: 100%">

            <el-table-column

              align="left"

              prop="tardeName"

              label="商品名稱"

              width="220"

            >

            </el-table-column>

            <el-table-column

              class="el-table-one"

              width="100"

              prop="amount"

              label="數(shù)量"

            >

            </el-table-column>

            <el-table-column prop="price" label="單價" width="100">

            </el-table-column>

            <el-table-column prop="money" label="金額"> </el-table-column>

          </el-table>

        </div>

      </div>

      <div class="print-2 bbt">

        <div class="display">

          <span>件數(shù):{{ orderDetails.productNums }} </span>

          <span>運費:{{ orderDetails.freightAmount }}元</span>

          <span>優(yōu)惠:{{ orderDetails.reduceAmount }}</span>

          <span>總價:{{ orderDetails.actualTotal }}</span>

        </div>

        <div class="display">

          <span>積分支付:{{ orderDetails.scoreReduce }} </span>

          <span

            >支付方式:{{

              ["積分支付", "微信支付", "支付寶"][orderDetails.payType]

            }}</span

          >

        </div>

      </div>

      <div class="print-3">

        <div class="display">

          <span>收貨人:{{ orderDetails.userAddrOrder.receiver }}</span>

          <span>聯(lián)系方式:{{ orderDetails.userAddrOrder.mobile }}</span>

        </div>

        <div class="display">

          <span

            >收貨地址:{{ orderDetails.userAddrOrder.province

            }}{{ orderDetails.userAddrOrder.city

            }}{{ orderDetails.userAddrOrder.area

            }}{{ orderDetails.userAddrOrder.addr }}</span

          >

        </div>

        <div class="display">

          <span>配送方式:{{ DvyType(orderDetails.dvyType) }}</span>

          <span>訂單類型:{{ OrderType(orderDetails.orderType) }} </span>

        </div>

        <!-- <div class="display">

          <span>配送時間:{{ orderDetails.DeliveryTime }}</span>

        </div> -->

        <div class="display">

          <span>門店熱線:{{ orderDetails.shopName }}</span>

          <span>門店地址:{{ orderDetails.shopAddress }} </span>

        </div>

        <div class="display">

          <span>備注:{{ orderDetails.remarks }}</span>

        </div>

        <h1>謝謝惠顧,歡迎下次光臨!</h1>

      </div>

    </div>

  /**

     * 打印訂單

     *

     */

    Printorder(order, MachineType) {

      this.$confirm(`確定打印訂單[${order.orderNumber}]`, "提示", {

        confirmButtonText: this.$i18n.t("shopFeature.edit.confirm"),

        cancelButtonText: this.$i18n.t("shopFeature.edit.cancel"),

        type: "warning",

      })

        .then(() => {

          this.$http({

            url: this.$http.adornUrl(

              `/order/order/printInfo/${order.orderNumber}`

            ),

            method: "get",

          })

            .then(({ data }) => {

              const { order, shopDetail } = data;

              console.log("???????? ~ .then ~ data", data);

              if (data) {

                const oldValue = {

                  clerk: "123", //店員

                  MachineNumber: "0050", //機號

                  cashier: "jdsf001", //收銀員

                };

                const { orderItems, userAddrOrder } = order;

                //訂單詳情字段

                this.orderDetails = { ...oldValue, ...order, ...shopDetail };

                //處理訂單商品

                const newData = orderItems.map((item) => {

                  const newObj = {

                    tardeName: `${item.prodName}【${item.skuName}】`,

                    amount: item.prodCount,

                    price: item.price,

                    money: item.productTotalAmount,

                  };

                  return newObj;

                });

                this.tableData = newData;

                const style =

                  "@page {  } " +

                  "@media print {    .print-table{padding-bottom: 15px;} .el-table .cell { text-align: left; line-height: 25px; } .el-table__body-wrapper .el-table__row td:nth-child(2) .cell{margin-left:20px}  .print-div {padding: 0px;font-size:10px  }.center { text-align: center; padding-bottom: 15px; font-size: 20px;font-weight: bold; }  .bbt { margin: 10px 0px 10px; border-bottom: 2px solid #000; } .display {  display: flex;  justify-content: space-between;  padding-bottom: 10px;  }";

                //處理打印改變

                const loading = this.$loading({

                  lock: true,

                  text: "Loading",

                  spinner: "el-icon-loading",

                  background: "rgba(0, 0, 0, 0.7)",

                });

                if (this.orderDetails) {

                  console.log(

                    "???????? ~ .then ~ this.orderDetails",

                    this.orderDetails

                  );

                  setTimeout(() => {

                    print({

                      printable: "print_area",

                      type: "html",

                      style: style, // 亦可使用引入的外部css;

                      scanStyles: false,

                    });

                    loading.close();

                  }, 1000);

                }

              }

              // this.$newMessage.success(this.$i18n.t('shopFeature.list.deleteSuccess'))

              // this.getMiniPagesList()

            })

            .catch((error) => {

              console.log("err", error);

            });

          // this.$notify({

          //   title: "成功",

          //   message: `打印成功[${order.orderNumber}]`,

          //   type: "success",

          // });

        })

        .catch(() => {});

    },

————————————————

版權(quán)聲明:本文為CSDN博主「Uxiao7」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接及本聲明。

原文鏈接:https://blog.csdn.net/Uxiao7/article/details/119827024

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
【音畫欣賞】真的好想你及代碼
網(wǎng)頁設(shè)計中當前正在訪問的導(dǎo)航欄高亮顯示的解決方案
Bootstrap柵格系統(tǒng)研究
同一個表單,進行批量刪除或批量其他操作時的方法
前端開發(fā)之div實現(xiàn)table表格系列教程一:創(chuàng)建表格
CSS實現(xiàn)水平垂直居中對齊
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服