uni-coods.vue 3.7 KB

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