seckill.vue 5.8 KB

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