collage.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. var app = new Vue({
  2. 'el': '#app',
  3. 'data': {
  4. // 列表数据
  5. dataList: [],
  6. // 参数
  7. params: {
  8. page: 1,
  9. pageSize: 10,
  10. },
  11. timeIds: [],
  12. loading: false,
  13. loaded: false,
  14. },
  15. created: function(){
  16. this.getDataList(0);
  17. },
  18. mounted: function(){
  19. var _this = this;
  20. $(window).scroll(function(){
  21. var scrollHeight = $(this).scrollTop();
  22. var height = $('body')[0].scrollHeight;
  23. var docHeight = $(this).outerHeight();
  24. if(docHeight+scrollHeight >= height){
  25. if(_this.loading || _this.loaded){
  26. return false;
  27. }
  28. _this.params.page++;
  29. _this.getDataList(1);
  30. }
  31. })
  32. },
  33. methods: {
  34. // 获取列表数据
  35. getDataList: function(more){
  36. var _this = this;
  37. $.hideLoading();
  38. $.showLoading("数据加载中...");
  39. $.post('/weixin/print/collageList', _this.params, function (res) {
  40. $.hideLoading();
  41. _this.loading = false;
  42. if (res.code == 'success') {
  43. if(res.data.data.length<=0 && _this.params.page > 1){
  44. _this.loaded = true;
  45. $.toast("已加载完全部...",'text');
  46. return false;
  47. }
  48. if(more){
  49. $.each(res.data.data, function(k,item){
  50. console.log(item);
  51. _this.dataList.push(item);
  52. });
  53. }else{
  54. _this.dataList = res.data.data
  55. }
  56. if(_this.dataList){
  57. _this.timeLock(_this.dataList);
  58. }
  59. }else if(res.code == 'login'){
  60. login(res.data.url);
  61. }
  62. }, "json");
  63. },
  64. // 倒计时
  65. timeLock: function (dataList) {
  66. var _this = this;
  67. $.each(dataList, function(k,item){
  68. var time = item.closeTime;
  69. if (time > 0 && item.collage_status == 2) {
  70. _this.timeIds[item.id] = setInterval(function () {
  71. time--;
  72. var text = '00<span>:</span>00<span>:</span>00';
  73. if (time > 0) {
  74. var hour = Math.floor(time / 3600);
  75. var minute = Math.floor(time / 60) % 60;
  76. var second = time % 60;
  77. hour = hour < 10 ? '0' + hour : hour;
  78. minute = minute < 10 ? '0' + minute : minute;
  79. second = second < 10 ? '0' + second : second;
  80. text = hour+'<span>:</span>'+minute+'<span>:</span>'+second;
  81. $("#time_"+item.id).html(text);
  82. } else {
  83. clearInterval(_this.timeId);
  84. $("#time_"+item.id).html(text);
  85. }
  86. }, 1000);
  87. }
  88. })
  89. },
  90. collage: function(id,num){
  91. if(num<=0){
  92. var _this = this;
  93. $.showLoading('当前拼团已成团,请刷新后重试');
  94. setTimeout(function () {
  95. _this.getDataList();
  96. }, 1200)
  97. return false;
  98. }
  99. $.actions({
  100. title: '选择操作',
  101. actions: [{
  102. text: "确认拼团",
  103. className: "color-success",
  104. onClick: function() {
  105. location.href = '/weixin/print/collage?pt=2&id='+id;
  106. }
  107. }]
  108. });
  109. },
  110. }
  111. })