| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- 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)
- }
- }
- );
- }
- }
- })
|