seckill.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="seckill-view">
  3. <view class="container">
  4. <view class="header">
  5. <view class="left">
  6. <view class="title">
  7. {{ title }}
  8. </view>
  9. <view class="time">{{hour<10?('0'+hour):hour}}</view>
  10. <view class="separator">:</view>
  11. <view class="time">{{minute<10?('0'+minute):minute}}</view>
  12. <view class="separator">:</view>
  13. <view class="time">{{second<10?('0'+second):second}}</view>
  14. </view>
  15. <view class="right" @click="naviageToPage('/pages/product/seckill')">
  16. <view>更多</view>
  17. <i class="el-icon-arrow-right" />
  18. </view>
  19. </view>
  20. <view class="content">
  21. <view v-if="showList.length>0" class="flex flex-wrap justify-between" style="width: 100%;height:100%">
  22. <view v-for="(item,index) in showList" :key="item.id"
  23. class="margin-bottom-sm bg-white flex align-center justify-center flex-direction"
  24. style="width: 45%;height: 520rpx;padding: 10rpx;margin-right: 18rpx;border-radius: 8rpx;"
  25. @click="navToDetailPage(item.productId)">
  26. <image style="width: 280rpx;height: 280rpx;margin: 10rpx;" :src="JSON.parse(item.image)[0].url"
  27. mode="aspectFit"></image>
  28. <view style="padding-top: 28rpx;">
  29. <view class="text-cut"
  30. style="width: 294rpx;height: 40rpx;font-size: 28rpx;font-weight: Medium; color: #2D4454;">{{item.title}}
  31. </view>
  32. <view class="text-cut margin-tb-xs" style="width: 294rpx;height: 40rpx;font-size: 28rpx;color: #999999;">
  33. {{item.info}}
  34. </view>
  35. <view style="padding-top: 6rpx;" class="flex align-center justify-between">
  36. <view style="width: 114rpx;height: 42rpx;line-height: 42rpx;font-size: 24rpx;color:#F62929;">
  37. ¥{{item.price}}</view>
  38. <view style="color: #B0B0B0;font-size: 24rpx;">{{item.unitName}}/份</view>
  39. <!-- <image @click.stop="addCart(item)" style="width: 48rpx;height: 48rpx;"-->
  40. <!-- src="../../../static/index/cart.png" mode="aspectFit" class="round"></image>-->
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <template v-else>
  46. <img src="../../../static/index/no_homebase.png">
  47. <view class="text">敬请期待,更多秒杀好货~</view>
  48. </template>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import dayjs from 'dayjs'
  55. import {
  56. getRestTime,
  57. getTime
  58. } from '../../../util/index.js'
  59. export default {
  60. name: 'Seckill',
  61. props: ['options'],
  62. data() {
  63. return {
  64. list: [],
  65. showList: [],
  66. hour: 0,
  67. minute: 0,
  68. second: 0
  69. }
  70. },
  71. mounted() {
  72. this.listCurrent()
  73. },
  74. computed: {
  75. title() {
  76. return this.options.title
  77. },
  78. count() {
  79. return this.options.count
  80. }
  81. },
  82. methods: {
  83. listCurrent() {
  84. this.$api.request('get', 'seckill/app/listCurrent', {
  85. storageId: this.$store.state.storageId,
  86. sort: 1
  87. }).then(({
  88. data = []
  89. }) => {
  90. this.list = data
  91. this.getShowList()
  92. })
  93. },
  94. naviageToPage(url, title) {
  95. this.$emit('naviage-to-page', url, title)
  96. },
  97. navToDetailPage(id) {
  98. this.$emit('nav-to-detail-page', id)
  99. },
  100. addCart(item) {
  101. this.$emit('add-cart', item)
  102. },
  103. getShowList() {
  104. this.showList = this.list.filter(({
  105. seckillStartTime,
  106. seckillStopTime
  107. }) => {
  108. const startTime = getTime(seckillStartTime),
  109. endTime = getTime(seckillStopTime),
  110. now = dayjs()
  111. return startTime.isBefore(now) && endTime.isAfter(now)
  112. }).slice(0, this.count)
  113. this.getRestTime(this.showList[0]?.seckillStopTime)
  114. if (this.$_timer) {
  115. clearTimeout(this.$_timer)
  116. this.$_timer = null
  117. }
  118. if (this.showList.length > 0) {
  119. this.$_timer = setTimeout(() => {
  120. this.getShowList()
  121. }, 1000)
  122. }
  123. },
  124. getRestTime(time) {
  125. const restTime = getRestTime(time)
  126. this.hour = restTime[0]
  127. this.minute = restTime[1]
  128. this.second = restTime[2]
  129. }
  130. }
  131. }
  132. </script>
  133. <style scoped lang="scss">
  134. .seckill-view {
  135. padding: 24rpx
  136. }
  137. .container {
  138. background-color: #fff;
  139. border-radius: 16rpx;
  140. }
  141. .header {
  142. padding: 32rpx 20rpx 0;
  143. display: flex;
  144. justify-content: space-between;
  145. align-items: center;
  146. }
  147. .title {
  148. font-size: 36rpx;
  149. color: #333;
  150. font-weight: 700;
  151. margin-right: 20rpx;
  152. display: inline-block;
  153. }
  154. .time {
  155. width: 36rpx;
  156. height: 30rpx;
  157. line-height: 32rpx;
  158. text-align: center;
  159. font-size: 24rpx;
  160. color: #fff;
  161. background-color: #000;
  162. border-radius: 4rpx;
  163. display: inline-block;
  164. }
  165. .separator {
  166. padding: 0 8rpx;
  167. display: inline-block;
  168. }
  169. .right {
  170. font-size: 26rpx;
  171. color: #999;
  172. }
  173. .content {
  174. // height: 400rpx;
  175. padding-bottom: 50rpx;
  176. display: flex;
  177. flex-direction: column;
  178. justify-content: center;
  179. align-items: center;
  180. .text {
  181. margin-top: 32rpx;
  182. font-size: 28rpx;
  183. color: #999;
  184. }
  185. }
  186. img {
  187. width: 240rpx;
  188. height: 240rpx;
  189. }
  190. </style>