uni-coods.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view class="goods-list">
  3. <view class="goods-item" v-for="item in list" :key="item.id" @click="toDetail(item)">
  4. <view class="goods-imgs">
  5. <view v-if="item.inventoryQty == 0" class="goods-staus">已售罄</view>
  6. <u-lazy-load img-mode="scaleToFill" :height="imgHeight" :image="item.homeImage" :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.sellGold}}</text>
  12. <u-image mode="scaleToFill" width="40rpx" height="40rpx" src="/static/ledou.png"></u-image>
  13. </view>
  14. <view @click.stop="addCart(item)" v-if="item.inventoryQty > 0">
  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. timer: null,
  40. finger: {x:0,y:0},
  41. linePos: null
  42. }
  43. },
  44. methods: {
  45. // 加入购物车
  46. addCart(item) {
  47. uni.$emit("addCart",{goodsNo:item.goodsNo,buyQty:1})
  48. },
  49. // 商品详情
  50. toDetail(item){
  51. uni.navigateTo({
  52. url:"/pages/goods/goodsDetail?id="+item.id
  53. })
  54. }
  55. },
  56. }
  57. </script>
  58. <style lang="scss" scoped>
  59. .goods-list{
  60. display: flex;
  61. flex-wrap: wrap;
  62. justify-content: space-between;
  63. padding-top: 20upx;
  64. .goods-item{
  65. background: #FFFFFF;
  66. width: 48%;
  67. margin-bottom: 5upx;
  68. .goods-imgs{
  69. position: relative;
  70. border-radius: 28upx 28upx 0 0;
  71. overflow: hidden;
  72. .goods-staus{
  73. width: 100%;
  74. height: 100%;
  75. position: absolute;
  76. z-index: 100;
  77. border-radius: 15rpx 15rpx 0 0;
  78. background: rgba($color: #000000, $alpha: 0.4);
  79. text-align: center;
  80. line-height: 250rpx;
  81. left: 0;
  82. top: 0;
  83. color: #eee;
  84. font-size: 30upx;
  85. font-weight: bold;
  86. }
  87. }
  88. .name{
  89. padding: 10upx 20upx 0;
  90. font-weight: bold;
  91. }
  92. .price{
  93. display: flex;
  94. align-items: center;
  95. justify-content: space-between;
  96. padding: 15upx 20upx;
  97. text{
  98. color: #d42a26;
  99. font-size: 36upx;
  100. margin-right: 6upx;
  101. font-weight: bold;
  102. }
  103. >view{
  104. &:first-child{
  105. font-size: 22upx;
  106. display: flex;
  107. align-items: center;
  108. }
  109. &:last-child{
  110. &:active{
  111. opacity: 0.5;
  112. }
  113. }
  114. }
  115. }
  116. }
  117. }
  118. </style>