seckill.vue 6.4 KB

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