Commit 58f2d962 by 姜雷

Merge branch 'develop' into test

parents e4dc3ec5 fa876401
......@@ -24,6 +24,7 @@ class App extends Component {
*/
config: Config = {
pages: [
'pages/scanEnter/scanEnter',
'pages/index/index',
'pages/pay/pay',
],
......
import { Component } from '@tarojs/taro';
import { ComponentClass, ReactElement } from 'react';
import { connect } from '@tarojs/redux';
import { UserState, updateUserInfo } from '../store/rootReducers/userinfo';
import {
DeviceState,
updateDeviceData,
resetDeviceData,
} from '../store/rootReducers/device';
import PrepayConfig from '../types/Order/Order';
import { updatePayData } from '../store/rootReducers/prepayConfig';
import { Customer } from '../types/Customer/Customer';
import Taro from '@tarojs/taro';
import { registerAndLogin } from '../api/customer';
import { getDeviceConfig } from '../api/device';
type DeviceEntity = {
serviceId: number;
equipmentNum: string;
};
export type LoginAndScanExportProps = {
loginHandle: () => Promise<void>;
scanHandle: () => void;
getDeviceEntity: (paramStr: string) => DeviceEntity;
getDeviceConfigHandle: ({
equipmentNum,
serviceId,
}: DeviceEntity) => Promise<void>;
};
type PageStateProps = {
userinfo: Customer;
};
type PageDispatchProps = {
updateUserInfo: (e: UserState) => void;
updateDeviceData: (e: DeviceState) => void;
updatePayData: (e: PrepayConfig[]) => void;
resetDeviceData: () => void;
};
type PageOwnProps = {
render: (e: LoginAndScanExportProps) => ReactElement;
};
interface LoginAndScan {
props: PageStateProps & PageDispatchProps & PageOwnProps;
}
@connect(
({ userinfo }) => ({
userinfo,
}),
dispatch => ({
updateUserInfo(data: UserState) {
dispatch(updateUserInfo(data));
},
updateDeviceData(data: DeviceState) {
dispatch(updateDeviceData(data));
},
updatePayData(data: PrepayConfig[]) {
dispatch(updatePayData(data));
},
resetDeviceData() {
dispatch(resetDeviceData());
},
}),
)
class LoginAndScan extends Component {
loginHandle() {
const { updateUserInfo } = this.props;
return Taro.login().then(res => {
const { code } = res;
return registerAndLogin({
code,
// userName: '',
}).then(res => {
const { token, customerId } = res;
updateUserInfo({
token,
customerId,
});
});
});
}
scanHandle() {
Taro.scanCode({
onlyFromCamera: true,
scanType: ['qrCode'],
})
.then(res => {
console.log(res);
const { path, result } = res;
if (path) {
let queryArr = path.split('?');
let queryStr = queryArr.length >= 2 ? queryArr[1] : '';
console.log(result, queryArr, queryStr);
const entity = this.getDeviceEntity(queryStr);
this.getDeviceConfigHandle(entity);
} else {
Taro.showToast({
title: '请扫描正确的小程序',
icon: 'none',
});
}
})
.catch(err => {
console.error(err);
});
}
getDeviceConfigHandle({ equipmentNum, serviceId }: DeviceEntity) {
Taro.showLoading();
const {
userinfo,
updateDeviceData,
updatePayData,
resetDeviceData,
} = this.props;
return getDeviceConfig({
customerId: userinfo.customerId,
equipmentNum: equipmentNum,
serviceId: serviceId,
})
.then(res => {
Taro.hideLoading();
console.log(res);
const { deviceInfoResponse, prepayConfigs } = res;
if (deviceInfoResponse.isUsed) {
console.log('设备使用中');
return;
}
if (deviceInfoResponse) {
updateDeviceData(deviceInfoResponse);
} else {
resetDeviceData();
}
if (prepayConfigs) {
updatePayData(prepayConfigs);
} else {
updatePayData([]);
}
Taro.navigateTo({
url: '/pages/pay/pay',
});
})
.catch(err => {
console.error(err);
Taro.showToast({
title: err.msg || '请扫描正确的设备码',
icon: 'none',
});
});
}
getDeviceEntity(paramStr: string): DeviceEntity {
let serviceId = Number(paramStr.slice(0, 2));
let equipmentNum = paramStr.slice(2);
return {
serviceId,
equipmentNum,
};
}
render() {
return this.props.render({
loginHandle: this.loginHandle,
scanHandle: this.scanHandle,
getDeviceEntity: this.getDeviceEntity,
getDeviceConfigHandle: this.getDeviceConfigHandle,
});
}
}
export default LoginAndScan;
.index {
.scan-icon {
position: relative;
padding: 0;
background-color: #fff;
border-color: #fff;
width: 460px;
height: 460px;
margin: 238px auto 168px;
image {
position: absolute;
background-color: #fff;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 2;
}
}
.scan-text {
padding: 50px 0;
text-align: center;
font-size: 28px;
line-height: 52px;
}
}
......@@ -10,7 +10,11 @@ import { getDeviceConfig } from '../../api/device';
import { UserState, updateUserInfo } from '../../store/rootReducers/userinfo';
import { connect } from '@tarojs/redux';
import { Customer } from '../../types/Customer/Customer';
import { DeviceState, updateDeviceData } from '../../store/rootReducers/device';
import {
DeviceState,
updateDeviceData,
resetDeviceData,
} from '../../store/rootReducers/device';
import PrepayConfig from '../../types/Order/Order';
import { updatePayData } from '../../store/rootReducers/prepayConfig';
......@@ -27,16 +31,20 @@ type PageDispatchProps = {
updateUserInfo: (e: UserState) => void;
updateDeviceData: (e: DeviceState) => void;
updatePayData: (e: PrepayConfig[]) => void;
resetDeviceData: () => void;
};
type PageOwnProps = {};
type PageState = {};
type PageState = {
errorText: string;
};
type IProps = PageStateProps & PageDispatchProps & PageOwnProps;
interface Index {
props: IProps;
state: PageState;
}
@connect(
......@@ -53,6 +61,9 @@ interface Index {
updatePayData(data: PrepayConfig[]) {
dispatch(updatePayData(data));
},
resetDeviceData() {
dispatch(resetDeviceData());
},
}),
)
class Index extends Component {
......@@ -60,31 +71,31 @@ class Index extends Component {
navigationBarTitleText: '多彩自助服务',
};
constructor(props) {
super(props);
this.state = {
errorText: '',
};
}
componentWillMount() {
this.loginHandle().then(() => {
const { userinfo } = this.props;
let queryArr = Object.keys(this.$router.params);
let scene: string = queryArr.length > 0 ? queryArr[0] : '';
console.log(this.$router.params);
let scene: string = queryArr.length > 0 ? queryArr[0] : '';
console.log('scene:', scene);
if (scene) {
Taro.showLoading();
let entity = this.getDeviceEntity(scene);
if (entity) {
getDeviceConfig({
customerId: userinfo.customerId,
...entity,
})
.then(res => {
console.log(res);
})
.catch(err => {
console.error(err);
Taro.showToast({
title: err.msg || '设备码有误',
icon: 'none',
});
});
this.getDeviceConfigHandle(entity);
}
} else {
Taro.redirectTo({
url: '/pages/scanEnter/scanEnter',
});
}
});
}
......@@ -117,35 +128,66 @@ class Index extends Component {
}
scanHandle() {
const { userinfo, updateDeviceData, updatePayData } = this.props;
Taro.scanCode({
onlyFromCamera: true,
scanType: ['qrCode'],
})
.then(res => {
console.log(res);
const { path, result } = res;
if (path) {
let queryArr = path.split('?');
let queryStr = queryArr.length >= 2 ? queryArr[1] : '';
console.log(result, queryArr, queryStr);
const { serviceId, equipmentNum } = this.getDeviceEntity(queryStr);
const entity = this.getDeviceEntity(queryStr);
this.getDeviceConfigHandle(entity);
} else {
Taro.showToast({
title: '请扫描正确的小程序',
icon: 'none',
});
this.setState({
errorText: '请扫描正确的小程序',
});
}
})
.catch(err => {
console.error(err);
});
}
getDeviceConfig({
getDeviceConfigHandle({ equipmentNum, serviceId }: DeviceEntity) {
Taro.showLoading();
const {
userinfo,
updateDeviceData,
updatePayData,
resetDeviceData,
} = this.props;
return getDeviceConfig({
customerId: userinfo.customerId,
equipmentNum: equipmentNum,
serviceId: serviceId,
})
.then(res => {
Taro.hideLoading();
console.log(res);
const { deviceInfoResponse, prepayConfigs } = res.data;
const { deviceInfoResponse, prepayConfigs } = res;
if (deviceInfoResponse.isUsed) {
console.log('设备使用中');
return;
}
if (deviceInfoResponse) {
updateDeviceData(deviceInfoResponse);
} else {
resetDeviceData();
}
if (prepayConfigs) {
updatePayData(prepayConfigs);
Taro.navigateTo({
} else {
updatePayData([]);
}
Taro.redirectTo({
url: '/pages/pay/pay',
});
})
......@@ -155,16 +197,9 @@ class Index extends Component {
title: err.msg || '请扫描正确的设备码',
icon: 'none',
});
this.setState({
errorText: err.msg || '请扫描正确的设备码',
});
} else {
Taro.showToast({
title: '请扫描正确的设备码',
icon: 'none',
});
}
})
.catch(err => {
console.error(err);
});
}
......@@ -181,19 +216,21 @@ class Index extends Component {
}
render() {
const { errorText } = this.state;
return (
<View className='index'>
{errorText}
{/* <Button
className='scan-icon'
onGetUserInfo={this.getUserInfoHandle}
open-type='getUserInfo'>
<Image src={scanIcon} />
</Button> */}
<View className='scan-icon' onClick={this.clickHandle}>
{/* <View className='scan-icon' onClick={this.clickHandle}>
<Image src={scanIcon} />
</View>
<View className='scan-text'>马上扫一扫</View>
<View className='scan-text'>使用多彩自助服务</View>
<View className='scan-text'>使用多彩自助服务</View> */}
</View>
);
}
......
......@@ -11,6 +11,16 @@
justify-content: space-between;
.Pay-info-rate {
line-height: 40px;
.Pay-info-rate-item {
display: flex;
}
.Pay-info-rate-name {
margin-right: 5px;
}
.Pay-info-rate-mark {
width: 250px;
text-align: right;
}
}
}
}
......
......@@ -10,7 +10,8 @@ import AES from 'crypto-js/aes';
import Utf8 from 'crypto-js/enc-utf8';
import ECBmode from 'crypto-js/mode-ecb';
import PaddingPkcs7 from 'crypto-js/pad-pkcs7';
import { paySuccess } from '../../api/Order/paySuccess';
// import { paySuccess } from '../../api/Order/paySuccess';
import './pay.scss';
type PageStateProps = {
device: Device;
......@@ -62,21 +63,27 @@ class Pay extends Component {
getPayOrder({
equipmentNum: device.code,
equipmentPos: device.position,
payType: '',
serviceId: 0,
payType: '2',
serviceId: device.serviceId,
smaproCustomerId: customerId,
smaproPrepayConfigId: payId,
})
.then(res => {
const { payStr, outTradeNo } = res;
const key = customerId.toString().padEnd(16, '0');
console.log('res: ', res);
const { payStr } = res;
let key = customerId.toString();
while (key.length < 16) {
key = key + '0';
}
const payData = JSON.parse(
AES.decrypt(payStr, Utf8.parse(key), {
mode: ECBmode,
padding: PaddingPkcs7,
}).toString(Utf8),
);
console.log(payData);
console.log('payData:', payData);
Taro.requestPayment({
timeStamp: payData.msg.timeStamp.toString(),
nonceStr: payData.msg.nonceStr,
......@@ -85,11 +92,21 @@ class Pay extends Component {
paySign: payData.msg.paySign,
}).then(res => {
console.log(res);
paySuccess({ orderId: outTradeNo });
Taro.showLoading({
title: '设备连接中',
// paySuccess({ orderId: outTradeNo });
// Taro.showLoading({
// title: '设备连接中',
// mask: true,
// });
Taro.showToast({
title: '支付成功!',
icon: 'success',
mask: true,
});
setTimeout(() => {
Taro.navigateTo({
url: '/pages/index/index?', // 需要问号不然回到首页可以取到业务参数
});
}, 2000);
});
})
.catch(err => {
......@@ -115,15 +132,11 @@ class Pay extends Component {
<View className='Pay-info'>
<View className='Pay-info-item'>
<Text>服务类型</Text>
<Text>
{prepayConfig && prepayConfig.length
? prepayConfig[0].serviceName
: ''}
</Text>
<Text>{device.serviceName ? device.serviceName : ''}</Text>
</View>
<View className='Pay-info-item'>
<Text>设备编号</Text>
<Text>{device.code}</Text>
<Text>{device.code ? device.code : ''}</Text>
</View>
<View className='Pay-info-item'>
<Text>设备位置</Text>
......@@ -133,18 +146,18 @@ class Pay extends Component {
<Text>适用费率</Text>
<View className='Pay-info-rate'>
{device.rates.map(item => (
<View key={item.name}>
<Text>{item.name}</Text>
<Text>{item.mark}</Text>
<View key={item.name} className='Pay-info-rate-item'>
<Text className='Pay-info-rate-name'>{item.name}</Text>
<Text className='Pay-info-rate-mark'>{item.mark}</Text>
</View>
))}
{/* <View>
<Text>冷水</Text>
<Text>0.02元/100ml</Text>
{/* <View className='Pay-info-rate-item'>
<Text className='Pay-info-rate-name'>冷水</Text>
<Text className='Pay-info-rate-mark'>0.02元/100ml</Text>
</View>
<View>
<Text>热水</Text>
<Text>0.02元/100ml</Text>
<View className='Pay-info-rate-item'>
<Text className='Pay-info-rate-name'>热水</Text>
<Text className='Pay-info-rate-mark'>0.02元/100ml</Text>
</View> */}
</View>
</View>
......@@ -153,7 +166,9 @@ class Pay extends Component {
温馨提示:如本次预付款未全部使用,系统将在使用结束后半小时内自动退还剩余金额,请留意查收!
</View>
<View className='Pay-money'>
{prepayConfig.map(payConfig => (
{prepayConfig &&
prepayConfig.length &&
prepayConfig.map(payConfig => (
<View
key={payConfig.id}
className={`Pay-money-item ${
......
.ScanEnter {
.scan-icon {
position: relative;
padding: 0;
background-color: #fff;
border-color: #fff;
width: 460px;
height: 460px;
margin: 238px auto 168px;
border-radius: 50%;
box-shadow: #dae2fb 0 0 32px;
overflow: hidden;
&:active {
box-shadow: #6180f4 0 0 32px;
}
image {
position: absolute;
background-color: #fff;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 2;
}
}
.scan-text {
text-align: center;
font-size: 28px;
line-height: 52px;
}
}
import { ComponentClass } from 'react';
import Taro, { Component, Config } from '@tarojs/taro';
import { View, Image } from '@tarojs/components';
import scanIcon from '../../images/icon_s@2x.png';
import './scanEnter.scss';
import { registerAndLogin } from '../../api/customer';
import { getDeviceConfig } from '../../api/device';
import { UserState, updateUserInfo } from '../../store/rootReducers/userinfo';
import { connect } from '@tarojs/redux';
import { Customer } from '../../types/Customer/Customer';
import {
DeviceState,
updateDeviceData,
resetDeviceData,
} from '../../store/rootReducers/device';
import PrepayConfig from '../../types/Order/Order';
import { updatePayData } from '../../store/rootReducers/prepayConfig';
type DeviceEntity = {
serviceId: number;
equipmentNum: string;
};
type PageStateProps = {
userinfo: Customer;
};
type PageDispatchProps = {
updateUserInfo: (e: UserState) => void;
updateDeviceData: (e: DeviceState) => void;
updatePayData: (e: PrepayConfig[]) => void;
resetDeviceData: () => void;
};
type PageOwnProps = {};
type PageState = {};
type IProps = PageStateProps & PageDispatchProps & PageOwnProps;
interface ScanEnter {
props: IProps;
}
@connect(
({ userinfo }) => ({
userinfo,
}),
dispatch => ({
updateUserInfo(data: UserState) {
dispatch(updateUserInfo(data));
},
updateDeviceData(data: DeviceState) {
dispatch(updateDeviceData(data));
},
updatePayData(data: PrepayConfig[]) {
dispatch(updatePayData(data));
},
resetDeviceData() {
dispatch(resetDeviceData());
},
}),
)
class ScanEnter extends Component {
config: Config = {
navigationBarTitleText: '多彩自助服务',
};
componentWillMount() {
this.loginHandle().then(() => {
// let queryArr = Object.keys(this.$router.params);
// console.log(this.$router.params);
// let scene: string = queryArr.length > 0 ? queryArr[0] : '';
// console.log('scene:', scene);
// if (scene) {
// Taro.showLoading();
// let entity = this.getDeviceEntity(scene);
// if (entity) {
// this.getDeviceConfigHandle(entity);
// }
// }
});
}
getDeviceEntity(paramStr: string): DeviceEntity {
let serviceId = Number(paramStr.slice(0, 2));
let equipmentNum = paramStr.slice(2);
return {
serviceId,
equipmentNum,
};
}
loginHandle() {
const { updateUserInfo } = this.props;
return Taro.login().then(res => {
const { code } = res;
return registerAndLogin({
code,
// userName: '',
}).then(res => {
const { token, customerId } = res;
updateUserInfo({
token,
customerId,
});
});
});
}
scanHandle() {
Taro.scanCode({
onlyFromCamera: true,
scanType: ['qrCode'],
})
.then(res => {
console.log(res);
const { path, result } = res;
if (path) {
let queryArr = path.split('?');
let queryStr = queryArr.length >= 2 ? queryArr[1] : '';
console.log(result, queryArr, queryStr);
const entity = this.getDeviceEntity(queryStr);
this.getDeviceConfigHandle(entity);
} else {
Taro.showToast({
title: '请扫描正确的小程序',
icon: 'none',
});
}
})
.catch(err => {
console.error(err);
});
}
getDeviceConfigHandle({ equipmentNum, serviceId }: DeviceEntity) {
Taro.showLoading();
const {
userinfo,
updateDeviceData,
updatePayData,
resetDeviceData,
} = this.props;
return getDeviceConfig({
customerId: userinfo.customerId,
equipmentNum: equipmentNum,
serviceId: serviceId,
})
.then(res => {
Taro.hideLoading();
console.log(res);
const { deviceInfoResponse, prepayConfigs } = res;
if (deviceInfoResponse.isUsed) {
console.log('设备使用中');
return;
}
if (deviceInfoResponse) {
updateDeviceData(deviceInfoResponse);
} else {
resetDeviceData();
}
if (prepayConfigs) {
updatePayData(prepayConfigs);
} else {
updatePayData([]);
}
Taro.navigateTo({
url: '/pages/pay/pay',
});
})
.catch(err => {
console.error(err);
Taro.showToast({
title: err.msg || '请扫描正确的设备码',
icon: 'none',
});
});
}
getUserInfoHandle(res) {
console.log(res);
const { detail } = res;
if (detail.userInfo) {
// this.scanHandle(detail.userInfo);
}
}
clickHandle() {
this.scanHandle();
}
render() {
return (
<View className='ScanEnter'>
{/* <Button
className='scan-icon'
onGetUserInfo={this.getUserInfoHandle}
open-type='getUserInfo'>
<Image src={scanIcon} />
</Button> */}
<View className='scan-icon' onClick={this.clickHandle}>
<Image src={scanIcon} />
</View>
<View className='scan-text'>马上扫一扫</View>
<View className='scan-text'>使用多彩自助服务</View>
</View>
);
}
}
export default ScanEnter as ComponentClass<PageOwnProps, PageState>;
......@@ -13,12 +13,17 @@ export const INITIAL_STATE = {
position: '',
positionId: '',
rates: [],
serviceId: 0,
serviceName: '',
};
export const updateDeviceData = (entity: DeviceState): Action => ({
type: 'UPDATE_DEVICE_DATA',
payload: entity,
});
export const resetDeviceData = (): Action => ({
type: 'UPDATE_DEVICE_DATA',
});
export default function device(
state: Device = INITIAL_STATE,
......@@ -30,6 +35,10 @@ export default function device(
...state,
...actions.payload,
};
case 'UPDATE_DEVICE_DATA':
return {
...INITIAL_STATE,
};
default:
return state;
}
......
......@@ -4,7 +4,7 @@ import { PrepayConfig } from '../../types/Order/Order';
export const INITIAL_STATE = [];
export const updatePayData = (entity: PrepayConfig[]): Action => ({
type: 'UPDATE_DEVICE_DATA',
type: 'UPDATE_PAY_DATA',
payload: entity,
});
......@@ -13,11 +13,8 @@ export default function prepayConfig(
actions: Action,
): PrepayConfig[] {
switch (actions.type) {
case 'UPDATE_DEVICE_DATA':
return {
...state,
...actions.payload,
};
case 'UPDATE_PAY_DATA':
return [...actions.payload];
default:
return state;
}
......
......@@ -12,4 +12,6 @@ export type Device = {
position: string;
positionId: string;
rates: Rate[];
serviceId: number;
serviceName: string;
};
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