category.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. <view 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="abnor-panel" v-if="!productList.length">
  19. <image class="icon" src="../../../static/svg/bags.svg"></image>
  20. 暂无数据
  21. </view>
  22. </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. .item {
  113. height: 192.31rpx;
  114. background: #fff;
  115. position: relative;
  116. padding: 13.74rpx 20.6rpx 0 199.18rpx;
  117. box-sizing: border-box;
  118. border-bottom: 1rpx solid #e0e0e0;
  119. &:last-child {
  120. border: none;
  121. }
  122. }
  123. .box {
  124. width: 157.97rpx;
  125. height: 157.97rpx;
  126. position: absolute;
  127. left: 20.6rpx;
  128. top: 13.74rpx;
  129. font-size: 27.47rpx;
  130. color: #fff;
  131. text-align: center;
  132. word-break: break-all;
  133. background: #0a9efe;
  134. display: flex;
  135. align-items: center;
  136. justify-content: center;
  137. padding: 0 13.74rpx;
  138. box-sizing: border-box;
  139. }
  140. .name {
  141. font-size: 27.47rpx;
  142. white-space: nowrap;
  143. overflow: hidden;
  144. text-overflow: ellipsis;
  145. }
  146. .desc {
  147. font-size: 24.73rpx;
  148. color: #999;
  149. display: -webkit-box;
  150. overflow: hidden;
  151. text-overflow: ellipsis;
  152. -webkit-line-clamp: 2;
  153. -webkit-box-orient: vertical;
  154. max-height: 82.42rpx;
  155. word-break: break-all;
  156. }
  157. .tags {
  158. overflow: hidden;
  159. .tag {
  160. float: left;
  161. font-size: 21.98rpx;
  162. color: #f97631;
  163. padding: 2.75rpx 13.74rpx;
  164. border: 1rpx solid #f97631;
  165. margin: 13.74rpx 13.74rpx 0 0;
  166. }
  167. }
  168. .price {
  169. font-size: 41.21rpx;
  170. color: #f97631;
  171. position: absolute;
  172. right: 20.6rpx;
  173. bottom: 20.6rpx;
  174. line-height: 1;
  175. &:before {
  176. content: '¥';
  177. font-size: 24.73rpx;
  178. }
  179. &::after {
  180. content: attr(data-text);
  181. font-size: 21.98rpx;
  182. color: #999;
  183. margin-left: 4.12rpx;
  184. vertical-align: middle;
  185. }
  186. }
  187. }
  188. .abnor-panel {
  189. position: fixed;
  190. left: 50%;
  191. top: 50%;
  192. transform: translate(-50%, -50%);
  193. margin-left: 82.42rpx;
  194. display: flex;
  195. flex-direction: column;
  196. white-space: nowrap;
  197. align-items: center;
  198. font-size: 27.47rpx;
  199. color: #999;
  200. .icon {
  201. width: 137.36rpx;
  202. height: 137.36rpx;
  203. margin-bottom: 41.21rpx;
  204. }
  205. }
  206. </style>