coupon.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. var pageNumber = 1, pagesize = 100;
  2. var typeId = getParam("typeId");
  3. mui.ready(function () {
  4. var btnArray = ['否', '是'];
  5. $.ajax(base_path + '/coupon/couponTypeList', {
  6. data: {
  7. "pageSize": pagesize,
  8. "pageNO": pageNumber,
  9. "typeId": typeId
  10. },
  11. dataType: 'json',
  12. type: 'post',
  13. timeout: 15000,
  14. xhrFields: {
  15. withCredentials: true
  16. },
  17. crossDomain: true,
  18. success: function (dt) {
  19. if (dt.isRedirect) {
  20. location.href = dt.redirectURL;
  21. } else {
  22. console.log(dt);
  23. if (dt.status) {
  24. var coupontype_data = [];
  25. coupontype_data = dt.data.typeList;
  26. var table = document.body.querySelector('.my-yhq');
  27. if (coupontype_data.length == 0) {
  28. $(".no_yhq").show()
  29. }
  30. mui(coupontype_data).each(function (index) {
  31. var li = document.createElement('li');
  32. li.className = 'my-yhq-cell';
  33. var ptrice;
  34. if (this.couponType == 1) {
  35. ptrice = accDiv(this.couponReduce, 100) + '元'
  36. } else {
  37. ptrice = "-" + (100 - this.couponReduce) + "%"
  38. }
  39. if (this.couponId != 1 && this.couponId != 2) {
  40. li.innerHTML = '<img width="100%" src="//s.iamberry.com/watero/images/shop/yhq_used_bg.png" /><div class="fixed-box"><div class="table"><div class="left-cell"><span class="tit">' + this.couponName + '</span><p class="time">有效期至' + this.couponEndDate + '</p><span class="condition">满' + accDiv(this.couponConsumeEnough, 100) + '元可使用</span></div><div class="right-cell my-btn" id=' + this.couponId + ' money=' + ptrice + '><div class="money"><span>' + ptrice + '</span></div><span class="my-btn-lq">立即领取</span></div></div></div>';
  41. table.appendChild(li)
  42. } else {
  43. $(".no_yhq").show()
  44. }
  45. })
  46. } else {
  47. var r = confirm(dt.message + '是否重新加载页面?');
  48. if (r == true) {
  49. location.href = domanUrl + base_path + "/couponWechat/coupon?dates=" + new Date().getTime()
  50. }
  51. }
  52. }
  53. }, error: function (xhr, type, errorThrown) {
  54. if (xhr.readyState == 4 && xhr.status == 200) {
  55. } else {
  56. location.href = domanUrl + base_path + "/couponWechat/coupon?dates=" + new Date().getTime()
  57. }
  58. }
  59. });
  60. getCartNum();
  61. document.querySelector('.loading-bg').style.display = 'none'
  62. });
  63. mui('body').on('tap', '.x-close', function () {
  64. mui.closePopup();
  65. location.reload(true)
  66. });
  67. mui('body').on('tap', '.my-btn', function () {
  68. var couponid = this.getAttribute('id');
  69. var money = this.getAttribute('money');
  70. $.ajax(base_path + '/coupon/getCoupon', {
  71. data: {"couponId": couponid},
  72. dataType: 'json',
  73. type: 'post',
  74. timeout: 15000,
  75. xhrFields: {
  76. withCredentials: true
  77. },
  78. crossDomain: true,
  79. success: function (dt) {
  80. if (dt.isRedirect) {
  81. location.href = dt.redirectURL;
  82. } else {
  83. console.log(dt);
  84. if (dt.status) {
  85. var btnArray = ['查看优惠券', '立 即 使 用'];
  86. mui.confirm('<span>' + money + ' </span>优惠券<img class="x-close" src="/watero/common/shop/images/x.png" />', '恭喜您成功领取一张', btnArray, function (e) {
  87. if (e.index == 1) {
  88. location.href = 'chanpin_list.html'
  89. } else {
  90. location.href = base_path + '/couponWechat/couponList'
  91. }
  92. })
  93. } else {
  94. var r = confirm(dt.message);
  95. if (r == true) {
  96. location.reload(true)
  97. }
  98. }
  99. }
  100. },
  101. error: function (xhr, type, errorThrown) {
  102. if (xhr.readyState == 4 && xhr.status == 200) {
  103. } else {
  104. location.href = domanUrl + base_path + "/couponWechat/coupon?dates=" + new Date().getTime()
  105. }
  106. }
  107. });
  108. });