channel.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="page" v-if="fetch && fetch.top">
  3. <use-tabbar></use-tabbar>
  4. <use-header :search-tip="searchTip" :search-auto="searchAuto" :searchId="id" :source="2"
  5. @search="search"></use-header>
  6. <view class="category">
  7. <!-- 左侧滚动分类 -->
  8. <scroll-view class="left" scroll-y>
  9. <u-sidebar v-model="top" @change="loadTop" :activeBold="true" lineColor="#ff6b6b" activeColor="#ff6b6b"
  10. activeBgColor="#ffffff00">
  11. <u-sidebar-item v-for="(item, index) in fetch.top" :key="index" :label="item.name"
  12. :value="item.id"></u-sidebar-item>
  13. </u-sidebar>
  14. </scroll-view>
  15. <!-- 右侧商品区域 -->
  16. <view class="right">
  17. <!-- tabs 固定 -->
  18. <view class="small-tabs-wrapper bg-main border-radius margin-bottom-sm padding-8">
  19. <u-tabs lineColor="#ff6b6b" activeColor="#ff6b6b" :list="fetch.top[top].cate" :activeStyle="{
  20. color: '#303133',
  21. fontWeight: 'bold',
  22. transform: 'scale(1.05)'
  23. }" :inactiveStyle="{
  24. color: '#606266',
  25. transform: 'scale(1)'
  26. }" @click="loadCate" scrollable></u-tabs>
  27. </view>
  28. <!-- 商品列表滚动 -->
  29. <scroll-view class="goods-list" scroll-y v-if="fetch.list && fetch.list.length > 0">
  30. <view class="use-hover" v-for="(item, index) in fetch.list" :key="index">
  31. <view class="goods border-radius padding bg-main"
  32. @click="Dever.location('source/info?id=' + item.id + '&title=' + item.name)">
  33. <view class="goods-left pos-r">
  34. <image class="border-radius-sm" :src="item.cover" mode="aspectFill"></image>
  35. <view v-if="item.tag" class="use-tag pos-a pos-top bg-base scale-08">
  36. {{ item.tag }}
  37. </view>
  38. </view>
  39. <view class="margin-left-sm pos-r flex-1">
  40. <text class="clamp-2">{{ item.name }}</text>
  41. <!-- ✅ 价格行 -->
  42. <view class="price-box">
  43. <template v-if="item.price && item.price > 0">
  44. <text class="price">{{ item.price_text }}</text>
  45. <text class="m-price" v-if="item.m_price > 0">{{ item.m_price_text }}</text>
  46. </template>
  47. <template v-else>
  48. <u--text type="info" v-if="item.info" :lines="2" :size="12" :text="item.info"></u--text>
  49. <text v-else class="price free-tag">免费</text>
  50. <text class="m-price" v-if="item.m_price > 0">{{ item.m_price_text }}</text>
  51. </template>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </scroll-view>
  57. <view v-else>
  58. <u-empty mode="data" :marginTop="100"></u-empty>
  59. </view>
  60. </view>
  61. </view>
  62. <use-copyright :title="fetch.channel.name" :desc="fetch.channel.desc"
  63. v-if="fetch && fetch.channel"></use-copyright>
  64. </view>
  65. </template>
  66. <script>
  67. export default {
  68. data() {
  69. return {
  70. searchAuto: true,
  71. searchTip: "请输入搜索关键字",
  72. id: 0,
  73. fetch: {},
  74. top: 0,
  75. cate: 0
  76. };
  77. },
  78. onLoad(options) {
  79. this.id = options.id;
  80. this.loadData();
  81. },
  82. //下拉刷新
  83. onPullDownRefresh() {
  84. this.loadGoods(1);
  85. },
  86. //加载更多
  87. onReachBottom() {
  88. this.loadGoods(2);
  89. },
  90. methods: {
  91. // 加载数据
  92. loadData(callback) {
  93. this.DeverApi.get(this, "source.channel", {
  94. channel_id: this.id
  95. }, res => {
  96. this.loadGoods(1);
  97. });
  98. },
  99. search() {
  100. console.log("home search");
  101. },
  102. loadTop(index) {
  103. this.top = index.index;
  104. this.loadGoods(1);
  105. },
  106. loadCate(tab) {
  107. this.cate = tab.index;
  108. this.loadGoods(1);
  109. },
  110. loadGoods(page) {
  111. var id = this.fetch.top[this.top]?.cate[this.cate]?.id;
  112. if (id) {
  113. this.DeverApi.page([page, "list"], this, "source.cate", {
  114. id: id,
  115. show: 2,
  116. });
  117. }
  118. }
  119. }
  120. };
  121. </script>
  122. <style>
  123. .page {
  124. display: flex;
  125. flex-direction: column;
  126. height: 100vh;
  127. overflow: hidden;
  128. background: #f5f5f5;
  129. }
  130. .use-header {
  131. height: 96rpx;
  132. }
  133. .category {
  134. flex: 1;
  135. display: flex;
  136. overflow: hidden;
  137. }
  138. .left {
  139. width: 198rpx;
  140. overflow-y: auto;
  141. -webkit-overflow-scrolling: touch;
  142. background-color: #f5f5f5;
  143. }
  144. .right {
  145. flex: 1;
  146. display: flex;
  147. flex-direction: column;
  148. overflow: hidden;
  149. background-color: #fff;
  150. }
  151. .small-tabs-wrapper {
  152. padding: 8rpx;
  153. margin-bottom: 12rpx;
  154. background: #fff;
  155. }
  156. .goods-list {
  157. flex: 1;
  158. overflow-y: auto;
  159. -webkit-overflow-scrolling: touch;
  160. padding-left: 4rpx;
  161. padding-right: 18rpx;
  162. }
  163. .goods {
  164. display: flex;
  165. padding-bottom: 14rpx;
  166. }
  167. .goods .goods-left image {
  168. width: 120rpx;
  169. height: 120rpx;
  170. }
  171. .use-tag {
  172. border-top-left-radius: 8rpx;
  173. border-bottom-right-radius: 8rpx;
  174. line-height: 1;
  175. padding: 8rpx 12rpx;
  176. font-size: 20rpx;
  177. background-color: #ff6b6c;
  178. color: #fff;
  179. }
  180. .price-box {
  181. margin-top: 20rpx;
  182. }
  183. .price {
  184. font-size: 32rpx;
  185. font-weight: bold;
  186. color: #ff6b6b;
  187. line-height: 1;
  188. flex-shrink: 0;
  189. /* 不让价格被挤压 */
  190. }
  191. .m-price {
  192. font-size: 24rpx;
  193. color: #999;
  194. text-decoration: line-through;
  195. line-height: 1;
  196. flex-shrink: 0;
  197. /* 不让原价被挤压 */
  198. }
  199. .price-desc {
  200. font-size: 24rpx;
  201. color: #666;
  202. }
  203. /* 免费标签 */
  204. .free-tag {
  205. color: #4caf50;
  206. background-color: #e6f5ea;
  207. padding: 4rpx 10rpx;
  208. border-radius: 6rpx;
  209. font-size: 24rpx;
  210. line-height: 1;
  211. }
  212. </style>