index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <view>
  3. <view class='header acea-row row-center-wrapper'>
  4. <scroll-view scroll-x="true" show-scrollbar="false" class="sort">
  5. <view v-for="(item,index) in sort" :key="index" :class='index==tab?"on":""' @click='change(index,item.type)'>
  6. {{item.name}}
  7. </view>
  8. </scroll-view>
  9. </view>
  10. <view class='aside'>
  11. <view class='item acea-row row-center-wrapper' :class='index==navActive?"on":""' v-for="(item,index) in warehouse"
  12. :key="index" @click='tap(index,item.id)'><text>{{item.name}}</text></view>
  13. </view>
  14. <view class='conter'>
  15. <scroll-view scroll-y="true" show-scrollbar="false">
  16. <view class="list">
  17. <block v-for="(item , index) in productList" :key="index">
  18. <navigator class="product" :url="'/pages/product/detail?id='+item.id" hover-class='none'>
  19. <image :src="item.img"></image>
  20. <view class="info">
  21. <view>{{item.title}}</view>
  22. <view class="price">¥{{item.price}}</view>
  23. <view class="text">
  24. <view>{{item.wget}}kg/件</view>
  25. <view>库存{{item.count}}</view>
  26. </view>
  27. </view>
  28. </navigator>
  29. </block>
  30. <view class='loadingicon acea-row row-center-wrapper' v-if='productList.length > 0'>
  31. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  32. </view>
  33. </view>
  34. </scroll-view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import {
  40. getWarehouse,
  41. productList
  42. } from '@/api/api.js';
  43. export default {
  44. data() {
  45. return {
  46. sort: [
  47. {
  48. 'name': '综合排序',
  49. 'type': 'all'
  50. },
  51. {
  52. 'name': '价格',
  53. 'type': 'price'
  54. },
  55. {
  56. 'name': '重量',
  57. 'type': 'wget'
  58. }
  59. ],
  60. warehouse: [
  61. {
  62. 'name': '全部',
  63. 'id': 0
  64. }
  65. ],
  66. productList: [],
  67. tab: 0,
  68. navActive: 0,
  69. height: 0,
  70. where: {
  71. type: 'all',
  72. warehouse: 0,
  73. page: 1,
  74. limit: 20
  75. },
  76. loadend: false,
  77. loading: false,
  78. loadTitle: '加载更多'
  79. }
  80. },
  81. mounted() {
  82. let that = this
  83. uni.getSystemInfo({
  84. success: function (res) {
  85. that.height = (res.windowHeight) * (750 / res.windowWidth) - 80;
  86. }
  87. })
  88. },
  89. onLoad() {
  90. this.getWarehouse();
  91. this.getProductList();
  92. },
  93. methods: {
  94. change: function(index, type) {
  95. let that = this;
  96. that.tab = index;
  97. that.$set(that.where, 'type', type)
  98. that.$set(that.where, 'page', 1);
  99. that.$set(that, 'productList', []);
  100. that.loadend = false;
  101. that.getProductList();
  102. },
  103. tap: function(index, id) {
  104. let that = this;
  105. that.navActive = index;
  106. that.$set(that.where, 'warehouse', id)
  107. that.$set(that.where, 'page', 1);
  108. that.$set(that, 'productList', []);
  109. that.loadend = false;
  110. that.getProductList();
  111. },
  112. getWarehouse: function() {
  113. let that = this;
  114. getWarehouse().then(res => {
  115. that.warehouse = that.warehouse.concat(res.data);
  116. })
  117. },
  118. getProductList: function() {
  119. let that = this;
  120. if (that.loadend) return;
  121. if (that.loading) return;
  122. that.loading = true;
  123. that.loadTitle = '';
  124. productList(that.where).then(res => {
  125. let list = res.data.list;
  126. let productList = that.productList.concat(list);
  127. let loadend = list.length < that.where.limit;
  128. that.loadend = loadend;
  129. that.loading = false;
  130. that.loadTitle = loadend ? '已全部加载' : '加载更多';
  131. that.$set(that, 'productList', productList);
  132. that.$set(that.where, 'page', that.where.page + 1);
  133. }).catch(err => {
  134. that.loading = false;
  135. that.loadTitle = '加载更多';
  136. });
  137. },
  138. onReachBottom() {
  139. this.getProductList();
  140. }
  141. }
  142. }
  143. </script>
  144. <style scoped lang="scss">
  145. .header {
  146. width: 570rpx;
  147. height: 80rpx;
  148. background-color: #fff;
  149. position: fixed;
  150. left: 180rpx;
  151. right: 0;
  152. top: 0;
  153. z-index: 9;
  154. border-bottom: 1rpx solid #f5f5f5;
  155. }
  156. .sort view{
  157. display: inline-block;
  158. width:33.3%;
  159. text-align: center;
  160. }
  161. .sort view.on{color: #ff5c00;}
  162. .aside {
  163. position: fixed;
  164. width: 180rpx;
  165. left: 0;
  166. bottom: 0;
  167. top:0;
  168. background-color: #f7f7f7;
  169. overflow-y: auto;
  170. overflow-x: hidden;
  171. }
  172. .aside .item {
  173. width: 100%;
  174. font-size: 26rpx;
  175. color: #424242;
  176. padding: 30rpx 10rpx;
  177. }
  178. .aside .item.on {
  179. background-color: #fff;
  180. border-left: 4rpx solid #ff5c00;
  181. width: 100%;
  182. text-align: center;
  183. color: #ff5c00;
  184. font-weight: bold;
  185. }
  186. .conter {
  187. margin: 80rpx 0 0 180rpx;
  188. padding: 0 20rpx;
  189. background-color: #fff;
  190. }
  191. .conter .list .product{
  192. display: flex;
  193. padding: 20rpx 0;
  194. border-top: 1rpx solid #f5f5f5;
  195. }
  196. .conter .list .product:nth-of-type(1){
  197. border-top: none;
  198. }
  199. .conter .list .product image{
  200. width:160rpx;
  201. height:160rpx;
  202. }
  203. .conter .list .product .info{
  204. padding-left: 20rpx;
  205. }
  206. .price{
  207. color: #f5222d;
  208. font-size: 32rpx;
  209. font-weight: bold;
  210. margin-top: 40rpx;
  211. }
  212. .text{
  213. width:350rpx;
  214. display: flex;
  215. justify-content:space-between;
  216. font-size: 24rpx;
  217. color:#666;
  218. }
  219. </style>