seckill.vue 7.4 KB

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