seckill.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <view class="seckill-section m-t" v-if="show">
  3. <view class="s-header">
  4. <view class="f-left-icon"></view>
  5. <view class="tit-box"><text class="tit">限时秒杀</text></view>
  6. <view class="tip-box">
  7. <text class="tip" v-if="status == 1">{{ showTime }}点场结束</text>
  8. <text class="tip" v-if="status == 2">距离下场开始</text>
  9. <text class="tip" v-if="status == 0">当天活动已结束</text>
  10. <uni-countdown v-if="status == 1 || status == 2" :show-day="false" :hour="stopTimeH" :minute="stopTimeM" :second="stopTimeS"></uni-countdown>
  11. </view>
  12. <view class="textNav iconfont iconenter" @click="navTo('/pages/product/seckill')">更多</view>
  13. </view>
  14. <scroll-view class="floor-list" scroll-x>
  15. <view class="scoll-wrapper position-relative" @click="navTo('/pages/product/seckill')">
  16. <view v-for="(item, index) in list" :key="index" class="floor-item">
  17. <image class="list-image" :src="item.image" mode="aspectFill"></image>
  18. <text class="title clamp">{{ item.title }}</text>
  19. <text class="price">¥{{ item.price }}</text>
  20. </view>
  21. <view v-if="list.length == 0" class="floor-item ">
  22. <image class="list-image" mode="aspectFill"></image>
  23. <text class="title clamp"></text>
  24. <text class="price"></text>
  25. </view>
  26. <view v-if="list.length == 0" class="noGoodsBg"><view>敬请期待</view></view>
  27. </view>
  28. </scroll-view>
  29. </view>
  30. </template>
  31. <script>
  32. import uniCountdown from '@/components/uni-countdown/uni-countdown.vue';
  33. import { timeComputed } from '@/utils/rocessor.js';
  34. export default {
  35. components: {
  36. uniCountdown
  37. },
  38. data() {
  39. return {
  40. list: [],
  41. page: 1,
  42. limit: 10,
  43. showTime: '', //显示的时间
  44. showTImeId: '', //显示时间id用于查询数据
  45. stopTimeH: 0,
  46. stopTimeM: 0,
  47. stopTimeS: 0,
  48. // 判断是否所有活动已经结束
  49. stop: false, //活动是否已经结束
  50. show: false, //是否显示活动
  51. status: 0 //获取状态值1为有活动开始中 2为活动未开始 0为活动已经结束
  52. };
  53. },
  54. created: function(e) {
  55. // 载入分类
  56. this.getClass();
  57. },
  58. methods: {
  59. navTo(url) {
  60. uni.navigateTo({
  61. url
  62. });
  63. },
  64. getList() {
  65. getSeckillList(
  66. {
  67. page: this.page,
  68. limit: this.limit
  69. },
  70. this.showTImeId
  71. )
  72. .then(e => {
  73. this.list = e.data;
  74. })
  75. .catch(e => {
  76. console.log(e);
  77. });
  78. },
  79. getClass() {
  80. let obj = this;
  81. getSeckillClass({})
  82. .then(({ data }) => {
  83. let arr = data.seckillTime;
  84. // 用于判断是否有数据
  85. let showDate = false;
  86. for (var i = 0; i < arr.length; i++) {
  87. let ar = arr[i];
  88. if (ar.status === 1 || ar.status === 2) {
  89. obj.status = ar.status;
  90. // 保存要显示的场次时间
  91. obj.showTime = ar.time;
  92. // 保存要显示活动商品的id
  93. obj.showTImeId = ar.id;
  94. // 保存当前状态值
  95. // 计算倒计时时间
  96. if (ar.status === 1) {
  97. obj.timeComputed(ar.stop * 1000);
  98. } else {
  99. // 获取需要开始
  100. let arTime = ar.time.split(':');
  101. let h = arTime[0];
  102. let m = arTime[1];
  103. let time = new Date();
  104. // 设置时间
  105. time.setHours(h, m, 0);
  106. obj.timeComputed(time.getTime());
  107. }
  108. // 获取商品列表
  109. obj.getList();
  110. // 保存当前有活动在举行
  111. showDate = true;
  112. // 任务查询结束跳出循环
  113. break;
  114. }
  115. }
  116. // 判断是否有活动
  117. if (arr.length > 0) {
  118. obj.show = true;
  119. }
  120. // 判断今天活动是否已经全部结束
  121. if (!showDate) {
  122. // 保存活动结束最后一个小时的活动商品
  123. obj.showTImeId = arr[arr.length - 1].id;
  124. // 活动已经结束
  125. obj.status = 0;
  126. // 获取结束时的商品
  127. obj.getList();
  128. console.log(obj.status);
  129. }
  130. // 如果所有场次均已经结束
  131. })
  132. .catch(e => {
  133. uni.showModal({
  134. title: JSON.stringify(e)
  135. });
  136. });
  137. },
  138. // 计算倒计时时间
  139. timeComputed(da) {
  140. let obj = this;
  141. let stopTime = timeComputed(da);
  142. obj.stopTimeH = stopTime.hours;
  143. obj.stopTimeM = stopTime.minutes;
  144. obj.stopTimeS = stopTime.seconds;
  145. }
  146. }
  147. };
  148. </script>
  149. <style lang="scss">
  150. /* 秒杀专区 */
  151. .seckill-section {
  152. padding: 4rpx 30rpx 24rpx;
  153. .s-header {
  154. display: flex;
  155. align-items: center;
  156. height: 92rpx;
  157. line-height: 1;
  158. .tit-box {
  159. flex-shrink: 0;
  160. }
  161. .tit {
  162. @extend %font-title;
  163. }
  164. .f-left-icon {
  165. @extend %f-left-icon;
  166. }
  167. .textNav {
  168. line-height: 1;
  169. padding: 15rpx 0;
  170. flex-shrink: 0;
  171. flex-grow: 1;
  172. min-width: 100rpx;
  173. }
  174. .tip-box {
  175. flex-grow: 1;
  176. display: flex;
  177. justify-content: flex-start;
  178. align-items: center;
  179. }
  180. .tip {
  181. font-size: $font-sm;
  182. color: $font-color-light;
  183. padding-left: 10rpx;
  184. padding-right: 10rpx;
  185. }
  186. .timer {
  187. display: inline-block;
  188. width: 40rpx;
  189. height: 36rpx;
  190. text-align: center;
  191. line-height: 36rpx;
  192. margin-right: 14rpx;
  193. font-size: $font-sm + 2rpx;
  194. color: #fff;
  195. border-radius: 2px;
  196. background: rgba(0, 0, 0, 0.8);
  197. }
  198. .iconenter {
  199. font-size: $font-sm;
  200. color: $font-color-light;
  201. flex: 1;
  202. text-align: right;
  203. }
  204. }
  205. .floor-list {
  206. white-space: nowrap;
  207. background-color: white;
  208. padding: 20rpx;
  209. border-radius: 5rpx;
  210. box-shadow: $box-shadow;
  211. }
  212. .scoll-wrapper {
  213. display: flex;
  214. align-items: flex-start;
  215. .noGoodsBg {
  216. display: flex;
  217. align-items: center;
  218. justify-content: center;
  219. height: 100%;
  220. position: absolute;
  221. top: 0;
  222. left: 0;
  223. width: 100%;
  224. color: $font-color-light;
  225. }
  226. .floor-item {
  227. width: 150rpx;
  228. margin-right: 20rpx;
  229. font-size: $font-sm + 2rpx;
  230. color: $font-color-dark;
  231. line-height: 1.8;
  232. .list-image {
  233. width: 150rpx;
  234. height: 150rpx;
  235. border-radius: 6rpx;
  236. }
  237. .price {
  238. color: $color-red;
  239. }
  240. }
  241. }
  242. }
  243. </style>