| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- var app = new Vue({
- 'el': '#app',
- 'data': {
- // 详情
- info: {},
- // 地址信息
- addressInfo: {},
- payType: 1,
- },
- created: function () {
- this.getInfo();
- this.getAddress();
- },
- mounted: function () {
- var _this = this;
- $(".weui-cells_checkbox .weui-check").change(function () {
- _this.payType = $(this).index('.weui-cells_checkbox .weui-check') + 1;
- })
- },
- methods: {
- // 获取列表数据
- getInfo: function () {
- var _this = this;
- var id = getParam('id');
-
- if (id <= 0 || id == '') {
- $.showLoading("商品参数错误...");
- setTimeout(function () {
- location.href = history.go(-1);
- }, 500)
- return false;
- }
- $.showLoading("数据加载中...");
- $.post('/weixin/goods/getInfo', {id: id}, function (res) {
- $.hideLoading();
- if (res.code == 'success') {
- _this.info = res.data
- } else if (res.code == 'login') {
- login(res.data.url);
- } else {
- $.showLoading("兑换商品获取失败...");
- setTimeout(function () {
- location.href = history.go(-1);
- }, 800)
- }
- }, "json");
- },
- // 默认地址
- getAddress: function () {
- var _this = this;
- $.post('/weixin/address/getAddress', {}, function (res) {
- if (res.code == 'success') {
- _this.addressInfo = res.data
- } else if (res.code == 'login') {
- login(res.data.url);
- }
- }, "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/order/index';
- }
- },
- paySubmit: function () {
- var _this = this;
- if (_this.payType == 0) {
- $.toast('请选择支付方式');
- return false;
- }
- var id = _this.info.id;
- if (id <= 0) {
- $.toast('支付订单参数错误,请刷新重试');
- return false;
- }
- var addressId = _this.addressInfo? _this.addressInfo.id : 0;
- var typeName = _this.payType == 1 ? '确认使用' + _this.info.score + '积分支付兑换该商品?' : '确认使用余额支付' + _this.info.score + '元兑换该商品?';
- $.confirm({
- title: '兑换支付',
- text: typeName,
- onOK: function () {
- $.showLoading("支付提交中...");
- $.post('/weixin/payment/exchange', {id: id, payType: _this.payType, addressId: addressId}, function (res) {
- $.hideLoading();
- if (res.code == 'success') {
- $.showLoading(res.message);
- setTimeout(function () {
- location.href = '/weixin/order/index';
- })
- } else if (res.code == 'login') {
- login(res.data.url);
- } else {
- $.toast(res.message, 'text');
- }
- }, "json");
- },
- onCancel: function () {
- return false;
- }
- });
- }
- }
- })
|