home-seckill.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="home-seckill bg-white">
  3. <view class="seckill-hd flex row-between">
  4. <view class="white xxl bold">超值秒杀</view>
  5. <view>
  6. <view class="white" v-show="currentStatus == 0">未开始</view>
  7. <view class="white" v-show="currentStatus == 2">已结束</view>
  8. <view class="white xs flex" v-if="currentTime > 0" v-show="currentStatus==1">
  9. <view class="m-r-10">距本场结束</view>
  10. <u-count-down :timestamp="currentTime" @end="refresh" :color="colorConfig.primary"
  11. bg-color="#fff" separator-color="#fff" font-size="24"
  12. height="36" separator-size="26"></u-count-down>
  13. </view>
  14. </view>
  15. </view>
  16. <scroll-view style="height: 120rpx; white-space: nowrap;" :scroll-into-view="'item-' + (active - 2)"
  17. scroll-x="true" scroll-with-animation="true">
  18. <view v-for="(item, index) in list" :key="index" :id="'item-' + index"
  19. class="time-item flex-col row-center col-center" :class="{active: index == active}"
  20. @tap="exchangeTime(index)">
  21. <view :class="'xl bold time'">{{ item.start_time }}</view>
  22. <view :class="'sm br60 state ' + ( item.status === 2 ? 'muted': '' )">
  23. {{ item.tips }}
  24. </view>
  25. </view>
  26. </scroll-view>
  27. <view v-if="goodsList.length" class="goods-seckill">
  28. <router-link v-for="(item, index) in goodsList" :key="index"
  29. :to="{path: '/pages/goods_details/goods_details', query: {id: item.goods_id || item.id}}">
  30. <view class="item bg-white flex">
  31. <view class="goods-img">
  32. <u-image width="214rpx" height="214rpx" :border-radius="10" :src="item.goods_image"></u-image>
  33. </view>
  34. <view class="goods-info m-l-20 flex-1">
  35. <view class="goods-name line-2">{{item.goods_name}}</view>
  36. <view class="price m-t-20 flex row-between">
  37. <view class="muted xxs">原价<price-format :first-size="22" :second-size="22"
  38. :subscript-size="22" :price="item.goods_min_price"></price-format>
  39. </view>
  40. <view class="muted xxs">{{item.seckill_total}}人购买</view>
  41. </view>
  42. <view class="btn flex row-between m-t-20">
  43. <price-format :color="colorConfig.primary" class="mr10" :first-size="38" :second-size="26"
  44. :subscript-size="26" :price="item.seckill_price" :weight="500"></price-format>
  45. <button :class="'br60 white ' + (currentStatus == 2? ' bg-gray' : currentStatus == 1
  46. ? 'bg-primary' : 'border-btn' )" size="xs">
  47. {{currentStatus == 2? '已结束': currentStatus == 1 ? '立即抢购' : '未开始'}}</button>
  48. </view>
  49. </view>
  50. </view>
  51. </router-link>
  52. </view>
  53. <router-link :to="'/bundle/pages/goods_seckill/goods_seckill'">
  54. <view class="xs flex row-center more">查看更多 <u-icon name="arrow-right"></u-icon>
  55. </view>
  56. </router-link>
  57. </view>
  58. </template>
  59. <script>
  60. export default {
  61. name: "home-seckill",
  62. props: {
  63. list: {
  64. type: Array,
  65. default: () => ([])
  66. }
  67. },
  68. data() {
  69. return {
  70. active: -1,
  71. goodsList: []
  72. };
  73. },
  74. methods: {
  75. exchangeTime(index) {
  76. this.active = index
  77. this.goodsList = this.list[index].goods
  78. },
  79. refresh() {
  80. uni.$emit('refreshhome')
  81. }
  82. },
  83. watch: {
  84. list: {
  85. handler(val) {
  86. // 抢购中
  87. let index = val.findIndex(item => item.status == 1);
  88. if (index == -1) {
  89. // 未开始
  90. index = val.findIndex(item => item.status == 0);
  91. }
  92. if (index == -1) {
  93. // 全部结束选中最后一个
  94. index = val.length - 1
  95. }
  96. this.active = index
  97. this.goodsList = val[index].goods
  98. },
  99. immediate: true,
  100. }
  101. },
  102. computed: {
  103. currentStatus() {
  104. const {
  105. active,
  106. list
  107. } = this
  108. return list[active] && list[active].status
  109. },
  110. currentTime() {
  111. const {
  112. active,
  113. list
  114. } = this
  115. if(list[active]) {
  116. return list[active].end_time_int - Date.now()/1000
  117. }
  118. return 0
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss">
  124. .home-seckill {
  125. border-radius: 14rpx;
  126. overflow: hidden;
  127. .seckill-hd {
  128. padding: 0 20rpx;
  129. height: 100rpx;
  130. background: url(../../static/images/index_bg_seckill.png) no-repeat;
  131. background-size: 100%;
  132. }
  133. .time-item {
  134. display: inline-flex;
  135. width: 160rpx;
  136. height: 100%;
  137. &.active {
  138. .time {
  139. color: $-color-primary;
  140. }
  141. .state {
  142. color: $-color-white;
  143. background-color: $-color-primary;
  144. }
  145. }
  146. .state {
  147. padding: 0 10rpx;
  148. }
  149. }
  150. .goods-seckill .item {
  151. padding: 20rpx;
  152. .border-btn {
  153. border: 1px solid $-color-primary;
  154. color: $-color-primary;
  155. }
  156. }
  157. .more {
  158. height: 80rpx;
  159. border-top: $-solid-border;
  160. }
  161. }
  162. </style>