seckill.vue 6.3 KB

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