Commit 7a454a1c by chenxu

打印小票功能

parent 06f6596f
......@@ -143,6 +143,9 @@ export default {
*getAdvertising(action, {call}) {
return yield call(api.getAdvertising, action);
},
*getStore(action, {call}) {
return yield call(api.getStore, action);
},
},
};
......
import React from 'react';
import RN, {DeviceEventEmitter, Image, View} from 'react-native';
import RN, {DeviceEventEmitter, Image, View, Text} from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
import {connect} from 'react-redux';
import {debounce} from 'throttle-debounce';
......@@ -7,7 +7,7 @@ import KeyEvent from 'react-native-keyevent';
import Icon from 'react-native-vector-icons/Ionicons';
import NumberModal from '../components/NumberModal';
import Modal from '../components/Modal';
import {font} from '../utils/common';
import {colors, font} from '../utils/common';
import Touch from '../components/Touch';
import ModalStyles from '../components/Modal/styles';
import Speech from '../utils/Speech';
......@@ -15,8 +15,9 @@ import Toast from '../components/Toast';
import NP from '../utils/np';
import {total} from '../utils/validity';
import RedPacketModal from '../components/RedPacketModal';
import {width, scaleSize} from '../utils/screen';
import {width, height, scaleSize} from '../utils/screen';
import EnterEvent from '../utils/EnterEvent';
import Printer from '../utils/Printer';
window.RN = RN;
window.Toast = Toast;
......@@ -59,6 +60,10 @@ const CounterMixins = ComposeComponent => {
autoplayTime: 10,
imgArr: [],
adType: 'image',
visible: false,
receipt: {},
printer: [],
time: 5,
};
componentWillMount = async () => {
......@@ -354,7 +359,7 @@ const CounterMixins = ComposeComponent => {
return '门店设置已解锁';
};
successPay = () => {
successPay = async () => {
Toast.hide();
const msg = '付款成功,祝您生活愉快~';
this.props.dispatch({
......@@ -362,10 +367,65 @@ const CounterMixins = ComposeComponent => {
type: 'app/step',
step: 3,
});
this.clearList();
this.setState({voiceModal: true, voiceTitle: msg});
Speech.speak(msg);
this.storeSetting(this.state.goodsArr);
this.onLucky();
this.clearList();
};
storeSetting = async printer => {
let group = await AsyncStorage.getItem('KEY');
let {data} = await this.props.dispatch({
type: 'store/getStore',
group,
});
if (data.code === 1) {
this.setState({receipt: data.data.receipt, printer});
if (data.data.receipt.enable) {
if (data.data.receipt.confirm) {
await this.setState({
visible: true,
time: data.data.receipt.tipsTime || 5,
});
this.interval = setInterval(async () => {
this.time -= 1;
await this.setState({time: this.state.time - 1});
if (this.state.time === 0) {
this.setState({
visible: false,
time: data.data.receipt.tipsTime || 5,
});
clearInterval(this.interval);
}
}, 1000);
} else {
this.print();
}
}
}
};
confirm = () => {
this.setState({visible: false});
this.print();
};
print = async () => {
let total = 0;
let goods = [];
this.state.printer.map(v => {
total += (v.price > 0 ? v.price : v.prePrice) * v.num;
goods.push(
`${v.name},${v.num},${v.price > 0 ? v.price : v.prePrice},${(v.price >
0
? v.price
: v.prePrice) * v.num}`,
);
});
goods.push(`总计, , ,${total.toFixed(2)}`);
await Printer.printNote(goods, this.state.receipt);
this.setState({printer: []});
};
// 付款成功,若达到领取红包的金额则弹出领取红包的弹窗
......@@ -780,9 +840,74 @@ const CounterMixins = ComposeComponent => {
};
render = () => {
let {voiceModal, voiceTitle, title, luckyVisible, amount} = this.state;
let {
voiceModal,
voiceTitle,
title,
luckyVisible,
amount,
visible,
time,
} = this.state;
return (
<View style={{flex: 1}}>
<Modal visible={visible} transparent>
{/*<View style={{width,height,backgroundColor:'rgba(0,0,0,.5)'}} />*/}
<View
style={{
height: height * 0.15,
backgroundColor: '#fff',
justifyContent: 'center',
alignItems: 'center',
}}>
<Text
style={{
textAlign: 'center',
fontSize: font.textMDActive,
}}>
是否打印小票?
</Text>
<View
style={{
flexDirection: 'row',
justifyContent: 'space-around',
marginTop: 30,
}}>
<Touch onPress={() => this.setState({visible: false})}>
<Text
style={{
width: width * 0.1,
height: width * 0.05,
borderRadius: width * 0.05,
textAlign: 'center',
textAlignVertical: 'center',
fontSize: font.textF,
margin: 20,
backgroundColor: '#959595',
color: '#fff',
}}>
取消({time}s)
</Text>
</Touch>
<Touch onPress={() => this.confirm()}>
<Text
style={{
width: width * 0.1,
height: width * 0.05,
borderRadius: width * 0.05,
textAlign: 'center',
textAlignVertical: 'center',
fontSize: font.textF,
margin: 20,
backgroundColor: colors.bg,
color: '#fff',
}}>
确认
</Text>
</Touch>
</View>
</View>
</Modal>
<NumberModal
title={title}
onClose={() => this.setState({modalS: false, dot: false})}
......
......@@ -579,6 +579,7 @@ class VerticalPage extends Component {
{goodsArr.map((item, index) => {
return (
<View
key={index}
style={
index % 2 === 0 ? styles.evenCell : styles.oddCell
}>
......
......@@ -82,3 +82,7 @@ export function verifysms({phone, code, userId, faceType}) {
export function getAdvertising(action) {
return axios.get(`/store/advertising?${qs.stringify(action)}`);
}
export function getStore({group}) {
return axios.get(`/store/setting/${group}`);
}
import {NativeModules} from 'react-native';
import axios from 'axios';
import moment from 'moment';
import {Buffer} from 'buffer';
const {Printer: _Printer} = NativeModules;
......@@ -156,6 +157,37 @@ if (_Printer) {
await Printer.halfCut(); // 半切
// await Printer.allCut(); // 全切
},
printNote: async (row, params) => {
let now = new Date();
await Printer.initPrinter(); // 初始化配置
await Printer.setPrinter(Command.ALIGN, Command.ALIGN_CENTER); //居中
await Printer.setFont(0, 1, 1, 1, 0); // 标题加粗大字号
await Printer.printText(params.storeName); //门店命
await Printer.setFont(0, 0, 0, 0, 0); // 默认字体
await Printer.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 0); // 换行
await Printer.setPrinter(Command.ALIGN, Command.ALIGN_LEFT); //左对齐
await Printer.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1); // 换行
await Printer.printText(
`单据日期:${moment(now).format('YYYY-MM-DD')}\n打印时间:${moment(
now,
).format('YYYY-MM-DD hh:mm:ss')}`,
); //门店
await Printer.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1); // 换行
await Printer.setFont(0, 0, 0, 1, 0); // 设置加粗
await Printer.printTable('商品,数量,单价,金额', ',', 384, row);
await Printer.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1); // 换行
await Printer.printText(`电话:${params.phone}`); //门店
await Printer.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 0); // 换行
await Printer.setFont(0, 0, 0, 1, 0); // 默认字体
await Printer.setPrinter(Command.ALIGN, Command.ALIGN_CENTER);
await Printer.printText(
`================================\n${params.bottomText}`,
); //门店
// await Printer.printBarCode(BarcodeType.QRCODE, 2, 3, 6, '123456');
await Printer.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1); // 换行
await Printer.sendBytesData([28, 33, 0]);
await Printer.halfCut(); // 半切
},
};
(async () => {
const isConnected = await Printer.isConnected();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment