prod-item.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <!-- 商品组件 -->
  3. <div class="list-con" :class="{ normalList: listType == 1 && this.$route.name != 'index' }">
  4. <div
  5. class="item"
  6. v-for="item in paleList"
  7. :key="item.prodId"
  8. @click="toProdDetail(item.prodId, item.seckillSearchVO ? item.seckillSearchVO.seckillId : '', item.groupActivityId)"
  9. >
  10. <!-- 团购(成团人数) -->
  11. <div class="group-number" v-if="item.groupActivitySearchVO">
  12. {{ item.groupActivitySearchVO.groupNumber }}{{$t('index.join')}}
  13. </div>
  14. <div class="goods-img">
  15. <!-- 秒杀/热销商品图 -->
  16. <img v-if="item.pic" :src="item.pic" @error="handlePicError" alt />
  17. <!-- 团购商品图 -->
  18. <img v-else-if="item.prodPic" :src="item.prodPic" alt @error="handlePicError"/>
  19. <img v-else src="~/assets/img/def.png" alt />
  20. </div>
  21. <div class="goods-msg">
  22. <div class="goods-name">{{ item.prodName }}</div>
  23. <div class="goods-price">
  24. <!-- 秒杀商品价格 -->
  25. <div class="price" v-if="item.activityPrice && listType==2 && pageType===0">
  26. <span class="big">{{ parsePrice(item.activityPrice)[0] }}</span>
  27. <span class="small">.{{ parsePrice(item.activityPrice)[1] }}</span>
  28. </div>
  29. <!-- 团购商品价格 -->
  30. <div class="price" v-else-if="item.activityPrice && listType==1 && pageType===0">
  31. <span class="big">{{ parsePrice(item.activityPrice)[0] }}</span>
  32. <span class="small">.{{ parsePrice(item.activityPrice)[1] }}</span>
  33. </div>
  34. <!-- 热销商品价格 -->
  35. <div class="price" v-else>
  36. <span class="big">{{ parsePrice(item.price)[0] }}</span>
  37. <span class="small">.{{ parsePrice(item.price)[1] }}</span>
  38. <span v-if="item.soldNum || item.soldNum === 0" class="small sold-number">
  39. {{$t('prodDetail.sold')}} {{item.soldNum}}
  40. </span>
  41. </div>
  42. <!-- <div class="old-price" v-if="!item.brief">¥{{toPrice(item.price)}}</div> -->
  43. </div>
  44. </div>
  45. </div>
  46. <!-- 商品列表为空 -->
  47. <div class="empty" v-if="!paleList.length">
  48. <div class="img">
  49. <img src="~/assets/images/emptyPic/not-found.png" alt />
  50. </div>
  51. <div class="action">
  52. <div class="text">{{$t('sorryNoRelatedProducts')}}</div>
  53. <nuxt-link to="/list" class="btn">{{$t('lookAtOther')}}</nuxt-link>
  54. </div>
  55. </div>
  56. <!-- 商品列表为空 -->
  57. </div>
  58. </template>
  59. <script>
  60. export default {
  61. props: {
  62. paleList: {
  63. type: Array, //指定传入的类型
  64. default: () => []//这样可以指定默认的值
  65. },
  66. listType: {
  67. type: Number,
  68. default: 0
  69. },
  70. // 1: 商品列表页
  71. pageType: {
  72. type: Number,
  73. default: 0
  74. }
  75. },
  76. mounted() {
  77. console.log(this.listType)
  78. if(this.listType===2) {
  79. console.log(this.paleList);
  80. }
  81. },
  82. methods: {
  83. /**
  84. * 加载默认图片
  85. */
  86. handlePicError(e){
  87. e.target.src=require('@/assets/img/def.png')
  88. },
  89. /**
  90. * 处理价格样式
  91. */
  92. toPrice (val) {
  93. if (!val) {
  94. var val = Number(val)
  95. val = 0;
  96. }
  97. // 截取小数点后两位,没有则自动补0
  98. return (val.toFixed(2))
  99. },
  100. parsePrice (val) {
  101. var val = Number(val)
  102. if (!val) {
  103. val = 0;
  104. }
  105. // 截取小数点后两位,并以小数点为切割点将val转化为数组
  106. return val.toFixed(2).split(".");
  107. },
  108. /**
  109. * 跳转到商品详情页
  110. */
  111. toProdDetail (prodId, seckillId, groupActivityId) {
  112. if (seckillId) {
  113. this.$router.push({ name: 'secdetail-seckillId', params: { seckillId: seckillId } })
  114. } else if (groupActivityId) {
  115. this.$router.push({ name: 'detail-prodId', params: { prodId: prodId, groupActivityId: groupActivityId } })
  116. } else {
  117. this.$router.push({ path: '/detail/' + prodId })
  118. }
  119. },
  120. goIndex () {
  121. this.$router.push({ path: '/' })
  122. },
  123. /**
  124. * 图片访问失败时更为默认图片
  125. */
  126. handlePicError(event){
  127. event.target.src=require("../assets/img/def.png")
  128. }
  129. }
  130. }
  131. </script>
  132. <style scoped>
  133. .normalList {
  134. min-height: 440px;
  135. }
  136. .normalList .item {
  137. width: 275px;
  138. }
  139. .normalList .item .goods-img {
  140. width: 275px;
  141. height: 275px;
  142. line-height: 275px;
  143. }
  144. .normalList .empty {
  145. min-height: 380px;
  146. }
  147. /* 商品名字的样式修改 */
  148. .goods-list .list-con .item .goods-msg .goods-name {
  149. height: 20px;
  150. line-height: 14px;
  151. font-size: 14px;
  152. max-width: 100%;
  153. /* display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;
  154. overflow: hidden */
  155. }
  156. .sold-number {
  157. margin-left: 5px;
  158. color: #999;
  159. }
  160. </style>