Commit 6a8f7e53 by 姜雷

Merge branch 'develop' into test

parents 5785437b ca143f38
import { ComponentClass } from 'react'; import { ComponentClass } from "react";
import Taro, { Component, Config } from '@tarojs/taro'; import Taro, { Component, Config } from "@tarojs/taro";
import { View, Image } from '@tarojs/components'; import { View, Image } from "@tarojs/components";
import scanIcon from '../../images/icon_s@2x.png'; import scanIcon from "../../images/icon_s@2x.png";
import './index.scss'; import "./index.scss";
import { registerAndLogin } from '../../api/customer'; import { registerAndLogin } from "../../api/customer";
import { getDeviceConfig } from '../../api/device'; import { getDeviceConfig } from "../../api/device";
import { UserState, updateUserInfo } from '../../store/rootReducers/userinfo'; import { UserState, updateUserInfo } from "../../store/rootReducers/userinfo";
import { connect } from '@tarojs/redux'; import { connect } from "@tarojs/redux";
import { Customer } from '../../types/Customer/Customer'; import { Customer } from "../../types/Customer/Customer";
import { import {
DeviceState, DeviceState,
updateDeviceData, updateDeviceData,
resetDeviceData, resetDeviceData
} from '../../store/rootReducers/device'; } from "../../store/rootReducers/device";
import PrepayConfig from '../../types/Order/Order'; import PrepayConfig from "../../types/Order/Order";
import { updatePayData } from '../../store/rootReducers/prepayConfig'; import { updatePayData } from "../../store/rootReducers/prepayConfig";
import { getPathParams } from "@/utils/path";
type DeviceEntity = { type DeviceEntity = {
serviceId: number; serviceId: number;
...@@ -49,7 +50,7 @@ interface Index { ...@@ -49,7 +50,7 @@ interface Index {
@connect( @connect(
({ userinfo }) => ({ ({ userinfo }) => ({
userinfo, userinfo
}), }),
dispatch => ({ dispatch => ({
updateUserInfo(data: UserState) { updateUserInfo(data: UserState) {
...@@ -63,30 +64,43 @@ interface Index { ...@@ -63,30 +64,43 @@ interface Index {
}, },
resetDeviceData() { resetDeviceData() {
dispatch(resetDeviceData()); dispatch(resetDeviceData());
}, }
}), })
) )
class Index extends Component { class Index extends Component {
config: Config = { config: Config = {
navigationBarTitleText: '多彩自助服务', navigationBarTitleText: "多彩自助服务"
}; };
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
errorText: '', errorText: ""
}; };
} }
componentWillMount() { componentWillMount() {
this.loginHandle().then(() => { this.loginHandle().then(() => {
let codeStr = this.$router.params.q;
let queryArr = Object.keys(this.$router.params); let queryArr = Object.keys(this.$router.params);
console.log(this.$router.params); console.log(this.$router.params);
let scene: string = queryArr.length > 0 ? queryArr[0] : ''; let scene: string = queryArr.length > 0 ? queryArr[0] : "";
console.log('scene:', scene); console.log("scene:", scene);
if (scene) { if (codeStr) {
// Taro.showLoading();
let params = getPathParams(codeStr);
console.log("code", params);
if (params["code"]) {
let entity = this.getDeviceEntity(params["code"]);
if (entity) {
this.getDeviceConfigHandle(entity);
}
} else {
this.scanErrorWeQRcode();
}
} else if (scene) {
Taro.showLoading(); Taro.showLoading();
let entity = this.getDeviceEntity(scene); let entity = this.getDeviceEntity(scene);
if (entity) { if (entity) {
...@@ -94,7 +108,7 @@ class Index extends Component { ...@@ -94,7 +108,7 @@ class Index extends Component {
} }
} else { } else {
Taro.redirectTo({ Taro.redirectTo({
url: '/pages/scanEnter/scanEnter', url: "/pages/scanEnter/scanEnter"
}); });
} }
}); });
...@@ -105,7 +119,7 @@ class Index extends Component { ...@@ -105,7 +119,7 @@ class Index extends Component {
let equipmentNum = paramStr.slice(2); let equipmentNum = paramStr.slice(2);
return { return {
serviceId, serviceId,
equipmentNum, equipmentNum
}; };
} }
...@@ -113,18 +127,18 @@ class Index extends Component { ...@@ -113,18 +127,18 @@ class Index extends Component {
const { updateUserInfo } = this.props; const { updateUserInfo } = this.props;
return Taro.login().then(res => { return Taro.login().then(res => {
console.log('login info:', res); console.log("login info:", res);
const { code } = res; const { code } = res;
return registerAndLogin({ return registerAndLogin({
code, code
// userName: '', // userName: '',
}).then(res => { }).then(res => {
const { token, customerId, isAuth } = res; const { token, customerId, isAuth } = res;
updateUserInfo({ updateUserInfo({
token, token,
customerId, customerId,
isAuth, isAuth
}); });
}); });
}); });
...@@ -133,24 +147,24 @@ class Index extends Component { ...@@ -133,24 +147,24 @@ class Index extends Component {
scanHandle() { scanHandle() {
Taro.scanCode({ Taro.scanCode({
onlyFromCamera: true, onlyFromCamera: true,
scanType: ['qrCode'], scanType: ["qrCode"]
}) })
.then(res => { .then(res => {
console.log(res); console.log(res);
const { path, result } = res; const { path, result } = res;
if (path) { if (path) {
let queryArr = path.split('?'); let queryArr = path.split("?");
let queryStr = queryArr.length >= 2 ? queryArr[1] : ''; let queryStr = queryArr.length >= 2 ? queryArr[1] : "";
console.log(result, queryArr, queryStr); console.log(result, queryArr, queryStr);
const entity = this.getDeviceEntity(queryStr); const entity = this.getDeviceEntity(queryStr);
this.getDeviceConfigHandle(entity); this.getDeviceConfigHandle(entity);
} else { } else {
Taro.showToast({ Taro.showToast({
title: '请扫描正确的小程序', title: "请扫描正确的小程序",
icon: 'none', icon: "none"
}); });
this.setState({ this.setState({
errorText: '请扫描正确的小程序', errorText: "请扫描正确的小程序"
}); });
} }
}) })
...@@ -165,19 +179,19 @@ class Index extends Component { ...@@ -165,19 +179,19 @@ class Index extends Component {
userinfo, userinfo,
updateDeviceData, updateDeviceData,
updatePayData, updatePayData,
resetDeviceData, resetDeviceData
} = this.props; } = this.props;
return getDeviceConfig({ return getDeviceConfig({
customerId: userinfo.customerId, customerId: userinfo.customerId,
equipmentNum: equipmentNum, equipmentNum: equipmentNum,
serviceId: serviceId, serviceId: serviceId
}) })
.then(res => { .then(res => {
Taro.hideLoading(); Taro.hideLoading();
console.log(res); console.log(res);
const { deviceInfoResponse, prepayConfigs } = res; const { deviceInfoResponse, prepayConfigs } = res;
if (deviceInfoResponse.isUsed) { if (deviceInfoResponse.isUsed) {
console.log('设备使用中'); console.log("设备使用中");
return; return;
} }
if (deviceInfoResponse) { if (deviceInfoResponse) {
...@@ -192,17 +206,17 @@ class Index extends Component { ...@@ -192,17 +206,17 @@ class Index extends Component {
updatePayData([]); updatePayData([]);
} }
Taro.redirectTo({ Taro.redirectTo({
url: '/pages/pay/pay', url: "/pages/pay/pay"
}); });
}) })
.catch(err => { .catch(err => {
console.error(err); console.error(err);
Taro.showToast({ Taro.showToast({
title: err.msg || '请扫描正确的设备码', title: err.msg || "请扫描正确的设备码",
icon: 'none', icon: "none"
}); });
this.setState({ this.setState({
errorText: err.msg || '请扫描正确的设备码', errorText: err.msg || "请扫描正确的设备码"
}); });
}); });
} }
...@@ -219,10 +233,20 @@ class Index extends Component { ...@@ -219,10 +233,20 @@ class Index extends Component {
this.scanHandle(); this.scanHandle();
} }
scanErrorWeQRcode() {
Taro.showToast({
title: "请扫描正确的小程序",
icon: "none"
});
this.setState({
errorText: "请扫描正确的小程序"
});
}
render() { render() {
const { errorText } = this.state; const { errorText } = this.state;
return ( return (
<View className='index'> <View className="index">
{errorText} {errorText}
{/* <Button {/* <Button
className='scan-icon' className='scan-icon'
......
...@@ -857,7 +857,7 @@ class Pay extends Component { ...@@ -857,7 +857,7 @@ class Pay extends Component {
<Text>适用费率</Text> <Text>适用费率</Text>
<View className='Pay-info-rate'> <View className='Pay-info-rate'>
{device.rates.map(item => ( {device.rates.map(item => (
<View key={item.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>
...@@ -884,7 +884,7 @@ class Pay extends Component { ...@@ -884,7 +884,7 @@ class Pay extends Component {
prepayConfig.length && prepayConfig.length &&
prepayConfig.map(payConfig => ( prepayConfig.map(payConfig => (
<View <View
key={payConfig.id} key='id'
className={`Pay-money-item ${ className={`Pay-money-item ${
payConfig.id == payId ? 'seleted' : '' payConfig.id == payId ? 'seleted' : ''
}`} }`}
......
import { ComponentClass } from 'react'; import { ComponentClass } from "react";
import Taro, { Component, Config } from '@tarojs/taro'; import Taro, { Component, Config } from "@tarojs/taro";
import { View, Image } from '@tarojs/components'; import { View, Image } from "@tarojs/components";
import scanIcon from '../../images/icon_s@2x.png'; import scanIcon from "../../images/icon_s@2x.png";
import './scanEnter.scss'; import "./scanEnter.scss";
import { registerAndLogin } from '../../api/customer'; import { registerAndLogin } from "../../api/customer";
import { getDeviceConfig } from '../../api/device'; import { getDeviceConfig } from "../../api/device";
import { UserState, updateUserInfo } from '../../store/rootReducers/userinfo'; import { UserState, updateUserInfo } from "../../store/rootReducers/userinfo";
import { connect } from '@tarojs/redux'; import { connect } from "@tarojs/redux";
import { Customer } from '../../types/Customer/Customer'; import { Customer } from "../../types/Customer/Customer";
import { import {
DeviceState, DeviceState,
updateDeviceData, updateDeviceData,
resetDeviceData, resetDeviceData
} from '../../store/rootReducers/device'; } from "../../store/rootReducers/device";
import PrepayConfig from '../../types/Order/Order'; import PrepayConfig from "../../types/Order/Order";
import { updatePayData } from '../../store/rootReducers/prepayConfig'; import { updatePayData } from "../../store/rootReducers/prepayConfig";
import { getPathParams } from "@/utils/path";
type DeviceEntity = { type DeviceEntity = {
serviceId: number; serviceId: number;
...@@ -46,7 +47,7 @@ interface ScanEnter { ...@@ -46,7 +47,7 @@ interface ScanEnter {
@connect( @connect(
({ userinfo }) => ({ ({ userinfo }) => ({
userinfo, userinfo
}), }),
dispatch => ({ dispatch => ({
updateUserInfo(data: UserState) { updateUserInfo(data: UserState) {
...@@ -60,12 +61,12 @@ interface ScanEnter { ...@@ -60,12 +61,12 @@ interface ScanEnter {
}, },
resetDeviceData() { resetDeviceData() {
dispatch(resetDeviceData()); dispatch(resetDeviceData());
}, }
}), })
) )
class ScanEnter extends Component { class ScanEnter extends Component {
config: Config = { config: Config = {
navigationBarTitleText: '多彩自助服务', navigationBarTitleText: "多彩自助服务"
}; };
componentWillMount() { componentWillMount() {
...@@ -89,7 +90,7 @@ class ScanEnter extends Component { ...@@ -89,7 +90,7 @@ class ScanEnter extends Component {
let equipmentNum = paramStr.slice(2); let equipmentNum = paramStr.slice(2);
return { return {
serviceId, serviceId,
equipmentNum, equipmentNum
}; };
} }
...@@ -97,17 +98,17 @@ class ScanEnter extends Component { ...@@ -97,17 +98,17 @@ class ScanEnter extends Component {
const { updateUserInfo } = this.props; const { updateUserInfo } = this.props;
return Taro.login().then(res => { return Taro.login().then(res => {
console.log('login info:', res); console.log("login info:", res);
const { code } = res; const { code } = res;
return registerAndLogin({ return registerAndLogin({
code, code
// userName: '', // userName: '',
}).then(res => { }).then(res => {
const { token, customerId, isAuth } = res; const { token, customerId, isAuth } = res;
updateUserInfo({ updateUserInfo({
token, token,
customerId, customerId,
isAuth, isAuth
}); });
}); });
}); });
...@@ -116,21 +117,26 @@ class ScanEnter extends Component { ...@@ -116,21 +117,26 @@ class ScanEnter extends Component {
scanHandle() { scanHandle() {
Taro.scanCode({ Taro.scanCode({
onlyFromCamera: true, onlyFromCamera: true,
scanType: ['qrCode'], scanType: ["qrCode"]
}) })
.then(res => { .then(res => {
console.log(res); console.log(res);
const { path, result } = res; const { path, result } = res;
let param = getPathParams(result);
if (path) { if (path) {
let queryArr = path.split('?'); let queryArr = path.split("?");
let queryStr = queryArr.length >= 2 ? queryArr[1] : ''; let queryStr = queryArr.length >= 2 ? queryArr[1] : "";
console.log(result, queryArr, queryStr); console.log(result, queryArr, queryStr);
const entity = this.getDeviceEntity(queryStr); const entity = this.getDeviceEntity(queryStr);
this.getDeviceConfigHandle(entity); this.getDeviceConfigHandle(entity);
} else if (param["code"]) {
console.log(param["code"]);
const entity = this.getDeviceEntity(param["code"]);
this.getDeviceConfigHandle(entity);
} else { } else {
Taro.showToast({ Taro.showToast({
title: '请扫描正确的小程序', title: "请扫描正确的小程序",
icon: 'none', icon: "none"
}); });
} }
}) })
...@@ -145,19 +151,19 @@ class ScanEnter extends Component { ...@@ -145,19 +151,19 @@ class ScanEnter extends Component {
userinfo, userinfo,
updateDeviceData, updateDeviceData,
updatePayData, updatePayData,
resetDeviceData, resetDeviceData
} = this.props; } = this.props;
return getDeviceConfig({ return getDeviceConfig({
customerId: userinfo.customerId, customerId: userinfo.customerId,
equipmentNum: equipmentNum, equipmentNum: equipmentNum,
serviceId: serviceId, serviceId: serviceId
}) })
.then(res => { .then(res => {
Taro.hideLoading(); Taro.hideLoading();
console.log(res); console.log(res);
const { deviceInfoResponse, prepayConfigs } = res; const { deviceInfoResponse, prepayConfigs } = res;
if (deviceInfoResponse.isUsed) { if (deviceInfoResponse.isUsed) {
console.log('设备使用中'); console.log("设备使用中");
return; return;
} }
if (deviceInfoResponse) { if (deviceInfoResponse) {
...@@ -172,14 +178,14 @@ class ScanEnter extends Component { ...@@ -172,14 +178,14 @@ class ScanEnter extends Component {
updatePayData([]); updatePayData([]);
} }
Taro.navigateTo({ Taro.navigateTo({
url: '/pages/pay/pay', url: "/pages/pay/pay"
}); });
}) })
.catch(err => { .catch(err => {
console.error(err); console.error(err);
Taro.showToast({ Taro.showToast({
title: err.msg || '请扫描正确的设备码', title: err.msg || "请扫描正确的设备码",
icon: 'none', icon: "none"
}); });
}); });
} }
...@@ -198,18 +204,18 @@ class ScanEnter extends Component { ...@@ -198,18 +204,18 @@ class ScanEnter extends Component {
render() { render() {
return ( return (
<View className='ScanEnter'> <View className="ScanEnter">
{/* <Button {/* <Button
className='scan-icon' className='scan-icon'
onGetUserInfo={this.getUserInfoHandle} onGetUserInfo={this.getUserInfoHandle}
open-type='getUserInfo'> open-type='getUserInfo'>
<Image src={scanIcon} /> <Image src={scanIcon} />
</Button> */} </Button> */}
<View className='scan-icon' onClick={this.clickHandle}> <View className="scan-icon" onClick={this.clickHandle}>
<Image src={scanIcon} /> <Image src={scanIcon} />
</View> </View>
<View className='scan-text'>马上扫一扫</View> <View className="scan-text">马上扫一扫</View>
<View className='scan-text'>使用多彩自助服务</View> <View className="scan-text">使用多彩自助服务</View>
</View> </View>
); );
} }
......
export const getPathParams = (path: string) => {
let paramsArr = decodeURIComponent(path).split("?");
if (paramsArr.length > 1) {
let params = {};
paramsArr = paramsArr[1].split("&");
for (let index = 0; index < paramsArr.length; index++) {
const element = paramsArr[index].split("=");
if (element.length) {
params[element[0]] = element[1];
}
}
return params;
} else {
return {};
}
};
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