前端实现分页打印(一)

news2025/1/20 3:41:55

实现页面为结算单,也页面由固定头部,订单信息,产品列表,金额汇总,订单明细
其中产品列表需要动态计算分压,订单明细由于存在多个子单,订单收费项目可配置化,导致也存在多个分页需要处理

效果预览在这里插入图片描述

存在的难点

  1. 分页,为了方便计算,产品列表的行高进行了固定
  2. 字体大小,由于web字体最小只能设置10像素,所以结算页面统一为12像素,打印模块使用缩放,进行缩小字体元素
  3. 背景,由于实用的printjs在生成pdf时会将background丢失,唯一能渲染出来的是边框颜色,所以背景都使用定位,叠加的方式实现

插件依赖

使用了printjs, printjs官方介绍: A tiny javascript library to help printing from the web.

页面开发及思路

  1. 对页面组件惊醒细化拆分
  2. 对拆分后的组件尽心分组,渲染
# 页面模块结构如下

invoice
|-    index.vue #页面入口文件
|-    hooks.ts # 抽离函数以及数据状态管理
|_    component # 页面组件
    |- ContentRender.vue # 渲染首页头部以及订单信息
    |- InvoiceHeader.vue # 首页头部
    |- OderInvoiceInfo.vue # 订单编号客户信息等
    |- ProductInfoRender.vue # 渲染产品列表
    |- ProductsTable.vue # 产品列表表格
    |- ProductTableTitle.vue # 表单自定义表头
    |- ProductInfoColumn.vue # 产品信息模块
    |- product-info-data.ts # 产品信息
    |- Summation.vue # 产品合计
    |- FeeDtailRender.vue # 产品明细渲染
    |- MergeOrderFeeDetail.vue # 遍历渲染订单明细
    |- OriginOrderFeeDetail.vue # 订单明细组件
    |- PageFooter.vue # 页面通用底部


代码模块书写

依赖数据 product-info-data.ts 呢日用

// table column solts
interface TableColumnSolts {
    title?: string;
    customRender: string;
}
// table column
export interface TableColumnItem {
    dataIndex: string;
    key: string;
    slots?: TableColumnSolts;
    title?: string | Function;
    titleStr?: string;
    tipContent?: string;
    [key: string]: any;
}
// 商品

export const customeTitleColumn: TableColumnItem[] = [
    {
        dataIndex: 'originQuantity',
        key: 'originQuantity',
        titleStr: '原单数量',
        tipContent: '订单第一次创建的数量',
        align: 'center',
        slots: {
            title: 'yuandan',
            customRender: 'quantity',
        },
    },
    {
        dataIndex: 'quantity',
        key: 'quantity',
        titleStr: '订单数量',
        tipContent: '主单+子单数量',
        align: 'center',
        slots: {
            title: 'dingdan',
            customRender: 'orderQuantity',
        },
    },
    {
        dataIndex: 'returnQuantity',
        key: 'returnQuantity',
        titleStr: '退货数量',
        align: 'center',
        tipContent: '主单+子单退货单据状态为[已完成]',
        slots: {
            title: 'tuihuo',
            customRender: 'quantity',
        },
    },
    {
        dataIndex: 'saleQuantity',
        key: 'saleQuantity',
        titleStr: '结算数量',
        align: 'center',
        tipContent: '订单数量-退货数量',
        slots: {
            title: 'jiesuan',
            customRender: 'quantity',
        },
    },
    {
        dataIndex: 'installQuantity',
        key: 'installQuantity',
        titleStr: '安装数量',
        align: 'center',
        tipContent: '安装数量-退货数量',
        slots: {
            title: 'anzhuang',
            customRender: 'quantity',
        },
    },
    {
        dataIndex: 'salesPrice',
        key: 'salesPrice',
        title: '单价(¥)',
        align: 'center',
        slots: {
            customRender: 'Price',
        },
    },
    {
        dataIndex: 'serviceFeeRatio',
        key: 'serviceFeeRatio',
        title: '服务费率',
        align: 'center',
        slots: {
            customRender: 'serviceFeeRatio',
        },
    },
    {
        dataIndex: 'unReturnNum',
        key: 'unReturnNum',
        titleStr: '退货未入库数量',
        tipContent: '产生退货,未进行入库',
        align: 'center',
        width: 85,
        slots: {
            title: 'noInWarehose',
            customRender: 'quantity',
        },
    },
    {
        dataIndex: 'unOrderNum',
        key: 'unOrderNum',
        titleStr: '安装未补单数量',
        tipContent: '已经安装,未进行补单',
        width: 85,
        align: 'center',
        slots: {
            title: 'noCreateOrder',
            customRender: 'quantity',
        },
    },
];
export const columns: TableColumnItem[] = [
    {
        dataIndex: 'index',
        key: 'index',
        title: '序号',
        align: 'center',
        slots: {
            customRender: 'Index',
        },
    },
    {
        dataIndex: 'productTypeName',
        key: 'productTypeName',
        title: '类别',
        width: 100,
        slots: {
            customRender: 'ProductType',
        },
    },
    {
        dataIndex: 'name',
        key: 'name',
        title: '产品名称',
        width: 204,
        slots: {
            customRender: 'ProductInfo',
        },
    },
    ...customeTitleColumn,
];

// 测试 多条数据拓展,自己可以循环多创建一些
export const testFeeList = [
    {
        id: 14,
        code: 'PRODUCT_FEE',
        name: '产品费',
        type: 1,
        value: 1,
        amount: 5664711.2,
        itemNum: 0,
        version: 235,
        required: 1,
        enableState: 1,
        allowDiscount: 1,
        lowestDiscount: 0.8,
        originalAmount: 7080889,
    },
];

export const resData = {
    id: 316,
    orderId: 'SO2022050156496',
    storeId: '8',
    storeName: '凉山门店',
    houseId: '253',
    projectNo: 'PM2022050554572',
    customerName: '张三100',
    customerPhone: '13510001100',
    linkman: '张三100',
    phone: '13510001100',
    principalId: 7,
    principal: '高富帅',
    area: '广东省深圳市南山区',
    type: 1,
    discountAmount: 0,
    adjustAmount: 0,
    amount: 43.29,
    paidAmount: 43.29,
    refundAmount: 0,
    status: 3,
    version: 0,
    productFeeVersion: 235,
    createTime: '2022-05-01T16:31:03',
    statProductAmount: 92.79,
    statServiceAmount: 0,
    statExtendAmount: 14.95,
    statDiscountAmount: 0,
    statAmount: 64.45,
    statPaidAmount: 0,
    statRefundAmount: 0,
    statRealReceiptAmount: 0,
    statChangeAmount: 21.16,
    statOriginAmount: 43.29,
    extendFeeList: [
        {
            id: 10,
            name: '产品费',
            code: 'PRODUCT_FEE',
            originalAmount: 43.29,
            discount: 10,
            amount: 43.29,
            version: 235,
            type: 1,
            value: 100,
            lowestDiscount: 5,
            allowDiscount: 1,
            required: 1,
            itemNum: 0,
        },
        ...testFeeList,
    ],
    itemList: [
        {
            skuId: 56,
            name: '门窗传感器 T1',
            productTypeName: '门窗传感器',
            freeGiftQuantity: 0,
            img:
                'https://retail-cos.aqara.cn/retail_image_prod/dd0bbffc0bdf409599e68a62e838bd49.png',
            sn: '6970504211186',
            specification: '门窗传感器 T1',
            unit: 'Pcs',
            quantity: 1.0,
            returnQuantity: 0.0,
            salesPrice: 43.29,
            serviceFee: 0,
            retailPrice: 43.29,
            discountPrice: 0.0,
            discountAmount: 0.0,
            salesAmount: 43.29,
            paidAmount: 0.0,
            price: 43.29,
            requireService: 0,
            returnAmount: 0.0,
        },
        {
            skuId: 3,
            name:
                'G10摄像机G10摄像机G10摄像机G10摄像机G10摄像机G10摄像机G10摄像机G10摄像机G10摄像机G10摄像机G10摄像机G10摄像机G10摄像机G10摄像机G10摄像机',
            freeGiftQuantity: 0,
            img: 'https://dev-img.aqaramaster.com/uat/product/image/20220110/8/G2H黄-T1.png',
            sn: 'FSZJ-G10-0001',
            specification: '绿色',
            productTypeName:
                '摄像摄像机摄像机摄像机摄像机摄像机摄像机摄像机摄像机摄像机摄像机摄像机摄像机摄像机机',
            unit: '厘米',
            originQuantity: 555.0,
            quantity: 566.0,
            returnQuantity: 566,
            saleQuantity: 566.0,
            installQuantity: 566.0,
            salesPrice: 566.9,
            serviceFee: 566,
            unOrderNum: 566,
            retailPrice: 566666666,
            discountPrice: 566666666,
            discountAmount: 566666666,
            salesAmount: 566666666,
            paidAmount: 566666666,
            price: 5666,
            requireService: 5666,
            returnAmount: 5666,
        },
    ],
    // 子单数据
    subOrders: [
        {
            id: 433,
            orderId: 'SO2022111547851',
            storeId: '8',
            houseId: '253',
            customerName: '张三100',
            customerPhone: '13510001100',
            linkman: '张三100',
            phone: '13510001100',
            principalId: 7,
            principal: '高富帅',
            area: '广东省深圳市南山区',
            type: 1,
            discountAmount: 0.0,
            adjustAmount: 0.0,
            amount: 64.45,
            paidAmount: 0.0,
            refundAmount: 0.0,
            status: 1,
            version: 0,
            createTime: '2022-11-15T15:55:28',
            statProductAmount: 0,
            statServiceAmount: 0,
            statExtendAmount: 0,
            statDiscountAmount: 0,
            statAmount: 0,
            statPaidAmount: 0,
            statRefundAmount: 0,
            statRealReceiptAmount: 0,
            statChangeAmount: 0,
            statOriginAmount: 0,
            extendFeeList: [
                {
                    id: 58,
                    name: '扯皮费',
                    originalAmount: 10,
                    discount: 10,
                    amount: 10,
                    version: 302,
                    type: 2,
                    value: 10,
                    lowestDiscount: 6,
                    allowDiscount: 0,
                    required: 1,
                    itemNum: 0,
                    enableState: 1,
                },
                {
                    id: 24,
                    name: '延保定金-固定非必收不允许打折50',
                    originalAmount: 50.25,
                    amount: 50.25,
                    version: 302,
                    type: 2,
                    value: 50.25,
                    lowestDiscount: 5,
                    allowDiscount: 1,
                    required: 0,
                    itemNum: 0,
                    enableState: 0,
                },
                {
                    id: 22,
                    name: '安装费-比例必收不允许打折10',
                    originalAmount: 4.95,
                    discount: 10,
                    amount: 4.95,
                    version: 302,
                    type: 1,
                    value: 10,
                    lowestDiscount: 10,
                    allowDiscount: 0,
                    required: 1,
                    itemNum: 0,
                    enableState: 1,
                },
                ...testFeeList,
            ],
            itemList: [
                {
                    skuId: 3,
                    name: 'G10摄像机',
                    freeGiftQuantity: 0,
                    img:
                        'https://dev-img.aqaramaster.com/uat/product/image/20220110/8/G2H黄-T1.png',
                    sn: 'FSZJ-G10-0001',
                    specification: '绿色',
                    unit: '厘米',
                    quantity: 5.0,
                    returnQuantity: 0.0,
                    salesPrice: 9.9,
                    serviceFee: 0,
                    retailPrice: 9.9,
                    discountPrice: 0.0,
                    discountAmount: 0.0,
                    salesAmount: 49.5,
                    paidAmount: 0.0,
                    price: 12.89,
                    requireService: 0,
                    returnAmount: 0.0,
                },
            ],
        },
    ],
};

index.vue 内容

<template>
    <div class="order-invoice">
        <div class="order-invoice-header">
            <h3 class="order-invoice-title">结算单</h3>
            <div class="btn-wrap">
                <a-button @click="goBack">
                    返回
                </a-button>

                <a-button @click="printPage">
                    打印结算单
                </a-button>
            </div>
        </div>
        <div class="PrintOrderInvoiceWrap">
            <div class="print-content" id="PrintOrderInvoice">
                <ContentRender :isPrintModel="true" />
                <ProductTableRender :isPrintModel="true" />
                <Summation />
                <FeeDetailRender />
            </div>
        </div>
        <div class="order-invoce-content" id="PrintOrderInvoiceWeb">
            <ContentRender />
            <ProductTableRender />
            <Summation />
            <FeeDetailRender />
        </div>
    </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import ContentRender from './component/ContentRender.vue';
import ProductTableRender from './component/ProductInfoRender.vue';
import Summation from './component/Summation.vue';
import FeeDetailRender from './component/FeeDtailRender.vue';

// const { pageList } = useCalcProductPages();
export default defineComponent({
    name: 'OrderInvoice',
    components: {
        ContentRender, // 结算单信息
        ProductTableRender, // 结算单产品列表
        Summation, // 费用合计
        FeeDetailRender, // 费用明细
    },
    setup() {
        // 返回上一页面
        const goBack = () => {
            router.back();
        };
        
        const printPage = () => {
            
            return false;
        };

        return {
            checkFormInfo,
            printPage,
            goBack,
        };
    },
});
</script>

<style lang="less" scoped>
@import url('~@/less/mixin');
.order-invoice {
    background-color: @white;
    .bR();
    margin-top: 16px;
    padding-bottom: 16px;
    font-size: 12px;
    color: #000;
}
.order-invoice-header {
    .box();
    height: 48px;
    padding: 0 24px;
    border-bottom: 1px solid @border-color;
    .order-invoice-title {
        font-size: @font-xl;
        color: @font-black;
        font-weight: 500;
    }
    .ant-btn {
        margin-left: 10px;
    }
}
.order-invoce-content {
    padding: 0 24px;
}
</style>
<style lang="less">
.PrintOrderInvoiceWrap {
    position: absolute;
    right: 99999999cm;
}
// 打印配置值
#PrintOrderInvoice {
    width: 278mm;
    padding: 12px 32px 32px;
    box-sizing: border-box;
    font-size: 9px;
    color: #000;
    .order-invoice-header {
        .small-title {
            width: 60mm;
            transform: scale(0.76) translate(30px, 13px);
        }
    }
    .print-font {
        transform: scale(0.75);
    }
    .order-invoices-product-table-wrap .order-invoice-table {
        min-width: 278mm;
    }
}
</style>

ProductInfoRender 代码书写

<template>
    <div class="order-invoice-product-render">
        <div class="table-list">
           <!-- table-item 每个item是一页,需要定宽定高 -->
            <div
                class="table-item"
                :class="{
                    otherProductList: key > 0,
                }"
                v-for="(page, key) in pageList"
                :key="key"
            >
                <ProductTable :data="page" :pageIndex="key" />
                <PageFooter
                    :currentPage="key"
                    :style="{
                        marginTop: getMarginButtom(page.length, key) + 'px',
                    }"
                />
                <!-- 需要做换行处理 -->
                <div class="empty-box" v-if="key === 0"></div>
            </div>
        </div>
    </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import ProductTable from './ProductsTable.vue';
import PageFooter from './PageFooter.vue';

export default defineComponent({
    name: 'OrderInvoiceProductRender',
    components: {
        ProductTable,
        PageFooter,
    },
    props: {
        isPrintModel: {
            type: Boolean,
            default: false,
        },
    },
    setup(props) {
        const pageList = []

        const getMarginButtom = (): number  => {
           return 0
        };

        return {
            pageList,
            getMarginButtom,
        };
    },
});
</script>

<style lang="less" scoped>
.table-item {
    margin-bottom: 4px;
}
.otherProductList {
    margin-top: 32px;
    margin-bottom: 0;
}
#PrintOrderInvoice {
    .order-invoice-product-render {
        min-width: 274mm;
        :deep(.page-footer) {
            transform: translateY(28px);
        }
    }
    .empty-box {
        min-height: 58px;
        min-width: 274mm;
    }
    .otherProductList {
        margin-top: 0;
        // min-height: 210mm;
        height: 793px;
        padding-top: 50px;
        min-width: 1036px;
        box-sizing: border-box;
    }
}
// 处理页面在没有加载出来的时候 会有抖动的问题
#PrintOrderInvoiceWeb {
    .order-invoice-product-render {
        min-height: 579px;
    }
}
</style>


ProductsTable.vue 相关代码

由于打印的时候 需要定制话,antd自带的table相对比较麻烦。所以web显示 使用antd的table组件,打印使用自己手写的table

<template>
    <div class="order-invoices-product-table-wrap">
        <!-- 只有在网页并且第一个产品列表才显示 -->
        <div class="info-tip-column" v-if="pageIndex === 0 && !isPrintModel">
            <div class="info-tip-item">结算单</div>
            <div class="info-tip-item">需退库(补单)的产品数量</div>
        </div>
        <div class="custom-table-wrap" v-if="isPrintModel">
            <div class="print-table-bg-div"></div>
            <div class="print-table-title-line"></div>
            <table class="print-table-header">
                <thead>
                    <tr class="title-tr">
                        <th v-for="column in initColumns()" :key="column.key">
                            {{ column.title ? column.title : column.titleStr }}
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(info, idx) in data" :key="info.skuId">
                        <td class="num-td">
                            <div class="tab-td-content-wrap">{{ idx + 1 }}</div>
                        </td>
                        <td class="product-type-td">
                            <div class="tab-td-content-wrap">{{ info.productTypeName }}</div>
                        </td>
                        <td class="product-name-td">
                            <ProductInfoColumn :info="info" />
                        </td>
                        <td class="num-td">
                            <div class="tab-td-content-wrap">{{ info.originQuantity }}</div>
                        </td>
                        <!-- 订单数量 -->
                        <td class="num-td">
                            <div class="tab-td-content-wrap">{{ info.quantity }}</div>
                        </td>
                        <td class="num-td">
                            <div class="tab-td-content-wrap">{{ info.returnQuantity }}</div>
                        </td>
                        <td class="num-td">
                            <div class="tab-td-content-wrap">{{ info.saleQuantity }}</div>
                        </td>
                        <td class="num-td">
                            <div class="tab-td-content-wrap">{{ info.installQuantity }}</div>
                        </td>

                        <td class="num-td">
                            <div class="tab-td-content-wrap">
                                {{ filterPrice(info.salesPrice) }}
                            </div>
                        </td>
                        <td class="num-td">
                            <div class="tab-td-content-wrap">{{ info.serviceFeeRatio }}%</div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <a-table
            :columns="initColumns()"
            :data-source="data"
            size="small"
            :pagination="false"
            :bordered="true"
            :style="{ marginBottom: getMarginButtom() + 'px' }"
            :rowKey="(record) => record.skuId"
            class="order-invoice-table"
            v-else
        >
            <!-- 序号 -->
            <template #Index="{ index }">
                <div>{{ index + 1 }}</div>
            </template>
            <template #ProductType="{ text }">
                <div class="ProductTypeDiv">{{ text }}</div>
            </template>
            <template #ProductInfo="{ record }">
                <ProductInfoColumn :info="record" />
            </template>
            <template #name="{ text }">
                <a>{{ text }}</a>
            </template>
            <!-- 价格 -->
            <template #Price="{ text }">
                <div>¥{{ filterPrice(text || 0) }}</div>
            </template>
            <!-- 数量 -->
            <template #orderQuantity="{ text, record }">
                <div>
                    {{ text || 0
                    }}{{ record.freeGiftQuantity ? ` 赠品:${record.freeGiftQuantity}` : '' }}
                </div>
            </template>
            <!-- 数量 -->
            <template #quantity="{ text }">
                <div>{{ text || 0 }}</div>
            </template>
            <!-- 服务费率 -->
            <template #serviceFeeRatio="{ text }">
                <div>{{ text || 0 }}%</div>
            </template>
            <!-- 处理自定义title -->
            <template
                v-for="item in customeTitleColumn"
                :key="item.slots.title"
                #[item.slots.title]
            >
                <ProductTableTitle
                    :info="item"
                    :isPrintModel="isPrintModel"
                    :class="{
                        width78: ['noInWarehose', 'noCreateOrder'].includes(item.slots.title),
                    }"
                />
            </template>
        </a-table>
    </div>
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue';
import { filterPrice } from '@/components/calculate-price/calculate';
import { columns, customeTitleColumn, TableColumnItem } from './product-info-data';
import ProductTableTitle from './ProductTableTitle.vue';
import ProductInfoColumn from './ProductInfoColumn.vue';

const { calcProductTableMarginBottom } = useCalcProductPages();
export default defineComponent({
    name: 'OrderInvoicesProductsTable',
    props: {
        data: {
            type: Array as PropType<any[]>,
            default() {
                return [];
            },
        },
        pageIndex: {
            type: Number as PropType<number>,
            default: 0,
        },
        isPrintModel: {
            type: Boolean,
            default: false,
        },
    },
    components: {
        ProductTableTitle, // 自定义提示表头
        ProductInfoColumn, // 产品信息
    },
    setup(props: { pageIndex: number; data: any[]; isPrintModel: boolean }) {
        const getMarginButtom = (): number => {
            // 首页margin bottom 处理
            const marginBottom = 10

            return marginBottom;
        };
        // 打印模式下 部分信息不打印
        const initColumns = (): TableColumnItem[] => {
            if (props.isPrintModel) {
                return columns.slice(0, -2);
            }
            return columns;
        };
        // 这个函数不重要 就不写了
        const filterPrice = (price: any): any => price;
        return {
            initColumns,
            customeTitleColumn,
            getMarginButtom,
            filterPrice, // 价格过滤函数
        };
    },
});
</script>

<style lang="less" scoped>
@lineHeight: 44px;
.order-invoices-product-table-wrap {
    position: relative;
    .ant-table-wrapper .ant-table-body tr > td {
        padding: 5px;
    }
    .width85 {
        width: 78px;
    }
    .order-invoice-table {
        margin-bottom: 16px;
    }
    .info-tip-column {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 39px;
        background: #d6d7d7;
        text-align: center;
        border-bottom: 2px solid #000;
    }
    .info-tip-item:nth-of-type(1) {
        flex: 1;
    }
    .info-tip-item:nth-of-type(2) {
        min-width: 170px;
        line-height: 38px;
        border-left: 1px solid #62647a;
    }
    :deep(.ant-table .ant-table-content .ant-table-thead tr) {
        height: 39px;
    }
    :deep(.ant-table .ant-table-content .ant-table-thead tr th) {
        background: #d6d7d7;
        padding: 0 !important;
        line-height: 19px;
        border-color: #d6d7d7;
        border-bottom-color: #3e415c;
    }
    :deep(.ant-table.ant-table-small
            > .ant-table-content
            > .ant-table-body
            > table
            > .ant-table-tbody
            > tr
            > td) {
        padding: 0 5px !important;
        height: @lineHeight;
    }
    .ProductTypeDiv {
        max-width: 100px;
        overflow: hidden;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        text-overflow: ellipsis;
        white-space: break-spaces;
    }

    .print-table-header {
        width: 100%;
        min-width: 274mm;
        max-width: 274mm;
        position: relative;
        border: 2px solid #dfdfdf;
        border-collapse: collapse;
        z-index: 2;
        th {
            height: @lineHeight;
            text-align: center;
            transform: scale(0.76);
        }
        td {
            height: @lineHeight;
            border: 2px solid #dfdfdf;
            transform: scale(0.76);
        }
        .title-tr {
            border-bottom: 2px solid #000;
            position: relative;
            z-index: 2;

            // background: #d6d7d7;
            height: @lineHeight;
        }

        .product-name-td {
            width: 204px;
        }
        .num-td {
            text-align: center;
        }
        :deep(.product-img) {
            scale: 1.2;
        }
        .tab-td-content-wrap {
            min-width: 120%;
            transform: translate(-8%, -42%);
            max-width: 60px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            position: absolute;
        }
        .product-type-td {
            min-width: 60px;
        }
    }
    .print-table-bg-div {
        border-bottom: @lineHeight solid #d6d7d7;
        width: 100%;
        min-width: 274mm;
        position: absolute;
        z-index: 1;
    }
    .print-table-title-line {
        border-bottom: 2px solid #000;
        width: 100%;
        min-width: 274mm;
        position: absolute;
        z-index: 4;
        transform: translateY(44px);
    }
}
#PrintOrderInvoice {
    .order-invoices-product-table-wrap {
        font-size: 9px;
    }
}
</style>

ContentRender 代码书写

<template>
    <div class="order-invoice-content-render">
        <InvoiceHeader v-if="isPrintModel" />
        <OrderInvoiceInfo />
    </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import InvoiceHeader from './InvoiceHeader.vue';
import OrderInvoiceInfo from './OderInvoiceInfo.vue';

export default defineComponent({
    name: 'OrderInvoceContentRender',
    components: {
        InvoiceHeader,
        OrderInvoiceInfo,
    },
    props: {
        isPrintModel: {
            type: Boolean,
            default: false,
        },
    },
    setup() {
        return {};
    },
});
</script>

<style>
.order-invoice-content-render {
    background-color: #fff;
    min-width: 274mm;
}
</style>

OriginOrderFeeDetail.vue 费用详情相关

订单汇急速一个固定的页面,这里不补齐,只有这个费用明细 需要合并 多个,以及是否展示页面通用底部 所贴上来

<template>
    <div
        class="origin-order-fee-detail"
        :class="{
            feeDetailTop: info && info.showFooter,
            lastFeeDetailTop: info && info.isLastFeeDetail,
        }"
    >
        <div class="origin-order-fee-title-bg"></div>
        <div class="origin-order-fee-title">
            <div class="scale-font">{{ title }}({{ info ? info.orderId : '' }})</div>
        </div>
        <div class="price-info-wrap" :style="{ ...(info ? info.marginBottom : {}) }">
            <div
                class="price-info-content"
                v-for="(item, key) in getExtendFeeList(info)"
                :key="key"
            >
                <div class="price-info-item">
                    <div
                        class="price-info-item-label"
                        :class="{ overLength: item.name && item.name.length > 14 }"
                        :title="item.name"
                    >
                        <div class="scale-font">{{ item.name }}</div>
                    </div>
                    <div class="price-info-item-value">
                        <div class="scale-font">{{ item.originalAmount }}</div>
                    </div>
                </div>
                <div class="price-info-item">
                    <div class="price-info-item-label">
                        <div class="scale-font">折扣</div>
                    </div>
                    <div class="price-info-item-value">
                        <div class="scale-font">{{ item.discount }}</div>
                    </div>
                </div>
                <div class="price-info-item">
                    <div class="price-info-item-label">
                        <div class="scale-font">应收金额</div>
                    </div>
                    <div class="price-info-item-value">
                        <div class="scale-font">{{ item.amount }}</div>
                    </div>
                </div>
            </div>
        </div>
        <PageFooter v-show="info ? info.showFooter : false" :currentPage="currentPage" />
    </div>
</template>

<script lang="ts">
import { computed, defineComponent, PropType } from 'vue';
import { OrderFeeDetailInfo, CostConfigItem } from '../hooks';
import PageFooter from './PageFooter.vue';

export default defineComponent({
    name: 'OriginOrderFeeDetail',
    components: {
        PageFooter,
    },
    props: {
        title: {
            type: String,
            default: '订单-费用明细',
        },
        info: {
            type: Object as PropType<OrderFeeDetailInfo>,
        },
        startIndex: {
            type: Number,
            default: 0,
        },
    },
    setup(props) {
        const getExtendFeeList = (info: OrderFeeDetailInfo | null): CostConfigItem[] => {
            if (info) {
                return info.extendFeeList;
            }
            return [];
        };
        const currentPage = computed(() => {
            const index: number = props.info ? props.info.pageIndex + props.startIndex : 0;
            return index;
        });
        return {
            getExtendFeeList,
            currentPage,
        };
    },
});
</script>

<style lang="less" scoped>
@height: 30px;
@printWidth: 274mm;
.origin-order-fee-detail {
    text-align: center;

    color: #000;
    padding-bottom: 16px;
    &.feeDetailTop {
        margin-bottom: 0;
    }
    .origin-order-fee-title {
        height: @height;
        line-height: @height;
        background: #d6d7d7;
        border-bottom: 2px solid #000;
        text-align: center;
    }
    .price-info-wrap {
        border-bottom: 1px solid #dfdfdf;
        border-left: 1px solid #dfdfdf;
        .price-info-content .price-info-item:nth-of-type(3) {
            border-right-width: 1px;
        }
    }
    .price-info-content {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        flex-wrap: wrap;
        border: 1px solid #dfdfdf;
        border-bottom: 0;
        text-align: right;
        min-width: 100%;
    }
    .price-info-item {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        border-bottom: 1px solid #dfdfdf;
        border-right: 2px solid #dfdfdf;
    }
    .price-info-item-label,
    .price-info-item-value {
        min-width: 50%;
        line-height: @height;
        padding: 0 8px;
        box-sizing: border-box;
        height: @height;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .price-info-item-label {
        border-right: 2px solid #dfdfdf;
    }
}

#PrintOrderInvoice {
    .origin-order-fee-detail {
        min-width: @printWidth;
        position: relative;
        margin-top: -2px;
        .price-info-item,
        .price-info-item-label {
            border-width: 2px;
        }
    }
    .scale-font {
        width: 132%;
        overflow: hidden;
        transform: scale(0.76) translate(-17%, 6%);
    }

    .lastFeeDetailTop {
        padding-top: 28px;
        margin-bottom: 0;
    }
    .origin-order-fee-title,
    .price-info-wrap {
        min-width: @printWidth;
    }
    .origin-order-fee-title {
        position: relative;
        z-index: 3;
        background: transparent;
        .scale-font {
            transform: scale(0.76) translate(5%, 0);
        }
    }
    .origin-order-fee-title-bg {
        border-bottom: @height solid #d6d7d7;
        min-width: @printWidth;
        position: absolute;
        z-index: 1;
    }
}
</style>

PageFooter.vue

主要显示自定义脚注信息,分页信息等

<template>
    <div class="page-footer">
        <div class="info-item">
            {{ checkFormInfo.storeName }}
            /{{ checkFormInfo.principal }} / {{ checkFormInfo.principalPhone }}
        </div>
        <div class="info-item right-info-item">
            第 {{ currentPage + 1 }} 页/共 {{ paginationInfo.totalPageSize }} 页
        </div>
    </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { useLoadCheckFormInfo, usePaginationInfo } from '../hooks';

export default defineComponent({
    name: 'OrderInvoicePageFooter',
    props: {
        currentPage: {
            type: Number,
            default: 0,
        },
    },
    setup() {
        const { checkFormInfo } = useLoadCheckFormInfo();
        const { paginationInfo } = usePaginationInfo();
        return { checkFormInfo, paginationInfo };
    },
});
</script>

<style lang="less" scoped>
.page-footer {
    line-height: 20px;
    color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
#PrintOrderInvoice {
    .page-footer {
        min-width: 274mm;
        font-size: 9px;
        .info-item {
            width: 160mm;
            text-align: left;
            transform: scale(0.76) translate(-14%);
        }
        .right-info-item {
            width: 60mm;
            text-align: right;
            transform: scale(0.76) translate(14%);
        }
    }
}
</style>

总结

  1. 以上 主要贴出了主要代码
  2. 关于分页,为了方便处理 将产品列表,收费明细进行了组件化渲染,方便进行控制以及固定宽高(物理打印A4是固定的宽高)
  3. 其次 web展示和打印是有显示差异化 js逻辑 使用一个isPrintModel判断,css相关的使用一个标签包裹,并设置id=PrintOrderInvoice,printjs打印需要一个dom id 作为选择器,所以 就使用id作为趣分类额
  4. 最后,关于计算的逻辑 我放到另外一个开个一篇,否则代码量太大,没法看

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/93049.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Apereo Cas在项目中接入

1.介绍 Apereo CAS的一个功能就是单点登录&#xff0c;统一的登录登出接口与页面&#xff0c;让系统中的模块只需要关注在业务点&#xff0c;而把安全认证的功能交给统一认证来做。所以客户端的集成主要是单点登录的集成&#xff0c;客户端指定需要做安全认证的页面&#xff0…

8年软件测试工程师感悟—我亲身经历的2022年软件质量工作

这两天和朋友谈到软件测试的发展&#xff0c;其实软件测试已经在不知不觉中发生了非常大的改变&#xff0c;前几年的软件测试行业还是一个风口&#xff0c;随着不断地转行人员以及毕业的大学生疯狂地涌入软件测试行业&#xff0c;目前软件测试行业“缺口”已经基本饱和。当然&a…

PyTorch深度学习框架学习记录(2)--MNIST手写数字识别(续)

文章目录前言MNIST手写数字识别数据的准备工作数据的处理主干网络的定义损失函数的使用&#xff08;修改&#xff09;训练和预测运行前言 这个是我在学习中的其中一种方式实现MNIST手写的识别&#xff0c;思路我觉得比较清晰&#xff0c;后面会把另外的方法代码整理发布。 MN…

是否有 API 可供云对接?

涂鸦提供了两种维度供开发者拉取&#xff1a;应用维度、产品维度。 应用维度&#xff1a;设备绑定的用户属于开发者在涂鸦云应用中的用户&#xff0c;开发者间接拥有权限操作属于自己应用用户的设备&#xff1b; 产品维度&#xff1a;设备所属产品属于开发者在涂鸦云产品中的设…

2022年总结:道阻且长,行则将至

前言 今年是第四个年头写总结了&#xff0c;直到这个时候&#xff0c;我仍未想出今年的标题是什么。 2019年总结&#xff0c;平凡的我仍在平凡的生活 2020年总结&#xff0c;所有努力只为一份期待 2021年总结&#xff1a;前路有光&#xff0c;初心莫忘 如果非得用一句话来…

(Java)SpringMVC学习笔记(二)

前言 继续学习SpringMVC视频教程&#xff0c;争取今明后三天把设定的目标完成 SpringMVC 框架搭建 这一步花了我一上午时间&#xff0c;报了个404错误&#xff0c;没办法&#xff0c;只能从头开始创建项目&#xff08;心态差点整爆炸&#xff0c;第一次是自认不懂&#xff0…

格力博通过创业板注册:上半年营收32亿 拟募资34.56亿

雷递网 雷建平 12月15日格力博&#xff08;江苏&#xff09;股份有限公司&#xff08;简称&#xff1a;“格力博”&#xff09;日前通过注册&#xff0c;准备在深交所创业板上市。格力博计划募资34.56亿元&#xff0c;其中&#xff0c;11.69亿元用于年产500万件新能源园林机械智…

【从零开始学习深度学习】25.卷积神经网络之LeNet模型介绍及其Pytorch实现【含完整代码】

目录1. LeNet模型介绍与实现2. 输入为Fashion-MNIST时各层输出形状3. 获取Fashion-MNIST数据和并使用LeNet模型进行训练4.完整代码之前我们对Fashion-MNIST数据集中的图像进行分类时&#xff0c;是将28*28图像中的像素逐行展开&#xff0c;得到长度为784的向量&#xff0c;并输…

Spring Cloud基于JWT创建统一的认证服务

认证服务肯定要有用户信息&#xff0c;不然怎么认证是否为合法用户&#xff1f;因为是内部的调用认证&#xff0c;可以简单一点&#xff0c;用数据库管理就是一种方式。或者可以配置用户信息&#xff0c;然后集成分布式配置管理就完美了。 表结构 本教程中的案例把查数据库这…

2022-年终总结

2022年已经到了尾声&#xff0c;后半年度过的太漫长了&#xff0c;也是自己这两年来成长速度最快的一次了&#xff08;后文揭晓&#xff09; 今年的年中总结链接 上半年我沉浸在读各类技术书籍中&#xff0c;但是后半年的我几乎放弃了读书&#xff0c;转而投身到另外一个学习渠…

Linux Phy 驱动解析

文章目录1. 简介2. phy_device2.1 mdio bus2.2 mdio device2.3 mdio driver2.4 poll task2.4.1 自协商配置2.4.2 link 状态读取2.4.3 link 状态通知3. phylink3.1 phylink_create()3.2 phylink_connect_phy()3.3 phylink_start()3.3 poll task参考资料1. 简介 在调试网口驱动的…

从另外一个角度解释AUC

AUC到底代表什么呢&#xff0c;我们从另外一个角度解释AUC&#xff0c;我们先看看一个auc曲线 蓝色曲线下的面积(我的模型的AUC)比红线下的面积(理论随机模型的AUC)大得多&#xff0c;所以我的模型一定更好。 我的模型比随机模型好多少呢?理论随机模型只是对角线&#xff0c;…

加密与认证技术

加密与认证技术密码技术概述密码算法与密码体制的基本概念加密算法与解密算法秘钥的作用什么是密码密钥长度对称密码体系对称加密的基本概念典型的对称加密算法DES加密算法3DES加密算法非对称密码体系非对称加密基本概念密码技术概述 密码技术是保证网络安全的核心技术之一&am…

【windows Server 2019系列】 构建IIS服务器

个人名片&#xff1a; 对人间的热爱与歌颂&#xff0c;可抵岁月冗长&#x1f31e; Github&#x1f468;&#x1f3fb;‍&#x1f4bb;&#xff1a;念舒_C.ying CSDN主页✏️&#xff1a;念舒_C.ying 个人博客&#x1f30f; &#xff1a;念舒_C.ying Web服务器也称为WWW(World W…

电子厂测试题——难倒众多主播——大司马也才90分

一、选择题 1、1-2 ( ) A.1 B.3 C.-1 D.-3 2、|1-2|( ) A.1 B.3 C. -1 D.-3 3、1x2x3( ) A.5 B.6 C.7 D.8 4、3643( ) A.29 B.16 C.8 D.3 5、55x5( ) A.15 B.30 C.50 D.125 二、填空题(请填写阿拉伯数字) 6、110100 1000_______ 7、一个三角形砍去1个角&#…

Feign的两种最佳实践方式介绍

何谓最佳实践呢&#xff1f;就是企业中各种踩坑&#xff0c;最后总结出来的相对比较好的使用方式&#xff1b; 下面给大家介绍两种比较好的实践方案&#xff1a; 方式一&#xff08;继承&#xff09;&#xff1a;给消费者的FeignClient和提供着的Controller定义一个统一的父接…

在逆变器中驱动和保护IGBT

在逆变器中驱动和保护IGBT 介绍 ACPL-339J是一款先进的1.0 A双输出&#xff0c;易于使用&#xff0c;智能的手机IGBT门驱动光耦合器接口。专为支持而设计MOSFET制造商的各种电流评级&#xff0c;ACPL-339J使它更容易为系统工程师支持不同的系统额定功率使用一个硬件平台通过…

全面解析若依框架(springboot-vue前后分离--后端部分)

1、 若依框架分解 - 启动配置 前端启动 # 进入项目目录 cd ruoyi-ui# 安装依赖 npm install# 强烈建议不要用直接使用 cnpm 安装&#xff0c;会有各种诡异的 bug&#xff0c;可以通过重新指定 registry 来解决 npm 安装速度慢的问题。 npm install --registryhttps://regist…

算法刷题打卡第47天:排序数组---归并排序

排序数组 难度&#xff1a;中等 给你一个整数数组 nums&#xff0c;请你将该数组升序排列。 示例 1&#xff1a; 输入&#xff1a;nums [5,2,3,1] 输出&#xff1a;[1,2,3,5]示例 2&#xff1a; 输入&#xff1a;nums [5,1,1,2,0,0] 输出&#xff1a;[0,0,1,1,2,5]归并排…

用CSS给健身的侣朋友做一个喝水记录本

前言 事情是这样的&#xff0c;由于七八月份的晚上时不时就坐在地摊上开始了喝酒撸串的一系列放肆的长肉肉项目。 这不&#xff0c;前段时间女朋友痛下决心&#xff08;心血来潮&#xff09;地就去报了一个健身的私教班&#xff0c;按照教练给的饮食计划中&#xff0c;其中有一…