123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- <template>
- <view class="container commodity-list-wrapper" :style="{'overflow':(showSkeleton? 'hidden' : 'auto'),'height': (showSkeleton? windowHeight + 'px' : 'auto')}">
- <list-skeleton v-if="showSkeleton" :listType='0'></list-skeleton>
- <scroll-view :style="{'height':scrollHeight+'px'}" @scrolltolower="toLower" scroll-y v-if="commodityList.length > 0">
- <view v-for="(item,index) in commodityList" :key="index" :id="item.id" class="all-type-list-content commodity-list" @click.stop="navToDetailPage(item.id)">
- <image mode='widthFix' :src="item.mainImage" class="list-img" alt="list-img"></image>
- <view class="list-details-info">
- <text class="list-details-title">{{item.name}}</text>
- <text class="list-details-specs">规格:{{item.unit}}</text>
- <text class="list-details-miniQuantity" v-if="fromRegularPurchasePage">起订量:{{item.minBuyNumber}}</text>
- <view class="list-details-price">
- <view v-if="!loginStatus" class="list-login-now">
- <text @click.stop="toLoginPage" class="login-now">登录查看价格<text class="iconfont icon-xiayibu" style="font-size: 22rpx;margin: 0 6rpx;"></text></text>
- </view>
- <view class="list-price" v-else>
- <text>¥<text class="price-larger">{{item.retailPrice.toFixed(2)}}</text></text>
- </view>
- <button v-if="fromRegularPurchasePage" class="add-cart-btn" @click.stop="addCartNow(item.id, item.minBuyNumber)">加入购物车</button>
- </view>
- </view>
- </view>
- <button class="show-more-btn" v-if="showRegularBtn" @click="getListFromServer(true)">查看更多</button>
- <view v-if="showLoading && commodityList.length > 4 && !showRegularBtn">
- <view class="loading-wrapper loading-wrapper-now" v-if="loadingNow">{{loadingText}}<text v-if="loadingText === '已至底部'">‧ ‧ ‧</text></view>
- <view class="loading-wrapper loading-wrapper-btm" v-else>———<text class="btm-text">已至底部</text>———</view>
- </view>
- </scroll-view>
- <view class="cart-icon" v-if="fromRegularPurchasePage" @click="toCartPage">
- <text v-if="cartNum > 0" class="uni-badge uni-badge-error uni-small uni-badge--small icon-num">
- {{cartNum}}
- </text>
- <image src='../../../static/icon-cart-active@3x.png' mode="widthFix"></image>
- </view>
- <view class="empty-container" v-if="showEmpty && !fromRegularPurchasePage">
- <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AY2ZjAABpmnBICH4247.png"></image>
- <text class="error-text">{{emptyText}}</text>
- </view>
- <view class="empty-container" v-if="showEmpty && fromRegularPurchasePage">
- <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AWdWzAAGlgAP0das422.png" mode="aspectFit"></image>
- <text class="error-text">您还没有购买过任何商品哟~</text>
- <button class="submit-btn toIndexPage" @click="toIndexPage">去逛逛</button>
- </view>
- <!-- 透明模态层 -->
- <modal-layer v-if='isModallayer'></modal-layer>
- </view>
- </template>
- <script>
- import listSkeleton from '@/components/module/listTemplate/listSkeleton'
- import modalLayer from "@/components/modal-layer"
-
- export default{
- name:'CommodityList',
- components:{
- listSkeleton,
- modalLayer
- },
- props: {
- emptyText: {
- type: String
- },
- },
- data(){
- return{
- isModallayer:false,
- windowHeight: '',
- showSkeleton: true,
- showEmpty: false,
- userID: '',
- loginStatus: true,
- scrollHeight: '',
- commodityList: [],
- showLoading: false,
- loadingNow: true,
- loadingText: '上拉加载更多',
- pageSize: 10,
- pageNum: 1,
- hasNextPage: false,
- totalPage: 1,
- pullFlag: true,
- fromRegularPurchasePage: false,
- cartNum: 0,
- showRegularBtn: false
- }
- },
- created() {
- let self = this;
- self.$api.getStorage().then((resolve) =>{
- self.userID = resolve.userID
- })
- self.setScrollHeight();
- self.$api.loginStatus().then((resolveData) => {
- self.loginStatus = resolveData;
- });
- },
- methods:{
- toLoginPage() {
- const {lastPageType, lastPageVal} = this.$parent;
- uni.navigateTo({
- url:`/pages/user-module/login?listType=${lastPageType}&listVal=${lastPageVal}`
- })
- },
- toLower() {
- // 第一次加载排除常用商品
- if(!this.showRegularBtn) {
- if(this.hasNextPage && this.pullFlag) {
- this.getListFromServer(true);
- }
- }
- },
- setScrollHeight() {
- const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
- this.windowHeight = windowHeight - 1;
- this.scrollHeight = windowHeight - 1;
- },
- getListFromServer(loadMore) {
- let self = this;
- const thisServerurl = self.$parent.serverUrl;
- self.showLoading = true;
- self.loadingNow = true;
- self.loadingText = '加载中';
- if(loadMore) {
- self.pageNum += 1;
- }
- if(self.$parent.lastPageType === '再次购买') {
- self.fromRegularPurchasePage = true;
- }
- self.$api.get(thisServerurl,{index:self.pageNum,pageSize:self.pageSize,
- organizeID:self.userOrganizeID},
- response => {
- const code = response.code;
- if(code == 1) {
- const resData = self.fromRegularPurchasePage ?response.data.page :response.data;
- const resList = resData.results,
- getCartNum = response.data.count;
- this.cartNum = getCartNum > 99 ?'99+' :getCartNum;
- if(!loadMore && self.fromRegularPurchasePage && resData.hasNextPage) {
- self.showRegularBtn = true;
- }
- if(resList && resList.length > 0){
- self.hasNextPage = resData.hasNextPage;
- self.totalPage = resData.totalPage;
- if(loadMore) {
- self.commodityList = [...self.commodityList,...resList];
- self.showRegularBtn = false;
- } else {
- self.commodityList = [...resList];
- self.showSkeleton = false;
- }
- // 防上拉暴滑
- self.pullFlag = false;
- setTimeout(()=>{
- self.pullFlag = true;
- },500)
- // 底部提示文案
- if(self.hasNextPage) {
- self.loadingText = '上拉加载更多';
- } else {
- self.showLoading = true;
- self.loadingNow = false;
- }
- } else {
- if(!loadMore) {
- self.showEmpty = true;
- }
- }
- } else {
- this.$util.msg(response.msg,3000);
- }
- }
- )
- },
- addCartNow(productID, miniQuantity) {
- this.$api.post('/details/addCart',
- {
- productID: productID,
- userID: this.userID,
- productCount: miniQuantity,
- organizeID: this.userOrganizeID
- },
- response => {
- if (response.code == "1") {
- this.$util.msg(response.msg,1500,true,'success');
- this.cartNum = response.data;
- }else{
- this.$util.msg(response.msg,2000);
- }
- }
- )
- },
- navToDetailPage(id) {
- this.isModallayer = true;
- this.$api.navigateTo(`/pages/goods/product?id=${id}`);
- this.isModallayer = false;
- },
- toCartPage() {
- uni.switchTab({
- url: '/pages/tabBar/cart/cart'
- })
- },
- toIndexPage() {
- uni.switchTab({
- url: '/pages/tabBar/home/home'
- })
- }
-
- }
- }
- </script>
- <style lang="scss">
- .commodity-list-wrapper {
- scroll-view {
- height: 100%;
- border-top: 2rpx solid rgba(0,0,0,0.07);
- }
- .empty-container-image {
- margin-top: -300rpx;
- }
- .toIndexPage {
- bottom: 390rpx;
- }
- .show-more-btn {
- width: 276rpx;
- height: 52rpx;
- line-height: 52rpx;
- border: 2rpx solid #D8D8D8;
- background: #F7F7F7;
- font-size: 26rpx;
- margin: 26rpx 0;
- position: absolute;
- left: 50%;
- margin-left: -138rpx;
- }
- }
- .all-type-list-content {
- height: 216rpx;
- padding: 24rpx;
- background: #fff;
- margin-bottom: 2rpx;
- display: flex;
- flex-direction: row;
- box-sizing: content-box;
- .list-img {
- width: 210rpx;
- height: 218rpx !important;
- margin-right: 26rpx;
- border-radius: 10rpx;
- border: 2rpx solid #f3f3f3;
- }
- }
- .list-details-info {
- width: 466rpx;
- display: flex;
- flex-direction: column;
- font-size: 26rpx;
- position: relative;
- .list-details-title {
- line-height: 38rpx;
- text-overflow: ellipsis;
- overflow: hidden;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- line-clamp: 2;
- -webkit-box-orient: vertical;
- }
- .list-details-specs {
- margin-top: 8rpx;
- color: #999999;
- }
- .list-details-miniQuantity {
- margin-top: 7rpx;
- }
- }
- .list-details-price {
- width: 100%;
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- position: absolute;
- bottom: 0;
- right: 0;
- .price-icon {
- width: 22rpx;
- height: 28rpx;
- vertical-align: middle;
- margin-right: 10rpx;
- }
- .price-icon + text {
- font-size: 25rpx;
- vertical-align: middle;
- }
- .list-login-now {
- color: #F8C499;
- position: absolute;
- bottom: 0;
- }
- .login-now {
- padding: 10rpx 10rpx 10rpx 0;
- }
- .list-price {
- color: #FF2A2A;
- .price-larger {
- font-size: 32rpx;
- }
- }
- .add-cart-btn {
- width: 144rpx;
- height: 56rpx;
- line-height: 56rpx;
- color: #fff;
- font-size: 24rpx;
- margin-right: 0;
- background:linear-gradient(45deg,rgba(255,41,41,1) 0%,rgba(255,109,27,1) 100%);
- }
- }
- .cart-icon {
- width: 92rpx;
- height: 92rpx;
- border-radius: 50%;
- background: #E2E2E2;
- position: fixed;
- right: 24rpx;
- bottom: 186rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- cursor: pointer;
- image {
- width: 58rpx;
- height: 58rpx;
- }
- text {
- font-size: 28rpx;
- position: absolute;
- top: -10rpx;
- right: 0;
- }
- }
- </style>
|