seckill.vue 6.9 KB

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