category.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view class="container">
  3. <view class="search-wrap">
  4. <u-search placeholder="搜索" disabled height="32" :show-action="false" @click="handleSearchClick"></u-search>
  5. </view>
  6. <view class="category-box">
  7. <view class="box-left">
  8. <u-list @scrolltolower="scrolltolower">
  9. <u-list-item class="category-item" v-for="(item, index) in categoryList" :key="item.id">
  10. <view class="item-title" :class="{ active: currentIndex === index }" @click="handleCategoryClick(index)">
  11. <text>{{ item.name }}</text>
  12. </view>
  13. </u-list-item>
  14. </u-list>
  15. </view>
  16. <view class="box-right">
  17. <view class="category-image">
  18. <u--image :showLoading="true" :src="categoryList[currentIndex].image" width="530rpx" height="160rpx" @click="click"></u--image>
  19. </view>
  20. <view>
  21. <u-list class="prod-list" @scrolltolower="scrolltolower">
  22. <u-list-item v-for="(item, index) in productList" :key="item.id">
  23. <view class="prod-item" @click="handleProdItemClick(item.id)">
  24. <u--image class="prod-image" width="140rpx" height="140rpx" :src="item.image"></u--image>
  25. <view class="item-info">
  26. <view class="info-text">
  27. <u--text :lines="1" size="14px" color="#333333" :text="item.title"></u--text>
  28. <u-gap height="2px"></u-gap>
  29. <u--text :lines="1" size="12px" color="#939393" :text="item.desc"></u--text>
  30. </view>
  31. <view class="price-and-cart">
  32. <custom-text-price color="red" size="12" intSize="18" :price="item.price"></custom-text-price>
  33. <u-icon name="shopping-cart" color="#2979ff" size="28"></u-icon>
  34. </view>
  35. </view>
  36. </view>
  37. </u-list-item>
  38. </u-list>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import UText from '../../uni_modules/uview-ui/components/u-text/u-text'
  46. export default {
  47. components: { UText },
  48. data() {
  49. return {
  50. currentIndex: 0,
  51. categoryList: [
  52. {
  53. id: 1,
  54. image: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  55. name: '关注'
  56. },
  57. {
  58. id: 2,
  59. image: 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  60. name: '推荐'
  61. },
  62. {
  63. id: 3,
  64. image: 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  65. name: '电影'
  66. },
  67. {
  68. id: 4,
  69. image: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  70. name: '科技'
  71. },
  72. {
  73. id: 5,
  74. image: 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  75. name: '音乐'
  76. },
  77. {
  78. id: 6,
  79. image: 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  80. name: '美食'
  81. },
  82. {
  83. id: 7,
  84. image: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  85. name: '文化'
  86. },
  87. {
  88. id: 8,
  89. image: 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  90. name: '财经'
  91. },
  92. {
  93. id: 9,
  94. image: 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  95. name: '手工'
  96. }
  97. ],
  98. productList: [
  99. {
  100. id: 0,
  101. image: 'https://cdn.uviewui.com/uview/album/1.jpg',
  102. title: '山不在高,有仙则名。水不在深,有龙则灵。斯是陋室,惟吾德馨。',
  103. desc: '山不在于高,有了神仙就会有名气。水不在于深,有了龙就会有灵气。这是简陋的房子,只是我品德好就感觉不到简陋了。',
  104. price: '13.00'
  105. },
  106. {
  107. id: 2,
  108. image: 'https://cdn.uviewui.com/uview/album/2.jpg',
  109. title: '商品222',
  110. desc: '',
  111. price: '23.00'
  112. },
  113. {
  114. id: 3,
  115. image: 'https://cdn.uviewui.com/uview/album/3.jpg',
  116. title: '商品333',
  117. desc: '商品描述信息2',
  118. price: '33.00'
  119. },
  120. {
  121. id: 4,
  122. image: 'https://cdn.uviewui.com/uview/album/4.jpg',
  123. title: '商品444',
  124. desc: '商品描述信息4',
  125. price: '43.00'
  126. },
  127. {
  128. id: 5,
  129. image: 'https://cdn.uviewui.com/uview/album/5.jpg',
  130. title: '商品555',
  131. desc: '商品描述信息5',
  132. price: '53.00'
  133. }
  134. ]
  135. }
  136. },
  137. onLoad() {},
  138. methods: {
  139. handleSearchClick(e) {
  140. console.log('监听点击准备跳转页面')
  141. },
  142. handleCategoryClick(index) {
  143. if (this.currentIndex !== index) {
  144. this.currentIndex = index
  145. // TODO 查询下分类商品
  146. }
  147. },
  148. handleProdItemClick(productId) {
  149. uni.$u.route('/pages/product/product', {
  150. productId: productId
  151. })
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. .search-wrap {
  158. background: $custom-bg-color;
  159. padding: 20rpx;
  160. }
  161. .category-box {
  162. display: flex;
  163. .box-left {
  164. width: 180rpx;
  165. padding-top: 20rpx;
  166. border-right: $custom-border-style;
  167. .category-item {
  168. border-bottom: $custom-border-style;
  169. padding: 20rpx 0;
  170. .item-title {
  171. padding-left: 30rpx;
  172. font-size: 30rpx;
  173. &.active {
  174. border-left: 6rpx solid $u-primary;
  175. font-weight: 700;
  176. }
  177. }
  178. }
  179. }
  180. .box-right {
  181. width: 550rpx;
  182. padding-right: 20rpx;
  183. .category-image {
  184. padding: 20rpx;
  185. }
  186. .prod-list {
  187. height: auto !important;
  188. .prod-item {
  189. padding: 10rpx 20rpx;
  190. background: #fff;
  191. @include flex-space-between;
  192. border-bottom: $custom-border-style;
  193. .prod-image {
  194. border-radius: 10rpx;
  195. /deep/ * {
  196. border-radius: 10rpx;
  197. }
  198. }
  199. .item-info {
  200. width: 350rpx;
  201. padding: 5rpx;
  202. .info-text {
  203. height: 70rpx;
  204. padding-bottom: 10rpx;
  205. }
  206. .price-and-cart {
  207. @include flex-space-between;
  208. }
  209. }
  210. }
  211. }
  212. }
  213. }
  214. </style>