Authored by 孙凯

add 扫描二维码 review by hongmo

//
// YH_QRCodeHelper.h
// YH_Mall
// QRNativeConfig.h
// YH_Vendor
//
// Created by redding on 16/8/29.
// Copyright © 2016年 YOHO. All rights reserved.
// Created by 孙凯 on 2017/6/16.
// Copyright © 2017年 Facebook. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "RCTBridgeModule.h"
@interface YH_QRCodeHelper : NSObject <RCTBridgeModule>
@interface QRNativeConfig : NSObject <RCTBridgeModule>
@end
... ...
//
// YH_QRCodeHelper.m
// YH_Mall
// QRNativeConfig.m
// YH_Vendor
//
// Created by redding on 16/8/29.
// Copyright © 2016年 YOHO. All rights reserved.
// Created by 孙凯 on 2017/6/16.
// Copyright © 2017年 Facebook. All rights reserved.
//
#import "YH_QRCodeHelper.h"
#import "QRNativeConfig.h"
#import "RCTEventDispatcher.h"
#import "YH_AVScanViewController.h"
#import "AppDelegate.h"
@implementation YH_QRCodeHelper
@implementation QRNativeConfig
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE()
RCT_REMAP_METHOD(displayQRScanner, displayQRScannerWithResolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
RCT_EXPORT_METHOD(startScanQRCode) {
dispatch_async(dispatch_get_main_queue(), ^{
YH_AVScanViewController *avscanViewController = [[YH_AVScanViewController alloc] init];
avscanViewController.scanType = YHScanType_Express;
[avscanViewController.view setFrame:[[UIScreen mainScreen] bounds]];
avscanViewController.resultCallBack = ^(NSString *info) {
resolve(info);
};
YH_AVScanViewController *avscanViewController = [[YH_AVScanViewController alloc] init];
avscanViewController.scanType = YHScanType_Express;
[avscanViewController.view setFrame:[[UIScreen mainScreen] bounds]];
avscanViewController.resultCallBack = ^(NSString *info) {
[self.bridge.eventDispatcher sendAppEventWithName:@"scanQRComplete"
body:info];
};
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.window.rootViewController presentViewController:avscanViewController animated:YES completion:^{}];
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.window.rootViewController presentViewController:avscanViewController animated:YES completion:^{}];
});
}
... ...
... ... @@ -5,10 +5,6 @@ import LoadMoreIndicator from '../indicator/LoadMoreIndicator';
import LoadingIndicator from '../indicator/LoadingIndicator';
import moment from 'moment';
import DeliverGoodsCell from './DeliverGoodsCell';
import {NativeModules} from 'react-native';
import { DeviceEventEmitter } from 'react-native';
let QRNativeConfig = NativeModules.QRNativeConfig;
import {
StyleSheet,
... ... @@ -125,7 +121,7 @@ export default class DeliverGoods extends Component {
value={expressNum}
/>
<TouchableOpacity onPress={() => {
QRNativeConfig.startScanQRCode();
this.props.startScanQRCode && this.props.startScanQRCode();
}}>
<View style={styles.camera}>
</View>
... ... @@ -140,18 +136,12 @@ export default class DeliverGoods extends Component {
style={styles.listContainer}
dataSource={this.dataSource.cloneWithRows(initialRes)}
renderRow={this._renderRow}
enableEmptySections={true}
/>
{this.state.showPicker ? this._picker() : null}
</View>
);
}
componentWillMount() {
let that = this;
DeviceEventEmitter.addListener('scanQRComplete', function(param) {
this.props.setExpressNum && this.props.setExpressNum(param.QRCode);
});
}
}
let {width, height} = Dimensions.get('window');
... ...
... ... @@ -5,13 +5,15 @@ import React, { Component } from 'react';
import Immutable, {List, Record} from 'immutable';
import DeliverGoods from '../components/DeliverGoods/DeliverGoods'
import {
import ReactNative,{
StyleSheet,
View,
Text,
ListView,
Dimensions,
Platform,
NativeAppEventEmitter,
NativeModules,
} from 'react-native';
import {bindActionCreators} from 'redux';
... ... @@ -51,8 +53,21 @@ class DeliverGoodsContainer extends Component {
super(props);
this._setExpressNum = this._setExpressNum.bind(this);
this._setExpressValue = this._setExpressValue.bind(this);
this._startScanQRCode = this._startScanQRCode.bind(this);
this.subscription = NativeAppEventEmitter.addListener(
'scanQRComplete',
(param) => {
console.log(param);
this.props.actions.setExpressNum(param);
}
);
}
componentWillUnmount() {
this.subscription && this.subscription.remove();
}
componentDidMount() {
this.props.actions.getExpressList();
this.props.actions.queryBySupplierId();
... ... @@ -66,6 +81,10 @@ class DeliverGoodsContainer extends Component {
this.props.actions.setExpressValue(value,initialRes);
}
_startScanQRCode(){
NativeModules.QRNativeConfig.startScanQRCode();
}
render() {
let {deliverGoods,initialRes,expressNum,expressValue} = this.props;
... ... @@ -77,7 +96,8 @@ class DeliverGoodsContainer extends Component {
expressNum={expressNum}
expressValue={expressValue}
setExpressNum={this._setExpressNum}
setExpressValue={this._setExpressValue}/>
setExpressValue={this._setExpressValue}
startScanQRCode={this._startScanQRCode}/>
</View>
);
}
... ...
... ... @@ -91,9 +91,22 @@ export function deliveryGoods() {
dispatch(deliveryGoodsRequest())
return new DeliverGoodsService().deliveryGoods(expressId,expressNumber,shopId,expressGoodsMap)
.then((json) => {
Alert.alert(
'提交成功!',
'',
[{text: 'OK', onPress: () => {
Actions.pop();
}}]
);
dispatch(deliveryGoodsSuccess(json))
})
.catch((error) => {
Alert.alert(
'提交失败!',
error.message,
[{text: 'OK', onPress: () => {
}}]
);
dispatch(deliveryGoodsFailure(error))
});
};
... ...
... ... @@ -53,9 +53,26 @@ export function stockOut() {
dispatch(stockOutRequest())
return new OutOfStockService().stockOut(proReqFormId,productSku,num,shopId)
.then((json) => {
Alert.alert(
'提交成功!',
'',
[{text: 'OK', onPress: () => {
Actions.pop();
}}]
);
dispatch(stockOutSuccess(json))
})
.catch((error) => {
Alert.alert(
'提交失败!',
error.message,
[{text: 'OK', onPress: () => {
}}]
);
dispatch(stockOutFailure(error))
});
};
... ...