Commit 09371b1d by 姜雷

Merge branch 'develop' into test

parents 79c03d98 0fed48a4
...@@ -84,7 +84,6 @@ class Pay extends Component { ...@@ -84,7 +84,6 @@ class Pay extends Component {
readId: '', readId: '',
}, },
}; };
this.checkBluetoothAndWs();
} }
componentWillMount() { componentWillMount() {
...@@ -95,6 +94,7 @@ class Pay extends Component { ...@@ -95,6 +94,7 @@ class Pay extends Component {
payId: prepayConfig[0].id, payId: prepayConfig[0].id,
}); });
} }
this.checkBluetoothAndWs();
} }
componentWillUnmount() { componentWillUnmount() {
...@@ -103,7 +103,11 @@ class Pay extends Component { ...@@ -103,7 +103,11 @@ class Pay extends Component {
} }
connectDeviceSocket() { connectDeviceSocket() {
Taro.connectSocket({ url: SOCKET_URL }).then(task => { let connectHandle;
if (socketTask) {
connectHandle = new Promise(resolve => resolve(socketTask));
} else {
connectHandle = Taro.connectSocket({ url: SOCKET_URL }).then(task => {
socketTask = task; socketTask = task;
task.onOpen(() => { task.onOpen(() => {
console.log('onOpen'); console.log('onOpen');
...@@ -128,7 +132,11 @@ class Pay extends Component { ...@@ -128,7 +132,11 @@ class Pay extends Component {
if (msg.length > 100) { if (msg.length > 100) {
this.sendMessageToDevice('[]'); this.sendMessageToDevice('[]');
} else if (msg.length > 20) { } else if (msg.length > 20) {
for (let index = 0; index <= Math.floor(msg.length / 20); index++) { for (
let index = 0;
index <= Math.floor(msg.length / 20);
index++
) {
let str = msg.substring(index * 20, (index + 1) * 20); let str = msg.substring(index * 20, (index + 1) * 20);
this.sendMessageToDevice(str); this.sendMessageToDevice(str);
} }
...@@ -154,6 +162,10 @@ class Pay extends Component { ...@@ -154,6 +162,10 @@ class Pay extends Component {
}); });
}); });
} }
connectHandle.then(() => {
console.log('socket done');
});
}
reConnectDeviceSocket(cancel: boolean) { reConnectDeviceSocket(cancel: boolean) {
if (cancel) { if (cancel) {
...@@ -220,6 +232,7 @@ class Pay extends Component { ...@@ -220,6 +232,7 @@ class Pay extends Component {
} }
} }
checkIsShower(): boolean { checkIsShower(): boolean {
return true;
const { device } = this.props; const { device } = this.props;
return device.serviceId === 5; return device.serviceId === 5;
} }
...@@ -250,7 +263,7 @@ class Pay extends Component { ...@@ -250,7 +263,7 @@ class Pay extends Component {
}, },
() => { () => {
this.startConnectDevice(); this.startConnectDevice();
}, }
); );
}) })
.catch(err => { .catch(err => {
...@@ -390,7 +403,7 @@ class Pay extends Component { ...@@ -390,7 +403,7 @@ class Pay extends Component {
let abStr = ''; let abStr = '';
Taro.onBLECharacteristicValueChange(res => { Taro.onBLECharacteristicValueChange(res => {
console.log( console.log(
`characteristic ${res.characteristicId} has changed, now is ${res.value}`, `characteristic ${res.characteristicId} has changed, now is ${res.value}`
); );
console.log(res.value); console.log(res.value);
let datastr = ab2str(res.value); let datastr = ab2str(res.value);
...@@ -445,7 +458,7 @@ class Pay extends Component { ...@@ -445,7 +458,7 @@ class Pay extends Component {
Taro.onBLEConnectionStateChange(res => { Taro.onBLEConnectionStateChange(res => {
// const { showerState } = this.state; // const { showerState } = this.state;
console.log( console.log(
`device ${res.deviceId} state has changed, connected: ${res.connected}`, `device ${res.deviceId} state has changed, connected: ${res.connected}`
); );
if (res.connected) { if (res.connected) {
this.setState({ this.setState({
...@@ -640,7 +653,7 @@ class Pay extends Component { ...@@ -640,7 +653,7 @@ class Pay extends Component {
let service = services.find( let service = services.find(
item => item =>
item.uuid.toLocaleLowerCase() === item.uuid.toLocaleLowerCase() ===
'6e401103-b5a3-f393-e0a9-e50e24dcca9e', '6e401103-b5a3-f393-e0a9-e50e24dcca9e'
); );
if (!service) { if (!service) {
service = services[0]; service = services[0];
...@@ -763,7 +776,7 @@ class Pay extends Component { ...@@ -763,7 +776,7 @@ class Pay extends Component {
AES.decrypt(payStr, Utf8.parse(key), { AES.decrypt(payStr, Utf8.parse(key), {
mode: ECBmode, mode: ECBmode,
padding: PaddingPkcs7, padding: PaddingPkcs7,
}).toString(Utf8), }).toString(Utf8)
); );
console.log('payData:', payData); console.log('payData:', payData);
Taro.requestPayment({ Taro.requestPayment({
...@@ -838,28 +851,28 @@ class Pay extends Component { ...@@ -838,28 +851,28 @@ class Pay extends Component {
const { device, prepayConfig, userinfo } = this.props; const { device, prepayConfig, userinfo } = this.props;
const { payId } = this.state; const { payId } = this.state;
return ( return (
<View className='Pay'> <View className="Pay">
<View className='Pay-info'> <View className="Pay-info">
<View className='Pay-info-item'> <View className="Pay-info-item">
<Text>服务类型</Text> <Text>服务类型</Text>
<Text>{device.serviceName ? device.serviceName : ''}</Text> <Text>{device.serviceName ? device.serviceName : ''}</Text>
</View> </View>
<View className='Pay-info-item'> <View className="Pay-info-item">
<Text>设备编号</Text> <Text>设备编号</Text>
<Text>{device.code ? device.code : ''}</Text> <Text>{device.code ? device.code : ''}</Text>
</View> </View>
<View className='Pay-info-item'> <View className="Pay-info-item">
<Text>设备位置</Text> <Text>设备位置</Text>
<Text className='Pay-info-position'>{device.position}</Text> <Text className="Pay-info-position">{device.position}</Text>
</View> </View>
{device.rates.length && ( {device.rates.length && (
<View className='Pay-info-item'> <View className="Pay-info-item">
<Text>适用费率</Text> <Text>适用费率</Text>
<View className='Pay-info-rate'> <View className="Pay-info-rate">
{device.rates.map(item => ( {device.rates.map(item => (
<View key='name' className='Pay-info-rate-item'> <View key="name" className="Pay-info-rate-item">
<Text className='Pay-info-rate-name'>{item.name}</Text> <Text className="Pay-info-rate-name">{item.name}</Text>
<Text className='Pay-info-rate-mark'>{item.mark}</Text> <Text className="Pay-info-rate-mark">{item.mark}</Text>
</View> </View>
))} ))}
{/* <View className='Pay-info-rate-item'> {/* <View className='Pay-info-rate-item'>
...@@ -874,17 +887,17 @@ class Pay extends Component { ...@@ -874,17 +887,17 @@ class Pay extends Component {
</View> </View>
)} )}
</View> </View>
<View className='Pay-tip'> <View className="Pay-tip">
{device.refundMode === DeviceRefundMode.notRefund {device.refundMode === DeviceRefundMode.notRefund
? '温馨提示:设备成功开启后,未使用金额将不会退换!' ? '温馨提示:设备成功开启后,未使用金额将不会退换!'
: '温馨提示:如本次预付款未全部使用,系统将在使用结束后半小时内自动退还剩余金额,请留意查收!'} : '温馨提示:如本次预付款未全部使用,系统将在使用结束后半小时内自动退还剩余金额,请留意查收!'}
</View> </View>
<View className='Pay-money'> <View className="Pay-money">
{prepayConfig && {prepayConfig &&
prepayConfig.length && prepayConfig.length &&
prepayConfig.map(payConfig => ( prepayConfig.map(payConfig => (
<View <View
key='id' key="id"
className={`Pay-money-item ${ className={`Pay-money-item ${
payConfig.id == payId ? 'seleted' : '' payConfig.id == payId ? 'seleted' : ''
}`} }`}
...@@ -898,13 +911,13 @@ class Pay extends Component { ...@@ -898,13 +911,13 @@ class Pay extends Component {
<Input className='Pay-money-item' placeholder='输入>0.5数额' /> */} <Input className='Pay-money-item' placeholder='输入>0.5数额' /> */}
</View> </View>
{userinfo.isAuth ? ( {userinfo.isAuth ? (
<Button className='Pay-btn' onClick={this.payHandle}> <Button className="Pay-btn" onClick={this.payHandle}>
确定支付 确定支付
</Button> </Button>
) : ( ) : (
<Button <Button
className='Pay-btn' className="Pay-btn"
open-type='getPhoneNumber' open-type="getPhoneNumber"
onGetphonenumber={this.getPhoneHandle}> onGetphonenumber={this.getPhoneHandle}>
确定支付 确定支付
</Button> </Button>
......
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