seckill.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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">
  62. <view class="left-wrapper"><image src="../../static/img/spimg1.jpg" mode="scaleToFill"></image></view>
  63. <view class="right-wrapper">
  64. <view class="right-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">¥77</view>
  75. <!-- <view class="old-price">¥99</view> -->
  76. </view>
  77. <view class="sp-btn">马上拼</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. uni.navigateTo({
  156. url: '/pages/product/product?id=' + data.id + '&type=1'
  157. });
  158. }
  159. },
  160. // 获取商品
  161. getList(ind, source) {
  162. // 获取数据对象
  163. let date = this.indexList[ind];
  164. console.log(date, source);
  165. if (source === 'tabChange' && date.loaded === true) {
  166. //tab切换只有第一次需要加载数据
  167. return;
  168. }
  169. if (date.loadingType === 'noMore') {
  170. //防止重复加载
  171. return;
  172. }
  173. if (date.loadingType === 'loading') {
  174. //防止重复加载
  175. return;
  176. }
  177. // 修改当前对象状态为加载中
  178. date.loadingType = 'loading';
  179. getSeckillList(
  180. {
  181. page: date.page,
  182. limit: date.limit
  183. },
  184. date.id
  185. )
  186. .then(e => {
  187. date.dataList.push(...e.data);
  188. // 查询翻页增加
  189. date.page++;
  190. // 判断是否可以继续加载
  191. if (date.limit == e.data.length) {
  192. date.loadingType = 'more';
  193. } else {
  194. date.loadingType = 'noMore';
  195. }
  196. // 设置当前数据已加载完毕
  197. this.$set(date, 'loaded', true);
  198. })
  199. .catch(e => {
  200. console.log(e);
  201. });
  202. },
  203. // 获取秒杀时间段
  204. getClass() {
  205. let obj = this;
  206. getSeckillClass({})
  207. .then(({ data }) => {
  208. console.log('data',data)
  209. obj.indexList = data.seckillTime.map((e, ind) => {
  210. // 初始化翻页页数
  211. e.page = 1;
  212. // 初始每次加载的数据条数
  213. e.limit = 6;
  214. // 创建储存订单数据
  215. e.dataList = [];
  216. // 初始化加载
  217. e.loadingType = 'more';
  218. let ar = e;
  219. // 判断是否为进行中的活动
  220. if (ar.status === 1) {
  221. // 计算倒计时时间
  222. obj.timeComputed(ar.stop * 1000, ar);
  223. } else {
  224. // 获取距离开始还需要多少时间
  225. let arTime = ar.time.split(':');
  226. let h = arTime[0];
  227. let m = arTime[1];
  228. let time = new Date();
  229. // 设置时间
  230. time.setHours(h, m, 0);
  231. // 计算倒计时时间
  232. obj.timeComputed(time.getTime(), ar);
  233. }
  234. return e;
  235. });
  236. // 获取当前活动中的下标值
  237. obj.classIndex = data.seckillTimeIndex;
  238. // 获取当前显示中对象的数据
  239. obj.$nextTick(() => {
  240. obj.getList(obj.classIndex);
  241. });
  242. if (obj.indexList.length <= 4) {
  243. // 当数量小于等于4的时候自适应宽度
  244. obj.topNavWidth = 100 / obj.indexList.length + '%';
  245. } else {
  246. // 页面渲染完毕后加载scroll-view左侧距离
  247. obj.$nextTick(() => {
  248. obj.numClassWidht();
  249. });
  250. }
  251. })
  252. .catch(e => {
  253. console.log(e);
  254. });
  255. },
  256. // 计算倒计时时间
  257. timeComputed(da, ar) {
  258. let obj = this;
  259. // 计算时间,保存需要多少时间到期
  260. let stopTime = timeComputed(da);
  261. console.log(stopTime);
  262. ar.stopTimeH = stopTime.hours;
  263. ar.stopTimeM = stopTime.minutes;
  264. ar.stopTimeS = stopTime.seconds;
  265. }
  266. }
  267. };
  268. </script>
  269. <style lang="scss">
  270. page,
  271. .seckillBox {
  272. min-height: 100%;
  273. height: 100%;
  274. }
  275. // 头部时间段样式
  276. .class-box {
  277. white-space: nowrap;
  278. height: 60px;
  279. .item {
  280. text-align: center;
  281. display: inline-block;
  282. color: #fff;
  283. padding: 11.5px 5px;
  284. background-color: #901b21;
  285. line-height: 1;
  286. .time {
  287. font-size: 16px;
  288. padding-bottom: 3px;
  289. &.action {
  290. color: #901b21;
  291. }
  292. }
  293. .status {
  294. font-size: 12px;
  295. margin: 0 auto;
  296. width: 60px;
  297. padding: 3px 0;
  298. &.action {
  299. color: #901b21;
  300. border-radius: 99px;
  301. background-color: #fff;
  302. }
  303. }
  304. }
  305. .action {
  306. color: #901b21;
  307. background-color: #fff;
  308. }
  309. }
  310. // 列表上方标题样式
  311. .title-box {
  312. margin-top: 10px;
  313. padding: 10px;
  314. background-color: #ffffff;
  315. .title-box-left {
  316. font-size: 15px;
  317. color: $font-color-base;
  318. }
  319. .title-box-right {
  320. .tip {
  321. font-size: 15px;
  322. color: #999999;
  323. padding-right: 5px;
  324. }
  325. /deep/ .uni-countdown__number {
  326. border-radius: 3px;
  327. width: 22px;
  328. }
  329. /deep/ .uni-countdown__splitor,
  330. /deep/ .uni-countdown__number {
  331. height: 20px;
  332. line-height: 18px;
  333. }
  334. }
  335. }
  336. // 列表样式
  337. .list-Box {
  338. height: calc(100% - 60px);
  339. .list {
  340. height: calc(100% - 55px);
  341. }
  342. }
  343. // 商品列表
  344. $slider-color: #fe9398; //滑块左侧颜色
  345. .goodsList-item {
  346. background-color: #ffffff;
  347. padding: 30rpx;
  348. border-bottom: 1px solid $border-color-light;
  349. image {
  350. flex-shrink: 0;
  351. border-radius: $border-radius-sm;
  352. height: 180rpx;
  353. width: 180rpx;
  354. }
  355. .slider {
  356. margin-top: 15rpx;
  357. justify-content: flex-start;
  358. .slider-box {
  359. width: 196rpx;
  360. border-radius: 99px;
  361. border: 1px solid $slider-color;
  362. height: 16rpx;
  363. .slider-action {
  364. background-color: $slider-color;
  365. height: 100%;
  366. }
  367. }
  368. .sales-nub {
  369. color: $font-color-light;
  370. font-size: 24rpx;
  371. padding-left: 20rpx;
  372. }
  373. }
  374. .goodsList-content {
  375. margin-left: 20rpx;
  376. flex-grow: 1;
  377. height: 180rpx;
  378. position: relative;
  379. .title {
  380. font-size: $font-base;
  381. color: $font-color-dark;
  382. font-weight: 500;
  383. width: 0;
  384. min-width: 100%;
  385. }
  386. .goods-money {
  387. position: absolute;
  388. left: 0;
  389. bottom: 0;
  390. width: 100%;
  391. .money-box {
  392. .money {
  393. font-size: $font-lg + 10rpx;
  394. color: $color-red;
  395. font-weight: bold;
  396. }
  397. .otMoney-box {
  398. font-size: $font-sm;
  399. .otMoney {
  400. color: $font-color-light;
  401. padding-right: 20rpx;
  402. text-decoration: line-through;
  403. }
  404. .sales {
  405. color: $font-color-light;
  406. }
  407. }
  408. }
  409. .cart {
  410. font-size: $font-base;
  411. border-radius: 99px;
  412. padding: 15rpx 30rpx;
  413. line-height: 1;
  414. color: #ffffff;
  415. background-color: $color-gray;
  416. &.seckill-action {
  417. border: 1px solid $color-red;
  418. background-color: $color-red;
  419. }
  420. }
  421. }
  422. }
  423. }
  424. .spgood {
  425. width: 710rpx;
  426. height: 290rpx;
  427. background: #FFFFFF;
  428. box-shadow: 0px 0px 20px 0px rgba(50, 50, 52, 0.06);
  429. border-radius: 10rpx;
  430. padding: 15rpx 20rpx 15rpx 14rpx;
  431. display: flex;
  432. margin: 0 auto;
  433. margin-bottom: 20rpx;
  434. .left-wrapper {
  435. width: 260rpx;
  436. height: 260rpx;
  437. border-radius: 10rpx;
  438. image {
  439. width: 260rpx;
  440. height: 260rpx;
  441. border-radius: 10rpx;
  442. }
  443. }
  444. .right-wrapper {
  445. padding-left: 22rpx;
  446. width: 100%;
  447. height: 200rpx;
  448. // background-color: red;
  449. .right-title {
  450. padding-top: 12rpx;
  451. width: 100%;
  452. // height: 29rpx;
  453. // font-size: 30rpx;
  454. // font-weight: bold;
  455. // color: #333333;
  456. font-size: 30rpx;
  457. font-weight: bold;
  458. color: #333333;
  459. line-height: 35rpx;
  460. }
  461. .right-addr {
  462. margin-top: 18rpx;
  463. display: flex;
  464. .shop-img {
  465. width: 26rpx;
  466. height: 23rpx;
  467. margin: 0 4rpx 0 0;
  468. image {
  469. width: 100%;
  470. height: 100%;
  471. }
  472. }
  473. .shop-name {
  474. // height: 22rpx;
  475. font-size: 22rpx;
  476. font-weight: 500;
  477. color: #dcb876;
  478. }
  479. .point-img {
  480. width: 16rpx;
  481. height: 23rpx;
  482. margin: 0 4rpx 0 14rpx;
  483. image {
  484. width: 100%;
  485. height: 21rpx;
  486. }
  487. }
  488. .point-disc {
  489. font-size: 24rpx;
  490. font-weight: 500;
  491. padding-top: 3rpx;
  492. color: #dcb876;
  493. }
  494. }
  495. .ex-addr {
  496. margin-top: 16rpx;
  497. // padding-left: 22rpx;
  498. height: 22rpx;
  499. font-size: 25rpx;
  500. font-weight: 500;
  501. color: #dcb876;
  502. image {
  503. height: 22rpx;
  504. }
  505. .name-img {
  506. // vertical-align: ;
  507. width: 26rpx;
  508. margin: 0 4rpx -3rpx 0;
  509. }
  510. .point-img {
  511. width: 16rpx;
  512. margin: 0 4rpx -3rpx 14rpx;
  513. }
  514. }
  515. .right-bottom {
  516. margin-top: 117rpx;
  517. // justify-items: flex-end;
  518. display: flex;
  519. justify-content: space-between;
  520. .sp-price {
  521. height: 52rpx;
  522. display: flex;
  523. vertical-align: bottom;
  524. line-height: 52rpx;
  525. .now-price {
  526. // font-size: 30rpx;
  527. // font-weight: bold;
  528. // color: #901b21;
  529. padding-top: 19rpx;
  530. margin-right: 16rpx;
  531. font-size: 36rpx;
  532. font-weight: bold;
  533. color: #901B21;
  534. line-height: 35rpx;
  535. // vertical-align: bottom;
  536. }
  537. .old-price {
  538. font-size: 22rpx;
  539. font-weight: 500;
  540. text-decoration: line-through;
  541. color: #aaaaaa;
  542. }
  543. }
  544. .sp-btn {
  545. width: 136.6rpx;
  546. height: 60rpx;
  547. border-radius: 30rpx;
  548. font-size: 26rpx;
  549. text-align: center;
  550. line-height: 60rpx;
  551. font-weight: 400;
  552. color: #ffffff;
  553. background-color: #dcb876;
  554. }
  555. }
  556. }
  557. }
  558. .jg {
  559. height: 34rpx;
  560. }
  561. </style>