import moment from 'moment'; import { Platform, AsyncStorage, NativeModules } from 'react-native'; import { IPrinterData, IOrderInfo, IPrintWare } from './types'; import { Printer_start, Printer_additem, Printer_end, printDriver, print, devices } from './printer'; const WeightUnits = [ { value: '公斤', rate: 1000 }, { value: '斤', rate: 500 }, { value: '100克', rate: 100 }, { value: '50克', rate: 50 }, { value: '克', rate: 1 }, ]; function endWith(s1, s2) { const d = s1.length - s2.length; return d >= 0 && s1.lastIndexOf(s2) == d; } function isPrint(text0) { return ( endWith(text0, ':--') || endWith(text0, ':0') || endWith(text0, ':0.00') || endWith(text0, ':') || endWith(text0, ': ') || endWith(text0, ':undefined') || endWith(text0, ':0(0)') ); } /** * 小票id * @type {string} */ const tempPrintCount = { count: '', printTimes: 1 }; const printReceipt = { refund: {}, offlineCashier: {}, carSaleOrder: {}, onlineOrder: {}, onlineRefund: {}, exit: {}, }; /** * 打印机初始化 */ const printerInit = () => {}; /** * 打印机销毁 */ const printerDestroy = () => {}; const printOrderByDevice = ( devices: Array, printData: IPrinterData, templateType: | string | 'order' | 'returnOrder' | 'reprintOrder' | 'carSaleOrder' | 'onlineOrder' | 'onlineRefund' | 'exit', printWare: IPrintWare, ) => { return new Promise(resolve => { AsyncStorage.getItem('ENABLE_PRINT', async (_, res) => { // if (err) console.log(err); if (null == res || Boolean(res)) { printDriver(printWare.device.brand, printWare.device.model); //初始化打印序号 if (!printWare.isOnline || printData.printNumber == '') { printData.printNumber = tempPrintCount.count; tempPrintCount.count = ''; } console.log('-------------------开始打印---------------------', printData); const items = devices; console.log('items =>', items); const tasks = items.map(device => async () => { // devices.forEach(device => { console.log('-------------------打印机信息---------------------', device); if (templateType == 'order') { printTestOrderData(device, printData, printReceipt.offlineCashier); } else if (templateType == 'returnOrder') { printTestOrderData(device, printData, printReceipt.refund); } else if (templateType == 'reprintOrder') { printTestOrderData(device, printData, printReceipt.offlineCashier); } else if (templateType == 'carSaleOrder') { printTestOrderData(device, printData, printReceipt.carSaleOrder); } else if (templateType == 'onlineOrder') { printTestOrderData(device, printData, printReceipt.onlineOrder); } else if (templateType == 'onlineRefund') { printTestOrderData(device, printData, printReceipt.onlineRefund); } else if (templateType == 'exit') { printTestOrderData(device, printData, printReceipt.exit); } }); for (var t of tasks) { await t(); } resolve(null); } else { resolve(null); } }); }); }; const custom = ( datas: [ { text: string | any; font: string | Number; align: string | Number; type?: null | 'columnsText' | 'line' | 'lineWrap'; }, ], printWare: IPrintWare, ) => { return new Promise(resolve => { AsyncStorage.getItem('ENABLE_PRINT', async (_, res) => { // if (err) console.log(err); if (null == res || Boolean(res)) { printDriver(printWare.device.brand, printWare.device.model); console.log('-------------------开始打印---------------------', datas); print(async device => { console.log('-------------------打印机信息---------------------', device); await Printer_start(device); for (var { text, font, align, type } of datas) { if (type) { switch (type) { case 'line': await Printer_additem({ func: 'line', params: [] }); break; case 'columnsText': await Printer_additem({ func: 'printColumnsText', params: text, // params: [texts, [15, 15], ["0", "0"], false] }); break; case 'lineWrap': await Printer_additem({ func: 'lineWrap', params: [1] }); break; } } else { if (text.includes('null')) { console.log('*****print data has null*****', text); } else { await Printer_additem({ func: 'printlnText', params: [text, font, align], }); } } } // }); //结束打印 await Printer_end(); }); resolve(null); } else { resolve(null); } }); }); }; /** * 打印订单 */ const printOrder = ( printData: IPrinterData, templateType: | string | 'order' | 'returnOrder' | 'reprintOrder' | 'carSaleOrder' | 'onlineOrder' | 'onlineRefund' | 'exit', printWare: IPrintWare, ) => { console.log('QianmiPrint:printOrder:printWare', printWare); console.log('QianmiPrint:printOrder:printData', printData); return new Promise(resolve => { AsyncStorage.getItem('ENABLE_PRINT', async (_, res) => { // if (err) console.log(err); if (null == res || Boolean(res)) { printDriver(printWare.device.brand, printWare.device.model, printWare.device.innerPrinterModal); //初始化打印序号 if (!printWare.isOnline || printData.printNumber == '') { printData.printNumber = tempPrintCount.count; tempPrintCount.count = ''; } console.log('QianmiPrint.开始打印---------------------', printData); console.log('QianmiPrint.开始打印:打印机---------------------', devices); const items = await devices(); console.log('devices items =>', items); const tasks = items.map(device => async () => { if (device.from === 'x30') return; console.log('QianmiPrint:printOrder', '----printer----', device); if (templateType == 'order') { // TODO: 这块代码需要重构,判断肯定有重合 if ( ('print.365' === device.from && printData.totalStatus === undefined) || ('print.yly' === device.from && printData.totalStatus === undefined) ) { await printTestOrderData(device, printData, printReceipt.offlineCashier); return; } if ( ('print.365' === device.from && printData.totalStatus != 'ALL_ORDER') || ('print.yly' === device.from && printData.totalStatus != 'ALL_ORDER') ) { // 直接收银WIFI的不打印 return; } else { if (printData.totalStatus === 'ALL_ORDER') { // 销售单 直接打印不受自动打印控制 await printTestOrderData(device, printData, printReceipt.offlineCashier); } else if (null == device.printMode || 'auto' === device.printMode) { await printTestOrderData(device, printData, printReceipt.offlineCashier); } } } else if (templateType == 'returnOrder') { await printTestOrderData(device, printData, printReceipt.refund); } else if (templateType == 'reprintOrder') { await printTestOrderData(device, printData, printReceipt.offlineCashier); } else if (templateType == 'carSaleOrder') { await printTestOrderData(device, printData, printReceipt.carSaleOrder); } else if (templateType == 'onlineOrder') { await printTestOrderData(device, printData, printReceipt.onlineOrder); } else if (templateType == 'onlineRefund') { await printTestOrderData(device, printData, printReceipt.onlineRefund); } else if (templateType == 'exit') { await printTestOrderData(device, printData, printReceipt.exit); } }); try { for (let t of tasks) { await t(); } } catch (error) { console.log(error); } resolve(null); } else { resolve(null); } }); }); }; /** * 打印订单 */ const printTemplateData = (printData: IPrinterData, printTemplate: any, printWare: IPrintWare) => { printDriver(printWare.device.brand, printWare.device.model); //初始化打印序号 if (!printWare.isOnline || printData.printNumber == '') { printData.printNumber = tempPrintCount.count; tempPrintCount.count = ''; } console.log('-------------------开始打印---------------------', printData); print(device => { if (device.from === 'x30') { return; } console.log('-------------------打印机信息---------------------', device); printTestOrderData(device, printData, printTemplate); }); }; const sendPos = (posCMD: string) => { if (NativeModules.SprtPrinter && NativeModules.SprtPrinter.sendPos) { print(device => { // if (device && device.name && device.name.indexOf('X30-') >= 0) { // if (null == device.printMode || 'auto' == device.printMode) { // if (Platform.OS === 'android') NativeModules.SprtPrinter.sendPos(device.address, posCMD); // if (Platform.OS === 'ios') NativeModules.SprtPrinter.sendPos(posCMD); // } // } console.log('sendPos', device, posCMD); if (device && device.name) { // X30这个名字变来变去的; if ( device.name.indexOf('X30-') >= 0 || device.name.indexOf('OP380') >= 0 || device.name.indexOf('QR380') >= 0 ) { if (Platform.OS === 'android') { NativeModules.SprtPrinter.sendPos(device.address, posCMD); } else { NativeModules.SprtPrinter.sendPos(posCMD); } } else if (device.name.indexOf('D31S-') >= 0) { console.log('sendPos:D31S', device, posCMD); if (Platform.OS === 'android') { NativeModules.SprtPrinter.sendPos(device.address, posCMD); } else { NativeModules.SprtPrinter.sendPos(posCMD); } } } }); } }; /** * 打印测试订单数据 * @param {IPrinterData} printData */ var printTestOrderData = async (device, data: IPrinterData, template) => { console.log('-------------------打印模版---------------------', template); if (JSON.stringify(template) == '{}') { console.log('-----没有打印模版'); return; } await Printer_start(device); function Prop(obj, is, value?: any) { if (typeof is == 'string') is = is.split('.'); if (is.length == 1 && value !== undefined) return (obj[is[0]] = value); else if (is.length == 0) return obj; else { var prop = is.shift(); //Forge a path of nested objects if there is a value to set if (value !== undefined && obj[prop] == undefined) obj[prop] = {}; return Prop(obj[prop], is, value); } } function eval2(str, obj?) { return str.replace(/\$\{(.+?)\}/g, (match, p1) => { if (__DEV__) console.log(match); return Prop(obj ? { data: obj } : { data: data }, p1); }); } if (__DEV__) { console.log('打印数据---', data); console.log('打印模版---', template); } var children = template.children; // for (var child of children) { try { for (var index = 0; index < children.length; index++) { var child = children[index]; // children.forEach(async child => { if (__DEV__) console.log('child=>', child); if (child.props.type == 'single') { //打印单行 var cs = child.props.items; // for(var item of cs){ // child.props.items.forEach(async item => { for (var i = 0; i < cs.length; ++i) { var item = cs[i]; if (item.isShow) { if (__DEV__) console.log('item=>', item); var text = eval2(item.key); // printlnText(text, 'middle'); // Printer_additem({ func: "printlnText", params: [text, "middle"] }); if (!isPrint(text)) { await Printer_additem({ func: 'printlnText', params: [text, 'middle'], }); } } // }); } } else if (child.props.type == 'double') { //打印双行 var items = child.props.items; var rowItem = []; // items.forEach(item => { for (var item of items) { var text0 = eval2(item.key); if (!isPrint(text0) && item.isShow) { rowItem.push(item); } } // }); var lastData = 0 == rowItem.length % 2 ? null : rowItem.pop(); for (var i = 0; i < rowItem.length; i += 2) { var text0 = eval2(rowItem[i].key); var text1 = eval2(rowItem[i + 1].key); await Printer_additem({ func: 'printColumnsText', params: [[text0, text1], [15, 15], ['0', '0'], false], }); } if (lastData) { var text0 = eval2(lastData.key); //printlnText(text0, 'middle'); await Printer_additem({ func: 'printlnText', params: [text0, 'middle'], }); } } else if (child.props.type == 'table') { //打印table var columnTitles = []; var cs = child.props.items; // for(var item of cs){ for (var m = 0; m < cs.length; ++m) { var item = cs[m]; // child.props.items.forEach(item => { if (item.isShow) { columnTitles.push(item.title); } // }); } //printColumnsText(columnTitles, [10, 6, 4, 7], ["1", "2", "2", "2"]); if (columnTitles.length == 5) { var array = [columnTitles[0], columnTitles[2], columnTitles[3], columnTitles[4]]; // Printer_additem({ func: 'printColumnsText', params: [array, [11, 5, 5, 6], ["0", "2", "2", "2"]] }); await Printer_additem({ func: 'printColumnsText', params: [array, [3, 7, 7, 7], ['0', '2', '2', '2']], }); } else if (columnTitles.length == 4) { // Printer_additem({ func: 'printColumnsText', params: [columnTitles, [11, 5, 5, 6], ["0", "2", "2", "2"]] }); await Printer_additem({ func: 'printColumnsText', params: [columnTitles, [3, 7, 7, 7], ['0', '2', '2', '2']], }); } else if (columnTitles.length == 3) { await Printer_additem({ func: 'printColumnsText', params: [columnTitles, [10, 9, 8], ['0', '2', '2']], }); } else if (columnTitles.length == 2) { await Printer_additem({ func: 'printColumnsText', params: [columnTitles, [10, 10], ['0', '2']], }); } else if (columnTitles.length == 1) { await Printer_additem({ func: 'printColumnsText', params: [columnTitles, [15], ['0']], }); } //print row value var props = child.props.items; // data.items.forEach(async data => { let items = data.items as any[]; // for(var item of items){ for (var l = 0; l < items.length; ++l) { var item = items[l]; if (__DEV__) console.log('goods data', item); var columnValue = []; for (var i = 0; i < props.length; i++) { if (__DEV__) console.log('props[i].key', props[i].key); if (props[i].isShow) { var text = eval2(props[i].key, item); // if (text.length > 18) { // text = text.substr(0, 18) + '...'; // } columnValue.push(text); } } // printColumnsText(columnValue, [10, 6, 4, 7], ["1", "2", "2", "2"]); if (columnTitles.length == 5) { //var productName = ProductName(columnValue[0]); var productName = columnValue[0]; // var spec = columnValue[1]; // if (spec == '' || spec == undefined) { // spec == ''; // } // else { // spec = '(' + columnValue[1] + ')'; // } // productName = productName + spec; var array = [productName, columnValue[2], columnValue[3], columnValue[4]]; //var array = [columnValue[0], columnValue[2], columnValue[3], columnValue[4]]; //单独打印 await Printer_additem({ func: 'printlnText', params: [productName, null, 0], }); // Printer_additem({ func: 'printColumnsText', params: [array.slice(1), [15, 5, 6], ["2", "2", "2"]] }); // Printer_additem({ func: 'printColumnsText', params: [array, [11, 5, 5, 6], ["0", "2", "2", "2"]] }); await Printer_additem({ func: 'printColumnsText', params: [array.slice(1), [10, 8, 8], ['2', '2', '2']], }); } else if (columnTitles.length == 4) { await Printer_additem({ func: 'printlnText', params: [columnValue[0], null, 0], }); // Printer_additem({ func: 'printColumnsText', params: [columnValue, [11, 5, 5, 6], ["0", "2", "2", "2"]] }); // Printer_additem({ func: 'printColumnsText', params: [columnValue.slice(1), [15, 5, 6], ["2", "2", "2"]] }); await Printer_additem({ func: 'printColumnsText', params: [columnValue.slice(1), [10, 8, 8], ['2', '2', '2']], }); } else if (columnTitles.length == 3) { await Printer_additem({ func: 'printlnText', params: [columnValue[0], null, 0], }); await Printer_additem({ func: 'printColumnsText', params: [columnValue.slice(1), [15, 8], ['2', '2']], }); // Printer_additem({ func: 'printColumnsText', params: [columnValue, [10, 9, 8], ["0","2", "2"]] }); } else if (columnTitles.length == 2) { await Printer_additem({ func: 'printlnText', params: [columnValue[0], null, 0], }); await Printer_additem({ func: 'printColumnsText', params: [columnValue.slice(1), [10], ['2']], }); // Printer_additem({ func: 'printColumnsText', params: [columnValue, [10, 10], ["0", "2"]] }); } else if (columnTitles.length == 1) { await Printer_additem({ func: 'printColumnsText', params: [columnValue, [15], ['0']], }); } // }); } } else { // child.props.items.forEach(async item => { var cs = child.props.items; // for (var item of cs){ for (var j = 0; j < cs.length; ++j) { var item = cs[j]; //打印 文本 / 线 if (__DEV__) console.log('item4=>', item); if (item.isShow && item.type == 'text') { console.log('item.key=', item.key); var val = eval2(item.key); var text = val + (item.value ? item.value : ''); if (isPrint(text)) continue; var align = item.align ? (item.align == 'center' ? 1 : 2) : 0; //字体对齐 //printlnText(text, 'middle', align); var font = item.font ? item.font : 'middle'; if (text.includes('null') || text.includes('undefined')) { console.log('*****print data has null*****', text); } else { await Printer_additem({ func: 'printlnText', params: [text, font, align], }); } if (item.key.includes('storeName')) { //店铺后面打印空行 //lineWrap(1); await Printer_additem({ func: 'lineWrap', params: [1] }); } } if (item.type == 'line') { //line(); await Printer_additem({ func: 'line', params: [] }); } if (item.type == 'qrCode' && item.isShow) { var text = item.value; await Printer_additem({ func: 'printQrCode', params: [text] }); } if (item.type == 'qrCode' && item.isShow) { var text = item.value; await Printer_additem({ func: 'printQrCode', params: [text] }); } if (item.type == 'barCode' && item.isShow) { var text = item.value; await Printer_additem({ func: 'printBarCode', params: [text] }); } if (item.isShow && item.type == 'hideText') { var text = eval2(item.key); if (text && text.length == 16) { text = text.substr(0, 8) + '****' + text.substr(12, 16); } //printlnText(text, 'middle'); if (text.includes('null')) { console.log('*****print data has null*****', text); } else { await Printer_additem({ func: 'printlnText', params: [text, 'middle'], }); } } // }); } } // }); } } catch (error) { console.error(error); } //结束打印 return Printer_end(); }; //获取打印序号 var getPrinterNumber = async () => { var ticketNumber = ''; await AsyncStorage.getItem('ticketInfo', (err, res) => { var ticketInfo = { printCount: '1', time: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'), }; if (__DEV__) console.log(err); //解析 if (!res) { AsyncStorage.setItem('ticketInfo', JSON.stringify(ticketInfo)); ticketNumber = 'B1'; return; } var resultTicket = JSON.parse(res); var lastTime = resultTicket.time; var lastCount = resultTicket.printCount; //时间参数 var current = moment(new Date()).format('YYYY-MM-DD HH:mm:ss'); var curDate = moment(new Date()).format('YYYY-MM-DD'); var yestday = moment(current) .subtract(1, 'days') .format('YYYY-MM-DD HH:mm:ss'); //当前时间差距大于一天 || 上次时间小于5点, 本次时间大于5点 每天5点更新count if ( moment(yestday).isAfter(moment(lastTime)) || (moment(lastTime).isBefore(moment(`${curDate} 05:00:00`)) && moment(current).isAfter(moment(`${curDate} 05:00:00`))) ) { AsyncStorage.setItem('ticketInfo', JSON.stringify(ticketInfo)); ticketNumber = 'B1'; } else { var temp = 'B' + (lastCount + 1); ticketInfo.printCount = Number(lastCount) + 1 + ''; ticketInfo.time = moment(new Date()).format('YYYY-MM-DD HH:mm:ss'); AsyncStorage.setItem('ticketInfo', JSON.stringify(ticketInfo)); ticketNumber = temp; } }); return ticketNumber; }; /** * 组合打印数据 * @param newCartData * @param totalFee * @param revenueFee * @param changeFee * @param memberInfo * @param originalPrice * @param cutValue * @param payType * @returns {IPrinterData} * @private */ var combinePrintOrderData = ( newCartData, totalFee, revenueFee, changeFee, memberInfo, originalPrice, cutValue, payType, employeeName, companyName, ) => { var cartItems = []; //var totalItem = newCartData.totalCount; newCartData.items.forEach(currentValue => { var itemTotal = 0; if (currentValue.itemType === 3) { WeightUnits.forEach(item => { if (item.value == currentValue.unit) { itemTotal = toFixed( (currentValue.quantity * (memberInfo.userId ? currentValue.levelPrice : currentValue.originalPrice)) / item.rate, ); // 小计 } }); } else { itemTotal = toFixed( currentValue.quantity * (memberInfo.userId ? currentValue.levelPrice : currentValue.originalPrice), ); // 小计 } var data = { //itemName: getProductName(currentValue.title), // 商品名称 itemName: currentValue.title, // 商品名称 itemPrice: toFixed(memberInfo.userId ? currentValue.levelPrice : currentValue.originalPrice), // 单价 itemNum: currentValue.realNumber || currentValue.quantity, // 数量 itemTotal: itemTotal, // 小计 itemType: currentValue.itemType, //itemSpec: (currentValue.productSpecification ? currentValue.productSpecification : ''), }; cartItems.push(data); }); var empName = '--'; if (employeeName) { if (Number(employeeName) && employeeName.length == 11) { empName = employeeName.substr(0, 3) + '****' + empName.substr(7, 11); } else { empName = employeeName; } } var printData = { storeName: companyName ? companyName : '店铺名称', // 店铺名称 tid: newCartData.tid, // 订单号 payTime: moment().format('YYYY-MM-DD HH:mm:ss'), // 支付时间 printTime: moment().format('YYYY-MM-DD HH:mm:ss'), // 支付时间 payType: payType, // 支付类型 totalCount: cartItems.reduce((all, cell) => { return cell.itemType == 3 ? 1 + all : cell.itemNum + all; }, 0), // 商品数量 discountFee: String(toFixed(originalPrice - totalFee)), // 优惠金额 totalFee: String(toFixed(revenueFee)), // 实收 oddChange: String(toFixed(changeFee)), // 找零 sumMoney: totalFee, //总额 memberMobile: memberInfo.mobile ? memberInfo.mobile : '--', // 手机号 memberName: memberInfo.nickName ? memberInfo.nickName : '', allIntegral: memberInfo.integral, // 积分余额 integral: '--', curIntegral: newCartData.score ? newCartData.score : memberInfo.mobile ? '0' : '--', balance: memberInfo.balance ? memberInfo.balance : '--', //账户余额 bugfix address: '', //收获地址 cardNumber: '', //会员卡号 shopAd: '谢谢惠顾期待下一次', // 底部显示 items: cartItems, // 商品列表 cashierName: empName, cutFee: Math.abs(cutValue) + '', } as IPrinterData; console.log('_combinePrintOrderData---', printData, memberInfo); return printData; }; // var getProductName = (title) => { // var index = title.indexOf(' '); // var productName = title; // if (index > 0) { // productName = title.substring(0, index); // } // return productName; // } /** * * @param {IOrderInfo} orderInfo * @returns {IPrinterData} */ var combinePrintOrderInfo = (orderInfo: IOrderInfo, employeeName, companyName) => { var cartItems = []; var buyerInfo = orderInfo.buyerInfo; orderInfo.itemInfos.forEach(item => { var data = { //itemName: getProductName(item.itemName), // 商品名称 itemName: item.itemName, // 商品名称 itemPrice: toFixed(item.initItemPrice), // 单价 itemNum: (item as any).realNumber, // 数量 itemTotal: toFixed((item.initItemPrice * (item as any).realNumber).toFixed(2)), // 小计 itemType: item.itemType, //itemSpec: item.productSpecification ? item.productSpecification : '', }; cartItems.push(data); }); var empName = '--'; if (employeeName) { if (Number(employeeName) && employeeName.length == 11) { empName = employeeName.substr(0, 3) + '****' + employeeName.substr(7, 11); } else { empName = employeeName; } } if (orderInfo.totalCashPaidPrice) { orderInfo.totalFee = orderInfo.totalCashPaidPrice; } var printData = { storeName: companyName ? companyName : '店铺名称', // 店铺名称 tid: orderInfo.tid, // 订单号 payTime: moment().format('YYYY-MM-DD HH:mm:ss'), // 支付时间 printTime: moment().format('YYYY-MM-DD HH:mm:ss'), // 支付时间 payType: { CAP: '现金', OLP0843: '支付宝', OLP0842: '微信', CAP0830: '银行卡(自动退还到卡中)', OLP0830: '银行卡(自动退还到卡中)', CCP: '银行卡(请现金退还)', CCP0830: '银行卡(请现金退还)', OBP0842: '余额', OBP: '余额', OLP0820: '支付宝支付', OLP0802: '微信支付', OLP0855: '云闪付', }[[orderInfo.payTypeId].join('')] || orderInfo.payTypeName, // 支付类型 //totalCount: cartItems.reduce((all, cell) => { return (cell.itemType == 3 ? 1 + all : cell.itemNum + all) }, 0), // 商品数量 totalCount: orderInfo.totalCount, printNumber: 'A' + orderInfo.serialNo, cutFee: Math.abs(orderInfo.cutValue) + '', sumMoney: orderInfo.totalTradeCash, totalFee: orderInfo.totalFee ? orderInfo.totalFee : '0', //车销 discountFee: orderInfo.discountFee == undefined || orderInfo.discountFee == null ? toFixed(orderInfo.totalTradePrePrice + orderInfo.totalDiscountPrePrice) + '' : orderInfo.discountFee, oddChange: orderInfo.totalCashChangePrice ? orderInfo.totalCashChangePrice : '0', curIntegral: orderInfo.score ? orderInfo.score : '--', memberMobile: buyerInfo.type == '散客' ? '--' : buyerInfo.mobile, // 手机号 memberName: buyerInfo.nickName, allIntegral: '0', // 积分余额 balance: '', //账户余额 bugfix address: '', //收获地址 cardNumber: '', //会员卡号 shopAd: '谢谢惠顾期待下一次', // 底部显示 items: cartItems, // 商品列表 cashierName: empName, invoiceFee: orderInfo.invoiceFee ? orderInfo.invoiceFee : '0', pointsDeduction: orderInfo.pointsDeduction ? orderInfo.pointsDeduction : '', payStatus: orderInfo.payStatus ? orderInfo.payStatus : '', integral: orderInfo.score, //当此积分 scorePay: 0 === orderInfo.scorePay ? 0 : orderInfo.scorePay ? orderInfo.scorePay + '(' + orderInfo.scorePay * 100 + ')' : '', } as IPrinterData; console.log('combinePrintOrderInfo---', printData, buyerInfo); return printData; }; /** * 不四舍五入的取两位小数 fomart 保留2位小数后 去尾数0 */ const toFixed = (number: number | string) => { if (typeof number != 'string') { number = number.toString(); } var numberArray = number.split('.'); if (numberArray[1]) { if (numberArray[1].length == 1) { numberArray[1] = numberArray[1]; } else if (numberArray[1].length > 2) { numberArray[1] = numberArray[1].substring(0, 2); } } return parseFloat(numberArray.join('.')); }; const enable = (value: Boolean) => { return AsyncStorage.setItem('ENABLE_PRINT', String(value)); }; const getEnable = () => { return AsyncStorage.getItem('ENABLE_PRINT'); }; export default { printerInit, printerDestroy, printOrder, printOrderByDevice, enable, getEnable, sendPos, combinePrintOrderData, combinePrintOrderInfo, getPrinterNumber, tempPrintCount, custom, printReceipt, printTemplateData, };