hotindex.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="quality-recommend">
  3. <!-- <view class="return_img"><image src="../../static/img/img47.png"></image></view> -->
  4. <div class="slider-banner swiper">
  5. <view class="swiper">
  6. <swiper indicator-dots="true" :autoplay="autoplay" :circular="circular" :interval="interval" :duration="duration"
  7. indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff">
  8. <block v-for="(item,index) in imgUrls" :key="index">
  9. <swiper-item>
  10. <image :src="item.img" class="slide-image"></image>
  11. </swiper-item>
  12. </block>
  13. </swiper>
  14. </view>
  15. </div>
  16. <div class="title flex-center">
  17. <div class="line"></div>
  18. <div class="name">
  19. <span class="iconfont" :class="icon"></span>{{ name }}
  20. </div>
  21. <div class="line"></div>
  22. </div>
  23. <view class="wrapper">
  24. <GoodList :bastList="goodsList" :is-sort="false"></GoodList>
  25. <uni-load-more :status="loadingType"></uni-load-more>
  26. <!-- <view class="txt-bar" v-if="goodsList.length>0 && !isScroll">我是有底线的~</view>
  27. <emptyPage v-if="goodsList.length==0 && !isScroll" title="暂无数据~"></emptyPage> -->
  28. </view>
  29. </div>
  30. </template>
  31. <script>
  32. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  33. import emptyPage from '@/components/emptyPage.vue'
  34. import GoodList from "@/components/goodList/index.vue";
  35. import {groomList,productDetail} from '@/api/product.js'
  36. // import { getGroomList } from "@/api/store";
  37. export default {
  38. name: "HotNewGoods",
  39. components: {
  40. GoodList,
  41. emptyPage,
  42. },
  43. props: {},
  44. data: function() {
  45. return {
  46. imgUrls: [],
  47. goodsList: [],
  48. specList:'',
  49. specSelected:'',
  50. productValue:[],
  51. loadingType:'loading',
  52. name: "",
  53. icon: "",
  54. type:0,
  55. autoplay:true,
  56. circular:true,
  57. interval: 3000,
  58. duration: 500,
  59. page:1,
  60. limit:10,
  61. isScroll:true
  62. };
  63. },
  64. //加载更多
  65. onReachBottom() {
  66. this.loadData();
  67. },
  68. onLoad: function(option) {
  69. this.type = option.type
  70. console.log(option);
  71. this.titleInfo();
  72. this.getIndexGroomList();
  73. },
  74. methods: {
  75. titleInfo: function() {
  76. if (this.type === "1") {
  77. this.name = "精品推荐";
  78. this.icon = "icon-jingpintuijian";
  79. // document.title = "精品推荐";
  80. uni.setNavigationBarTitle({
  81. title:"精品推荐"
  82. })
  83. } else if (this.type === "2") {
  84. this.name = "热门榜单";
  85. this.icon = "icon-remen";
  86. uni.setNavigationBarTitle({
  87. title:"热门榜单"
  88. })
  89. } else if (this.type === "3") {
  90. this.name = "首发新品";
  91. this.icon = "icon-xinpin";
  92. uni.setNavigationBarTitle({
  93. title:"首发新品"
  94. })
  95. }else if (this.type === "4") {
  96. this.name = "促销单品";
  97. this.icon = "icon-xinpin";
  98. uni.setNavigationBarTitle({
  99. title:"促销单品"
  100. })
  101. }
  102. },
  103. getIndexGroomList: function() {
  104. if(!this.isScroll) return
  105. let obj = this;
  106. let type = this.type;
  107. groomList({
  108. page:obj.page,
  109. limit:obj.limit
  110. },type).then(res => {
  111. console.log(res,'res')
  112. obj.imgUrls = res.data.banner;
  113. let goodsList = obj.goodsList.concat(res.data.list);
  114. console.log(obj.page,'1')
  115. let a = res.data.list.length;
  116. for(let i = 0 ;i<a;i++){
  117. let goodsid;
  118. goodsid = res.data.list[i].id;
  119. console.log(obj.page,'2')
  120. productDetail({}, goodsid)
  121. .then(({data}) => {
  122. obj.specList = data.productAttr;//保存产品属性
  123. obj.specSelected = []; //初始化默认选择对象
  124. obj.productValue = data.productValue;
  125. for (let i = 0; i < obj.specList.length; i++) {
  126. // 设置默认数据
  127. let attrValue = obj.specList[i].attr_value[0];
  128. attrValue.check = true;
  129. obj.specSelected.push(attrValue.attr);
  130. }
  131. let str = obj.specSelected.join(',');
  132. let actionPrice = obj.productValue[str].price;
  133. console.log(obj.page,'3')
  134. console.log(actionPrice,i,'actionPrice')
  135. if(obj.page == 1)
  136. {
  137. goodsList[i].price = actionPrice;
  138. }else{
  139. let a = (obj.page - 1) * 10 + i;
  140. goodsList[a].price = actionPrice;
  141. }
  142. });
  143. }
  144. setTimeout(function(){
  145. console.log(obj.page,'4')
  146. console.log(goodsList,'goodsList2')
  147. obj.goodsList = goodsList;
  148. // 判断是否还有下一页,有是more 没有是nomore
  149. if (obj.limit == res.data.list.length) {
  150. obj.page++;
  151. obj.loadingType = 'more';
  152. } else {
  153. obj.loadingType = 'nomore';
  154. }
  155. if (type === 'refresh') {
  156. if (loading == 1) {
  157. uni.hideLoading();
  158. } else {
  159. uni.stopPullDownRefresh();
  160. }
  161. }
  162. }, 500);
  163. obj.isScroll = res.data.list.length>=obj.limit
  164. })
  165. .catch(function(res) {
  166. console.log(res)
  167. });
  168. }
  169. },
  170. onReachBottom() {
  171. this.getIndexGroomList()
  172. }
  173. };
  174. </script>
  175. <style lang="scss">
  176. /deep/ .empty-box{
  177. background-color: #f5f5f5;
  178. }
  179. .return_img{
  180. z-index: 100;
  181. position: absolute;
  182. top:20rpx;
  183. left:20rpx;
  184. image{
  185. width: 50rpx;
  186. height: 50rpx;
  187. }
  188. }
  189. .swiper,swiper,swiper-item,.slide-image{
  190. width: 100%;
  191. height: 280rpx;
  192. }
  193. .quality-recommend {
  194. .wrapper{
  195. background: #fff;
  196. }
  197. .title {
  198. height: 120rpx;
  199. font-size:32rpx;
  200. color: #282828;
  201. background-color: #f5f5f5;
  202. .line{
  203. width: 230rpx;
  204. height: 2rpx;
  205. background-color: #e9e9e9;
  206. }
  207. }
  208. }
  209. .txt-bar{
  210. padding: 20rpx 0;
  211. text-align: center;
  212. font-size: 26rpx;
  213. color: #666;
  214. background-color: #f5f5f5;
  215. }
  216. </style>