seckill.vue 9.5 KB

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