seckill.vue 15 KB

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