seckill.vue 9.6 KB

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