seckill.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. <template>
  2. <view class="seckillBox">
  3. <scroll-view scroll-x="true" class="class-box flex " :scroll-left="scrollLeft" :scroll-with-animation="true">
  4. <view @click="tabClass(idx)" class="item" :style="{ width: topNavWidth }" v-for="(item, idx) in indexList" :key="idx" :class="{ action: idx == classIndex }">
  5. <view class="time" :class="{ action: idx == classIndex }">{{ item.time }}</view>
  6. <view class="status" :class="{ action: idx == classIndex }">{{ item.state }}</view>
  7. </view>
  8. </scroll-view>
  9. <swiper class="list-Box" :current="classIndex" @change="swiperChange" duration="500">
  10. <swiper-item class="list-item" v-for="(ls, idx) in indexList" :key="idx">
  11. <!-- <view class=" b-b position-relative">
  12. <view class="title-box flex ">
  13. <view class="title-box-left">
  14. <text v-if="ls.status == 1">抢购中先下先得哦!</text>
  15. <text v-if="ls.status == 2">精品好货即将开抢!</text>
  16. <text v-if="ls.status == 0">本场已结束,下次早点来哦!</text>
  17. </view>
  18. <view class="title-box-right flex">
  19. <text class="tip" v-if="ls.status == 1">距离结束</text>
  20. <text class="tip" v-if="ls.status == 2">距离开始</text>
  21. <uni-countdown
  22. color="#F9F9F8"
  23. background-color="#666666"
  24. v-if="ls.status == 1 || ls.status == 2"
  25. :show-day="false"
  26. :hour="ls.stopTimeH"
  27. :minute="ls.stopTimeM"
  28. :second="ls.stopTimeS"
  29. ></uni-countdown>
  30. </view>
  31. </view>
  32. </view> -->
  33. <scroll-view scroll-y="true" class="list" @scrolltolower="getList(classIndex)">
  34. <view class="jg"></view>
  35. <!-- <view class="goodsList-item flex" :key="ind" v-for="(lss, ind) in ls.dataList">
  36. <image :src="lss.image" lazy-load mode="scaleToFill"></image>
  37. <view class="goodsList-content">
  38. <view class="title clamp">
  39. <text>{{ lss.title }}</text>
  40. </view>
  41. <view class="slider flex">
  42. <view class="slider-box"><view class="slider-action" :style="{ width: lss.percent + '%' }"></view></view>
  43. <view class="sales-nub">已抢{{ lss.percent + '%' }}</view>
  44. </view>
  45. <view class="goods-money flex">
  46. <view class="money-box">
  47. <view class="money">
  48. <text class="font-size-sm">¥</text>
  49. {{ lss.price }}
  50. </view>
  51. <view class="otMoney-box">
  52. <text class="otMoney">¥{{ lss.ot_price }}</text>
  53. </view>
  54. </view>
  55. <view @click="navProduct(ls, ind)" class="cart" :class="{ 'seckill-action': ls.status == 1 }">
  56. {{ ls.status == 1 ? '去抢购' : ls.status == 2 ? '未开始' : '已结束' }}
  57. </view>
  58. </view>
  59. </view>
  60. </view> -->
  61. <view class="spgood" :key="ind" v-for="(lss, ind) in ls.dataList">
  62. <view class="left-wrapper"><image :src="lss.image" mode="scaleToFill"></image></view>
  63. <view class="right-wrapper">
  64. <view class="right-title clamp">{{ lss.title }}</view>
  65. <view class="ex-addr">
  66. <image src="../../static/img/shop.png" mode="" class="name-img"></image>
  67. 子臣台州旗舰店
  68. <image src="../../static/img/point.png" mode="" class="point-img"></image>
  69. 200m
  70. </view>
  71. <!-- <view class="pepple-num"><image src="../../static/icon/hot.png" mode="scaleToFill"></image>2人团</view> -->
  72. <view class="right-bottom">
  73. <view class="sp-price">
  74. <view class="now-price">¥{{ lss.price }}</view>
  75. <!-- <view class="old-price">¥99</view> -->
  76. </view>
  77. <view class="sp-btn" @click="navProduct(ls, ind)" :class="{ 'seckill-action': ls.status == 1 }">{{ ls.status == 1 ? '马上拼' : ls.status == 2 ? '未开始' : '已结束' }}</view>
  78. </view>
  79. </view>
  80. </view>
  81. <uni-load-more :status="ls.loadingType"></uni-load-more>
  82. </scroll-view>
  83. </swiper-item>
  84. </swiper>
  85. </view>
  86. </template>
  87. <script>
  88. import { getSeckillList, getSeckillClass } from '@/api/product.js';
  89. import uniCountdown from '@/components/uni-countdown/uni-countdown.vue';
  90. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  91. import { timeComputed } from '@/utils/rocessor.js';
  92. export default {
  93. components: {
  94. uniCountdown,
  95. uniLoadMore
  96. },
  97. data() {
  98. return {
  99. indexList: [], //分类列表
  100. showTime: '', //显示的时间
  101. showTImeId: '', //显示时间id用于查询数据
  102. // 判断是否所有活动已经结束
  103. stop: false, //活动是否已经结束
  104. show: false, //是否显示活动
  105. status: 0, //获取状态值1为有活动开始中 2为活动未开始 0为活动已经结束
  106. topNavWidth: '25%', //设置导航默认宽度
  107. classIndex: 0, //当前进行中的活动
  108. itemWidht: 0 //顶部分类宽度
  109. };
  110. },
  111. computed: {
  112. // 计算左侧距离
  113. scrollLeft() {
  114. if (this.classIndex > 1) {
  115. return this.itemWidht * (this.classIndex - 1.5);
  116. } else {
  117. return 0;
  118. }
  119. }
  120. },
  121. onLoad: function(e) {
  122. // 载入分类
  123. this.getClass();
  124. },
  125. methods: {
  126. //抢购时间切换时触发效果
  127. swiperChange(e) {
  128. this.classIndex = e.target.current;
  129. this.getList(this.classIndex, 'tabChange');
  130. },
  131. // 获取项目宽度
  132. numClassWidht() {
  133. uni.createSelectorQuery()
  134. .select('.seckillBox')
  135. .fields(
  136. {
  137. size: true
  138. },
  139. data => {
  140. // 设置项目宽度
  141. this.itemWidht = Math.floor((data.width / 750) * 187.5);
  142. }
  143. )
  144. .exec();
  145. },
  146. // 切换当前选中的秒杀活动
  147. tabClass(ind) {
  148. // 保存当前选中的对象
  149. this.classIndex = ind;
  150. },
  151. // 跳转到商品详情
  152. navProduct(ls, ind) {
  153. if (ls.status == 1) {
  154. let data = ls.dataList[ind];
  155. console.log(data,'66666666')
  156. uni.navigateTo({
  157. url: '/pages/product/product?id=' + data.id + '&type=1&product_id=' + data.product_id
  158. });
  159. }
  160. },
  161. // 获取商品
  162. getList(ind, source) {
  163. // 获取数据对象
  164. let date = this.indexList[ind];
  165. console.log(date, source);
  166. if (source === 'tabChange' && date.loaded === true) {
  167. //tab切换只有第一次需要加载数据
  168. return;
  169. }
  170. if (date.loadingType === 'noMore') {
  171. //防止重复加载
  172. return;
  173. }
  174. if (date.loadingType === 'loading') {
  175. //防止重复加载
  176. return;
  177. }
  178. // 修改当前对象状态为加载中
  179. date.loadingType = 'loading';
  180. getSeckillList(
  181. {
  182. page: date.page,
  183. limit: date.limit
  184. },
  185. date.id
  186. )
  187. .then(e => {
  188. date.dataList.push(...e.data);
  189. // 查询翻页增加
  190. date.page++;
  191. // 判断是否可以继续加载
  192. if (date.limit == e.data.length) {
  193. date.loadingType = 'more';
  194. } else {
  195. date.loadingType = 'noMore';
  196. }
  197. // 设置当前数据已加载完毕
  198. this.$set(date, 'loaded', true);
  199. })
  200. .catch(e => {
  201. console.log(e);
  202. });
  203. },
  204. // 获取秒杀时间段
  205. getClass() {
  206. let obj = this;
  207. getSeckillClass({})
  208. .then(({ data }) => {
  209. console.log('data',data)
  210. obj.indexList = data.seckillTime.map((e, ind) => {
  211. // 初始化翻页页数
  212. e.page = 1;
  213. // 初始每次加载的数据条数
  214. e.limit = 6;
  215. // 创建储存订单数据
  216. e.dataList = [];
  217. // 初始化加载
  218. e.loadingType = 'more';
  219. let ar = e;
  220. // 判断是否为进行中的活动
  221. if (ar.status === 1) {
  222. // 计算倒计时时间
  223. obj.timeComputed(ar.stop * 1000, ar);
  224. } else {
  225. // 获取距离开始还需要多少时间
  226. let arTime = ar.time.split(':');
  227. let h = arTime[0];
  228. let m = arTime[1];
  229. let time = new Date();
  230. // 设置时间
  231. time.setHours(h, m, 0);
  232. // 计算倒计时时间
  233. obj.timeComputed(time.getTime(), ar);
  234. }
  235. return e;
  236. });
  237. // 获取当前活动中的下标值
  238. obj.classIndex = data.seckillTimeIndex;
  239. // 获取当前显示中对象的数据
  240. obj.$nextTick(() => {
  241. obj.getList(obj.classIndex);
  242. });
  243. if (obj.indexList.length <= 4) {
  244. // 当数量小于等于4的时候自适应宽度
  245. obj.topNavWidth = 100 / obj.indexList.length + '%';
  246. } else {
  247. // 页面渲染完毕后加载scroll-view左侧距离
  248. obj.$nextTick(() => {
  249. obj.numClassWidht();
  250. });
  251. }
  252. })
  253. .catch(e => {
  254. console.log(e);
  255. });
  256. },
  257. // 计算倒计时时间
  258. timeComputed(da, ar) {
  259. let obj = this;
  260. // 计算时间,保存需要多少时间到期
  261. let stopTime = timeComputed(da);
  262. console.log(stopTime);
  263. ar.stopTimeH = stopTime.hours;
  264. ar.stopTimeM = stopTime.minutes;
  265. ar.stopTimeS = stopTime.seconds;
  266. }
  267. }
  268. };
  269. </script>
  270. <style lang="scss">
  271. page,
  272. .seckillBox {
  273. min-height: 100%;
  274. height: 100%;
  275. }
  276. // 头部时间段样式
  277. .class-box {
  278. white-space: nowrap;
  279. height: 60px;
  280. .item {
  281. text-align: center;
  282. display: inline-block;
  283. color: #fff;
  284. padding: 11.5px 5px;
  285. background-color: #901b21;
  286. line-height: 1;
  287. .time {
  288. font-size: 16px;
  289. padding-bottom: 3px;
  290. &.action {
  291. color: #901b21;
  292. }
  293. }
  294. .status {
  295. font-size: 12px;
  296. margin: 0 auto;
  297. width: 60px;
  298. padding: 3px 0;
  299. &.action {
  300. color: #901b21;
  301. border-radius: 99px;
  302. background-color: #fff;
  303. }
  304. }
  305. }
  306. .action {
  307. color: #901b21;
  308. background-color: #fff;
  309. }
  310. }
  311. // 列表上方标题样式
  312. .title-box {
  313. margin-top: 10px;
  314. padding: 10px;
  315. background-color: #ffffff;
  316. .title-box-left {
  317. font-size: 15px;
  318. color: $font-color-base;
  319. }
  320. .title-box-right {
  321. .tip {
  322. font-size: 15px;
  323. color: #999999;
  324. padding-right: 5px;
  325. }
  326. /deep/ .uni-countdown__number {
  327. border-radius: 3px;
  328. width: 22px;
  329. }
  330. /deep/ .uni-countdown__splitor,
  331. /deep/ .uni-countdown__number {
  332. height: 20px;
  333. line-height: 18px;
  334. }
  335. }
  336. }
  337. // 列表样式
  338. .list-Box {
  339. height: calc(100% - 60px);
  340. .list {
  341. height: calc(100% - 55px);
  342. }
  343. }
  344. // 商品列表
  345. $slider-color: #fe9398; //滑块左侧颜色
  346. .goodsList-item {
  347. background-color: #ffffff;
  348. padding: 30rpx;
  349. border-bottom: 1px solid $border-color-light;
  350. image {
  351. flex-shrink: 0;
  352. border-radius: $border-radius-sm;
  353. height: 180rpx;
  354. width: 180rpx;
  355. }
  356. .slider {
  357. margin-top: 15rpx;
  358. justify-content: flex-start;
  359. .slider-box {
  360. width: 196rpx;
  361. border-radius: 99px;
  362. border: 1px solid $slider-color;
  363. height: 16rpx;
  364. .slider-action {
  365. background-color: $slider-color;
  366. height: 100%;
  367. }
  368. }
  369. .sales-nub {
  370. color: $font-color-light;
  371. font-size: 24rpx;
  372. padding-left: 20rpx;
  373. }
  374. }
  375. .goodsList-content {
  376. margin-left: 20rpx;
  377. flex-grow: 1;
  378. height: 180rpx;
  379. position: relative;
  380. .title {
  381. font-size: $font-base;
  382. color: $font-color-dark;
  383. font-weight: 500;
  384. width: 0;
  385. min-width: 100%;
  386. }
  387. .goods-money {
  388. position: absolute;
  389. left: 0;
  390. bottom: 0;
  391. width: 100%;
  392. .money-box {
  393. .money {
  394. font-size: $font-lg + 10rpx;
  395. color: $color-red;
  396. font-weight: bold;
  397. }
  398. .otMoney-box {
  399. font-size: $font-sm;
  400. .otMoney {
  401. color: $font-color-light;
  402. padding-right: 20rpx;
  403. text-decoration: line-through;
  404. }
  405. .sales {
  406. color: $font-color-light;
  407. }
  408. }
  409. }
  410. .cart {
  411. font-size: $font-base;
  412. border-radius: 99px;
  413. padding: 15rpx 30rpx;
  414. line-height: 1;
  415. color: #ffffff;
  416. background-color: $color-gray;
  417. &.seckill-action {
  418. border: 1px solid $color-red;
  419. background-color: $color-red;
  420. }
  421. }
  422. }
  423. }
  424. }
  425. .spgood {
  426. width: 710rpx;
  427. height: 290rpx;
  428. background: #FFFFFF;
  429. box-shadow: 0px 0px 20px 0px rgba(50, 50, 52, 0.06);
  430. border-radius: 10rpx;
  431. padding: 15rpx 20rpx 15rpx 14rpx;
  432. display: flex;
  433. margin: 0 auto;
  434. margin-bottom: 20rpx;
  435. .left-wrapper {
  436. width: 260rpx;
  437. height: 260rpx;
  438. border-radius: 10rpx;
  439. image {
  440. width: 260rpx;
  441. height: 260rpx;
  442. border-radius: 10rpx;
  443. }
  444. }
  445. .right-wrapper {
  446. padding-left: 22rpx;
  447. width: 100%;
  448. height: 200rpx;
  449. // background-color: red;
  450. .right-title {
  451. padding-top: 12rpx;
  452. width: 358rpx;
  453. // height: 29rpx;
  454. // font-size: 30rpx;
  455. // font-weight: bold;
  456. // color: #333333;
  457. font-size: 30rpx;
  458. font-weight: bold;
  459. color: #333333;
  460. line-height: 35rpx;
  461. }
  462. .right-addr {
  463. margin-top: 18rpx;
  464. display: flex;
  465. .shop-img {
  466. width: 26rpx;
  467. height: 23rpx;
  468. margin: 0 4rpx 0 0;
  469. image {
  470. width: 100%;
  471. height: 100%;
  472. }
  473. }
  474. .shop-name {
  475. // height: 22rpx;
  476. font-size: 22rpx;
  477. font-weight: 500;
  478. color: #dcb876;
  479. }
  480. .point-img {
  481. width: 16rpx;
  482. height: 23rpx;
  483. margin: 0 4rpx 0 14rpx;
  484. image {
  485. width: 100%;
  486. height: 21rpx;
  487. }
  488. }
  489. .point-disc {
  490. font-size: 24rpx;
  491. font-weight: 500;
  492. padding-top: 3rpx;
  493. color: #dcb876;
  494. }
  495. }
  496. .ex-addr {
  497. margin-top: 16rpx;
  498. // padding-left: 22rpx;
  499. height: 22rpx;
  500. font-size: 25rpx;
  501. font-weight: 500;
  502. color: #dcb876;
  503. image {
  504. height: 22rpx;
  505. }
  506. .name-img {
  507. // vertical-align: ;
  508. width: 26rpx;
  509. margin: 0 4rpx -3rpx 0;
  510. }
  511. .point-img {
  512. width: 16rpx;
  513. margin: 0 4rpx -3rpx 14rpx;
  514. }
  515. }
  516. .right-bottom {
  517. margin-top: 117rpx;
  518. // justify-items: flex-end;
  519. display: flex;
  520. justify-content: space-between;
  521. .sp-price {
  522. height: 52rpx;
  523. display: flex;
  524. vertical-align: bottom;
  525. line-height: 52rpx;
  526. .now-price {
  527. // font-size: 30rpx;
  528. // font-weight: bold;
  529. // color: #901b21;
  530. padding-top: 19rpx;
  531. margin-right: 16rpx;
  532. font-size: 36rpx;
  533. font-weight: bold;
  534. color: #901B21;
  535. line-height: 35rpx;
  536. // vertical-align: bottom;
  537. }
  538. .old-price {
  539. font-size: 22rpx;
  540. font-weight: 500;
  541. text-decoration: line-through;
  542. color: #aaaaaa;
  543. }
  544. }
  545. .sp-btn {
  546. width: 136.6rpx;
  547. height: 60rpx;
  548. border-radius: 30rpx;
  549. font-size: 26rpx;
  550. text-align: center;
  551. line-height: 60rpx;
  552. font-weight: 400;
  553. color: #ffffff;
  554. // background-color: #dcb876;
  555. background-color: #999999;
  556. &.seckill-action {
  557. background-color: #dcb876;
  558. // background-color: #999999;
  559. }
  560. }
  561. }
  562. }
  563. }
  564. .jg {
  565. height: 34rpx;
  566. }
  567. </style>