| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- var app = new Vue({
- el: '#app',
- data: {
- submitting: false,
- // 详情
- info: {},
- type: '',
- orderId: 0,
- // 提交参数
- params: {
- money: '',
- score: '',
- },
- },
- created: function () {
- this.getInfo();
- this.type = getParam('type');
- this.orderId = getParam('id');
- },
- updated: function(){
- var _this = this;
- $(".weui-money").blur(function(){
- var money = $.trim($(this).val());
- var patt = /^(\d+\.\d{1,2}|\d+)$/gi;
- if(!patt.test(money)){
- money = !isNaN(parseFloat(money))? moneyFormat(parseFloat(money), 2) : '0.00';
- }
- $(this).val(money);
- });
- $(".weui-money").keyup(function(){
- var money = $.trim($(this).val());
- var patt = /^(\d+\.\d{1,2}|\d+)$/gi;
- console.log(money)
- if(!patt.test(money)){
- money = !isNaN(parseFloat(money))? moneyFormat(parseFloat(money), 2) : '0.00';
- }
- var score = parseFloat(money) * _this.info.score_rate;
- score = score>0? score : 0;
- _this.params.score = parseInt(score);
- })
- },
- methods: {
- // 获取用户信息
- getInfo: function(){
- var _this = this;
- var id = getParam('id');
- $.post('/weixin/member/getMemberInfo', {id: id, type: 2}, function (res) {
- if (res.code == 'success') {
- _this.info = res.data
- }else if(res.code == 'login'){
- login(res.data.url);
- }else if(res.code == 'exception'){
- showAlert(res.message);
- }else{
- $.toast(res.message, 'text');
- }
- }, "json");
- },
- // 提交
- doSubmit: function(){
- var _this = this;
- if (_this.submitting) {
- return false;
- }
- if(_this.params.money <=0 || _this.params.money == null){
- $.toast('请输入提现金额','text');
- return false;
- }
- if(confirm('确认充值?')){
- $.showLoading('数据提交中...');
- $.post('/weixin/member/doRecharge', _this.params, function (res) {
- $.hideLoading();
- if (res.code == 'success') {
- // TODO 2.调起微信支付
- if (typeof WeixinJSBridge == "undefined") {
- $.toast('请在微信环境中使用...', "text");
- if (document.addEventListener) {
- document.addEventListener('WeixinJSBridgeReady', function(){
- _this.weixinPay(res.data);
- }, false);
- } else if (document.attachEvent) {
- document.attachEvent('WeixinJSBridgeReady', function(){
- _this.weixinPay(res.data);
- });
- document.attachEvent('onWeixinJSBridgeReady', function(){
- _this.weixinPay(res.data);
- });
- }
- } else {
- _this.weixinPay(res.data);
- }
- } else if (res.code == 'login') {
- login(res.data.url);
- }else{
- $.toast(res.message,'text');
- }
- },'json');
- }
- },
- // 发起微信支付
- weixinPay: function (params) {
- var _this = this;
- WeixinJSBridge.invoke(
- 'getBrandWCPayRequest', {
- "appId": params.appId, //公众号名称,由商户传入
- "timeStamp": params.timeStamp, //时间戳,自1970年以来的秒数
- "nonceStr": params.nonceStr, //随机串
- "package": params.package,
- "signType": params.signType, //微信签名方式:
- "paySign": params.sign, //微信签名
- },
- function (res) {
- if (res.err_msg == "get_brand_wcpay_request:ok") {
- $.toast('充值成功');
- setTimeout(function () {
- _this.params.money = '';
- _this.getInfo();
- if(_this.type == 'pay'){
- location.href = '/weixin/order/pay?id='+_this.orderId;
- }
- }, 800)
- }
- }
- );
- }
- }
- });
|