uni-coods.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. if(row){
  61. let good = row.shoppingCartGoodsList.find(item => item.goodsNo == data.goodsNo)
  62. return !good ? true : good.buyQty < data.inventoryQty
  63. }else{
  64. return true
  65. }
  66. },
  67. // 加入购物车
  68. addCart(item) {
  69. console.log('addCart0')
  70. if(this.hasZgKucun(item)){
  71. this.$bindClick(function(){
  72. console.log('addCart1')
  73. uni.$emit("addCart",{goodsNo:item.goodsNo,buyQty:1})
  74. })
  75. }else{
  76. uni.showToast({
  77. icon: 'none',
  78. title: '此商品库存不足'
  79. })
  80. }
  81. },
  82. // 商品详情
  83. toDetail(item){
  84. uni.navigateTo({
  85. url:"/pages/goods/goodsDetail?id="+item.id + "&goldLimit="+this.goldLimit
  86. })
  87. }
  88. },
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. .goods-list{
  93. display: flex;
  94. flex-wrap: wrap;
  95. justify-content: space-between;
  96. padding-top: 20upx;
  97. .goods-item{
  98. background: #FFFFFF;
  99. width: 48%;
  100. margin-bottom: 5upx;
  101. .goods-imgs{
  102. position: relative;
  103. border-radius: 28upx 28upx 0 0;
  104. overflow: hidden;
  105. .goods-staus{
  106. width: 100%;
  107. height: 100%;
  108. position: absolute;
  109. z-index: 100;
  110. border-radius: 15rpx 15rpx 0 0;
  111. background: rgba($color: #000000, $alpha: 0.4);
  112. text-align: center;
  113. line-height: 250rpx;
  114. left: 0;
  115. top: 0;
  116. color: #eee;
  117. font-size: 30upx;
  118. font-weight: bold;
  119. }
  120. }
  121. .name{
  122. padding: 10upx 0;
  123. font-weight: bold;
  124. font-size: 30rpx;
  125. }
  126. .price{
  127. display: flex;
  128. align-items: center;
  129. justify-content: space-between;
  130. padding: 15upx 0;
  131. text{
  132. color: #d42a26;
  133. font-size: 36upx;
  134. margin-right: 6upx;
  135. font-weight: bold;
  136. }
  137. >view{
  138. &:first-child{
  139. font-size: 22upx;
  140. display: flex;
  141. align-items: center;
  142. }
  143. &:last-child{
  144. &:active{
  145. opacity: 0.5;
  146. }
  147. }
  148. }
  149. }
  150. }
  151. }
  152. </style>