spikeList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <template>
  2. <view class="spikeListBox">
  3. <JHeader :dark="false" title="秒杀专区" width="50" height="50" style="padding: 24upx 0 0;"></JHeader>
  4. <view v-if="!queryInfo.shopSeckillId">
  5. <view class="spikeBg">
  6. 秒杀专区
  7. </view>
  8. <view class="tabs-nav-warp spikeNav">
  9. <scroll-view class="tabs-nav" scroll-x="true">
  10. <view class="ul">
  11. <view
  12. v-for="(item, index) in querySessionData" :key="index" class="li" :class="{ active: index === active }"
  13. @click="changeTit(index, item)"
  14. >
  15. <view class="timeItem">
  16. <view class="date" :class="{ endCls: currentTime > item.endTime }">{{ item.startTime }}</view>
  17. <view v-if="currentTime > item.timestamp" class="state fs24">抢购中</view>
  18. <view v-if="currentTime < item.timestamp" class="state">即将开始</view>
  19. <view v-if="currentTime > item.endTime" class="state">已结束</view>
  20. </view>
  21. </view>
  22. </view>
  23. </scroll-view>
  24. </view>
  25. </view>
  26. <view v-else class="shopStopTime">
  27. <view v-if="spikeLikeData.state === 1" class="TimeBigBox">
  28. <label>距离结束:</label>
  29. <view class="flex-row-plus fs34 flex-items-plus mar-top-10">
  30. <view class="countdown-box flex-items-plus">{{ hou }}</view>
  31. <view class="font-color-999">:</view>
  32. <view class="countdown-box flex-items-plus">{{ min }}</view>
  33. <view class="font-color-999">:</view>
  34. <view class="countdown-box flex-items-plus">{{ sec }}</view>
  35. </view>
  36. </view>
  37. <view v-else class="TimeBigBox">
  38. <label>距离开始:</label>
  39. <view class="flex-row-plus fs34 flex-items-plus mar-top-10">
  40. <view class="countdown-box flex-items-plus">{{ hou }}</view>
  41. <view class="font-color-999">:</view>
  42. <view class="countdown-box flex-items-plus">{{ min }}</view>
  43. <view class="font-color-999">:</view>
  44. <view class="countdown-box flex-items-plus">{{ sec }}</view>
  45. </view>
  46. </view>
  47. </view>
  48. <view class="spikeList mar-top-20">
  49. <view v-if="spikeLikeList && spikeLikeList.length">
  50. <view v-for="(item, index) in spikeLikeList" :key="index" class="listItem">
  51. <view class="itemBox">
  52. <img :src="common.seamingImgUrl(item.productImage) || common.seamingImgUrl(item.image)" class="pic-img default-img">
  53. </view>
  54. <view class="itemInfo">
  55. <p>{{ item.productName }}</p>
  56. <view v-if="queryInfo.shopId" class="number">限量件 {{ item.discount }} / 剩余{{ item.stockNumber }}件</view>
  57. <view v-else class="number">限量件 {{ item.discount }} / 剩余{{ item.stockNumber }}件</view>
  58. <view class="originalPrice">原价: ¥{{ item.originalPrice }}</view>
  59. <view class="price">
  60. <view class="currentPrice flex-items font-color-FF7800">
  61. <view class="iconBox flex-items">
  62. <image src="../../../static/images/new-business/shop/spikeIcon.png"></image>
  63. </view>
  64. <view class="flex-row-plus flex-items priceInfo">
  65. <label class="fs24">¥</label>
  66. <label class="fs36">{{ item.price }}</label>
  67. </view>
  68. </view>
  69. <view
  70. v-if="spikeLikeData.state === 1 || (platformSeckillList[platformIndex] && platformSeckillList[platformIndex].state === 3)"
  71. class="snapUpBtn" @click="gogoodsDetails(item.shopId, item.productId, item.skuId)"
  72. >
  73. <view class="btnText">去抢购</view>
  74. <view class="progressBox">
  75. <progress
  76. activeColor="#FFFFFF" :percent="getPercent(item.saleNumber || item.stockNumber, item.total)"
  77. active stroke-width="5"
  78. />
  79. </view>
  80. </view>
  81. <view
  82. v-if="spikeLikeData.state === 0 || (platformSeckillList[platformIndex] && platformSeckillList[platformIndex].state === 2)"
  83. class="snapUpBtn"
  84. :class="{ btnStyle1: spikeLikeData.state === 0 || (platformSeckillList[platformIndex] && platformSeckillList[platformIndex].state === 2) }"
  85. >
  86. <view class="btnText">即将开始</view>
  87. <view class="progressBox">
  88. <progress
  89. activeColor="#FFFFFF" :percent="getPercent(item.saleNumber || item.stockNumber, item.total)"
  90. active stroke-width="5"
  91. />
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. <view style="padding-bottom: 45upx;">
  99. <LoadingMore
  100. :status="!isEmpty && !spikeLikeList.length
  101. ? 'loading' : !isEmpty && spikeLikeList.length && (spikeLikeList.length >= spikeLikeTotal) ? 'no-more' : ''"
  102. >
  103. </LoadingMore>
  104. <tui-no-data v-if="isEmpty" :fixed="false" style="margin-top: 60upx;">暂无数据</tui-no-data>
  105. </view>
  106. </view>
  107. </view>
  108. </template>
  109. <script>
  110. import { getQueryProductListBySessionApi, getQueryPlatformSeckillListApi, getPlatformSeckillsCanvasApi, getPlatformSeckillsQuerySessionApi, getShopSeckillIndexApi } from '../../../api/anotherTFInterface'
  111. export default {
  112. name: 'SpikeList',
  113. data() {
  114. return {
  115. isEmpty: false,
  116. spikeLikeList: [],
  117. spikeLikeTotal: 0,
  118. queryInfo: {
  119. page: 1,
  120. pageSize: 20,
  121. shopId: 0,
  122. shopSeckillId: 0
  123. },
  124. spikeLikeData: {},
  125. hou: '00',
  126. min: '00',
  127. sec: '00',
  128. selectIndex: 0,
  129. size: 10,
  130. querySessionData: [],
  131. session: '',
  132. currentTime: '',
  133. active: 0,
  134. platformSeckillId: 0,
  135. platformSeckillList: [],
  136. ticker: null // 定时器
  137. }
  138. },
  139. onLoad(options) {
  140. this.currentTime = new Date().getTime()
  141. if (options.shopId && options.shopSeckillId) {
  142. this.queryInfo.shopId = options.shopId
  143. this.queryInfo.shopSeckillId = options.shopSeckillId
  144. } else {
  145. this.queryInfo.shopId = 0
  146. this.queryInfo.shopSeckillId = 0
  147. }
  148. },
  149. onShow() {
  150. this.queryInfo.page = 1,
  151. this.queryInfo.pageSize = 10,
  152. this.querySessionData = []
  153. this.spikeLikeList = []
  154. if (!this.queryInfo.shopId) {
  155. this.getQuerySession()
  156. this.getQueryPlatformSeckillData()
  157. } else {
  158. this.getShopSeckillList()
  159. }
  160. },
  161. beforeDestroy() {
  162. // 销毁前清楚定时器
  163. clearInterval(this.ticker)
  164. },
  165. methods: {
  166. changeTit(index, item) {
  167. if (this.active === index) {
  168. return false
  169. }
  170. this.active = index
  171. this.queryInfo.page = 1
  172. this.queryInfo.pageSize = 10
  173. this.session = item.time.substring(0, 16)
  174. this.spikeLikeList = []
  175. this.platformSeckillId = this.platformSeckillList[index].seckillId
  176. this.getPlatformSeckillsData(index)
  177. },
  178. // 查询秒杀列表
  179. getQueryPlatformSeckillData() {
  180. getQueryPlatformSeckillListApi({}).then((res) => {
  181. this.platformSeckillList = res.data
  182. this.platformSeckillId = res.data[0].seckillId
  183. this.getPlatformSeckillsData(0)
  184. })
  185. },
  186. // 平台首页根据seckillId查询对应的秒杀商品列表
  187. getPlatformSeckillsData(index) {
  188. // uni.showLoading({
  189. // mask: true,
  190. // title: '数据加载中...',
  191. // })
  192. getPlatformSeckillsCanvasApi({ seckillId: this.platformSeckillId })
  193. .then((res) => {
  194. uni.hideLoading()
  195. if (res.data[0].products === 0) {
  196. } else {
  197. this.spikeLikeList = res.data[index].products
  198. }
  199. })
  200. .catch((e) => {
  201. uni.hideLoading()
  202. })
  203. },
  204. // 平台秒杀头部时间
  205. getQuerySession() {
  206. getPlatformSeckillsQuerySessionApi({}).then((res) => {
  207. let arr = []
  208. arr = res.data
  209. arr.forEach((item) => {
  210. const obj = {}
  211. obj.time = item
  212. const date = new Date(this.getCaption(item, 0).replace(/-/g, '/'))
  213. const endDate = new Date(this.getCaption(item, 1).replace(/-/g, '/'))
  214. obj.timestamp = date.getTime()
  215. obj.endTime = endDate.getTime()
  216. obj.startTime = item.substring(5, 16)
  217. this.querySessionData.push(obj)
  218. })
  219. this.session = this.querySessionData[0].time.substring(0, 16)
  220. })
  221. },
  222. // 时间处理
  223. getCaption(obj, state) {
  224. var index = obj.lastIndexOf('\|')
  225. if (state == 0) {
  226. obj = obj.substring(0, index)
  227. } else {
  228. obj = obj.substring(index + 1, obj.length)
  229. }
  230. return obj
  231. },
  232. // 跳转商品详情页
  233. gogoodsDetails(shopId, productId, skuId) {
  234. uni.navigateTo({
  235. url: '/another-tf/another-serve/goodsDetails/index?shopId=' + shopId + '&productId=' + productId + '&skuId=' + skuId
  236. })
  237. },
  238. // 按钮进度条
  239. getPercent(num, total) {
  240. num = parseFloat(num)
  241. total = parseFloat(total)
  242. if (isNaN(num) || isNaN(total)) {
  243. return '-'
  244. }
  245. return total <= 0 ? '0%' : Math.round((num / total) * 10000) / 100.0
  246. },
  247. // // 获取首页更多秒杀
  248. // getSpikeLike() {
  249. // uni.showLoading({
  250. // mask: true,
  251. // title: '数据加载中...',
  252. // })
  253. // let param = {
  254. // page: this.queryInfo.page,
  255. // pageSize: this.queryInfo.pageSize,
  256. // session: this.session
  257. // }
  258. // getQueryProductListBySessionApi(param).then(res => {
  259. // uni.hideLoading()
  260. // this.spikeLikeData = res.data
  261. // if (res.data.list.length === 0) {
  262. // this.page = this.page
  263. // } else {
  264. // this.spikeLikeList = this.spikeLikeList.concat(res.data.list)
  265. // }
  266. // })
  267. // },
  268. // 获取店铺更多秒杀
  269. getShopSeckillList(isLoadmore) {
  270. uni.showLoading()
  271. getShopSeckillIndexApi(this.queryInfo).then((res) => {
  272. this.spikeLikeData = res.data
  273. if (this.ticker) { // 这一段是防止进入页面出去后再进来计时器重复启动
  274. clearInterval(this.ticker)
  275. }
  276. this.ticker = setInterval(() => {
  277. if (this.spikeLikeData.time > 0) {
  278. this.shopCountDown(this.spikeLikeData.time)
  279. this.spikeLikeData.time -= 1000
  280. }
  281. if (this.spikeLikeData.enableTime > 0) {
  282. this.shopCountDown(this.spikeLikeData.enableTime)
  283. this.spikeLikeData.enableTime -= 1000
  284. }
  285. }, 1000)
  286. this.spikeLikeTotal = res.data.page.total
  287. if (isLoadmore) {
  288. this.spikeLikeList.push(...res.data.page.list)
  289. } else {
  290. this.spikeLikeList = res.data.page.list
  291. }
  292. this.isEmpty = this.spikeLikeList.length === 0
  293. uni.hideLoading()
  294. })
  295. .catch((e) => {
  296. uni.hideLoading()
  297. })
  298. },
  299. // 处理店铺秒杀倒计时
  300. shopCountDown(timeAll) {
  301. const msec = timeAll
  302. let hou = parseInt(msec / 3600000)
  303. let min = parseInt((msec % 3600000) / 60000)
  304. let sec = parseInt(((msec % 3600000) % 60000) / 1000)
  305. if (hou < 10) {
  306. hou = '0' + hou
  307. }
  308. if (min < 10) {
  309. min = '0' + min
  310. }
  311. if (sec < 10) {
  312. sec = '0' + sec
  313. }
  314. this.hou = hou
  315. this.min = min
  316. this.sec = sec
  317. }
  318. },
  319. onReachBottom() {
  320. if (this.spikeLikeList.length < this.spikeLikeTotal) {
  321. ++this.queryInfo.page
  322. this.getShopSeckillList(true)
  323. }
  324. }
  325. }
  326. </script>
  327. <style lang="less" scoped>
  328. .spikeListBox {
  329. padding: 20rpx;
  330. min-height: 100vh;
  331. background-color: #333333;
  332. box-sizing: border-box;
  333. .shopStopTime {
  334. text-align: center;
  335. color: #FFFFFF;
  336. .TimeBigBox {
  337. display: flex;
  338. align-items: center;
  339. justify-content: center;
  340. }
  341. .countdown-box {
  342. padding: 0 8rpx;
  343. height: 48rpx;
  344. color: #FFFFFF;
  345. background: linear-gradient(90deg, #C83732 0%, #E25C44 100%);
  346. margin: 10rpx;
  347. }
  348. }
  349. .spikeBg {
  350. margin: 50rpx auto;
  351. font-size: 40upx;
  352. font-weight: bold;
  353. text-align: center;
  354. color: #ffffff;
  355. }
  356. .spikeList {
  357. .listItem {
  358. display: flex;
  359. padding: 20upx;
  360. margin-bottom: 20upx;
  361. background: #FFFFFF;
  362. &:last-child {
  363. border-bottom: none;
  364. }
  365. .itemBox {
  366. width: 260upx;
  367. height: 260upx;
  368. margin-right: 30upx;
  369. img {
  370. width: 100%;
  371. height: 100%;
  372. }
  373. }
  374. .itemInfo {
  375. flex: 1;
  376. .iconBox {
  377. image {
  378. width: 58rpx;
  379. height: 36rpx;
  380. }
  381. }
  382. p {
  383. font-size: 26upx;
  384. color: #333333;
  385. line-height: 35upx;
  386. height: 70rpx;
  387. margin-bottom: 20upx;
  388. text-overflow: -o-ellipsis-lastline;
  389. overflow: hidden;
  390. text-overflow: ellipsis;
  391. display: -webkit-box;
  392. -webkit-line-clamp: 2;
  393. line-clamp: 2;
  394. -webkit-box-orient: vertical;
  395. }
  396. .number {
  397. color: #C5AA7B;
  398. font-size: 26rpx;
  399. height: 40rpx;
  400. background: #FFFFFF;
  401. border: 2rpx solid #E4E5E6;
  402. font-weight: 400;
  403. display: inline;
  404. padding: 0 5rpx;
  405. }
  406. .originalPrice {
  407. font-size: 24upx;
  408. margin-top: 20upx;
  409. text-decoration: line-through;
  410. color: #CCCCCC;
  411. }
  412. .price {
  413. display: flex;
  414. justify-content: space-between;
  415. align-items: center;
  416. .priceInfo {
  417. font-size: 40rpx;
  418. color: #C83732;
  419. }
  420. .snapUpBtn {
  421. width: 160upx;
  422. height: 84upx;
  423. text-align: center;
  424. background: linear-gradient(90deg, #C83732 0%, #E25C44 100%);
  425. box-shadow: 0rpx 6rpx 12rpx rgba(233, 0, 0, 0.3);
  426. opacity: 1;
  427. border-radius: 10rpx;
  428. .progressBox {
  429. width: 82%;
  430. margin: 0 auto;
  431. border-radius: 10rpx;
  432. overflow: hidden
  433. }
  434. .btnText {
  435. color: #FFFFFF;
  436. font-weight: 400;
  437. opacity: 0.5;
  438. margin: 10rpx 0;
  439. }
  440. .uni-progress {
  441. border-radius: 10rpx;
  442. }
  443. }
  444. .btnStyle1 {
  445. background: linear-gradient(90deg, #29C790 0%, #75D98C 100%);
  446. box-shadow: 0 6rpx 12rpx rgba(52, 203, 144, 0.3);
  447. }
  448. }
  449. }
  450. }
  451. }
  452. .tabs-nav {
  453. margin-top: 20rpx;
  454. .ul {
  455. white-space: nowrap;
  456. .li {
  457. display: inline-block;
  458. margin-left: 60rpx;
  459. font-size: 32rpx;
  460. color: #9499a8;
  461. position: relative;
  462. padding-bottom: 18rpx;
  463. .timeItem {
  464. text-align: center;
  465. .date {
  466. font-size: 24rpx;
  467. color: #FFFFFF;
  468. width: 150rpx;
  469. white-space: normal;
  470. }
  471. .state {
  472. font-size: 24rpx;
  473. color: #999999;
  474. display: inline-block;
  475. }
  476. .endCls {
  477. color: #999999;
  478. }
  479. }
  480. }
  481. .active {
  482. .timeItem {
  483. .date {
  484. color: #C83732;
  485. width: 150rpx;
  486. white-space: normal;
  487. }
  488. .state {
  489. display: inline-block;
  490. padding: 0 10rpx;
  491. color: #FFFFFF;
  492. background: #C83732;
  493. }
  494. }
  495. }
  496. }
  497. }
  498. }
  499. </style>