uni-coods.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.sellGold}}</text>
  12. <u-image mode="scaleToFill" width="40rpx" height="40rpx" src="/static/ledou.png"></u-image>
  13. </view>
  14. <view @click.stop="addCart" v-if="item.status == 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. watch: {
  45. list(newValue, oldValue) {
  46. console.log(newValue,'------------')
  47. }
  48. },
  49. methods: {
  50. // 加入购物车
  51. addCart(e) {
  52. // 请求接口
  53. this.$store.state.vuex_cartNums = Number(this.$store.state.vuex_cartNums) + 1
  54. },
  55. // 商品详情
  56. toDetail(item){
  57. uni.navigateTo({
  58. url:"/pages/goods/goodsDetail?id="+item.id
  59. })
  60. }
  61. },
  62. }
  63. </script>
  64. <style lang="scss" scoped>
  65. .goods-list{
  66. display: flex;
  67. flex-wrap: wrap;
  68. justify-content: space-between;
  69. padding-top: 20upx;
  70. .goods-item{
  71. background: #FFFFFF;
  72. width: 48%;
  73. margin-bottom: 5upx;
  74. .goods-imgs{
  75. position: relative;
  76. border-radius: 28upx 28upx 0 0;
  77. overflow: hidden;
  78. .goods-staus{
  79. width: 100%;
  80. height: 100%;
  81. position: absolute;
  82. z-index: 100;
  83. border-radius: 15rpx 15rpx 0 0;
  84. background: rgba($color: #000000, $alpha: 0.4);
  85. text-align: center;
  86. line-height: 250rpx;
  87. left: 0;
  88. top: 0;
  89. color: #eee;
  90. font-size: 30upx;
  91. font-weight: bold;
  92. }
  93. }
  94. .name{
  95. padding: 10upx 20upx 0;
  96. font-weight: bold;
  97. }
  98. .price{
  99. display: flex;
  100. align-items: center;
  101. justify-content: space-between;
  102. padding: 15upx 20upx;
  103. text{
  104. color: #d42a26;
  105. font-size: 36upx;
  106. margin-right: 6upx;
  107. font-weight: bold;
  108. }
  109. >view{
  110. &:first-child{
  111. font-size: 22upx;
  112. display: flex;
  113. align-items: center;
  114. }
  115. &:last-child{
  116. &:active{
  117. opacity: 0.5;
  118. }
  119. }
  120. }
  121. }
  122. }
  123. }
  124. </style>