exchange-pay.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. var app = new Vue({
  2. 'el': '#app',
  3. 'data': {
  4. // 详情
  5. info: {},
  6. // 地址信息
  7. addressInfo: {},
  8. payType: 1,
  9. },
  10. created: function () {
  11. this.getInfo();
  12. this.getAddress();
  13. },
  14. mounted: function () {
  15. var _this = this;
  16. $(".weui-cells_checkbox .weui-check").change(function () {
  17. _this.payType = $(this).index('.weui-cells_checkbox .weui-check') + 1;
  18. })
  19. },
  20. methods: {
  21. // 获取列表数据
  22. getInfo: function () {
  23. var _this = this;
  24. var id = getParam('id');
  25. if (id <= 0 || id == '') {
  26. $.showLoading("商品参数错误...");
  27. setTimeout(function () {
  28. location.href = history.go(-1);
  29. }, 500)
  30. return false;
  31. }
  32. $.showLoading("数据加载中...");
  33. $.post('/weixin/goods/getInfo', {id: id}, function (res) {
  34. $.hideLoading();
  35. if (res.code == 'success') {
  36. _this.info = res.data
  37. } else if (res.code == 'login') {
  38. login(res.data.url);
  39. } else {
  40. $.showLoading("兑换商品获取失败...");
  41. setTimeout(function () {
  42. location.href = history.go(-1);
  43. }, 800)
  44. }
  45. }, "json");
  46. },
  47. // 默认地址
  48. getAddress: function () {
  49. var _this = this;
  50. $.post('/weixin/address/getAddress', {}, function (res) {
  51. if (res.code == 'success') {
  52. _this.addressInfo = res.data
  53. } else if (res.code == 'login') {
  54. login(res.data.url);
  55. }
  56. }, "json");
  57. },
  58. timeLock: function () {
  59. var _this = this;
  60. var time = _this.info.endTime;
  61. if (time > 0) {
  62. _this.timeId = setInterval(function () {
  63. time--;
  64. if (time > 0) {
  65. var minute = Math.floor(time / 60) % 60;
  66. var second = time % 60;
  67. minute = minute < 10 ? '0' + minute : minute;
  68. second = second < 10 ? '0' + second : second;
  69. _this.timeText = minute + ':' + second;
  70. } else {
  71. _this.timeText = '00:00';
  72. clearInterval(_this.timeId);
  73. _this.getInfo();
  74. }
  75. }, 1000);
  76. } else {
  77. // location.href = '/weixin/order/index';
  78. }
  79. },
  80. paySubmit: function () {
  81. var _this = this;
  82. if (_this.payType == 0) {
  83. $.toast('请选择支付方式');
  84. return false;
  85. }
  86. var id = _this.info.id;
  87. if (id <= 0) {
  88. $.toast('支付订单参数错误,请刷新重试');
  89. return false;
  90. }
  91. var addressId = _this.addressInfo? _this.addressInfo.id : 0;
  92. var typeName = _this.payType == 1 ? '确认使用' + _this.info.score + '积分支付兑换该商品?' : '确认使用余额支付' + _this.info.score + '元兑换该商品?';
  93. $.confirm({
  94. title: '兑换支付',
  95. text: typeName,
  96. onOK: function () {
  97. $.showLoading("支付提交中...");
  98. $.post('/weixin/payment/exchange', {id: id, payType: _this.payType, addressId: addressId}, function (res) {
  99. $.hideLoading();
  100. if (res.code == 'success') {
  101. $.showLoading(res.message);
  102. setTimeout(function () {
  103. location.href = '/weixin/order/index';
  104. })
  105. } else if (res.code == 'login') {
  106. login(res.data.url);
  107. } else {
  108. $.toast(res.message, 'text');
  109. }
  110. }, "json");
  111. },
  112. onCancel: function () {
  113. return false;
  114. }
  115. });
  116. }
  117. }
  118. })