uni-coods.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view class="goods-item" @click="toDetail">
  3. <view class="goods-imgs">
  4. <view v-if="data.status == 1" class="goods-staus">已售罄</view>
  5. <u-lazy-load img-mode="scaleToFill" :height="imgHeight" :image="data.src" :loading-img="loadingImg" :error-img="errorImg"></u-lazy-load>
  6. </view>
  7. <view class="name ellipsis-two">{{data.name}}</view>
  8. <view class="price">
  9. <view>
  10. <text>{{data.price}}</text>
  11. <u-image mode="scaleToFill" width="40rpx" height="40rpx" src="/static/ledou.png"></u-image>
  12. </view>
  13. <view @click.stop="addCart">
  14. <u-image mode="scaleToFill" width="45rpx" height="45rpx" src="/static/addCart.png"></u-image>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. props: {
  22. imgHeight: {
  23. type: Number,
  24. default: 250
  25. },
  26. data:{
  27. type: Object,
  28. default: function(){
  29. return {}
  30. }
  31. }
  32. },
  33. data() {
  34. return {
  35. loadingImg: '/static/loading.gif',
  36. errorImg: '/static/imgError.png'
  37. }
  38. },
  39. methods: {
  40. // 加入购物车
  41. addCart() {
  42. // 请求接口
  43. this.$store.state.vuex_cartNums = Number(this.$store.state.vuex_cartNums) + 1
  44. },
  45. // 商品详情
  46. toDetail(){
  47. uni.navigateTo({
  48. url:"/pages/goods/goodsDetail?id="+this.data.id
  49. })
  50. }
  51. },
  52. }
  53. </script>
  54. <style lang="scss">
  55. .goods-item{
  56. background: #FFFFFF;
  57. width: 48%;
  58. margin-bottom: 5upx;
  59. .goods-imgs{
  60. position: relative;
  61. border-radius: 28upx 28upx 0 0;
  62. overflow: hidden;
  63. .goods-staus{
  64. width: 100%;
  65. height: 100%;
  66. position: absolute;
  67. z-index: 10000;
  68. border-radius: 15rpx;
  69. background: rgba($color: #000000, $alpha: 0.4);
  70. text-align: center;
  71. line-height: 250rpx;
  72. left: 0;
  73. top: 0;
  74. color: #eee;
  75. font-size: 30upx;
  76. font-weight: bold;
  77. }
  78. }
  79. .name{
  80. padding: 10upx 20upx 0;
  81. font-weight: bold;
  82. }
  83. .price{
  84. display: flex;
  85. align-items: center;
  86. justify-content: space-between;
  87. padding: 15upx 20upx;
  88. text{
  89. color: #d42a26;
  90. font-size: 36upx;
  91. margin-right: 6upx;
  92. font-weight: bold;
  93. }
  94. >view{
  95. &:first-child{
  96. font-size: 22upx;
  97. display: flex;
  98. align-items: center;
  99. }
  100. }
  101. }
  102. }
  103. </style>