category.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <view class="page-wrap">
  3. <scroll-view scroll-y class="nav-panel">
  4. <view :class="{ item: true, active: navActive === index }" @click="navActive = index" v-for="(item, index) in navList" :key="index">
  5. {{ item.categoryName }}
  6. </view>
  7. </scroll-view>
  8. <scroll-view scroll-y class="product-panel">
  9. <view class="item" v-for="(item, index) in productList" :key="index" @click="handleOpenDetail(item.id)">
  10. <view class="box">{{ item.name }}</view>
  11. <view class="name">{{ item.name }}</view>
  12. <view class="desc">{{ item.title }}</view>
  13. <view class="tags">
  14. <view class="tag" v-for="(tag, tagIndex) in item.tags" :key="tagIndex">{{ filterDict(tag, tagList) }}</view>
  15. </view>
  16. <view class="price">{{ item.salePrice }}</view>
  17. </view>
  18. <view class="c-abnor" v-if="!productList.length">
  19. <image class="icon" src="@/static/svg/bags.svg"></image>
  20. 暂无数据
  21. </view>
  22. </scroll-view>
  23. </view>
  24. </template>
  25. <script>
  26. import productService from '@/api/product.js';
  27. import systemService from '@/api/system.js';
  28. import { filterDict } from '@/utils/util.js';
  29. export default {
  30. data() {
  31. return {
  32. navActive: 0,
  33. navList: [],
  34. productList: [],
  35. tagList: []
  36. };
  37. },
  38. watch: {
  39. navActive() {
  40. this.getProductList();
  41. }
  42. },
  43. onLoad() {
  44. this.getCategoryList();
  45. this.getTagConfig();
  46. },
  47. methods: {
  48. // 获取分类列表
  49. async getCategoryList() {
  50. const { data } = await productService.getCategoryList();
  51. this.navList = data;
  52. this.getProductList();
  53. },
  54. // 获取产品列表
  55. async getProductList() {
  56. const { navActive, navList } = this;
  57. const { categoryName } = navList[navActive];
  58. const { rows } = await productService.getProductList({
  59. categoryOne: categoryName,
  60. categoryTwo: categoryName
  61. });
  62. this.productList = rows.map((item) => {
  63. return {
  64. ...item,
  65. tags: item.label ? item.label.split(',') : []
  66. };
  67. });
  68. },
  69. // 获取标签配置
  70. async getTagConfig() {
  71. const { rows } = await systemService.getDict('fin_product_tag');
  72. this.tagList = rows;
  73. },
  74. // 打开商品详情
  75. handleOpenDetail(id) {
  76. uni.navigateTo({
  77. url: 'index?id=' + id
  78. });
  79. },
  80. // 引用方法需要手动注入,否则报错
  81. filterDict
  82. }
  83. };
  84. </script>
  85. <style lang="scss" scoped>
  86. .page-wrap {
  87. padding-left: 164.84rpx;
  88. }
  89. .nav-panel {
  90. position: fixed;
  91. left: 0;
  92. top: 0;
  93. bottom: 0;
  94. width: 164.84rpx;
  95. background: #f2f2f2;
  96. .item {
  97. white-space: nowrap;
  98. overflow: hidden;
  99. text-overflow: ellipsis;
  100. line-height: 89.29rpx;
  101. text-align: center;
  102. padding: 0 13.74rpx;
  103. font-size: 24.73rpx;
  104. color: #333;
  105. }
  106. .active {
  107. color: #00bcd2;
  108. background: #fff;
  109. }
  110. }
  111. .product-panel {
  112. height: 100vh;
  113. .item {
  114. height: 192.31rpx;
  115. background: #fff;
  116. position: relative;
  117. padding: 13.74rpx 20.6rpx 0 199.18rpx;
  118. box-sizing: border-box;
  119. border-bottom: 1rpx solid #e0e0e0;
  120. &:last-child {
  121. border: none;
  122. }
  123. }
  124. .box {
  125. width: 157.97rpx;
  126. height: 157.97rpx;
  127. position: absolute;
  128. left: 20.6rpx;
  129. top: 13.74rpx;
  130. font-size: 27.47rpx;
  131. color: #fff;
  132. text-align: center;
  133. word-break: break-all;
  134. background: #0a9efe;
  135. display: flex;
  136. align-items: center;
  137. justify-content: center;
  138. padding: 0 13.74rpx;
  139. box-sizing: border-box;
  140. }
  141. .name {
  142. font-size: 27.47rpx;
  143. white-space: nowrap;
  144. overflow: hidden;
  145. text-overflow: ellipsis;
  146. }
  147. .desc {
  148. font-size: 24.73rpx;
  149. color: #999;
  150. display: -webkit-box;
  151. overflow: hidden;
  152. text-overflow: ellipsis;
  153. -webkit-line-clamp: 2;
  154. -webkit-box-orient: vertical;
  155. max-height: 82.42rpx;
  156. word-break: break-all;
  157. }
  158. .tags {
  159. overflow: hidden;
  160. .tag {
  161. float: left;
  162. font-size: 21.98rpx;
  163. color: #f97631;
  164. padding: 2.75rpx 13.74rpx;
  165. border: 1rpx solid #f97631;
  166. margin: 13.74rpx 13.74rpx 0 0;
  167. }
  168. }
  169. .price {
  170. font-size: 41.21rpx;
  171. color: #f97631;
  172. position: absolute;
  173. right: 20.6rpx;
  174. bottom: 20.6rpx;
  175. line-height: 1;
  176. &:before {
  177. content: '¥';
  178. font-size: 24.73rpx;
  179. }
  180. &::after {
  181. content: attr(data-text);
  182. font-size: 21.98rpx;
  183. color: #999;
  184. margin-left: 4.12rpx;
  185. vertical-align: middle;
  186. }
  187. }
  188. }
  189. .c-abnor {
  190. margin-left: 82.42rpx;
  191. }
  192. </style>