乐造打印设置

1、前端

template-code="shipment-PrintModel" 打印模板页面 配置的Code唯一代码

复制代码
      <HiprintGeneral :print-data="printData" template-code="shipment-PrintModel">
        <template #default="{ startPrint }">
          <tips-icon icon="print" mode="button" type="primary" style="margin: 0 8px" @click="handlePrint(startPrint)">打印</tips-icon>
        </template>
      </HiprintGeneral>

2、JS实现

javascript 复制代码
//  打印数据,按模板要求将明细统一放入jobTasks字段
const printData = ref<any[]>([]);

const handlePrint = async (startPrint: (isPrint?: boolean) => void) => {
  if (!selectedRow.value) {
    message.warn('请先选择一条发运单');
    startPrint(false);
    return;
  }
  try {
    // 优先调用详情接口,确保打印包含完整明细而不是当前分页数据。
    const res = await queryById({ objId: selectedRow.value.objId }); //queryById:根据ID查询发运单详情(含明细)
    //主表数据
    const order = res?.code === '0' && res.data ? res.data : selectedRow.value;
    //明细数据
    const detailList = Array.isArray(order.detailList)
      ? order.detailList
      : ((await queryDetailByMainId({ mainId: order.objId }))?.data || []); // queryDetailByMainId:根据主表ID查询明细列表
    // 模板表头中的出库单号、仓库及机台号来源于首条发运明细。
    const firstDetail = detailList[0] || {};
    const printDetails = detailList.map((item: any, index: number) => ({
      ...item,
      // Author:Bingo Date:2026-09-09 打印序号从1开始,供Hiprint明细表直接绑定。
      _index: index + 1,
    }));
    printData.value = [{
      ...order,
      // Hiprint模板的明细表绑定字段为jobTasks。
      jobTasks: printDetails,
      // Author:Bingo Date:2026-09-09 打印合计:"物料明细行数"及"出库数量"之和。
      totalMaterialCount: printDetails.length,
      totalShipmentQty: printDetails.reduce((sum: number, item: any) => sum + (Number(item.tj0shipmentQty) || 0), 0),
    }];
    await nextTick();
    startPrint(true);
  } catch (error) {
    console.error('发运单打印数据查询失败', error);
    message.error('获取发运单打印数据失败');
    startPrint(false);
  }
};

Hiprint模板:shipment-PrintModel 对应的代码。

javascript 复制代码
{"codeData":{"panels":[{"index":0,"name":1,"height":210,"width":296.6,"paperHeader":24,"paperFooter":582,"printElements":[
{"options":{"left":18,"top":18,"height":16,"width":740,"title":"****有限公司","fontSize":18,"fontWeight":"bolder","textAlign":"center"},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":18,"top":40,"height":15,"width":740,"title":"发 运 单","fontSize":14,"fontWeight":"bolder","textAlign":"center"},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":680,"top":12,"height":62,"width":62,"field":"tj0shipmentOrderNo","hideTitle":true,"textType":"qrcode"},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":18,"top":76,"height":66,"width":740,"borderWidth":"0.75"},"printElementType":{"title":"矩形","type":"rect"}},
{"options":{"left":18,"top":98,"height":0,"width":740,"borderWidth":"0.75"},"printElementType":{"title":"横线","type":"hline"}},
{"options":{"left":18,"top":120,"height":0,"width":740,"borderWidth":"0.75"},"printElementType":{"title":"横线","type":"hline"}},
{"options":{"left":18,"top":76,"height":66,"width":0,"borderWidth":"0.75"},"printElementType":{"title":"竖线","type":"vline"}},
{"options":{"left":100,"top":76,"height":0,"width":0,"borderWidth":"0"},"printElementType":{"title":"竖线","type":"vline"}},
{"options":{"left":275,"top":76,"height":66,"width":0,"borderWidth":"0.75"},"printElementType":{"title":"竖线","type":"vline"}},
{"options":{"left":445,"top":76,"height":66,"width":0,"borderWidth":"0.75"},"printElementType":{"title":"竖线","type":"vline"}},
{"options":{"left":530,"top":76,"height":0,"width":0,"borderWidth":"0"},"printElementType":{"title":"竖线","type":"vline"}},
{"options":{"left":610,"top":76,"height":0,"width":0,"borderWidth":"0"},"printElementType":{"title":"竖线","type":"vline"}},
{"options":{"left":24,"top":82,"height":12,"width":72,"title":"发货通知单号"},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":105,"top":82,"height":12,"width":165,"field":"tj0shipmentOrderNo","hideTitle":true},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":281,"top":82,"height":12,"width":72,"title":"出库类型"},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":358,"top":82,"height":12,"width":82,"field":"outboundOrderType","hideTitle":true},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":451,"top":82,"height":12,"width":70,"title":"创建人"},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":535,"top":82,"height":12,"width":70,"field":"creatorName","hideTitle":true},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":24,"top":104,"height":12,"width":72,"title":"创建时间"},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":105,"top":104,"height":12,"width":165,"field":"createAt","hideTitle":true},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":281,"top":104,"height":12,"width":72,"title":"快递单号"},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":358,"top":104,"height":12,"width":82,"field":"tj0trackingNo","hideTitle":true},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":451,"top":104,"height":12,"width":70,"title":"承运公司"},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":535,"top":104,"height":12,"width":215,"field":"tj0carrier","hideTitle":true},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":24,"top":126,"height":12,"width":72,"title":"收货人"},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":105,"top":126,"height":12,"width":165,"field":"tj0receiverName","hideTitle":true},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":281,"top":126,"height":12,"width":72,"title":"收货电话"},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":358,"top":126,"height":12,"width":82,"field":"tj0receiverPhone","hideTitle":true},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":451,"top":126,"height":12,"width":70,"title":"收货地址"},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":535,"top":126,"height":12,"width":215,"field":"tj0receiveAddr","hideTitle":true},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":18,"top":150,"height":300,"width":740,"field":"jobTasks","tableBodyRowHeight":20.25,"columns":[[{"width":36,"title":"序号","field":"_index"},{"width":78,"title":"物料编号","field":"tj0materielCode"},{"width":130,"title":"物料名称","field":"tj0materialName"},{"width":62,"title":"调出仓库","field":"tj0sourceWarehouse"},{"width":62,"title":"调入仓库","field":"tj0InWareHouse"},{"width":80,"title":"领料单凭证号","field":"tj0MaterialRequisitionVouche"},{"width":58,"title":"是否SN管理","field":"tj0isSnManaged"},{"width":55,"title":"机台号","field":"tj0MachineNumber"},{"width":48,"title":"箱号","field":"boxNumber"},{"width":50,"title":"单位","field":"tj0unit"},{"width":81,"title":"客户名称","field":"customerName"},{"width":64,"title":"出库数量","field":"tj0shipmentQty"},{"width":54,"title":"备注","field":"remark"}]]},"printElementType":{"title":"表格","type":"table"}},
{"options":{"left":18,"top":458,"height":14,"width":220,"title":"合计出库物料:","field":"totalMaterialCount"},"printElementType":{"title":"文本","type":"text"}},
{"options":{"left":250,"top":458,"height":14,"width":220,"title":"合计出库数量:","field":"totalShipmentQty"},"printElementType":{"title":"文本","type":"text"}}
,{"options":{"left":18,"top":500,"height":14,"width":300,"title":"复核人:","fontFamily":"SimSun","fontSize":9},"printElementType":{"title":"文本","type":"text"}}
,{"options":{"left":430,"top":500,"height":14,"width":300,"title":"收货人:","fontFamily":"SimSun","fontSize":9},"printElementType":{"title":"文本","type":"text"}}
,{"options":{"left":18,"top":530,"height":0,"width":340,"borderWidth":"0.75"},"printElementType":{"title":"横线","type":"hline"}}
,{"options":{"left":430,"top":530,"height":0,"width":340,"borderWidth":"0.75"},"printElementType":{"title":"横线","type":"hline"}}
] }]}}
相关推荐
陈无左耳、2 年前
Hiprint 打印插件在 Vue3 中的深度剖析
vue3·hiprint
manson72302 年前
Odoo14使用hiPrint实现打印功能
python·odoo14·hiprint