|
|
|
@ -12,32 +12,38 @@ |
|
|
|
|
选择金额 |
|
|
|
|
</view> |
|
|
|
|
<view class="list"> |
|
|
|
|
<view class="box" :class="{'on':100 == inputAmount}" @click="select(100)"> |
|
|
|
|
<view class="heTitle">100元</view> |
|
|
|
|
</view> |
|
|
|
|
|
|
|
|
|
<view class="box" :class="{'on':200 == inputAmount}" @click="select(200)"> |
|
|
|
|
<view class="heTitle">200元</view> |
|
|
|
|
</view> |
|
|
|
|
|
|
|
|
|
<view class="box" :class="{'on':300 == inputAmount}" @click="select(300)"> |
|
|
|
|
<view class="heTitle">300元</view> |
|
|
|
|
<view class="box" :class="{'on':item.realPrice == inputAmount}" v-for="(item,index) in amountList" |
|
|
|
|
@click="select(item)"> |
|
|
|
|
<view class="heTitle">{{item.realPrice}}元</view> |
|
|
|
|
</view> |
|
|
|
|
</view> |
|
|
|
|
<view class="bombtn width94 font16"> |
|
|
|
|
<view class="width50 flleft payem">应付: {{inputAmount}}元</view> |
|
|
|
|
<view class="width50 flright paybtn">立即购买</view> |
|
|
|
|
<view class="width50 flright paybtn" @click="addOrderPay">立即购买</view> |
|
|
|
|
</view> |
|
|
|
|
</view> |
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
|
// #ifdef H5 |
|
|
|
|
var jweixin = require('jweixin-module'); |
|
|
|
|
// #endif |
|
|
|
|
let app = getApp(); |
|
|
|
|
import { |
|
|
|
|
getListOutRechargePrice, |
|
|
|
|
addOrderPay, |
|
|
|
|
orderToUNionPay |
|
|
|
|
} from '../../../Utils/Api.js'; |
|
|
|
|
export default { |
|
|
|
|
data() { |
|
|
|
|
return { |
|
|
|
|
typeId: '', |
|
|
|
|
inputAmountId: '', |
|
|
|
|
inputAmount: '', |
|
|
|
|
inputPhone:'' |
|
|
|
|
inputPhone: '', |
|
|
|
|
amoutType: '', |
|
|
|
|
codesVlues: '', |
|
|
|
|
amountList: [] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
onLoad(options) { |
|
|
|
@ -46,24 +52,174 @@ |
|
|
|
|
uni.setNavigationBarTitle({ |
|
|
|
|
title: '中国移动' |
|
|
|
|
}) |
|
|
|
|
this.amoutType = 2; |
|
|
|
|
this.getListOutRechargePrice(2); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (this.typeId == 2) { |
|
|
|
|
uni.setNavigationBarTitle({ |
|
|
|
|
title: '中国联通' |
|
|
|
|
title: '中国电信' |
|
|
|
|
}) |
|
|
|
|
this.amoutType = 1; |
|
|
|
|
this.getListOutRechargePrice(1); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (this.typeId == 3) { |
|
|
|
|
uni.setNavigationBarTitle({ |
|
|
|
|
title: '中国电信' |
|
|
|
|
title: '中国联通' |
|
|
|
|
}) |
|
|
|
|
this.amoutType = 3; |
|
|
|
|
this.getListOutRechargePrice(3); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
select(amoutinfos) { |
|
|
|
|
this.inputAmount = amoutinfos; |
|
|
|
|
this.inputAmount = amoutinfos.realPrice; |
|
|
|
|
this.inputAmountId = amoutinfos.id; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查询价格 |
|
|
|
|
*/ |
|
|
|
|
getListOutRechargePrice(item) { |
|
|
|
|
uni.showLoading({ |
|
|
|
|
title: '加载中...' |
|
|
|
|
}) |
|
|
|
|
let params = { |
|
|
|
|
type: item |
|
|
|
|
} |
|
|
|
|
getListOutRechargePrice(params).then(res => { |
|
|
|
|
uni.hideLoading() |
|
|
|
|
if (res.return_code == '000000') { |
|
|
|
|
this.amountList = res.return_data; |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 提交订单 |
|
|
|
|
*/ |
|
|
|
|
addOrderPay() { |
|
|
|
|
if (this.inputPhone == '') { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: '请输入充值号码', |
|
|
|
|
icon: "none" |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (this.inputAmount == '') { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: '请选择价格', |
|
|
|
|
icon: "none" |
|
|
|
|
}); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
let params = { |
|
|
|
|
"orderPrice": this.inputAmount, |
|
|
|
|
"payPrice": this.inputAmount, |
|
|
|
|
"rechargeContent": this.inputPhone, |
|
|
|
|
"rechargeModel": this.amoutType, |
|
|
|
|
"agentKey": this.codesVlues, |
|
|
|
|
"objectId": this.inputAmountId, |
|
|
|
|
} |
|
|
|
|
uni.showLoading({ |
|
|
|
|
title: '加载中...' |
|
|
|
|
}) |
|
|
|
|
addOrderPay(params).then(res => { |
|
|
|
|
uni.hideLoading() |
|
|
|
|
if (res.return_code == '000000') { |
|
|
|
|
let params = { |
|
|
|
|
"orderId": res.return_data.id, |
|
|
|
|
"openId": app.globalData.openId |
|
|
|
|
} |
|
|
|
|
this.orderToUNionPay(params); |
|
|
|
|
} else { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: res.return_msg, |
|
|
|
|
icon: "none" |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
//获取订单信息 |
|
|
|
|
orderToUNionPay(item) { |
|
|
|
|
orderToUNionPay(item).then(res => { |
|
|
|
|
if (res.return_code == '000000') { |
|
|
|
|
//判断是否是公众号 |
|
|
|
|
// #ifdef H5 |
|
|
|
|
//判断微信浏览器 |
|
|
|
|
this.payRequest(res); |
|
|
|
|
// #endif |
|
|
|
|
} else { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: res.return_msg, |
|
|
|
|
icon: 'none' |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
//唤起支付 |
|
|
|
|
payRequest: function(self) { |
|
|
|
|
uni.showLoading({ |
|
|
|
|
title: '支付中...' |
|
|
|
|
}) |
|
|
|
|
jweixin.config({ |
|
|
|
|
// debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 |
|
|
|
|
appId: self.return_data.appId, // 必填,公众号的唯一标识 |
|
|
|
|
timestamp: self.return_data.timeStamp, // 必填,生成签名的时间戳 |
|
|
|
|
nonceStr: self.return_data.nonceStr, // 必填,生成签名的随机串 |
|
|
|
|
signature: self.return_data.sign, // 必填,签名,见附录1 |
|
|
|
|
jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 |
|
|
|
|
}); |
|
|
|
|
uni.hideLoading(); |
|
|
|
|
jweixin.ready(function() { |
|
|
|
|
jweixin.checkJsApi({ |
|
|
|
|
jsApiList: ['chooseWXPay'], // 需要检测的JS接口列表,所有JS接口列表见附录2, |
|
|
|
|
success: function(res) {}, |
|
|
|
|
fail: function(res) {} |
|
|
|
|
}); |
|
|
|
|
jweixin.chooseWXPay({ |
|
|
|
|
appId: self.return_data.appId, |
|
|
|
|
timestamp: self.return_data |
|
|
|
|
.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 |
|
|
|
|
nonceStr: self.return_data.nonceStr, // 支付签名随机串,不长于 32 位 |
|
|
|
|
package: self.return_data |
|
|
|
|
.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***) |
|
|
|
|
signType: 'MD5', // 签名方式,默认为'SHA1',使用新版支付需传入'MD5' |
|
|
|
|
paySign: self.return_data.sign, // 支付签名 |
|
|
|
|
success: function(res) { |
|
|
|
|
// 支付成功后的回调函数 |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: '支付成功' |
|
|
|
|
}) |
|
|
|
|
if (that.jumpType == 4) { |
|
|
|
|
uni.reLaunch({ |
|
|
|
|
url: '/pages/tabBar/user/user' |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
uni.reLaunch({ |
|
|
|
|
url: '../success/success?id=' + that.couponId |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
cancel: function(r) {}, |
|
|
|
|
fail: function(res) {} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
jweixin.error(function(res) { |
|
|
|
|
uni.showToast({ |
|
|
|
|
icon: 'none', |
|
|
|
|
title: '支付失败了', |
|
|
|
|
duration: 4000 |
|
|
|
|
}); |
|
|
|
|
// config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。 |
|
|
|
|
/*alert("config信息验证失败");*/ |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -119,11 +275,13 @@ |
|
|
|
|
font-size: 15px; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.bombtn { |
|
|
|
|
position: fixed; |
|
|
|
|
height: 45px; |
|
|
|
|
bottom: 20px; |
|
|
|
|
border-radius: 6px; |
|
|
|
|
|
|
|
|
|
.payem { |
|
|
|
|
height: 45px; |
|
|
|
|
line-height: 45px; |
|
|
|
|