Files
xdd-uniapp-new/pages/shop/GoodsClass/index.vue
T
2023-09-20 21:49:33 +08:00

579 lines
15 KiB
Vue

<template>
<view class="productSort">
<hx-navbar :back="false" :fixed="true" color="#080F1A" :left-slot="false" :right-slot="false">
<view class="acea-row row-center row-middle" style="width: 100%;">
<view class="main-title ">分类
<!-- <text class="pink-dot"></text> -->
</view>
</view>
</hx-navbar>
<view class="index">
<view class="header acea-row row-center-wrapper" :style="{top:headerTop}">
<view @click="goGoodSearch()" class="search acea-row row-middle">
<text class="iconfont icon-xiazai5"></text>
搜索商品
</view>
</view>
</view>
<view class="aside" :style="{top:contentTop}">
<view class="item acea-row row-center-wrapper" :class="categoryDivindex === navActive ? 'on' : ''"
v-for="(item, categoryDivindex) in category" :key="categoryDivindex" @click="asideTap(categoryDivindex)">
<text>{{ item.cateName }}</text>
</view>
</view>
<view class="conter">
<mescroll-body ref="mescrollRef" top="16rpx" bottom="0" class='cotent-scroll' :up="upOption" :down="downOption"
@up="upCallback" @down="downCallback" @init="mescrollInit" @emptyclick="emptyClick">
<view class="text acea-row row-center row-middle">
<view class="h-line"></view>
<view class="cate-name">
{{curCategoryName}}
</view>
<view class="h-line"></view>
</view>
<view class="acea-row">
<view @click="goodsDetail(item)" class="item acea-row cate-goods-item" v-for="(item, index) in goodsList"
:key="index" :style="{width:goodsColumnWidth}">
<view class="img-box">
<image :style="{width:goodsColumnWidth,height:goodsColumnWidth}" :src="item.image" />
<view v-if="item.vipPrice && item.vipPrice > 0" class="price-tag">
<!-- <image style="width: 100%;height: 100%;" :src="webUrl+'/20210806130336255505.png'" mode=""></image> -->
<image style="width: 94rpx;height: 42rpx;" :src="webUrl+'/20220525103739004011.png'" mode="scaleToFill"></image>
</view>
</view>
<view class="pro-info line2"><text>{{ item.storeName }}</text></view>
<!-- <view class="market-price">{{item.otPrice}}</view> -->
<view class="money acea-row row-middle row-between" style="width: 100%;">
<!-- <text>{{ item.price }}</text> -->
<text class="num" v-if="item.vipPrice && item.vipPrice > 0">{{item.vipPrice}}</text>
<text class="num" v-else>{{ item.price }}</text>
<!-- <view class="shoppingCart acea-row row-center row-middle">
</view> -->
</view>
</view>
</view>
</mescroll-body>
</view>
<view style="height:100rpx;"></view>
</view>
</template>
<script>
import {
getCategory,
fetchNormal
} from "@/api/store";
import MescrollMixins from "@/mixins/mescroll-mixins.js";
import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue";
import NP from "number-precision";
import {
trim
} from "@/utils";
import {
mapGetters
} from 'vuex';
import hxNavbar from "@/components/hx-navbar/hx-navbar.vue"
var that;
export default {
name: "GoodsClass",
components: {
hxNavbar,
MescrollBody
},
props: {},
computed: mapGetters(["userInfo"]),
mixins: [
MescrollMixins({
getPageData(mescroll) {
// 此时mescroll会携带page的参数:
let pageNum = mescroll.num; // 页码, 默认从1开始
let pageSize = mescroll.size; // 页长, 默认每页10条
var params = {
page: pageNum,
// limit: pageSize,
// keyword: that.keyword,
sid: that.sid,
// news: 0,
// priceOrder: "",
// salesOrder: ""
}
var _this = this;
fetchNormal(params)
.then(res => {
//mescroll.endByPage(res.data.length, res.data.total_pages);
if (mescroll.num == 1) {
_this.goodsList = []; //如果是第一页需手动制空列表
//_this.adjustPage();
}
_this.goodsList = _this.goodsList.concat(res.data.map((goods) => {
goods.price = _this.$force2Decimal(goods.price);
// goods.vipPrice = _this.$force2Decimal(goods.vipPrice);
if (that.$store.getters.token && that.userInfo) {
var p = NP.times(goods.price, NP.divide(parseFloat(that.userInfo.discount), 100))
goods.vipPrice = that.$force2Decimal(p);
}
return goods;
})); //追加新数据
mescroll.endSuccess(res.data.length);
})
.catch(err => {
mescroll.endErr();
//uni.hideLoading();
uni.showToast({
title: err + '',
icon: 'none',
mask: false,
duration: 1500
});
})
}
})
],
data: function() {
return {
keyword: '',
sid: 0, //二给分类id
curCategoryName: '全部商品',
category: [],
navActive: 0,
tabName: "", // 跳转初始分类名
search: "",
lock: false,
upOption: {
noMoreSize: 10, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
auto: false,
empty: {
tip: '暂无商品' // 提示
// btnText:'点击刷新'
}
},
downOption: {
auto: true
},
goodsList: [],
headerTop: '128rpx',
goodsColumnWidth: '246rpx',
contentTop: '224rpx',
webUrl: this.$VUE_APP_RESOURCES_URL
};
},
watch: {
"$yroute.query.id": function(n) {
if (n) {
this.activeCateId(n);
}
}
},
onShow() {
let name=uni.getStorageSync("name");
if(name){
this.tabName = name;
uni.removeStorageSync("name");
}
this.loadCategoryData();
},
onLoad: function(option) {
that = this;
uni.getSystemInfo({
success: (e) => {
// this.compareVersion(e.SDKVersion, '2.5.0')
let statusBar = 0;
let customBar = 0;
// #ifdef MP
statusBar = e.statusBarHeight
customBar = e.statusBarHeight + 45
if (e.platform === 'android') {
//this.$store.commit('SET_SYSTEM_IOSANDROID', false)
customBar = e.statusBarHeight + 50
}
// #endif
// #ifdef MP-WEIXIN
statusBar = e.statusBarHeight
// @ts-ignore
//uni.getMenuButtonBoundingClientRect();
const custom = uni.getMenuButtonBoundingClientRect()
customBar = custom.bottom + custom.top - e.statusBarHeight
// #endif
// #ifdef MP-ALIPAY
statusBar = e.statusBarHeight
customBar = e.statusBarHeight + e.titleBarHeight
// #endif
// #ifdef APP-PLUS
console.log('app-plus', e)
statusBar = e.statusBarHeight
customBar = e.statusBarHeight + 45
// #endif
// #ifdef H5
statusBar = 0
customBar = e.statusBarHeight + 45
// #endif
// 这里你可以自己决定存放方式,建议放在store中,因为store是实时变化的
// this.$store.commit('SET_STATUS_BAR', statusBar)
// this.$store.commit('SET_CUSTOM_BAR', customBar)
// this.$store.commit('SET_SYSTEM_INFO', e)
//两列商品宽度
that.goodsColumnWidth = (e.screenWidth - uni.upx2px(180 + 3 * 30)) / 2 + 'px';
console.log('goodsColumnWidth:' + that.goodsColumnWidth);
//状态栏图片高度
that.headerTop = statusBar + 44 + 'px';
that.contentTop = statusBar + 44 + uni.upx2px(96) + 'px';
}
});
},
// mounted: function() {
// document.addEventListener("scroll", this.onScroll, false);
// },
methods: {
goodsDetail: function(item) {
this.$yrouter.push({
path: '/pages/shop/GoodsCon/index',
query: {
id: item.id
}
})
},
emptyClick: function() {
//触发加载请求
this.mescroll && this.mescroll.triggerDownScroll()
},
goGoodSearch() {
this.$yrouter.push("/pages/shop/GoodSearch/index");
},
goGoodsList(child) {
this.$yrouter.push({
path: "/pages/shop/GoodsList/index",
query: {
id: child.id,
title: child.cateName
}
});
},
activeCateId(n) {
let index = 0;
n = parseInt(n);
if (!n) return;
this.category.forEach((cate, i) => {
if (cate.id === n) index = i;
});
if (index !== this.navActive) {
this.asideTap(index);
}
},
loadCategoryData() {
var that = this;
getCategory(0,35).then(res => {
//that.category = res.data;
that.category = [];
res.data.forEach(function(fcat, idx) {
if (fcat.children) {
fcat.children.forEach(function(sub, sidex) {
that.category.push(sub);
});
}
});
that.category.unshift({
"id": 0,
"pid": 0,
"cateName": "全部商品"
});
that.$nextTick(() => {
if (that.$yroute.query.id) {
that.activeCateId(that.$yroute.query.id);
}
for (let i = 0; i < that.category.length; i++) {
if (that.tabName == that.category[i].cateName)that.asideTap(i);
}
});
});
},
submitForm: function() {
var val = trim(this.search);
if (val) {
this.$yrouter.push({
path: "/pages/shop/GoodsList/index",
query: {
s: val
}
});
setTimeout(() => (this.search = ""), 500);
}
},
asideTap(index) {
this.navActive = index;
this.curCategoryName = this.category[index].cateName;
this.sid = this.category[index].id;
//触发加载请求
this.mescroll.scrollTo(0, 0);
this.mescroll && this.mescroll.resetUpScroll(false);
}
},
beforeDestroy: function() {
// document.removeEventListener("scroll", this.onScroll, false);
}
};
</script>
<style scoped lang="less">
/*产品分类*/
.productSort {
height: 100%;
background: #fff;
}
.productSort .header {
width: 100%;
height: 0.96*100rpx;
background-color: #fff;
position: fixed;
left: 0;
right: 0;
top: 0;
z-index: 9;
// border-bottom: 1px solid #f5f5f5;
border-bottom: 2rpx solid #DADCE0;
}
.productSort .header .input {
width: 7*100rpx;
height: 0.6*100rpx;
background-color: #f5f5f5;
border-radius: 0.5*100rpx;
padding: 0 0.25*100rpx;
}
.productSort .header .input .iconfont {
font-size: 0.35*100rpx;
color: #555;
}
.productSort .header .input input {
font-size: 0.26*100rpx;
height: 100%;
width: 5.97*100rpx;
}
.productSort .header .input input::placeholder {
color: #999;
}
.productSort .aside {
position: fixed;
width: 176rpx;
left: 0;
top: 0.96*100rpx;
bottom: 0 !important;
box-sizing: border-box;
border-right: 2rpx solid #DADCE0;
background-color: #fff;
overflow-y: auto;
overflow-x: hidden;
overflow-scrolling: touch;
}
.productSort .aside::-webkit-scrollbar {
width: 0 !important
}
.productSort .aside .item {
width: 100%;
height: 104rpx;
text{
display: inline-block;
width: 100%;
height: 28rpx;
font-size: 26rpx;
color: #666;
text-align: center;
}
}
.productSort .aside .item.on {
text{
border-left: 6rpx solid #FF564A;
color: #FF564A;
font-weight: bold;
}
}
.productSort .conter {
margin-left: 176rpx;
// padding: 0 0.14*100rpx;
// margin-top: 0.96*100rpx;
margin-top: 106rpx;
}
.productSort .conter .listw {
padding-top: 0.2*100rpx;
}
.productSort .conter .listw .title {
height: 0.9*100rpx;
}
.productSort .conter .listw .title .line {
width: 1*100rpx;
height: 0.02*100rpx;
background-color: #999;
}
.productSort .conter .listw .title .name {
font-size: 0.28*100rpx;
color: #333;
margin: 0 0.3*100rpx;
font-weight: bold;
}
.productSort .conter .list {
flex-wrap: wrap;
-ms-flex-wrap: wrap;
}
.productSort .conter .list .item {
width: 1.77*100rpx;
margin-top: 0.26*100rpx;
}
.productSort .conter .list .item .picture {
width: 1.2*100rpx;
height: 1.2*100rpx;
border-radius: 50%;
}
.productSort .conter .list .item .picture image {
width: 100%;
height: 100%;
border-radius: 50%;
}
.productSort .conter .list .item .name {
font-size: 0.24*100rpx;
color: #333;
height: 0.56*100rpx;
line-height: 0.56*100rpx;
width: 1.2*100rpx;
text-align: center;
}
.index .header .search {
display: flex;
justify-content: center;
background-color: #f6f6f6;
color: #C2C5CC;
font-size: 24rpx;
}
.conter .text {
margin-top: 20rpx;
}
.pink-dot {
width: 24rpx;
height: 24rpx;
background: rgba(255, 86, 74, 0.4);
border-radius: 50%;
position: absolute;
z-index: 0;
bottom: 0;
right: -12rpx;
}
.main-title {
font-size: 36rpx;
line-height: 36rpx;
color: #080F1A;
position: relative;
}
.h-line {
width: 56rpx;
height: 0px;
border: 1px solid #999999;
}
.cate-name {
font-size: 30rpx;
color: #999999; //rgba(255,45,105,1);
margin-left: 5*2rpx;
margin-right: 5*2rpx;
}
.shoppingCart {
width: 28*2rpx;
height: 28*2rpx;
background: rgba(255, 45, 105, 1);
border-radius: 50%;
}
.cart-icon {
width: 18*2rpx;
height: 18*2rpx;
}
.img-box {
position: relative;
}
.price-tag {
position: absolute;
top: 0;
left: 0;
// width: 48*2rpx;
// height: 33*2rpx;
// left: -14rpx;
// top: -20rpx;
}
.pro-info {
font-size: 14*2rpx;
}
.market-price {
font-size: 12*2rpx;
color: #C2C5CC;
text-decoration: line-through;
}
.cate-goods-item {
margin-left: 34rpx;
margin-top: 32rpx;
}
.money {
font-size: 24rpx;
color: #FF564A;
font-weight: bold;
}
</style>