时空网前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

333 lines
9.2 KiB

<template>
<view class="lf-row-center lf-flex-column">
<block v-if="tab_list.length">
<view class="ctab">
<u-tabs :list="tab_list" :is-scroll="true" :show-bar="false" :current="current" @change="change"></u-tabs>
</view>
<swiper :style="{height: 'calc('+ windowHeight +'px - 110rpx)', width: '750rpx'}" :current="current" @change="swiperChange">
<swiper-item v-for="(tab, tabIndex) in tab_list" :key="tabIndex">
<scroll-view class="com" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="isRefresher" @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh">
<view class="lf-row-between list" v-for="(item, index) in tab.list" :key="item.id" @click="toDetail(item)">
<view class="left">
<image :src="item.cover" mode="aspectFill"></image>
</view>
<view class="right">
<view class="lf-line-2 title">{{ item.name }}</view>
<view class="lf-flex tips">
<view class="lf-row-between lf-flex-1" v-if="item.specs[0]">
<view class="lf-flex">
<view class="u-line-progress">
<u-line-progress :percent="item.specs[0].sold_percent" height="20" :striped="true" active-color="#FE9903" :show-percent="false" inactive-color="#F5F5F5"></u-line-progress>
</view>
<text class="progress lf-m-r-10">{{ item.specs[0].sold_percent_text }}</text>
</view>
<view>
<text class="bought">{{ item.specs[0].sold_stock_text }}</text>
</view>
</view>
</view>
<view class="lf-row-between price">
<lf-price :price="item.specs[0].selling_price" v-if="item.specs[0]"></lf-price>
<text class="lf-font-24 original-price" v-if="item.specs[0]">¥{{ item.specs[0].original_price }}</text>
<text v-else></text>
<button>立即抢购</button>
</view>
</view>
</view>
<!-- 空数据的情况 -->
<view class="loading-more">
<text v-if="tab.list.length" :class="{'loading-more-text': tab.loadingClass}">{{ tab.loadingText }}</text>
<my-nocontent v-else></my-nocontent>
</view>
<!-- 回到顶部 -->
<u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}"></u-back-top>
</scroll-view>
</swiper-item>
</swiper>
</block>
<block v-else>
<my-nocontent></my-nocontent>
</block>
</view>
</template>
<script>
let SparkMD5 = require("@/common/SparkMD5.js"); // 签名加密js文件
export default {
data() {
return {
tab_list: [],
current: 0, // tab下表
pageSize: 10,
shareInfo: {},
windowHeight: 0, // 屏幕可用高度
isRefresher: false ,// scroll-view下拉刷新状态,当前默认没有触发
pt: 1,
s_id: ''
}
},
onLoad() {
this.windowHeight = getApp().globalData.windowHeight;
this.getCategoryList();
this.getShareInfo();
// 获取页面参数
let options = uni.getStorageSync('homePageOptions') || {};
if(Object.keys(options).length > 0){
this.pt = options.pt || 1;
this.s_id = options.share_id || '';
uni.removeStorageSync('homePageOptions');
if(this.pt == 2) {
this.bindUsders()
}
}
},
methods: {
//用户绑定
bindUsders() {
var _this = this;
let yy = new Date().getFullYear();
let mm = new Date().getMonth()+1;
let dd = new Date().getDate();
let hh = new Date().getHours();
let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
let gettime = yy+'-'+mm+'-'+dd+' '+hh+':'+mf+':'+ss;
let userInfo = uni.getStorageSync('userinfo') || {};
let timeDate = Math.round(new Date().getTime() / 1000).toString();
let md5TimeDate = SparkMD5.hash(timeDate)
let nowTime = new Date().toLocaleString();
console.log("进来啦~~~~~")
_this.$http(_this.API.API_BINDSALES, {
deed: md5TimeDate,
sid: _this.s_id,
t: gettime
}).then(res => {
_this.$msg('提交审核成功');
}).catch(err => {
console.log(err)
})
},
// 获取分享信息
getShareInfo(){
this.$http(this.API.API_SHARE_HOME).then(res => {
this.shareInfo = res.data;
});
},
// 切换tab
change(index) {
this.current = index;
if(this.tab_list[index].list.length <= 0){
this.getGoodsList(); // tab下没有数据,请求第一页
}
},
// 滑块下标值变化
swiperChange(event){
this.current = event.detail.current;
if(event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
if(this.tab_list[event.detail.current].list.length <= 0){
this.getGoodsList(); // tab下没有数据,请求第一页
}
},
// 获取分类tab
getCategoryList(options = {}){
this.$http(this.API.API_CATEGORY_LIST).then(res => {
let res_list = res.data || [];
let tab_list = res_list.map(item => {
return {
id: item.id,
name: item.name,
type: item.type,
list: [],
loadingClass: true,
loadingText: '正在加载中',
page: 1,
isPage: true
}
});
if(options.type == 'pageRefresh'){
uni.stopPullDownRefresh();
}else if(options.type == 'scrollRefresh'){
this.isRefresher = false;
}
this.tab_list = tab_list;
this.getGoodsList();
})
},
// 获取分类下的商品列表
getGoodsList(){
let per_page = this.pageSize;
let tab_item = this.tab_list[this.current];
this.$http(this.API.API_GOODS_LIST, {
category_id: tab_item.id,
type: tab_item.type,
page: tab_item.page,
per_page
}).then(res => {
let isPage = res.data.has_more_page;
tab_item.isPage = isPage;
if(!isPage){
tab_item.loadingClass = false;
tab_item.loadingText = '没有更多数据啦~';
}
if(tab_item.page == 1){
tab_item.list = res.data.items;
}else{
tab_item.list.push(...res.data.items);
}
})
},
// 去到详情页
toDetail(item){
this.$url('/pages/goodsDetail/index?id='+ item.id);
},
// 页面触底,加载下一页
onScrolltolower(){
let tab_item = this.tab_list[this.current];
if(tab_item.isPage){
tab_item.page = tab_item.page + 1;
this.getGoodsList();
}
},
// scroll-view 下拉刷新
onRefresherrefresh(){
this.isRefresher = true;
this.getCategoryList({type: 'scrollRefresh'});
}
},
// page 下拉刷新
onPullDownRefresh(){
// 新版逻辑,刷新则整个数据全部重新获取
this.getCategoryList({type: 'pageRefresh'});
// 旧版逻辑,刷新只刷tab下的商品列表
// let tab_item = this.tab_list[this.current];
// tab_item.page = 1;
// tab_item.isPage = true;
// tab_item.loadingClass = true;
// tab_item.loadingText = '正在加载中';
// this.getGoodsList();
},
onShareAppMessage(){
const token = this.$shared.createToken();
let options = {route: 'home'};
this.generateKooken(token, options); // 谁分享了就生成一个token
let shareInfo = {
title: this.shareInfo.title || '欢迎使用时空网小程序',
path: '/pages/route/index?token='+ token
}
if(this.shareInfo.cover){
shareInfo.imageUrl = this.shareInfo.cover;
}
return shareInfo;
}
}
</script>
<style lang="scss" scoped>
.title {
font-size: 28rpx;
color: $u-content-color;
height: 88rpx;
}
// tab
.ctab{
width: 100%;
margin: 20rpx 0 0rpx 0rpx;
padding: 0 22rpx;
}
// 商品列表
.com{
width: 100%;
height: 100%;
overflow: hidden;
.list{
border-radius: 10rpx;
overflow: hidden;
margin: 20rpx 32rpx;
background-color: #FFFFFF;
box-shadow: 0 10rpx 20rpx 0 rgba(0, 0, 0, 0.1);
align-items: flex-start;
.left{
overflow: hidden;
image{
width: 204rpx;
height: 204rpx;
margin: 20rpx;
border-radius: 10rpx;
}
}
.right{
overflow: hidden;
width: 64%;
.title{
margin: 18rpx 20rpx 0 0;
color: #222222;
font-size: 32rpx;
}
.tips{
margin: 16rpx 0;
overflow: hidden;
.u-line-progress{
width: 112rpx;
overflow: hidden;
margin-right:20rpx ;
}
.progress{
color: #777777;
font-size: 24rpx;
}
.bought{
color: #777777;
font-size: 24rpx;
margin-right: 20rpx;
}
}
.price{
overflow: hidden;
color:#FF0000;
.original-price{
text-decoration: line-through;
color: #777777;
}
// text{
// font-size: 48rpx;
// color:#FF0000;
// font-weight: 500;
// }
// text:nth-child(1){
// color: #FF0000;
// font-size: 28rpx;
// }
// text:nth-child(2){
// color: #FF0000;
// font-size: 48rpx;
// }
// text:nth-child(3){
// color: #FF0000;
// font-size: 28rpx;
// }
// text:nth-child(4){
// color: #777777;
// font-size: 28rpx;
// text-decoration:line-through;
// font-weight: 400;
// }
button{
width: 160rpx;
height: 60rpx;
background: #FE9903;
border-radius: 50px;
font-size: 24rpx;
color: #FFFFFF;
margin: 0rpx 20rpx 0rpx 20rpx;
border: none;
}
}
}
}
}
</style>