coupon_list.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. var tabindex = 0, pageNumber = 0, pagesize = 10;
  2. mui.init({
  3. pullRefresh: {
  4. container: '#pullrefresh_yhq_list',
  5. down: {},
  6. up: {contentrefresh: '正在加载...', callback: pullupRefresh}
  7. }
  8. });
  9. function pullupRefresh() {
  10. pageNumber += 1;
  11. var btnArray = ['否', '是'];
  12. $.ajax(base_path + '/coupon/couponItemList', {
  13. data: {
  14. "pageSize": pagesize,
  15. "useStatus": tabindex,
  16. "pageNO": pageNumber
  17. },
  18. dataType: 'json',
  19. type: 'post',
  20. timeout: 15000,
  21. xhrFields: {
  22. withCredentials: true
  23. },
  24. crossDomain: true,
  25. success: function (dt) {
  26. if (dt.isRedirect) {
  27. location.href = dt.redirectURL;
  28. } else {
  29. if (dt.status) {
  30. var coupon_data = [];
  31. coupon_data = dt.data.itemList;
  32. mui('#pullrefresh_yhq_list').pullRefresh().endPullupToRefresh(coupon_data.length < pagesize);
  33. var table = document.body.querySelector('.my-yhq-list');
  34. mui(coupon_data).each(function (index) {
  35. var li = document.createElement('li');
  36. li.className = 'my-yhq-cell';
  37. var ptrice;
  38. if (this.couponType == 1) {
  39. ptrice = accDiv(this.couponReduce, 100) + '元'
  40. } else {
  41. ptrice = "-" + (100 - this.couponReduce) + "%"
  42. }
  43. if (this.couponUseStatus == 1 && tabindex <= 1 && this.couponItemRemark == "normal") {
  44. li.innerHTML = '<img width="100%" src="/watero/common/shop/images/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.couponUseEndDate + '</p><span class="condition">满' + accDiv(this.couponConsumeEnough, 100) + '元可使用</span></div><div class="right-cell"><div class="money"><span>' + ptrice + '</span></div><span class="my-btn go_web_shop">立即使用</span></div></div></div'
  45. } else {
  46. li.innerHTML = '<img width="100%" src="/watero/common/shop/images/yhq_overdue_bg.png" /><div class="fixed-box grayscale"><div class="table"><div class="left-cell"><span class="tit grayscale">' + this.couponName + '</span><p class="time grayscale">有效期至' + this.couponUseEndDate + '</p><span class="condition">满' + accDiv(this.couponConsumeEnough, 100) + '元可使用</span></div><div class="right-cell"><div class="money grayscale"><span>' + ptrice + '</span></div><span class="my-btn grayscale">立即领取</span></div></div></div>'
  47. }
  48. table.appendChild(li)
  49. })
  50. } else {
  51. mui.confirm(dt.message + '是否重新加载页面?', '爱贝源-提示', btnArray, function (e) {
  52. if (e.index == 1) {
  53. }
  54. })
  55. }
  56. }
  57. }, error: function (xhr, type, errorThrown) {
  58. console.log(xhr)
  59. }
  60. })
  61. };mui.ready(function () {
  62. mui('#pullrefresh_yhq_list').pullRefresh().pullupLoading();
  63. getCartNum();
  64. document.querySelector('.loading-bg').style.display = 'none'
  65. });
  66. mui.each(document.querySelectorAll('.tab-yhq-list .mui-control-item'), function (index, el) {
  67. el.addEventListener('tap', function () {
  68. pageNumber = 0;
  69. switch (index) {
  70. case 0:
  71. tabindex = 0;
  72. break;
  73. case 1:
  74. tabindex = 1;
  75. break;
  76. case 2:
  77. tabindex = 2;
  78. break;
  79. default:
  80. tabindex = 3;
  81. break
  82. }
  83. $('.my-yhq-list').empty();
  84. mui('#pullrefresh_yhq_list').pullRefresh().refresh(true);
  85. mui('#pullrefresh_yhq_list').pullRefresh().pullupLoading()
  86. }, false)
  87. });