product-list.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view class="product-wrapper">
  3. <!-- 文章搜索筛选 -->
  4. <view class="search-sort">
  5. <template v-for="item in sortItems">
  6. <view
  7. class="sort-item"
  8. :key="item.id"
  9. :class="{ active: item.id === currentSortItem }"
  10. @click="onSortItemClick(item)"
  11. >
  12. <text v-text="item.name"></text>
  13. <text :class="[item.icon, item.sortType]"></text>
  14. </view>
  15. </template>
  16. </view>
  17. <!-- 文章搜索列表 -->
  18. <view class="product-list">
  19. <view class="product" v-for="product in list" :key="product.productId" @click="onToDetail(product)">
  20. <view class="cover"><image :src="product.image"></image></view>
  21. <view class="content">
  22. <view class="title" v-html="product.name"></view>
  23. <view class="unit">
  24. <text class="label">规格:</text>
  25. <text class="value" v-text="product.unit"></text>
  26. </view>
  27. <view class="code">
  28. <text class="label">商品编码:</text>
  29. <text class="value" v-text="product.code"></text>
  30. </view>
  31. <view class="foot">
  32. <view class="price">
  33. <view class="real-price">¥{{ makePrice(product) }}</view>
  34. <!-- <view class="old-price">¥480.00</view> -->
  35. </view>
  36. <view class="tag-list">
  37. <view class="tag coupon" v-if="product.couponsLogo">优惠券</view>
  38. <view class="tag svip" v-if="product.svipProductFlag == 1">svip</view>
  39. <template v-if="product.actStatus == 1">
  40. <template v-if="isPromotion(product.promotions)">
  41. <view class="tag other">
  42. {{ product.promotions.name }}
  43. <text>:¥{{ product.price | priceFormat }}</text>
  44. </view>
  45. </template>
  46. <template v-else>
  47. <view class="tag other">{{ product.promotions.name }}</view>
  48. </template>
  49. </template>
  50. <!-- <view class="tag reduce">活动价</view> -->
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import { debounce } from '@/common/config/common'
  60. const myDebounce = fn => debounce(fn, 200, false)
  61. export default {
  62. filters: {
  63. priceFormat(price) {
  64. if (!price) return ''
  65. return Number(text).toFixed(2)
  66. }
  67. },
  68. props: {
  69. list: {
  70. type: Array,
  71. default: () => []
  72. }
  73. },
  74. data() {
  75. const sortItems = [
  76. { id: 1, name: '综合', icon: '', sortType: '' },
  77. { id: 2, name: '销量', icon: 'sort', sortType: 'asc' }, // asc 升序 desc 降序
  78. { id: 3, name: '人气', icon: 'sort', sortType: 'asc' }, // asc 升序 desc 降序
  79. { id: 4, name: '价格', icon: 'sort', sortType: 'asc' }, // asc 升序 desc 降序
  80. { id: 5, name: '筛选', icon: 'iconfont icon-shaixuan', sortType: '' }
  81. ]
  82. return {
  83. sortItems: sortItems,
  84. currentSortItem: 1
  85. }
  86. },
  87. methods: {
  88. // 跳转产品详情
  89. onToDetail: myDebounce(function(product) {
  90. this.$api.navigateTo(`/pages/goods/product?id=${product.productId}`)
  91. }),
  92. // 是否有促销价
  93. isPromotion(promo) {
  94. if (!promo) return false
  95. return promo.type == 1 && promo.mode == 1
  96. },
  97. // 返回产品价格
  98. makePrice(product) {
  99. const price = this.isPromotion(product.promotions) ? product.originalPrice : product.price
  100. return Number(price).toFixed(2)
  101. },
  102. // sort item click
  103. onSortItemClick(item) {
  104. if (item.id === 5) {
  105. console.log('filter')
  106. } else if (item.id === this.currentSortItem) {
  107. item.sortType = item.sortType === 'asc' ? 'desc' : 'asc'
  108. } else {
  109. const lastCurrent = this.sortItems.find(a => a.id === this.currentSortItem)
  110. this.currentSortItem = item.id
  111. lastCurrent.sortType = 'asc'
  112. }
  113. this.$emit('change', item)
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. /* scss中可以用mixin来扩展 */
  120. @mixin ellipsis($line: 1) {
  121. overflow: hidden;
  122. text-overflow: ellipsis;
  123. display: -webkit-box;
  124. -webkit-line-clamp: $line;
  125. -webkit-box-orient: vertical;
  126. }
  127. .product-wrapper {
  128. .search-sort {
  129. background: #fff;
  130. display: flex;
  131. justify-content: space-evenly;
  132. align-items: center;
  133. line-height: 90rpx;
  134. .sort-item {
  135. display: flex;
  136. align-items: center;
  137. justify-content: center;
  138. flex: 1;
  139. font-size: 26rpx;
  140. color: #999999;
  141. text:first-child {
  142. margin-right: 4rpx;
  143. }
  144. &.active,
  145. &.active .sort.desc::after,
  146. &.active .sort.asc::before,
  147. &.active .icon-shaixuan {
  148. color: #F3B574;
  149. }
  150. .icon-shaixuan {
  151. font-size: 24rpx;
  152. color: #999999;
  153. }
  154. .sort {
  155. display: flex;
  156. flex-direction: column;
  157. align-items: center;
  158. line-height: 0.9;
  159. font-size: 14rpx;
  160. color: #aaa;
  161. transform: scale(0.7);
  162. &::after {
  163. content: '▼';
  164. }
  165. &::before {
  166. content: '▲';
  167. }
  168. }
  169. }
  170. }
  171. .product {
  172. display: flex;
  173. padding: 32rpx;
  174. border-top: 1rpx solid #e1e1e1;
  175. .cover {
  176. flex-shrink: 0;
  177. width: 220rpx;
  178. height: 220rpx;
  179. image {
  180. display: block;
  181. width: 100%;
  182. height: 100%;
  183. }
  184. }
  185. .content {
  186. flex: 1;
  187. margin-left: 24rpx;
  188. .title {
  189. font-size: 26rpx;
  190. color: #333333;
  191. line-height: 36rpx;
  192. height: 72rpx;
  193. @include ellipsis(2);
  194. }
  195. .unit,
  196. .code {
  197. font-size: 20rpx;
  198. color: #666666;
  199. margin-top: 8rpx;
  200. height: 28rpx;
  201. @include ellipsis(1);
  202. .value {
  203. color: #999;
  204. }
  205. }
  206. .foot {
  207. margin-top: 34rpx;
  208. display: flex;
  209. justify-content: space-between;
  210. align-items: flex-end;
  211. .price {
  212. display: flex;
  213. align-items: flex-end;
  214. .real-price {
  215. color: #F3B574;
  216. font-size: 24rpx;
  217. }
  218. .old-price {
  219. text-decoration: line-through;
  220. font-size: 20rpx;
  221. color: #999;
  222. margin-left: 8rpx;
  223. }
  224. }
  225. .tag-list {
  226. display: flex;
  227. .tag {
  228. height: 32rpx;
  229. font-size: 22rpx;
  230. flex-shrink: 0;
  231. box-sizing: border-box;
  232. padding: 0 8rpx;
  233. margin-right: 8rpx;
  234. border-radius: 6rpx;
  235. &:last-child {
  236. margin-right: 0;
  237. }
  238. &.coupon,
  239. &.reduce,
  240. &.other {
  241. border: 1rpx solid rgba(225, 86, 22, 0.2);
  242. line-height: 30rpx;
  243. color: #F3B574;
  244. }
  245. &.svip {
  246. line-height: 32rpx;
  247. color: #f0cb72;
  248. background: #333333;
  249. text-transform: uppercase;
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256. }
  257. </style>