card.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view class="goodsCard" @click="goGoodsDetail(data)">
  3. <view class="pic">
  4. <u-image width="360rpx" height="360rpx" mode="aspectFit" :src="data.cover" error-icon="../../../static/img/quesheng.png"></u-image>
  5. </view>
  6. <view class="inner">
  7. <view class="title">{{ data.title }}</view>
  8. <view class="titlesm" v-if="data.publish">{{data.publish}}</view>
  9. <view class="info">
  10. <view class="money">
  11. <view class="now">
  12. <text>¥</text>
  13. <text>{{ data.price_selling }}</text>
  14. </view>
  15. <!-- <view class="old" v-if="showOldMoney">
  16. <text>¥{{ data.oldMoney }}</text>
  17. </view> -->
  18. </view>
  19. <!-- <view class="sale">
  20. <text>月销</text>
  21. <text>{{ $replaceSale(data.num) }}</text>
  22. </view> -->
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. props: {
  30. // 数据源
  31. data: {
  32. type: Object,
  33. default: () => {
  34. return {};
  35. }
  36. },
  37. // 是否显示原价
  38. showOldMoney: {
  39. type: Boolean,
  40. default: false
  41. }
  42. },
  43. methods: {
  44. goGoodsDetail(item) {
  45. uni.navigateTo({
  46. url: '/pages-mall/pages/goods/detail?goodsId='+item.id
  47. });
  48. },
  49. addCart(item){
  50. this.$u.api.addCartAjax({
  51. goods_id:item.id,
  52. nums: 1,
  53. sku_id:1,//1是测试,应该传入skuId,外层没有返回,需要接口返回一下
  54. }).then(({code})=>{
  55. if(code==1){
  56. this.$u.toast('添加购物车成功')
  57. }
  58. })
  59. }
  60. }
  61. };
  62. </script>
  63. <style lang="scss" scoped>
  64. .goodsCard {
  65. width: 340rpx;
  66. background-color: $app-theme-bg-color;
  67. overflow: hidden;
  68. margin-bottom: 16rpx;
  69. background-color: #fff;
  70. border-radius: 10rpx 10rpx 0 0;
  71. .pic {
  72. overflow: hidden;
  73. width: 100%;
  74. background-color: #fff;
  75. }
  76. .inner {
  77. padding: 22rpx 18rpx 26rpx 24rpx;
  78. }
  79. .title {
  80. width: 100%;
  81. height: 3em;
  82. line-height: 1.5;
  83. word-break: break-all;
  84. white-space: pre-wrap;
  85. font-size: 28rpx;
  86. color: $app-theme-text-black-color;
  87. margin-bottom: 8rpx;
  88. // 默认单行,如果需要瀑布流则改成多行
  89. display: -webkit-box;
  90. overflow: hidden;
  91. -webkit-line-clamp: 2;
  92. -webkit-box-orient: vertical;
  93. }
  94. .titlesm{
  95. font-size: 24rpx;
  96. font-weight: 400;
  97. color: #999;
  98. margin-bottom: 8rpx;
  99. display: -webkit-box;
  100. overflow: hidden;
  101. -webkit-line-clamp: 2;
  102. -webkit-box-orient: vertical;
  103. }
  104. .info {
  105. display: flex;
  106. justify-content: space-between;
  107. align-items: flex-end;
  108. .money {
  109. display: flex;
  110. align-items: flex-end;
  111. .now {
  112. font-weight: bold;
  113. text:nth-child(1) {
  114. font-size: 20rpx;
  115. color: $app-theme-text-money-color;
  116. }
  117. text:nth-child(2) {
  118. font-size: 30rpx;
  119. color: $app-theme-text-money-color;
  120. }
  121. }
  122. .old {
  123. text {
  124. font-size: 20rpx;
  125. color: $app-theme-card-gray-color;
  126. text-decoration-line: line-through;
  127. }
  128. }
  129. }
  130. .sale {
  131. font-size: 24rpx;
  132. font-weight: 400;
  133. color: $app-theme-card-gray-color;
  134. }
  135. }
  136. }
  137. </style>