list.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view>
  3. <navbar v-model="screenHeight" title-color="#ffffff" background="#1b43c4" :iSimmersive="false" :placeholder="true" title="商品列表"></navbar>
  4. <view class="navbar">
  5. <view class="nav-item" :class="{current: filterIndex === 0}" @click="tabClick(0)">
  6. 综合排序
  7. </view>
  8. <view class="nav-item" :class="{current: filterIndex === 1}" @click="tabClick(1)">
  9. 销量优先
  10. </view>
  11. <view class="nav-item" :class="{current: filterIndex === 2}" @click="tabClick(2)">
  12. <view>价格</view>
  13. <view class="arrow-box">
  14. <text :class="{active: priceOrder === 1 && filterIndex === 2,'icon-arrow-up-active':priceOrder === 1 && filterIndex === 2}" class="icon iconfont icon-arrow-up">&#xe61c;</text>
  15. <text :class="{active: priceOrder === 2 && filterIndex === 2,'icon-arrow-down-active':priceOrder === 2 && filterIndex === 2}" class="icon iconfont icon-arrow-down">&#xe61c;</text>
  16. </view>
  17. </view>
  18. </view>
  19. <view style="height: 100rpx; background-color: #1b43c4"></view>
  20. <mescroll-body
  21. ref="mescrollRef"
  22. @init="mescrollInit"
  23. @down="downCallback"
  24. @up="upCallback"
  25. :height="(screenHeight-50)+'px'"
  26. >
  27. <view class="goods-list-box">
  28. <view
  29. class="goods-list-item-box"
  30. v-for="(item,index) in result"
  31. :key="index"
  32. @click="$utils.navigateTo('goods/view',{ id: item.id })"
  33. >
  34. <view class="goods-list-item-wrap">
  35. <view><image :src="item.photo"></view>
  36. <view>{{ item.title }}</view>
  37. <view>¥{{ item.price }}</view>
  38. </view>
  39. </view>
  40. </view>
  41. </mescroll-body>
  42. </view>
  43. </template>
  44. <script>
  45. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  46. import navbar from "@/components/navbar/navbar";
  47. export default {
  48. mixins: [MescrollMixin],
  49. components: {
  50. navbar
  51. },
  52. data() {
  53. return {
  54. screenHeight: 0,
  55. filterIndex: 0,
  56. priceOrder: 1,
  57. result: [],
  58. cat_id: 0
  59. }
  60. },
  61. onLoad(options) {
  62. this.cat_id = options.id;
  63. },
  64. onPageScroll(obj){
  65. this.scrollNum = obj.scrollTop;
  66. },
  67. methods: {
  68. tabClick(index){
  69. if(this.filterIndex === index && index !== 2){
  70. return;
  71. }
  72. this.filterIndex = index;
  73. if(index === 2){
  74. this.priceOrder = this.priceOrder === 1 ? 2: 1;
  75. }else{
  76. this.priceOrder = 0;
  77. }
  78. this.mescroll.resetUpScroll();
  79. },
  80. downCallback(){
  81. setTimeout(()=>{
  82. this.mescroll.resetUpScroll();
  83. },200);
  84. },
  85. triggerDownScroll(){
  86. this.mescroll.triggerDownScroll();
  87. },
  88. upCallback(page) {
  89. this.$http.getGoodsList({
  90. page: page.num,
  91. id: this.cat_id,
  92. type: this.filterIndex,
  93. sort: this.priceOrder
  94. }).then((result)=>{
  95. this.mescroll.endByPage(result.data.list.length, result.data.total);
  96. if(result.status==1){
  97. if(page.num == 1) this.result = [];
  98. this.result = this.result.concat(result.data.list);
  99. }else if(result.status == -1){
  100. this.mescroll.endErr();
  101. }
  102. }).catch(error=>{
  103. this.mescroll.endErr();
  104. });
  105. }
  106. }
  107. }
  108. </script>
  109. <style lang="scss" scoped>
  110. .navbar{
  111. position: fixed;
  112. top: calc(45px + env(safe-area-inset-top)) + rpx;
  113. /* #ifdef APP-PLUS */
  114. left: 0;
  115. /* #endif */
  116. /* #ifdef H5 */
  117. left: 0;
  118. /* #endif */
  119. display: flex;
  120. width: 100%;
  121. height: 100rpx;
  122. background: #1b43c4;
  123. z-index: 10111;
  124. .nav-item{
  125. flex: 1;
  126. display: flex;
  127. justify-content: center;
  128. align-items: center;
  129. height: 100%;
  130. font-size: 28rpx;
  131. color: #fff;
  132. position: relative;
  133. &.current{ color: #fff000; }
  134. .arrow-box{
  135. display: flex;
  136. flex-direction: column;
  137. .icon{
  138. display: flex;
  139. align-items: center;
  140. justify-content: center;
  141. width: 38rpx;
  142. height: 10rpx;
  143. line-height: 10rpx;
  144. margin-left: 0px;
  145. font-size: 30rpx;
  146. color: #fff;
  147. text-align: center;
  148. &.active{
  149. color: #fff000;
  150. }
  151. }
  152. .icon-arrow-up {}
  153. .icon-arrow-down {
  154. transform:rotate(-180deg);
  155. }
  156. }
  157. }
  158. }
  159. .goods-list-box{ margin-top: 20rpx; width: 100%;display: flex; flex-direction: row;flex-wrap: wrap; }
  160. .goods-list-item-box{ width: 50%; margin-bottom: 20rpx; }
  161. .goods-list-item-box:nth-child(2n+1) .goods-list-item-wrap { margin-left: 20rpx; margin-right: 10rpx; }
  162. .goods-list-item-box:nth-child(2n) .goods-list-item-wrap { margin-left: 10rpx; margin-right: 20rpx; }
  163. .goods-list-item-wrap{ height: 520rpx; background: #fff; overflow: hidden; border-radius: 16rpx; }
  164. .goods-list-item-wrap view { display: block; }
  165. .goods-list-item-wrap view:nth-child(1) { height: 370rpx; }
  166. .goods-list-item-wrap view:nth-child(1) image { padding: 20rpx 5%; width: 90%; height: 330rpx; }
  167. .goods-list-item-wrap view:nth-child(2) { height: 80rpx; font-size: 30rpx; padding: 0 20rpx; display: -webkit-box;overflow: hidden;-webkit-line-clamp: 2;-webkit-box-orient: vertical; }
  168. .goods-list-item-wrap view:nth-child(3){ font-size: 26rpx; padding: 10rpx; color: red; }
  169. </style>