uni-coods.vue 2.4 KB

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