uni-coods.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="goods-list">
  3. <view class="goods-item" v-for="item in list" :key="item.id">
  4. <view class="goods-imgs" @click="toDetail(item)">
  5. <view v-if="item.inventoryQty == 0&&item.state == 1" class="goods-staus">已售罄</view>
  6. <view v-if="item.state == 0" class="goods-staus">已下架</view>
  7. <u-lazy-load
  8. img-mode="scaleToFill"
  9. :height="imgHeight"
  10. :image="item.homeImage+'?x-oss-process=image/resize,m_pad,h_252,w_325,color_ffffff'"
  11. :loading-img="loadingImg"
  12. :error-img="errorImg">
  13. </u-lazy-load>
  14. </view>
  15. <view class="name ellipsis-two" @click="toDetail(item)">{{item.name}}</view>
  16. <view class="price">
  17. <view>
  18. <text>{{item.sellGold}}</text>
  19. <u-image mode="scaleToFill" width="40rpx" height="40rpx" src="/static/ledou.png"></u-image>
  20. </view>
  21. <view @click="addCart(item)" v-if="item.inventoryQty > 0">
  22. <u-image mode="scaleToFill" width="45rpx" height="45rpx" src="/static/addCart.png"></u-image>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. props: {
  31. imgHeight: {
  32. type: Number,
  33. default: 250
  34. },
  35. goldLimit: {
  36. type: [Number,String],
  37. default: 0
  38. },
  39. list:{
  40. type: Array,
  41. default: function(){
  42. return []
  43. }
  44. }
  45. },
  46. data() {
  47. return {
  48. loadingImg: '/static/loading.gif',
  49. errorImg: '/static/imgError.png',
  50. timer: null,
  51. finger: {x:0,y:0},
  52. linePos: null,
  53. }
  54. },
  55. methods: {
  56. // 判断当前商品库存是否够
  57. hasZgKucun(data){
  58. let list = this.$store.state.vuex_cartList
  59. let row = list.find(item=> item.goodsTypeNo == data.goodsTypeNo)
  60. let good = row.shoppingCartGoodsList.find(item => item.goodsNo == data.goodsNo)
  61. console.log(good,data.inventoryQty)
  62. return !good ? true : good.buyQty < data.inventoryQty
  63. },
  64. // 加入购物车
  65. addCart(item) {
  66. console.log(item)
  67. if(this.hasZgKucun(item)){
  68. this.$bindClick(function(){
  69. uni.$emit("addCart",{goodsNo:item.goodsNo,buyQty:1})
  70. })
  71. }else{
  72. uni.showToast({
  73. icon: 'none',
  74. title: '此商品库存不足'
  75. })
  76. }
  77. },
  78. // 商品详情
  79. toDetail(item){
  80. uni.navigateTo({
  81. url:"/pages/goods/goodsDetail?id="+item.id + "&goldLimit="+this.goldLimit
  82. })
  83. }
  84. },
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. .goods-list{
  89. display: flex;
  90. flex-wrap: wrap;
  91. justify-content: space-between;
  92. padding-top: 20upx;
  93. .goods-item{
  94. background: #FFFFFF;
  95. width: 48%;
  96. margin-bottom: 5upx;
  97. .goods-imgs{
  98. position: relative;
  99. border-radius: 28upx 28upx 0 0;
  100. overflow: hidden;
  101. .goods-staus{
  102. width: 100%;
  103. height: 100%;
  104. position: absolute;
  105. z-index: 100;
  106. border-radius: 15rpx 15rpx 0 0;
  107. background: rgba($color: #000000, $alpha: 0.4);
  108. text-align: center;
  109. line-height: 250rpx;
  110. left: 0;
  111. top: 0;
  112. color: #eee;
  113. font-size: 30upx;
  114. font-weight: bold;
  115. }
  116. }
  117. .name{
  118. padding: 10upx 0;
  119. font-weight: bold;
  120. font-size: 30rpx;
  121. }
  122. .price{
  123. display: flex;
  124. align-items: center;
  125. justify-content: space-between;
  126. padding: 15upx 0;
  127. text{
  128. color: #d42a26;
  129. font-size: 36upx;
  130. margin-right: 6upx;
  131. font-weight: bold;
  132. }
  133. >view{
  134. &:first-child{
  135. font-size: 22upx;
  136. display: flex;
  137. align-items: center;
  138. }
  139. &:last-child{
  140. &:active{
  141. opacity: 0.5;
  142. }
  143. }
  144. }
  145. }
  146. }
  147. }
  148. </style>