12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- mui.init();
- var id;
- /**
- *初始化、添加监听
- */
- mui.ready(function(){
- getMoney();
- getUserInfo();
- $(".mui-table").on("tap",".mui-btn",function(e) {
- if(!$(this).hasClass("mui-active")){
- $(this).addClass("mui-active");
- $(this).parent().siblings().find(".mui-btn").removeClass("mui-active");
- }
- });
- $(".mui-btn-primary").on("tap",function(e) {
- var pay = $(".mui-table .mui-active").attr("pay");
- var money = $(".mui-table .mui-active").attr("money");
- if(!pay||!money){
- layer.open({content: "请选择充值金额",time: 3});
- return;
- }
- mobile.ajaxPost(base+"/userMoney/save",{
- pay:pay,
- money:money
- },function(json){
- if(json.success){
- var data=json.data;
- id=data.id;
- if (typeof WeixinJSBridge == "undefined"){
- if( document.addEventListener ){
- document.addEventListener('WeixinJSBridgeReady', onBridgeReady(data.param), false);
- }else if (document.attachEvent){
- document.attachEvent('WeixinJSBridgeReady', onBridgeReady(data.param));
- document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(data.param));
- }
- }else{
- onBridgeReady(data.param);
- }
- }else{
- layer.open({content: json.msg,time: 3});
- }
- });
- });
- });
- function onBridgeReady(json){
- WeixinJSBridge.invoke(
- 'getBrandWCPayRequest',
- json,
- function(res){
- if(res.err_msg == "get_brand_wcpay_request:ok" ) {
- queryOrder();
- }else{
- layer.open({content: '充值失败',time: 3});
- }
- }
- );
- }
- function queryOrder(){
- mobile.ajaxPost(base+'/userMoney/queryOrder',{id:id},function(json){
- if(json.success){
- var data=json.data;
- if(data.trade_state=="SUCCESS"){
- getMoney();
- layer.open({content: '充值成功',time: 3});
- }else{
- layer.open({content: '充值失败',time: 3});
- }
- }else{
- layer.open({content: json.msg,time: 3});
- }
- });
- }
- //获取余额
- function getMoney() {
- mobile.ajaxPost(base + '/userMoney/getMoney', {}, function(json) {
- $('#money').html("¥"+json.data);
- },"");
- }
- //获取用户信息
- function getUserInfo() {
- mobile.ajaxPost(base + '/users/getByOpenid', {}, function(json) {
- if (json.data) {
- if(json.data.username){
- $("#userName").html(json.data.username);
- }else{
- $("#userName").html(json.data.nickname);
- }
- }
- });
- }
|