collect.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. {extend name="public/container"}
  2. {block name="title"}已收藏商品{/block}
  3. {block name="content"}
  4. <body style="background:#fff;">
  5. <div id="collect" class="user-collection-list">
  6. <section ref="bsDom">
  7. <div>
  8. <ul>
  9. <li class="border-1px" v-for="(item,index) in data.list" :class="{fail:item.is_fail == true}" v-cloak="">
  10. <a :href="productUrl(item)">
  11. <div class="picture"><img :src="item.image" /></div>
  12. <div class="info-content flex">
  13. <p class="pro-tit" v-text="item.store_name + '[秒杀产品]'" v-if="item.category == 'product_seckill'"></p>
  14. <p class="pro-tit" v-text="item.store_name + '[普通产品]'" v-else-if="item.category == 'product'"></p>
  15. <p class="pro-tit" v-text="item.store_name" v-else></p>
  16. <p class="price">
  17. <span v-text="'¥'+item.price"></span>
  18. <span class="old-price">¥{{item.ot_price}}</span>
  19. </p>
  20. <p class="count">{{ item.is_fail == true ? '已失效' : '已售'+item.sales }}</p>
  21. </div>
  22. </a>
  23. <div class="collection-delete" @click="removeCollect(item,index)"></div>
  24. </li>
  25. </ul>
  26. <p style="background-color: #fff;" class="loading-line" v-show="loading == true"><i></i><span>正在加载中</span><i></i></p>
  27. <p style="background-color: #fff;" class="loading-line" v-show="loading == false && data.loaded == false" v-cloak=""><i></i><span>加载更多</span><i></i></p>
  28. <p style="background-color: #fff;" class="loading-line" v-show="loading == false && data.loaded == true" v-cloak=""><i></i><span>没有更多了</span><i></i></p>
  29. </div>
  30. </section>
  31. </div>
  32. <script>
  33. require(['vue','axios','better-scroll','helper','store'],function(Vue,axios,BScroll,$h,storeApi){
  34. new Vue({
  35. el:"#collect",
  36. data:{
  37. data:{
  38. first:0,
  39. limit:8,
  40. list:[],
  41. loaded:false,
  42. top:0
  43. },
  44. loading: false,
  45. scroll:null
  46. },
  47. methods:{
  48. removeCollect:function (product,index){
  49. var that = this;
  50. storeApi.removeCollectProduct(product.pid,function(){
  51. that.data.list.splice(index,1);
  52. });
  53. },
  54. productUrl:function(product){
  55. if(product.category == 'product_seckill'){
  56. return product.is_fail == true ? 'javascript:void(0);' : $h.U({c:'store',a:'seckill_detail',p:{id:product.pid}});
  57. }else if(product.category == 'product'){
  58. return product.is_fail == true ? 'javascript:void(0);' : $h.U({c:'store',a:'detail',p:{id:product.pid}});
  59. }else{
  60. return 'javascript:void(0);';
  61. }
  62. },
  63. getList:function(){
  64. if(this.loading) return ;
  65. var that = this,group = that.data;
  66. if(group.loaded) return ;
  67. this.loading = true;
  68. storeApi.getCollectProduct({
  69. first:group.first,
  70. limit:group.limit
  71. },function(res){
  72. var list = res.data.data;
  73. group.loaded = list.length < group.limit;
  74. group.first += list.length;
  75. group.list = group.list.concat(list);
  76. that.loading = false;
  77. that.$set(that,'data',group);
  78. that.$nextTick(function(){
  79. if(list.length) that.bScrollInit();
  80. that.scroll.finishPullUp();
  81. });
  82. },function(err){that.loading = false; return true;});
  83. },
  84. bScrollInit:function () {
  85. var that = this;
  86. if(this.scroll === null){
  87. this.$refs.bsDom.style.height = (document.documentElement.clientHeight)+'px';
  88. this.$refs.bsDom.style.overflow = 'hidden';
  89. this.scroll = new BScroll(this.$refs.bsDom,{click:true,probeType:1,cancelable:false,deceleration:0.005,snapThreshold:0.01});
  90. this.scroll.on('pullingUp',function(){
  91. that.loading == false && that.getList();
  92. })
  93. }else{
  94. this.scroll.refresh();
  95. }
  96. }
  97. },
  98. mounted:function(){
  99. this.bScrollInit();
  100. this.getList();
  101. }
  102. })
  103. })
  104. </script>
  105. {/block}