index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div class="quality-recommend">
  3. <div class="slider-banner swiper">
  4. <view class="swiper">
  5. <swiper indicator-dots="true" :autoplay="autoplay" :circular="circular" :interval="interval" :duration="duration"
  6. indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff">
  7. <block v-for="(item,index) in imgUrls" :key="index">
  8. <swiper-item>
  9. <image :src="item.pic" class="slide-image"></image>
  10. </swiper-item>
  11. </block>
  12. </swiper>
  13. </view>
  14. </div>
  15. <div class="title acea-row row-center-wrapper">
  16. <div class="line"></div>
  17. <div class="name">
  18. <span class="iconfont" :class="icon"></span>{{ name }}
  19. </div>
  20. <div class="line"></div>
  21. </div>
  22. <view class="wrapper">
  23. <GoodList :bastList="goodsList" :is-sort="false" :isLogin='isLogin'></GoodList>
  24. <view class="txt-bar" v-if="goodsList.length>0 && !isScroll">我是有底线的~</view>
  25. <emptyPage v-if="goodsList.length==0 && !isScroll" title="暂无数据~"></emptyPage>
  26. </view>
  27. </div>
  28. </template>
  29. <script>
  30. import emptyPage from '@/components/emptyPage.vue'
  31. import GoodList from "@/components/goodList";
  32. import { getIndexData } from '@/api/api.js';
  33. import { getGroomList,getHotBanner } from "@/api/store";
  34. import util from "@/utils/util";
  35. import { mapGetters } from "vuex";
  36. const typeData = {
  37. best:{
  38. icon:'icon-jingpintuijian',
  39. name:'精品推荐'
  40. },
  41. hot:{
  42. icon:'icon-remen',
  43. name:'热门榜单'
  44. },
  45. new:{
  46. icon:'icon-xinpin',
  47. name:'首页新品'
  48. },
  49. good:{
  50. icon:'icon-xinpin',
  51. name:'推荐单品'
  52. },
  53. }
  54. export default {
  55. computed: mapGetters(['isLogin']),
  56. name: "HotNewGoods",
  57. components: {
  58. GoodList,
  59. emptyPage,
  60. },
  61. props: {},
  62. data: function() {
  63. return {
  64. imgUrls: [],
  65. goodsList: [],
  66. name: "",
  67. hotData:[],
  68. loaded:false,
  69. icon: "",
  70. type:0,
  71. autoplay:true,
  72. circular:true,
  73. interval: 3000,
  74. duration: 500,
  75. page:1,
  76. limit:8,
  77. isScroll:true
  78. };
  79. },
  80. /**
  81. * 用户点击右上角分享
  82. */
  83. // #ifdef MP
  84. onShareAppMessage: function() {
  85. let that = this;
  86. wx.showShareMenu({
  87. withShareTicket: true,
  88. menus: ['shareAppMessage', 'shareTimeline']
  89. })
  90. return {
  91. title: that.name || '',
  92. path: 'pages/columnGoods/HotNewGoods/index?type='+that.type,
  93. }
  94. },
  95. onShareTimeline: function() {
  96. let that = this;
  97. return {
  98. title: that.name || '',
  99. query: {
  100. type: that.type
  101. },
  102. imageUrl: ''
  103. }
  104. },
  105. // #endif
  106. onLoad: function(option) {
  107. this.type = option.type
  108. this.getIndexGroomList();
  109. this.getHotBanner();
  110. getIndexData().then(res=>{
  111. this.hotData = res.data.hot;
  112. }).finally(e=>{
  113. this.loaded = true;
  114. this.titleInfo();
  115. });
  116. },
  117. watch:{
  118. name(n){
  119. uni.setNavigationBarTitle({
  120. title:n||'加载中'
  121. })
  122. }
  123. },
  124. methods: {
  125. titleInfo: function() {
  126. if(!this.loaded){
  127. this.name = '';
  128. this.icon = '';
  129. }else{
  130. let name = (typeData[this.type]||{}).name || '精品推荐';
  131. let url = this.$route ? this.$route.fullPath : ('/' + util.getNowUrl());
  132. this.hotData.forEach(data=>{
  133. if(data.url == url) name = data.title;
  134. })
  135. this.name = name;
  136. this.icon = (typeData[this.type]||{}).icon || 'icon-jingpintuijian';
  137. }
  138. },
  139. getIndexGroomList: function() {
  140. if(!this.isScroll) return
  141. let that = this;
  142. let type = this.type;
  143. getGroomList(type,{
  144. page:this.page,
  145. limit:this.limit
  146. }).then(res => {
  147. that.goodsList = that.goodsList.concat(res.data.list);
  148. that.isScroll = res.data.list.length>=that.limit
  149. that.page++
  150. })
  151. .catch(function(res) {
  152. that.$util.Tips({ title: res });
  153. });
  154. },
  155. getHotBanner(){
  156. let that = this
  157. getHotBanner(this.type).then(res=>{
  158. that.imgUrls = res.data;
  159. })
  160. }
  161. },
  162. onReachBottom() {
  163. this.getIndexGroomList()
  164. }
  165. };
  166. </script>
  167. <style lang="scss">
  168. /deep/ .empty-box{
  169. background-color: #f5f5f5;
  170. }
  171. .swiper,swiper,swiper-item,.slide-image{
  172. width: 100%;
  173. height: 280rpx;
  174. }
  175. .quality-recommend {
  176. .wrapper{
  177. background: #fff;
  178. }
  179. .title {
  180. height: 120rpx;
  181. font-size:32rpx;
  182. color: #282828;
  183. background-color: #f5f5f5;
  184. .line{
  185. width: 230rpx;
  186. height: 2rpx;
  187. background-color: #e9e9e9;
  188. }
  189. }
  190. }
  191. .txt-bar{
  192. padding: 20rpx 0;
  193. text-align: center;
  194. font-size: 26rpx;
  195. color: #666;
  196. background-color: #f5f5f5;
  197. }
  198. </style>