category.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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="index">
  10. <view class="item-title" :class="index === currentIndex ? 'active' : ''" @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="index">
  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. <u--text-price color="red" size="12" intSize="18" :text="item.price"></u--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. id: 1,
  58. image: 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  59. name: '推荐'
  60. }, {
  61. id: 1,
  62. image: 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  63. name: '电影'
  64. }, {
  65. id: 1,
  66. image: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  67. name: '科技'
  68. }, {
  69. id: 1,
  70. image: 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  71. name: '音乐'
  72. }, {
  73. id: 1,
  74. image: 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  75. name: '美食'
  76. }, {
  77. id: 1,
  78. image: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  79. name: '文化'
  80. }, {
  81. id: 1,
  82. image: 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  83. name: '财经'
  84. }, {
  85. id: 1,
  86. image: 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  87. name: '手工'
  88. }],
  89. productList: [
  90. {
  91. id: 1,
  92. image: 'https://cdn.uviewui.com/uview/album/1.jpg',
  93. title: '山不在高,有仙则名。水不在深,有龙则灵。斯是陋室,惟吾德馨。',
  94. desc: '山不在于高,有了神仙就会有名气。水不在于深,有了龙就会有灵气。这是简陋的房子,只是我品德好就感觉不到简陋了。',
  95. price: '13.00'
  96. },
  97. {
  98. id: 2,
  99. image: 'https://cdn.uviewui.com/uview/album/2.jpg',
  100. title: '商品222',
  101. desc: '',
  102. price: '23.00'
  103. },
  104. {
  105. id: 3,
  106. image: 'https://cdn.uviewui.com/uview/album/3.jpg',
  107. title: '商品333',
  108. desc: '商品描述信息2',
  109. price: '33.00'
  110. },
  111. {
  112. id: 4,
  113. image: 'https://cdn.uviewui.com/uview/album/4.jpg',
  114. title: '商品444',
  115. desc: '商品描述信息4',
  116. price: '43.00'
  117. },
  118. {
  119. id: 5,
  120. image: 'https://cdn.uviewui.com/uview/album/5.jpg',
  121. title: '商品555',
  122. desc: '商品描述信息5',
  123. price: '53.00'
  124. }
  125. ]
  126. }
  127. },
  128. onLoad() {
  129. },
  130. methods: {
  131. handleSearchClick(e) {
  132. console.log('监听点击准备跳转页面')
  133. },
  134. handleCategoryClick(index){
  135. if (this.currentIndex !== index) {
  136. this.currentIndex = index;
  137. // TODO 查询下分类商品
  138. }
  139. },
  140. handleProdItemClick(productId){
  141. uni.$u.route('/pages/product/product', {
  142. productId: productId
  143. });
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. .search-wrap {
  150. background: $custom-bg-color;
  151. padding: 20rpx;
  152. }
  153. .category-box{
  154. display: flex;
  155. .box-left{
  156. width: 180rpx;
  157. padding-top: 20rpx;
  158. border-right: $custom-border-style;
  159. .category-item{
  160. border-bottom: $custom-border-style;
  161. padding: 20rpx 0;
  162. .item-title{
  163. padding-left: 30rpx;
  164. font-size: 30rpx;
  165. &.active{
  166. border-left: 6rpx solid $u-primary;
  167. font-weight: 700;
  168. }
  169. }
  170. }
  171. }
  172. .box-right{
  173. width: 550rpx;
  174. padding-right: 20rpx;
  175. .category-image{
  176. padding: 20rpx;
  177. }
  178. .prod-list {
  179. height: auto !important;
  180. .prod-item {
  181. padding: 10rpx 20rpx;
  182. background: #fff;
  183. display: flex;
  184. flex-direction: row;
  185. justify-content: space-between;
  186. border-bottom: $custom-border-style;
  187. .prod-image {
  188. border-radius: 10rpx;
  189. /deep/ * {
  190. border-radius: 10rpx;
  191. }
  192. }
  193. .item-info {
  194. width: 350rpx;
  195. padding: 5rpx;
  196. .info-text {
  197. height: 70rpx;
  198. padding-bottom: 10rpx;
  199. }
  200. .price-and-cart {
  201. display: flex;
  202. justify-content: space-between;
  203. }
  204. }
  205. }
  206. }
  207. }
  208. }
  209. </style>