seckill.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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(100% - 60px);
  367. .list {
  368. height: calc(100% - 55px);
  369. }
  370. }
  371. // 商品列表
  372. $slider-color: #fe9398; //滑块左侧颜色
  373. .goodsList-item {
  374. background-color: #ffffff;
  375. padding: 30rpx;
  376. border-bottom: 1px solid $border-color-light;
  377. image {
  378. flex-shrink: 0;
  379. border-radius: $border-radius-sm;
  380. height: 180rpx;
  381. width: 180rpx;
  382. }
  383. .slider {
  384. margin-top: 15rpx;
  385. justify-content: flex-start;
  386. .slider-box {
  387. width: 196rpx;
  388. border-radius: 99px;
  389. border: 1px solid $slider-color;
  390. height: 16rpx;
  391. .slider-action {
  392. background-color: $slider-color;
  393. height: 100%;
  394. }
  395. }
  396. .sales-nub {
  397. color: $font-color-light;
  398. font-size: 24rpx;
  399. padding-left: 20rpx;
  400. }
  401. }
  402. .goodsList-content {
  403. margin-left: 20rpx;
  404. flex-grow: 1;
  405. height: 180rpx;
  406. position: relative;
  407. .title {
  408. font-size: $font-base;
  409. color: $font-color-dark;
  410. font-weight: 500;
  411. width: 0;
  412. min-width: 100%;
  413. }
  414. .goods-money {
  415. position: absolute;
  416. left: 0;
  417. bottom: 0;
  418. width: 100%;
  419. .money-box {
  420. .money {
  421. font-size: $font-lg + 10rpx;
  422. color: $color-red;
  423. font-weight: bold;
  424. }
  425. .otMoney-box {
  426. font-size: $font-sm;
  427. .otMoney {
  428. color: $font-color-light;
  429. padding-right: 20rpx;
  430. text-decoration: line-through;
  431. }
  432. .sales {
  433. color: $font-color-light;
  434. }
  435. }
  436. }
  437. .cart {
  438. font-size: $font-base;
  439. border-radius: 99px;
  440. padding: 15rpx 30rpx;
  441. line-height: 1;
  442. color: #ffffff;
  443. background-color: $color-gray;
  444. &.seckill-action {
  445. border: 1px solid $color-red;
  446. background-color: $color-red;
  447. }
  448. }
  449. }
  450. }
  451. }
  452. .spgood {
  453. width: 710rpx;
  454. height: 290rpx;
  455. background: #FFFFFF;
  456. box-shadow: 0px 0px 20px 0px rgba(50, 50, 52, 0.06);
  457. border-radius: 10rpx;
  458. padding: 15rpx 20rpx 15rpx 14rpx;
  459. display: flex;
  460. margin: 0 auto;
  461. margin-bottom: 20rpx;
  462. .left-wrapper {
  463. width: 260rpx;
  464. height: 260rpx;
  465. border-radius: 10rpx;
  466. image {
  467. width: 260rpx;
  468. height: 260rpx;
  469. border-radius: 10rpx;
  470. }
  471. }
  472. .right-wrapper {
  473. padding-left: 22rpx;
  474. width: 100%;
  475. height: 200rpx;
  476. // background-color: red;
  477. .right-title {
  478. padding-top: 12rpx;
  479. width: 358rpx;
  480. // height: 29rpx;
  481. // font-size: 30rpx;
  482. // font-weight: bold;
  483. // color: #333333;
  484. font-size: 30rpx;
  485. font-weight: bold;
  486. color: #333333;
  487. line-height: 35rpx;
  488. }
  489. .right-addr {
  490. margin-top: 18rpx;
  491. display: flex;
  492. .shop-img {
  493. width: 26rpx;
  494. height: 23rpx;
  495. margin: 0 4rpx 0 0;
  496. image {
  497. width: 100%;
  498. height: 100%;
  499. }
  500. }
  501. .shop-name {
  502. // height: 22rpx;
  503. font-size: 22rpx;
  504. font-weight: 500;
  505. color: #dcb876;
  506. }
  507. .point-img {
  508. width: 16rpx;
  509. height: 23rpx;
  510. margin: 0 4rpx 0 14rpx;
  511. image {
  512. width: 100%;
  513. height: 21rpx;
  514. }
  515. }
  516. .point-disc {
  517. font-size: 24rpx;
  518. font-weight: 500;
  519. padding-top: 3rpx;
  520. color: #dcb876;
  521. }
  522. }
  523. .ex-addr {
  524. margin-top: 16rpx;
  525. // padding-left: 22rpx;
  526. height: 22rpx;
  527. font-size: 25rpx;
  528. font-weight: 500;
  529. color: #dcb876;
  530. image {
  531. height: 22rpx;
  532. }
  533. .name-img {
  534. // vertical-align: ;
  535. width: 26rpx;
  536. margin: 0 4rpx -3rpx 0;
  537. }
  538. .point-img {
  539. width: 16rpx;
  540. margin: 0 4rpx -3rpx 14rpx;
  541. }
  542. }
  543. .right-bottom {
  544. margin-top: 117rpx;
  545. // justify-items: flex-end;
  546. display: flex;
  547. justify-content: space-between;
  548. .sp-price {
  549. height: 52rpx;
  550. display: flex;
  551. vertical-align: bottom;
  552. line-height: 52rpx;
  553. .now-price {
  554. // font-size: 30rpx;
  555. // font-weight: bold;
  556. // color: #901b21;
  557. padding-top: 19rpx;
  558. margin-right: 16rpx;
  559. font-size: 36rpx;
  560. font-weight: bold;
  561. color: #901B21;
  562. line-height: 35rpx;
  563. // vertical-align: bottom;
  564. }
  565. .old-price {
  566. font-size: 22rpx;
  567. font-weight: 500;
  568. text-decoration: line-through;
  569. color: #aaaaaa;
  570. }
  571. }
  572. .sp-btn {
  573. width: 136.6rpx;
  574. height: 60rpx;
  575. border-radius: 30rpx;
  576. font-size: 26rpx;
  577. text-align: center;
  578. line-height: 60rpx;
  579. font-weight: 400;
  580. color: #ffffff;
  581. // background-color: #dcb876;
  582. background-color: #999999;
  583. &.seckill-action {
  584. background-color: #dcb876;
  585. // background-color: #999999;
  586. }
  587. }
  588. }
  589. }
  590. }
  591. .jg {
  592. height: 34rpx;
  593. }
  594. </style>