123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- <template>
- <view class="content">
- <view class="navbar">
- <view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{current: tabCurrentIndex === index}"
- @click="tabClick(index)">
- <view class="hour">
- <view>{{item.starttime_hour}}</view>
- <view class="text">{{state[item.state].text}}</view>
- </view>
- </view>
- </view>
- <swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
- <swiper-item v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
- <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
- <!-- 空白页 -->
- <empty v-if="tabItem.loaded === true && tabItem.list.length === 0"></empty>
- <!-- 产品列表 -->
- <view v-for="(item, index) in tabItem.list" :key="index" class="order-item">
- <view class="info" @click="navToDetailPage(item.product.product_id, tabItem.flash_id)">
- <view class="image">
- <image mode="aspectFill" :src="item.product.image"></image>
- </view>
- <view class="detail">
- <view class="title">{{item.product.title}}</view>
- <view class="introduction">{{item.introduction}}</view>
- <view class="price">
- <view class="sales">¥{{item.product.sales_price}} </view>
- <view class="market"> ¥{{item.product.market_price}}</view>
- </view>
- <ProgressBar class="ProgressBar" :Sold="item.sold" :widthUpx="250" :Width="percentage(item.number,item.sold)"
- Type="candy" :Vice="true"></ProgressBar>
- <view class="loot">{{tabItem.state > 0 ? "马上抢" : "未开始"}}</view>
- </view>
- </view>
- </view>
- <uni-load-more :status="tabItem.loadingType"></uni-load-more>
- </scroll-view>
- </swiper-item>
- </swiper>
- </view>
- </template>
- <script>
- import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
- import empty from "@/components/empty";
- import ProgressBar from '@/components/Progress-Bar/Progress-Bar';
- export default {
- components: {
- uniLoadMore,
- empty,
- ProgressBar
- },
- computed: {},
- data() {
- return {
- pageSize: 15,
- tabCurrentIndex: 0,
- navList: [],
- state: [{
- text: '未开始'
- }, {
- text: '已开抢'
- }, {
- text: '抢购进行中'
- }]
- }
- },
- onPullDownRefresh() {
- this.loadNavBar();
- },
- onLoad(options) {
- this.loadNavBar();
- },
- methods: {
- // 加载标签
- async loadNavBar() {
- let navbar = await this.$api.request('/flash/navbar', 'GET');
- uni.stopPullDownRefresh();
- if (navbar) {
- this.navList = navbar;
- this.navList.forEach((item, index) => {
- item = Object.assign(item, {
- list: [],
- page: 1,
- loadingType: 'more'
- }); //新增一个数组用来储存商品
- if (item.current) {
- this.tabCurrentIndex = index;
- }
- // 建议把后端处理的starttime_hour和text字段在这里用js处理
- });
- this.loadData('tabChange', this.navList[this.tabCurrentIndex].flash_id);
- this.setNavigationBarTitle(this.navList[this.tabCurrentIndex].title);
- //console.log(this.navList);
- }
- },
- // 加载数据
- async loadData(source = false, flash_id = 0) {
- //这里是将订单挂载到tab列表下
- let index = this.tabCurrentIndex;
- let navItem = this.navList[index];
- if (source === 'tabChange' && navItem.loaded === true) {
- //tab切换只有第一次需要加载数据
- return;
- }
- if (navItem.loadingType === 'loading') {
- //防止重复加载
- return;
- }
- if (navItem.loadingType == 'noMore') {
- //没有更多数据
- return;
- }
- navItem.loadingType = 'loading';
- let result = await this.$api.request('/flash/product', 'GET', {
- flash_id: flash_id,
- page: navItem.page,
- pagesize: this.pageSize
- });
- if (result) {
- if (result.length >= this.pageSize) {
- //判断是否还有数据, 有改为 more, 没有改为noMore
- navItem.loadingType = 'more';
- } else {
- navItem.loadingType = 'noMore';
- }
- // 页数加一
- navItem.page++;
- result.forEach((item, index) => {
- navItem.list.push(item);
- })
- //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
- this.$set(navItem, 'loaded', true);
- }
- },
- //顶部tab点击
- tabClick(index) {
- this.tabCurrentIndex = index;
- },
- //swiper 切换
- changeTab(e) {
- this.tabCurrentIndex = e.target.current;
- this.loadData('tabChange', this.navList[this.tabCurrentIndex].flash_id);
- this.setNavigationBarTitle(this.navList[this.tabCurrentIndex].title);
- },
- // 计算百分比
- percentage(number, sold) {
- if (sold == 0) {
- return 0;
- }
- return parseInt(sold / number * 100);
- },
- // 商品详情页
- navToDetailPage(product_id, flash_id = 0) {
- uni.navigateTo({
- url: `/pages/product/product?id=${product_id}&flash=${flash_id}`
- });
- },
- // 设置导航栏名称
- setNavigationBarTitle(title) {
- uni.setNavigationBarTitle({
- title: '限时秒杀|' + title
- });
- }
- }
- }
- </script>
- <style lang="scss">
- page,
- .content {
- //background: $page-color-base;
- background: #f5f5f5;
- height: 100%;
- }
- .swiper-box {
- height: calc(100% - 50px);
- }
- .list-scroll-content {
- height: 100%;
- }
- .navbar {
- display: flex;
- height: 50px;
- padding: 0 5px;
- background: #000;
- box-shadow: 0 1px 5px rgba(0, 0, 0, .06);
- position: relative;
- z-index: 10;
- overflow: auto;
- .nav-item {
- flex: 1;
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100%;
- font-size: 15px;
- //color: $font-color-dark;
- color: #fff;
- font-weight: 900;
- position: relative;
- text-align: center;
- min-width: 150upx;
- .hour {
- flex-flow: column;
- display: flex;
- .text {
- font-size: 10px;
- font-weight: 400;
- }
- }
- &.current {
- //color: $base-color;
- background-color: $base-color;
- &:after {
- content: '';
- position: absolute;
- //left: 50%;
- bottom: -10upx;
- //transform: translateX(-50%);
- transform: rotate(45deg);
- //width: 44px;
- width: 20upx;
- //height: 0;
- height: 20upx;
- background-color: $base-color;
- //border-bottom: 2px solid $base-color;
- }
- }
- }
- }
- .order-item {
- display: flex;
- flex-direction: column;
- padding-left: 30upx;
- background: #fff;
- margin-top: 16upx;
- .info {
- display: flex;
- flex-direction: row;
- .image {
- image {
- width: 250upx;
- height: 250upx;
- border-radius: 10upx;
- }
- }
- .detail {
- width: 440upx;
- height: 250upx;
- padding-left: 30upx;
- padding-top: 6upx;
- position: relative;
- .title {
- color: #303133;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .introduction {
- color: #999999;
- font-size: 26upx;
- -webkit-line-clamp: 2;
- overflow: hidden;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- }
- .price {
- position: absolute;
- bottom: 56upx;
- display: flex;
- flex-direction: row;
- .sales {
- font-size: 40upx;
- color: $base-color;
- font-weight: 500;
- }
- .market {
- vertical-align: bottom;
- font-size: 25upx;
- text-decoration: line-through;
- }
- }
- .ProgressBar {
- position: absolute;
- bottom: 0;
- }
- .loot {
- position: absolute;
- right: 0;
- bottom: 14rpx;
- background: $base-color;
- color: #fff;
- padding: 4upx 14upx;
- border-radius: 4upx;
- box-shadow: 2upx 2upx 8upx -2px #000;
- font-size: 32rpx;
- }
- }
- }
- }
- /* load-more */
- .uni-load-more {
- display: flex;
- flex-direction: row;
- height: 80upx;
- align-items: center;
- justify-content: center
- }
- .uni-load-more__text {
- font-size: 28upx;
- color: #999
- }
- .uni-load-more__img {
- height: 24px;
- width: 24px;
- margin-right: 10px
- }
- .uni-load-more__img>view {
- position: absolute
- }
- .uni-load-more__img>view view {
- width: 6px;
- height: 2px;
- border-top-left-radius: 1px;
- border-bottom-left-radius: 1px;
- background: #999;
- position: absolute;
- opacity: .2;
- transform-origin: 50%;
- animation: load 1.56s ease infinite
- }
- .uni-load-more__img>view view:nth-child(1) {
- transform: rotate(90deg);
- top: 2px;
- left: 9px
- }
- .uni-load-more__img>view view:nth-child(2) {
- transform: rotate(180deg);
- top: 11px;
- right: 0
- }
- .uni-load-more__img>view view:nth-child(3) {
- transform: rotate(270deg);
- bottom: 2px;
- left: 9px
- }
- .uni-load-more__img>view view:nth-child(4) {
- top: 11px;
- left: 0
- }
- .load1,
- .load2,
- .load3 {
- height: 24px;
- width: 24px
- }
- .load2 {
- transform: rotate(30deg)
- }
- .load3 {
- transform: rotate(60deg)
- }
- .load1 view:nth-child(1) {
- animation-delay: 0s
- }
- .load2 view:nth-child(1) {
- animation-delay: .13s
- }
- .load3 view:nth-child(1) {
- animation-delay: .26s
- }
- .load1 view:nth-child(2) {
- animation-delay: .39s
- }
- .load2 view:nth-child(2) {
- animation-delay: .52s
- }
- .load3 view:nth-child(2) {
- animation-delay: .65s
- }
- .load1 view:nth-child(3) {
- animation-delay: .78s
- }
- .load2 view:nth-child(3) {
- animation-delay: .91s
- }
- .load3 view:nth-child(3) {
- animation-delay: 1.04s
- }
- .load1 view:nth-child(4) {
- animation-delay: 1.17s
- }
- .load2 view:nth-child(4) {
- animation-delay: 1.3s
- }
- .load3 view:nth-child(4) {
- animation-delay: 1.43s
- }
- @-webkit-keyframes load {
- 0% {
- opacity: 1
- }
- 100% {
- opacity: .2
- }
- }
- </style>
|