|
@@ -14,6 +14,7 @@ import {
|
|
|
DeviceEventEmitter,
|
|
|
ScrollView,
|
|
|
BackHandler,
|
|
|
+ ToastAndroid,
|
|
|
StatusBar,
|
|
|
Modal,
|
|
|
Animated,
|
|
@@ -31,40 +32,16 @@ export default class Buy extends BasePage {
|
|
|
state = {
|
|
|
shopData: [
|
|
|
{
|
|
|
- appCode: '1006',
|
|
|
- days: 365,
|
|
|
- gmtCreated: 1520843765000,
|
|
|
- gmtModified: 1541127465000,
|
|
|
- id: 10018,
|
|
|
+ appCode: '',
|
|
|
+ days: 0,
|
|
|
+ gmtCreated: 0,
|
|
|
+ gmtModified: 0,
|
|
|
+ id: 0,
|
|
|
title: '',
|
|
|
- originalPrice: '499',
|
|
|
- payType: 3,
|
|
|
- price: '199',
|
|
|
- sort: 1
|
|
|
- },
|
|
|
- {
|
|
|
- appCode: '1006',
|
|
|
- days: 92,
|
|
|
- gmtCreated: 1520843761000,
|
|
|
- gmtModified: 1534387968000,
|
|
|
- id: 10017,
|
|
|
- title: '',
|
|
|
- originalPrice: '199',
|
|
|
- payType: 2,
|
|
|
- price: '99',
|
|
|
- sort: 2
|
|
|
- },
|
|
|
- {
|
|
|
- appCode: '1006',
|
|
|
- days: 31,
|
|
|
- gmtCreated: 1520843757000,
|
|
|
- gmtModified: 1537953249000,
|
|
|
- id: 10016,
|
|
|
- title: '',
|
|
|
- originalPrice: '99',
|
|
|
+ originalPrice: '',
|
|
|
payType: 1,
|
|
|
- price: '49',
|
|
|
- sort: 3
|
|
|
+ price: '',
|
|
|
+ sort: 0
|
|
|
}
|
|
|
],
|
|
|
currentTapindex: 0,
|
|
@@ -140,14 +117,7 @@ export default class Buy extends BasePage {
|
|
|
};
|
|
|
componentWillMount() {
|
|
|
//获取订购数据信息
|
|
|
- PayUtil.getMember().then((result) => {
|
|
|
- console.log('====================================');
|
|
|
- console.log('result', result);
|
|
|
- console.log('====================================');
|
|
|
- this.setState({
|
|
|
- shopData: result.data
|
|
|
- });
|
|
|
- });
|
|
|
+ this.getMember();
|
|
|
BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
|
|
|
}
|
|
|
componentWillUnmount() {
|
|
@@ -161,6 +131,17 @@ export default class Buy extends BasePage {
|
|
|
}
|
|
|
return true;
|
|
|
};
|
|
|
+
|
|
|
+ async getMember() {
|
|
|
+ await PayUtil.getMember().then((result) => {
|
|
|
+ console.log('====================================');
|
|
|
+ console.log('result', result);
|
|
|
+ console.log('====================================');
|
|
|
+ this.setState({
|
|
|
+ shopData: result.data
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
choseTicket = () => {
|
|
|
this.toNextPage('Ticket', { choseTicketCallBack: this.choseTicketCallBack.bind(this) });
|
|
|
};
|
|
@@ -184,58 +165,43 @@ export default class Buy extends BasePage {
|
|
|
: parseInt(old_price) - parseInt(this.state.ticketPrice);
|
|
|
}
|
|
|
pay = () => {
|
|
|
+ let data = this.state.shopData[this.state.currentTapindex];
|
|
|
switch (this.state.payType) {
|
|
|
case 1:
|
|
|
- let option = {
|
|
|
- method: 'POST',
|
|
|
- body: {
|
|
|
- productCode: '',
|
|
|
- type: '0',
|
|
|
- preferentialIds: '',
|
|
|
- useVoucher: this.state.useTicket
|
|
|
- }
|
|
|
+ let params = {
|
|
|
+ productCode: data.id,
|
|
|
+ type: '0',
|
|
|
+ preferentialIds: '',
|
|
|
+ useVoucher: this.state.useTicket
|
|
|
};
|
|
|
- PayUtil.payByWechat(option).then((result) => {
|
|
|
- //微信支付
|
|
|
+
|
|
|
+ PayUtil.payByWechat(params).then((result) => {
|
|
|
wechat.pay(
|
|
|
- result.partnerId,
|
|
|
- result.prepayId,
|
|
|
- result.nonceStr,
|
|
|
- result.timeStamp,
|
|
|
- result.package,
|
|
|
- result.sign
|
|
|
+ result.data.partnerid,
|
|
|
+ result.data.prepayid,
|
|
|
+ result.data.noncestr,
|
|
|
+ result.data.timestamp,
|
|
|
+ result.data.package,
|
|
|
+ result.data.sign,
|
|
|
+ (result) => {
|
|
|
+ ToastAndroid.show('支付成功', ToastAndroid.SHORT);
|
|
|
+ // console.log('wechat result', result);
|
|
|
+ }
|
|
|
);
|
|
|
});
|
|
|
|
|
|
break;
|
|
|
case 2:
|
|
|
//阿里支付
|
|
|
- let option_ali = {
|
|
|
- method: 'POST',
|
|
|
- body: {
|
|
|
- productCode: '',
|
|
|
- type: '0',
|
|
|
- preferentialIds: '',
|
|
|
- useVoucher: this.state.useTicket
|
|
|
- }
|
|
|
+ let params_ali = {
|
|
|
+ productCode: data.id,
|
|
|
+ type: '0',
|
|
|
+ preferentialIds: '',
|
|
|
+ useVoucher: this.state.useTicket
|
|
|
};
|
|
|
//先请求后台给支付数据
|
|
|
- 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(
|
|
|
+ PayUtil.payByAli(params_ali).then((result) => {
|
|
|
+ Alipay.pay(result.data.response).then(
|
|
|
function(data) {
|
|
|
//成功
|
|
|
console.log(data);
|