index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <div>
  3. <view class='flash-sale'>
  4. <!-- #ifdef H5 -->
  5. <view class='iconfont icon-xiangzuo' @tap='goBack' :style="'top:'+ (navH/2) +'rpx'" v-if="returnShow"></view>
  6. <!-- #endif -->
  7. <view class="saleBox"></view>
  8. <!-- 当前秒杀时间段的轮播图 -->
  9. <view class="header" v-if="dataList.length">
  10. <swiper indicator-dots="true" autoplay="true" :circular="circular" interval="3000" duration="1500"
  11. indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff">
  12. <block v-for="(items, index) in dataList[active].sliderPicUrls" :key="index">
  13. <swiper-item class="borRadius14">
  14. <image :src="items" class="slide-image borRadius14" lazy-load />
  15. </swiper-item>
  16. </block>
  17. </swiper>
  18. </view>
  19. <!-- 秒杀时间段 -->
  20. <view class="seckillList acea-row row-between-wrapper">
  21. <view class="priceTag">
  22. <image src="/static/images/priceTag.png"></image>
  23. </view>
  24. <view class='timeLsit'>
  25. <scroll-view class="scroll-view_x" scroll-x scroll-with-animation :scroll-left="scrollLeft"
  26. style="width:auto;overflow:hidden;">
  27. <block v-for="(item,index) in dataList" :key='index'>
  28. <view @tap='settimeList(item,index)' class='item' :class="active === index?'on':''">
  29. <view class='time'>{{ item.startTime }}</view>
  30. <view class="state" v-if="item.status === 1">即将开始</view>
  31. <view class="state" v-if="item.status === 2">进行中</view>
  32. <view class="state" v-if="item.status === 3">已结束</view>
  33. </view>
  34. </block>
  35. </scroll-view>
  36. </view>
  37. </view>
  38. <!-- 秒杀活动 -->
  39. <view class='list pad30' v-if='seckillList.length>0'>
  40. <block v-for="(item,index) in seckillList" :key='index'>
  41. <view class='item acea-row row-between-wrapper' @tap='goDetails(item)'>
  42. <view class='pictrue'>
  43. <image :src='item.picUrl' />
  44. </view>
  45. <view class='text acea-row row-column-around'>
  46. <view class='name line1'>{{item.name}}</view>
  47. <view class='money'><text class="font-color">¥</text>
  48. <text class='num font-color'>{{ fen2yuan(item.seckillPrice ) }}</text>
  49. <text class="y_money">¥{{ fen2yuan(item.marketPrice) }}</text>
  50. </view>
  51. <view class="limit">限量 <text class="limitPrice">{{ item.stock}} {{item.unitName}}</text>
  52. </view>
  53. <view class="progress">
  54. <view class='bg-reds' :style="'width:' + item.percent +'%;'"></view>
  55. <view class='piece'>已抢{{ item.percent }}%</view>
  56. </view>
  57. </view>
  58. <view class='grab bg-color' v-if="dataList[active].status === 2">马上抢</view>
  59. <view class='grab bg-color' v-else-if="dataList[active].status === 1">未开始</view>
  60. <view class='grab bg-color-hui' v-else>已结束</view>
  61. </view>
  62. </block>
  63. </view>
  64. </view>
  65. <view class='noCommodity' v-if="seckillList.length === 0 && (page !== 1 || active === 0)">
  66. <view class='pictrue'>
  67. <image src='../../../static/images/noShopper.png'></image>
  68. </view>
  69. </view>
  70. <home></home>
  71. </div>
  72. </template>
  73. <script>
  74. import home from '@/components/home/index.vue';
  75. import * as SeckillApi from '@/api/promotion/seckill.js';
  76. import * as Util from '@/utils/util.js';
  77. let app = getApp();
  78. export default {
  79. components: {
  80. home
  81. },
  82. data() {
  83. return {
  84. // ========== 秒杀时间段相关变量 ==========
  85. dataList: [], // 时间段数组
  86. active: 0, // 选中的 dataList 下标
  87. circular: true,
  88. autoplay: true,
  89. interval: 500,
  90. scrollLeft: 0,
  91. status: 1,
  92. // ========== 秒杀活动相关变量 ==========
  93. seckillList: [],
  94. loading: false,
  95. loadend: false,
  96. page: 1,
  97. limit: 4,
  98. pageloading: false,
  99. // ========== 导航相关变量 ==========
  100. returnShow: true,
  101. navH: ''
  102. }
  103. },
  104. onLoad() {
  105. const pages = getCurrentPages();
  106. this.returnShow = pages.length !== 1;
  107. // #ifdef H5
  108. this.navH = app.globalData.navHeight-18;
  109. // #endif
  110. this.getSeckillConfig();
  111. },
  112. methods: {
  113. /**
  114. * 获得时间段
  115. */
  116. getSeckillConfig: function() {
  117. SeckillApi.getSeckillConfigList().then(res => {
  118. this.dataList = res.data;
  119. this.dataList.forEach(config => {
  120. const startTimeInt = parseInt(config.startTime.split(':')[0]) * 60 + parseInt(config.startTime.split(':')[1]);
  121. const endTimeInt = parseInt(config.endTime.split(':')[0]) * 60 + parseInt(config.endTime.split(':')[1]);
  122. const nowInt = new Date().getHours() * 60 + new Date().getMinutes();
  123. if (nowInt < startTimeInt) {
  124. config.status = 1;
  125. } else if (nowInt > endTimeInt) {
  126. config.status = 3;
  127. } else {
  128. config.status = 2;
  129. }
  130. })
  131. // 加载秒杀活动
  132. this.getSeckillList();
  133. });
  134. },
  135. /**
  136. * 选择一个拼团时间段
  137. *
  138. * @param item 时间段
  139. * @param index 下标
  140. */
  141. settimeList: function(item, index) {
  142. this.active = index
  143. if (this.interval) {
  144. clearInterval(this.interval);
  145. this.interval = null
  146. }
  147. this.interval = 0;
  148. // 加载活动列表
  149. this.loadend = false;
  150. this.page = 1;
  151. this.seckillList = [];
  152. this.getSeckillList();
  153. },
  154. /**
  155. * 获得拼团活动列表
  156. */
  157. getSeckillList: function() {
  158. if (this.loadend || this.pageloading) {
  159. return;
  160. }
  161. SeckillApi.getSeckillActivityPage({
  162. id: this.dataList[this.active].id,
  163. pageNo: this.page,
  164. pageSize: this.limit
  165. }).then(res => {
  166. const seckillList = res.data.list;
  167. seckillList.forEach(item => {
  168. item.percent = parseInt(100 * (item.totalStock - item.stock) / item.totalStock);
  169. })
  170. this.page++;
  171. this.seckillList = this.seckillList.concat(seckillList);
  172. this.loadend = seckillList.length < this.limit;
  173. }).finally(() => {
  174. this.pageloading = false;
  175. })
  176. },
  177. goDetails(item) {
  178. uni.navigateTo({
  179. url: '/pages/activity/goods_seckill_details/index?id=' + item.id
  180. })
  181. },
  182. goBack: function() {
  183. uni.navigateBack();
  184. },
  185. fen2yuan(price) {
  186. return Util.fen2yuan(price)
  187. }
  188. },
  189. /**
  190. * 页面上拉触底事件的处理函数
  191. */
  192. onReachBottom: function() {
  193. this.getSeckillList();
  194. }
  195. }
  196. </script>
  197. <style>
  198. page {
  199. background-color: #F5F5F5 !important;
  200. }
  201. </style>
  202. <style scoped lang="scss">
  203. .icon-xiangzuo {
  204. font-size: 40rpx;
  205. color: #fff;
  206. position: fixed;
  207. left: 30rpx;
  208. z-index: 99;
  209. transform: translateY(-20%);
  210. }
  211. .flash-sale .header {
  212. width: 710rpx;
  213. height: 330rpx;
  214. margin: -276rpx auto 0 auto;
  215. border-radius: 14rpx;
  216. overflow: hidden;
  217. swiper{
  218. height: 330rpx !important;
  219. border-radius: 14rpx;
  220. overflow: hidden;
  221. }
  222. }
  223. .flash-sale .header image {
  224. width: 100%;
  225. height: 100%;
  226. border-radius: 14rpx;
  227. overflow: hidden;
  228. img{
  229. border-radius: 14rpx;
  230. }
  231. }
  232. .flash-sale .seckillList {
  233. padding: 25rpx;
  234. }
  235. .flash-sale .seckillList .priceTag {
  236. width: 75rpx;
  237. height: 70rpx;
  238. }
  239. .flash-sale .seckillList .priceTag image {
  240. width: 100%;
  241. height: 100%;
  242. }
  243. .flash-sale .timeLsit {
  244. width: 596rpx;
  245. white-space: nowrap;
  246. }
  247. .flash-sale .timeLsit .item {
  248. display: inline-block;
  249. font-size: 20rpx;
  250. color: #666;
  251. text-align: center;
  252. box-sizing: border-box;
  253. margin-right: 30rpx;
  254. width: 130rpx;
  255. }
  256. .flash-sale .timeLsit .item .time {
  257. font-size: 36rpx;
  258. font-weight: 600;
  259. color: #333;
  260. }
  261. .flash-sale .timeLsit .item.on .time {
  262. color: $theme-color;
  263. }
  264. .flash-sale .timeLsit .item.on .state {
  265. height: 30rpx;
  266. line-height: 30rpx;
  267. border-radius: 15rpx;
  268. width: 128rpx;
  269. /* padding: 0 12rpx; */
  270. background: linear-gradient(90deg, rgba(252, 25, 75, 1) 0%, rgba(252, 60, 32, 1) 100%);
  271. color: #fff;
  272. }
  273. .flash-sale .countDown {
  274. height: 92rpx;
  275. border-bottom: 1rpx solid #f0f0f0;
  276. margin-top: -14rpx;
  277. font-size: 28rpx;
  278. color: #282828;
  279. }
  280. .flash-sale .countDown .num {
  281. font-size: 28rpx;
  282. font-weight: bold;
  283. background-color: #ffcfcb;
  284. padding: 4rpx 7rpx;
  285. border-radius: 3rpx;
  286. }
  287. .flash-sale .countDown .text {
  288. font-size: 28rpx;
  289. color: #282828;
  290. margin-right: 13rpx;
  291. }
  292. .flash-sale .list .item {
  293. height: 230rpx;
  294. position: relative;
  295. /* width: 710rpx; */
  296. margin: 0 auto 20rpx auto;
  297. background-color: #fff;
  298. border-radius: 14rpx;
  299. padding: 25rpx 24rpx;
  300. }
  301. .flash-sale .list .item .pictrue {
  302. width: 180rpx;
  303. height: 180rpx;
  304. border-radius: 10rpx;
  305. background-color: #F5F5F5;
  306. }
  307. .flash-sale .list .item .pictrue image {
  308. width: 100%;
  309. height: 100%;
  310. border-radius: 10rpx;
  311. }
  312. .flash-sale .list .item .text {
  313. width: 440rpx;
  314. font-size: 30rpx;
  315. color: #333;
  316. height: 166rpx;
  317. }
  318. .flash-sale .list .item .text .name {
  319. width: 100%;
  320. }
  321. .flash-sale .list .item .text .money {
  322. font-size: 30rpx;
  323. color: $theme-color;
  324. }
  325. .flash-sale .list .item .text .money .num {
  326. font-size: 40rpx;
  327. font-weight: 500;
  328. font-family: 'Guildford Pro';
  329. }
  330. .flash-sale .list .item .text .money .y_money {
  331. font-size: 24rpx;
  332. color: #999;
  333. text-decoration-line: line-through;
  334. margin-left: 15rpx;
  335. }
  336. .flash-sale .list .item .text .limit {
  337. font-size: 22rpx;
  338. color: #999;
  339. margin-bottom: 5rpx;
  340. }
  341. .flash-sale .list .item .text .limit .limitPrice {
  342. margin-left: 10rpx;
  343. }
  344. .flash-sale .list .item .text .progress {
  345. overflow: hidden;
  346. background-color: #EEEEEE;
  347. width: 260rpx;
  348. border-radius: 18rpx;
  349. height: 18rpx;
  350. position: relative;
  351. }
  352. .flash-sale .list .item .text .progress .bg-reds {
  353. width: 0;
  354. height: 100%;
  355. transition: width 0.6s ease;
  356. background: linear-gradient(90deg, rgba(233, 51, 35, 1) 0%, rgba(255, 137, 51, 1) 100%);
  357. }
  358. .flash-sale .list .item .text .progress .piece {
  359. position: absolute;
  360. left: 8%;
  361. transform: translate(0%, -50%);
  362. top: 49%;
  363. font-size: 16rpx;
  364. color: #FFB9B9;
  365. }
  366. .flash-sale .list .item .grab {
  367. font-size: 28rpx;
  368. color: #fff;
  369. width: 150rpx;
  370. height: 54rpx;
  371. border-radius: 27rpx;
  372. text-align: center;
  373. line-height: 54rpx;
  374. position: absolute;
  375. right: 30rpx;
  376. bottom: 30rpx;
  377. background: #bbbbbb;
  378. }
  379. .flash-sale .saleBox {
  380. width: 100%;
  381. height: 298rpx;
  382. /* #ifdef MP */
  383. height: 300rpx;
  384. /* #endif */
  385. background: rgba(233, 51, 35, 1);
  386. border-radius: 0 0 50rpx 50rpx;
  387. }
  388. </style>