var app = new Vue({ 'el': '#app', 'data': { // 详情 info: {}, memberInfo: {}, // 参数 params: { page: 1, pageSize: 10, }, payType: 1, timeText: '00:00', timeId: null, }, created: function () { var _this = this; _this.getInfo(); _this.getMemberInfo(); _this.type = getParam('type'); setInterval(function(){ _this.getMemberInfo(); }, 8000); }, mounted: function () { var _this = this; $(".weui-cells_checkbox .weui-check").change(function () { _this.payType = $(this).index('.weui-cells_checkbox .weui-check') + 1; }) }, methods: { // 获取会员信息 getMemberInfo: function(){ var _this = this; $.post('/weixin/member/getMemberInfo', function (res) { if (res.code == 'success') { _this.memberInfo = res.data } else if (res.code == 'login') { login(res.data.url); } else { $.toast(res.message, 'text'); } }, "json"); }, // 获取列表数据 getInfo: function () { var _this = this; var id = getParam('id'); if (id <= 0 || id == '') { $.showLoading("结算订单参数错误..."); setTimeout(function () { location.href = '/weixin/member/index'; }, 500) return false; } $.showLoading("数据加载中..."); $.post('/weixin/order/getInfo', {id: id}, function (res) { $.hideLoading(); if (res.code == 'success') { _this.info = res.data _this.timeLock(); } else if (res.code == 'login') { login(res.data.url); } else { $.showLoading(res.message); setTimeout(function () { location.href = '/weixin/member/index'; }, 800) } }, "json"); }, timeLock: function () { var _this = this; var time = _this.info.endTime; if (time > 0) { _this.timeId = setInterval(function () { time--; if (time > 0) { var minute = Math.floor(time / 60) % 60; var second = time % 60; minute = minute < 10 ? '0' + minute : minute; second = second < 10 ? '0' + second : second; _this.timeText = minute + ':' + second; } else { _this.timeText = '00:00'; clearInterval(_this.timeId); _this.getInfo(); } }, 1000); } else { location.href = '/weixin/print/index'; } }, paySubmit: function () { var _this = this; if (_this.payType == 0) { $.toast('请选择支付方式'); return false; } var id = _this.info.id; if (id <= 0) { $.toast('支付订单参数错误,请刷新重试'); return false; } if (_this.payType == 1) { $.showLoading("支付提交中..."); $.post('/weixin/payment/index', {id: id, payType: _this.payType}, 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"); } else if (_this.payType == 2) { $.confirm({ title: '确认支付', text: '确认使用余额支付' + _this.info.total + '元?', onOK: function () { $.showLoading("支付提交中..."); $.post('/weixin/payment/index', {id: id, payType: _this.payType}, function (res) { $.hideLoading(); if (res.code == 'success') { if(res.data.type == 2){ $.showLoading(res.message); setTimeout(function () { location.href = '/weixin/order/collage'; }) }else{ $.showLoading(res.message); setTimeout(function () { location.href = '/weixin/order/complete?id=' + id; }) } } else if (res.code == 'login') { login(res.data.url); } else { $.toast(res.message, 'text'); } }, "json"); }, onCancel: function () { return false; } }); } }, // 发起微信支付 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") { setTimeout(function () { if(params.type == 2){ location.href = '/weixin/order/collage'; }else{ location.href = '/weixin/order/complete?id=' + _this.info.id; } }, 800) } } ); } } })