|
@@ -13,6 +13,8 @@ import {
|
|
|
TouchableHighlight,
|
|
|
DeviceEventEmitter,
|
|
|
ScrollView,
|
|
|
+ BackHandler,
|
|
|
+ StatusBar,
|
|
|
Modal,
|
|
|
Animated,
|
|
|
TextInput
|
|
@@ -22,7 +24,8 @@ import Dimensions from '../utils/dimensions';
|
|
|
import TopicTitle from '../components/TopicTitle';
|
|
|
import CourseTitle from '../components/CourseTitle';
|
|
|
import wechat from '../utils/wechat';
|
|
|
-import aliPay from '../utils/aliPay';
|
|
|
+import PayUtil from '../services/PayUtil';
|
|
|
+import Alipay from 'react-native-yunpeng-alipay';
|
|
|
|
|
|
export default class Buy extends BasePage {
|
|
|
state = {
|
|
@@ -34,7 +37,8 @@ export default class Buy extends BasePage {
|
|
|
slideAnim: new Animated.Value(-150),
|
|
|
ifDialogShow: false,
|
|
|
payType: 1,
|
|
|
- ticketPrice: 0
|
|
|
+ ticketPrice: 0,
|
|
|
+ useTicket: false
|
|
|
};
|
|
|
itemTap = (index) => {
|
|
|
this.setState({
|
|
@@ -62,6 +66,7 @@ export default class Buy extends BasePage {
|
|
|
</TouchableOpacity>
|
|
|
);
|
|
|
};
|
|
|
+
|
|
|
dialogComeout = (index) => {
|
|
|
if (index) {
|
|
|
this.setState(
|
|
@@ -71,14 +76,14 @@ export default class Buy extends BasePage {
|
|
|
() => {
|
|
|
Animated.timing(this.state.slideAnim, {
|
|
|
toValue: 0,
|
|
|
- duration: 300
|
|
|
+ duration: 100
|
|
|
}).start();
|
|
|
}
|
|
|
);
|
|
|
} else {
|
|
|
Animated.timing(this.state.slideAnim, {
|
|
|
toValue: -150,
|
|
|
- duration: 200
|
|
|
+ duration: 100
|
|
|
}).start();
|
|
|
setTimeout(() => {
|
|
|
this.setState({
|
|
@@ -99,11 +104,25 @@ export default class Buy extends BasePage {
|
|
|
}
|
|
|
);
|
|
|
};
|
|
|
+ componentWillMount() {
|
|
|
+ BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
|
|
|
+ }
|
|
|
+ componentWillUnmount() {
|
|
|
+ BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
|
|
|
+ }
|
|
|
+ onBackAndroid = () => {
|
|
|
+ if (this.state.ifDialogShow) {
|
|
|
+ this.dialogComeout(false);
|
|
|
+ } else {
|
|
|
+ this.goBack();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ };
|
|
|
choseTicket = () => {
|
|
|
this.toNextPage('Ticket', { choseTicketCallBack: this.choseTicketCallBack.bind(this) });
|
|
|
};
|
|
|
choseTicketCallBack(item) {
|
|
|
- /**
|
|
|
+ /**item参数
|
|
|
* type: 1,
|
|
|
price: 12,
|
|
|
num: 6,
|
|
@@ -111,42 +130,90 @@ export default class Buy extends BasePage {
|
|
|
*
|
|
|
*/
|
|
|
this.setState({
|
|
|
- ticketPrice: item.price
|
|
|
+ ticketPrice: item.price,
|
|
|
+ useTicket: true
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ getPrice(old_price) {
|
|
|
+ return parseInt(old_price) - parseInt(this.state.ticketPrice) < 0
|
|
|
+ ? 0
|
|
|
+ : parseInt(old_price) - parseInt(this.state.ticketPrice);
|
|
|
+ }
|
|
|
pay = () => {
|
|
|
switch (this.state.payType) {
|
|
|
case 1:
|
|
|
- //微信支付
|
|
|
- wechat.pay();
|
|
|
+ let option = {
|
|
|
+ method: 'POST',
|
|
|
+ body: {
|
|
|
+ productCode: '',
|
|
|
+ type: '0',
|
|
|
+ preferentialIds: '',
|
|
|
+ useVoucher: this.state.useTicket
|
|
|
+ }
|
|
|
+ };
|
|
|
+ PayUtil.payByWechat(option).then((result) => {
|
|
|
+ //微信支付
|
|
|
+ wechat.pay(
|
|
|
+ result.partnerId,
|
|
|
+ result.prepayId,
|
|
|
+ result.nonceStr,
|
|
|
+ result.timeStamp,
|
|
|
+ result.package,
|
|
|
+ result.sign
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
break;
|
|
|
case 2:
|
|
|
//阿里支付
|
|
|
- let params = {
|
|
|
- partner: 'asdfasdf', //app_id
|
|
|
- seller_id: '115681592@qq.com', //下单账号,用的芮总QQ邮箱,人家说没有可不填,但为了代表下单身份才用芮总QQ邮箱的
|
|
|
- out_trade_no: 'ALIPAY15307684880120000000001', //第三方订单号
|
|
|
- subject: '描述',
|
|
|
- body: '',
|
|
|
- total_fee: '0.01', //价格
|
|
|
- notify_url: 'http://xx.xx.xx.xx/api/0/alipay/alipayCallback', //回调地址
|
|
|
- service: 'm.pay',
|
|
|
- payment_type: '1',
|
|
|
- _input_charset: 'utf-8',
|
|
|
- it_b_pay: '30m',
|
|
|
- sign: 'sdfasdf', //签名
|
|
|
- sign_type: 'RSA'
|
|
|
+ let option_ali = {
|
|
|
+ method: 'POST',
|
|
|
+ body: {
|
|
|
+ productCode: '',
|
|
|
+ type: '0',
|
|
|
+ preferentialIds: '',
|
|
|
+ useVoucher: this.state.useTicket
|
|
|
+ }
|
|
|
};
|
|
|
- aliPay.pay(params);
|
|
|
+ //先请求后台给支付数据
|
|
|
+ PayUtil.payByAli(option_ali).then((result) => {
|
|
|
+ let data = 'partner=' + result.partner + '&';
|
|
|
+ 'seller_id=' + result.seller_id + '&';
|
|
|
+ 'out_trade_no=' + result.out_trade_no + '&';
|
|
|
+ 'subject=' + result.subject + '&';
|
|
|
+ 'body=' + result.body + '&';
|
|
|
+ 'total_fee=' + result.total_fee + '&';
|
|
|
+ 'notify_url=' + result.notify_url + '&';
|
|
|
+ 'service=' + result.service + '&';
|
|
|
+ 'payment_type=' + result.payment_type + '&';
|
|
|
+ '_input_charset=' + result._input_charset + '&';
|
|
|
+ 'it_b_pay=' + result.it_b_pay + '&';
|
|
|
+ 'sign=' + result.sign + '&';
|
|
|
+ 'sign_type=' + result.sign_type;
|
|
|
+ //调用阿里支付
|
|
|
+ Alipay.pay(data).then(
|
|
|
+ function(data) {
|
|
|
+ //成功
|
|
|
+ console.log(data);
|
|
|
+ },
|
|
|
+ function(err) {
|
|
|
+ //失败
|
|
|
+ console.log(err);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ });
|
|
|
break;
|
|
|
}
|
|
|
};
|
|
|
render() {
|
|
|
return (
|
|
|
<View style={{ flex: 1 }}>
|
|
|
+ <StatusBar barStyle={'dark-content'} backgroundColor={'white'} translucent={true} />
|
|
|
<View
|
|
|
style={{
|
|
|
- height: 30,
|
|
|
+ height: 50,
|
|
|
+ backgroundColor: 'white',
|
|
|
marginTop: 30
|
|
|
}}
|
|
|
>
|
|
@@ -165,6 +232,13 @@ export default class Buy extends BasePage {
|
|
|
<View>{this.state.shopData.map((item, index) => this.renderItem(item, index))}</View>
|
|
|
</View>
|
|
|
<View style={{ flex: 0.01, backgroundColor: 'rgba(242, 242, 242, 1)' }} />
|
|
|
+ <TouchableOpacity style={styles.payment} activeOpacity={1} onPress={this.choseTicket.bind(this)}>
|
|
|
+ <Text style={styles.left}>使用抵用券</Text>
|
|
|
+ <View style={styles.right}>
|
|
|
+ <Text style={styles.method}>-¥{this.state.ticketPrice}元</Text>
|
|
|
+ <Image source={require('../images/common/arrowRight.png')} />
|
|
|
+ </View>
|
|
|
+ </TouchableOpacity>
|
|
|
<TouchableOpacity style={styles.payment} activeOpacity={1} onPress={() => this.dialogComeout(true)}>
|
|
|
<Text style={styles.left}>支付方式</Text>
|
|
|
<View style={styles.right}>
|
|
@@ -177,13 +251,6 @@ export default class Buy extends BasePage {
|
|
|
<Image source={require('../images/common/arrowRight.png')} />
|
|
|
</View>
|
|
|
</TouchableOpacity>
|
|
|
- <TouchableOpacity style={styles.payment} activeOpacity={1} onPress={this.choseTicket.bind(this)}>
|
|
|
- <Text style={styles.left}>使用抵用券</Text>
|
|
|
- <View style={styles.right}>
|
|
|
- <Text style={styles.method}>-¥{this.state.ticketPrice}元</Text>
|
|
|
- <Image source={require('../images/common/arrowRight.png')} />
|
|
|
- </View>
|
|
|
- </TouchableOpacity>
|
|
|
<View style={{ flex: 0.01, backgroundColor: 'rgba(242, 242, 242, 1)' }} />
|
|
|
<View>
|
|
|
<Text style={{ fontSize: 14, width: '100%', textAlignVertical: 'center', textAlign: 'center' }}>
|
|
@@ -194,8 +261,7 @@ export default class Buy extends BasePage {
|
|
|
{this.state.ticketPrice > 0 ? (
|
|
|
(price = (
|
|
|
<Text style={styles.bottomLeft}>
|
|
|
- ¥{parseInt(this.state.shopData[this.state.currentTapindex].price) -
|
|
|
- parseInt(this.state.ticketPrice)}元
|
|
|
+ ¥{this.getPrice(this.state.shopData[this.state.currentTapindex].price)}元
|
|
|
</Text>
|
|
|
))
|
|
|
) : (
|
|
@@ -214,12 +280,7 @@ export default class Buy extends BasePage {
|
|
|
style={{ ...styles.dialog }}
|
|
|
underlayColor={0.1}
|
|
|
>
|
|
|
- <Animated.View
|
|
|
- style={{ ...styles.payMethod, bottom: this.state.slideAnim }}
|
|
|
- onPress={() => {
|
|
|
- alert(12311);
|
|
|
- }}
|
|
|
- >
|
|
|
+ <Animated.View style={{ ...styles.payMethod, bottom: this.state.slideAnim }} onPress={() => {}}>
|
|
|
<Text style={styles.payText}>选择支付方式</Text>
|
|
|
<TouchableOpacity
|
|
|
activeOpacity={0.9}
|
|
@@ -248,6 +309,7 @@ export default class Buy extends BasePage {
|
|
|
) : null}
|
|
|
</TouchableOpacity>
|
|
|
{/* <TextInput style={styles.payDialog} /> */}
|
|
|
+ <View style={{ flex: 0.2 }} />
|
|
|
</Animated.View>
|
|
|
</TouchableHighlight>
|
|
|
) : null}
|