index.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. {extend name="public/container"}
  2. {block name="title"}商品列表{/block}
  3. {block name="head_top"}
  4. <style>
  5. .nothing {
  6. position: absolute;
  7. top: 50%;
  8. left: 50%;
  9. width: 4rem;
  10. height: 4rem;
  11. -webkit-transform: translate(-50%, -50%);
  12. transform: translate(-50%, -50%);
  13. }
  14. </style>
  15. {/block}
  16. {block name="content"}
  17. <div v-cloak id="app">
  18. <div class="store-home">
  19. <div class="carousel">
  20. <div id="carousel" class="swiper-container">
  21. <div class="swiper-wrapper">
  22. <div v-for="(item, index) in banner" :key="index" :data-url="item.url" class="swiper-slide">
  23. <img class="img" :src="item.pic">
  24. </div>
  25. </div>
  26. </div>
  27. <div class="swiper-pagination"></div>
  28. </div>
  29. <div id="navigation" class="swiper-container navigation">
  30. <div class="swiper-wrapper">
  31. <div v-for="(item, index) in category" :key="item.id" :data-id="item.id"
  32. :class="{ on: index == categoryActiveIndex }" class="swiper-slide" @click="cateName(item.id,index)">{{ item.cate_name }}</div>
  33. </div>
  34. </div>
  35. <div class="goods-section">
  36. <div v-if="categoryGoods && categoryGoods.length" class="list">
  37. <a v-for="item in categoryGoods" :key="item.id" class="item" :href="'detail.html?id=' + item.id">
  38. <div class="image">
  39. <img class="img" :src="item.image">
  40. </div>
  41. <div class="text">
  42. <div class="title">{{ item.store_name }}</div>
  43. <div class="group">
  44. <div class="price">¥<span class="num">{{ item.price }}</span></div>
  45. <div class="sale">已售{{ item.sales }}件</div>
  46. </div>
  47. </div>
  48. </a>
  49. </div>
  50. <img v-else-if="finished" class="nothing" src="/wap/first/zsff/images/no_store.png">
  51. </div>
  52. </div>
  53. {include file="public/store_menu"}
  54. </div>
  55. <script>
  56. var banner = {$banner};
  57. require(['vue', 'store', 'helper'], function (Vue, api, $h) {
  58. var app = new Vue({
  59. el: '#app',
  60. data: {
  61. banner: banner ? banner : [],
  62. category: [],
  63. categoryGoods: [],
  64. categoryActiveIndex: 0,
  65. categoryActiveId: 0,
  66. page: 1,
  67. limit: 20,
  68. loading:false,
  69. finished:false,
  70. carousel: null
  71. },
  72. watch: {
  73. category: function (value) {
  74. if(value.length>0){
  75. this.getCategoryGoods(value[0].id);
  76. }
  77. }
  78. },
  79. created: function () {
  80. this.getCategory();
  81. },
  82. mounted: function () {
  83. this.$nextTick(function () {
  84. this.initCarousel();
  85. this.initNavigation();
  86. $h.EventUtil.listenTouchDirection(document, function () {
  87. this.getCategoryGoods();
  88. }.bind(this));
  89. });
  90. },
  91. destroyed: function () {
  92. this.carousel.destroy();
  93. this.navigation.destroy();
  94. },
  95. methods: {
  96. initCarousel: function () {
  97. this.carousel = new Swiper('#carousel', {
  98. speed: 1000,
  99. autoplay: 2500,
  100. spaceBetween: 20,
  101. autoplayDisableOnInteraction: false,
  102. pagination: '.swiper-pagination',
  103. paginationClickable: true,
  104. loop: true,
  105. observer: true,
  106. observeParents: true,
  107. onInit: function (swiper) {
  108. if (swiper.slides.length <= 3) {
  109. swiper.lockSwipes();
  110. }
  111. },
  112. onClick: function (swiper, event) {
  113. var url = event.target.dataset.url;
  114. if (url && url != '#') {
  115. location.href = url;
  116. }
  117. }
  118. });
  119. },
  120. initNavigation: function () {
  121. this.navigation = new Swiper('#navigation', {
  122. freeMode: true,
  123. slidesPerView: 'auto',
  124. observer: true,
  125. observeParents: true,
  126. onClick: function (swiper) {
  127. if (!swiper.clickedSlide) {
  128. return;
  129. }
  130. if (swiper.clickedSlide.offsetLeft < swiper.size / 2 - swiper.clickedSlide.clientWidth / 2) {
  131. swiper.setWrapperTranslate(0);
  132. } else if (swiper.clickedSlide.offsetLeft > swiper.virtualSize - swiper.clickedSlide.clientWidth / 2 - swiper.size / 2) {
  133. swiper.setWrapperTranslate(swiper.size - swiper.virtualSize);
  134. } else {
  135. swiper.setWrapperTranslate(swiper.size / 2 - swiper.clickedSlide.clientWidth / 2 - swiper.clickedSlide.offsetLeft);
  136. }
  137. if (this.categoryActiveIndex === swiper.clickedIndex) {
  138. return;
  139. }
  140. this.categoryActiveIndex = swiper.clickedIndex;
  141. this.categoryActiveId = swiper.clickedSlide.dataset.id;
  142. this.categoryGoods = [];
  143. this.finished = true;
  144. this.getCategoryGoods();
  145. }.bind(this)
  146. });
  147. },
  148. // 获取分类
  149. getCategory: function () {
  150. $h.loadFFF();
  151. api.baseGet($h.U({
  152. c: 'store',
  153. a: 'getcategory'
  154. }), function (res) {
  155. $h.loadClear();
  156. var data = res.data.data;
  157. this.category = data;
  158. if (this.navigation) {
  159. // this.navigation.update();
  160. } else {
  161. this.initNavigation();
  162. }
  163. if(this.category.length>0){
  164. this.categoryActiveId =this.category[0].id;
  165. }
  166. }.bind(this), function () {
  167. $h.loadClear();
  168. });
  169. },
  170. cateName:function(cid,index){
  171. this.page=1;
  172. this.categoryActiveId=cid;
  173. this.categoryActiveIndex=index;
  174. this.categoryGoods =[];
  175. this.loading=false;
  176. this.finished=false;
  177. this.getCategoryGoods();
  178. },
  179. // 获取分类商品
  180. getCategoryGoods: function (id) {
  181. if (this.finished) {
  182. return;
  183. }
  184. $h.loadFFF();
  185. api.baseGet($h.U({
  186. c: 'store',
  187. a: 'getproductlist',
  188. p: {
  189. cId: this.categoryActiveId,
  190. page: this.page,
  191. limit: this.limit
  192. }
  193. }), function (res) {
  194. $h.loadClear();
  195. var data = res.data.data;
  196. this.categoryGoods = this.categoryGoods.concat(data);
  197. this.finished = data.length < this.limit;
  198. this.page++;
  199. }.bind(this), function () {
  200. $h.loadClear();
  201. });
  202. }
  203. }
  204. });
  205. });
  206. </script>
  207. {/block}