recharge.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. var app = new Vue({
  2. el: '#app',
  3. data: {
  4. submitting: false,
  5. // 详情
  6. info: {},
  7. type: '',
  8. orderId: 0,
  9. // 提交参数
  10. params: {
  11. money: '',
  12. },
  13. },
  14. created: function () {
  15. this.getInfo();
  16. this.type = getParam('type');
  17. this.orderId = getParam('id');
  18. },
  19. updated: function(){
  20. $(".weui-money").blur(function(){
  21. var money = $.trim($(this).val());
  22. var patt = /^(\d+\.\d{1,2}|\d+)$/gi;
  23. if(!patt.test(money)){
  24. money = !isNaN(parseFloat(money))? moneyFormat(parseFloat(money), 2) : '0.00';
  25. }
  26. $(this).val(money);
  27. })
  28. },
  29. methods: {
  30. // 获取用户信息
  31. getInfo: function(){
  32. var _this = this;
  33. var id = getParam('id');
  34. $.post('/weixin/member/getMemberInfo', {id: id}, function (res) {
  35. if (res.code == 'success') {
  36. _this.info = res.data
  37. }else if(res.code == 'login'){
  38. login(res.data.url);
  39. }else{
  40. $.toast(res.message, 'text');
  41. }
  42. }, "json");
  43. },
  44. // 提交
  45. doSubmit: function(){
  46. var _this = this;
  47. if (_this.submitting) {
  48. return false;
  49. }
  50. if(_this.params.money <=0 || _this.params.money == null){
  51. $.toast('请输入提现金额','text');
  52. return false;
  53. }
  54. if(confirm('确认充值?')){
  55. $.showLoading('数据提交中...');
  56. $.post('/weixin/member/doRecharge', _this.params, function (res) {
  57. $.hideLoading();
  58. if (res.code == 'success') {
  59. // TODO 2.调起微信支付
  60. if (typeof WeixinJSBridge == "undefined") {
  61. $.toast('请在微信环境中使用...', "text");
  62. if (document.addEventListener) {
  63. document.addEventListener('WeixinJSBridgeReady', function(){
  64. _this.weixinPay(res.data);
  65. }, false);
  66. } else if (document.attachEvent) {
  67. document.attachEvent('WeixinJSBridgeReady', function(){
  68. _this.weixinPay(res.data);
  69. });
  70. document.attachEvent('onWeixinJSBridgeReady', function(){
  71. _this.weixinPay(res.data);
  72. });
  73. }
  74. } else {
  75. _this.weixinPay(res.data);
  76. }
  77. } else if (res.code == 'login') {
  78. login(res.data.url);
  79. }else{
  80. $.toast(res.message,'text');
  81. }
  82. },'json');
  83. }
  84. },
  85. // 发起微信支付
  86. weixinPay: function (params) {
  87. var _this = this;
  88. WeixinJSBridge.invoke(
  89. 'getBrandWCPayRequest', {
  90. "appId": params.appId, //公众号名称,由商户传入
  91. "timeStamp": params.timeStamp, //时间戳,自1970年以来的秒数
  92. "nonceStr": params.nonceStr, //随机串
  93. "package": params.package,
  94. "signType": params.signType, //微信签名方式:
  95. "paySign": params.sign, //微信签名
  96. },
  97. function (res) {
  98. if (res.err_msg == "get_brand_wcpay_request:ok") {
  99. $.toast('充值成功');
  100. setTimeout(function () {
  101. _this.params.money = '';
  102. _this.getInfo();
  103. if(_this.type == 'pay'){
  104. location.href = '/weixin/order/pay?id='+_this.orderId;
  105. }
  106. }, 800)
  107. }
  108. }
  109. );
  110. }
  111. }
  112. });