hotsale.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="container">
  3. <view class="hotsale-box" v-for="(hotitem,hotindex) in hotlist" :key="hotindex" @click="navToDetailPage(hotitem)">
  4. <view class="img">
  5. <image :src="hotitem.image"></image>
  6. </view>
  7. <view class="hostsale-info">
  8. <view class="name">{{hotitem.store_name}}</view>
  9. <view class="price-box ">
  10. <text class="price">¥{{hotitem.price}}</text>
  11. <!-- <text class="ot_price">¥{{hotitem.ot_price}}</text> -->
  12. <!-- <text class="seckill">秒杀</text> -->
  13. </view>
  14. <text class="number">库存:{{hotitem.stock}}</text>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import { groomList,productDetail } from '@/api/product.js'
  21. export default {
  22. onShow: function() {
  23. this.loadData();
  24. },
  25. data() {
  26. return{
  27. //热销产品
  28. hotlist:[],
  29. goodstype:1,
  30. }
  31. },
  32. methods: {
  33. // 获取首页数据
  34. async loadData() {
  35. let obj = this;
  36. //获取精品推荐放在热销商品
  37. groomList({},obj.goodstype)
  38. .then(({data}) => {
  39. console.log(data,999);
  40. //this.hotlist = data.list;
  41. let hotlists = data.list;
  42. for(let i = 0 ;i<10;i++){
  43. let goodsid = data.list[i].id;
  44. //console.log(goodsid,'goodsid')
  45. productDetail({}, goodsid)
  46. .then(({data}) => {
  47. //console.log(data,goodsid)
  48. obj.specList = data.productAttr;//保存产品属性
  49. obj.specSelected = []; //初始化默认选择对象
  50. obj.productValue = data.productValue;
  51. for (let i = 0; i < obj.specList.length; i++) {
  52. // 设置默认数据
  53. let attrValue = obj.specList[i].attr_value[0];
  54. attrValue.check = true;
  55. obj.specSelected.push(attrValue.attr);
  56. //console.log(obj.specSelected,'obj.specSelected')
  57. }
  58. let str = obj.specSelected.join(',');
  59. //console.log(str,'str')
  60. let actionPrice = obj.productValue[str].price;
  61. //console.log(actionPrice,'actionPrice')
  62. hotlists[i].origin_price = hotlists[i].price;
  63. hotlists[i].price = actionPrice;
  64. });
  65. }
  66. setTimeout(function(){ obj.hotlist = hotlists; obj.showCard = true; }, 1000);
  67. })
  68. .catch(e => {
  69. console.log(e)
  70. });
  71. },
  72. //商品推荐详情页
  73. navToDetailPage(item) {
  74. let id = item.id;
  75. //let type = 2;
  76. uni.navigateTo({
  77. url: '/pages/product/product?id=' + id
  78. });
  79. },
  80. }
  81. }
  82. </script>
  83. <style lang="scss">
  84. .container{
  85. line-height: 1;
  86. padding: 10rpx 25rpx;
  87. display: flex;
  88. flex-wrap: wrap;
  89. justify-content: space-between;
  90. .hotsale-box{
  91. width: 48.5%;
  92. background-color: #fff;
  93. border-radius: 10rpx;
  94. margin-top: 20rpx;
  95. .img{
  96. height: 340rpx;
  97. display: flex;
  98. justify-content: center;
  99. align-items: center;
  100. image{
  101. width: 270rpx;
  102. height: 270rpx;
  103. }
  104. }
  105. .hostsale-info{
  106. padding:20rpx 20rpx 30rpx 20rpx;
  107. .name{
  108. font-size: 26rpx;
  109. font-weight: bold;
  110. }
  111. .price-box{
  112. line-height: 1;
  113. .price{
  114. color: #FC4141;
  115. font-size: 24rpx;
  116. font-weight: bold;
  117. margin-right: 15rpx;
  118. }
  119. .ot_price{
  120. font-size:22rpx;
  121. font-weight:500;
  122. text-decoration:line-through;
  123. color:#aaaaaa;
  124. }
  125. .seckill{
  126. border: 2rpx solid #FC5B62;
  127. color: #FC5B62;
  128. text-align: center;
  129. font-size: 20rpx;
  130. margin-left: 6rpx;
  131. }
  132. }
  133. .number{
  134. font-size:26rpx;
  135. font-weight:500;
  136. color:#333333;
  137. }
  138. }
  139. }
  140. }
  141. </style>