123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <template>
- <view class="search-container">
- <go-search :theme="themeClass" @getSearchText="getSearchText"></go-search>
- <view class="container commodity-list-wrapper" v-if="isShowWrapper" :style="{'overflow':'auto','height': 'auto'}">
- <scroll-view :style="{'height':scrollHeight+'px'}" @scrolltolower="toLower" scroll-y v-if="!showEmpty">
- <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>
- </view>
- </view>
- </view>
- <view v-if="showLoading && commodityList.length > 4">
- <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="empty-container" v-if="showEmpty">
- <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/8D/Cmis215XHXWAHCoqAAELHadZ9Xg365.png"></image>
- <text class="error-text">抱歉,没有相关商品!</text>
- </view>
- <!-- 透明模态层 -->
- <modal-layer v-if='isModallayer'></modal-layer>
- </view>
- </view>
- </template>
- <script>
- import goSearch from '@/components/uni-search/go-search.vue'
- import modalLayer from "@/components/modal-layer"
- import authorize from '@/config/authorize.js'
- export default {
- components: {
- goSearch,
- modalLayer
- },
- data() {
- return {
- themeClass: 'block',
- searchInputVal:'',
- isShowWrapper:false,
- 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,
- }
- },
- created() {
- let self = this;
- self.$api.getStorage().then((resolve) =>{
- self.userID = resolve.userID
- })
- self.setScrollHeight();
- self.$api.loginStatus().then((resolveData) => {
- self.loginStatus = resolveData;
- });
- },
- onLoad() {
-
- },
- methods:{
- getSearchText(e) {
- this.searchInputVal = e
- this.getListFromServer(false)
- },
- toLoginPage() {
- const {lastPageType, lastPageVal} = this.$parent;
- uni.navigateTo({
- url:`/pages/login/login?listType=${lastPageType}&listVal=${lastPageVal}`
- })
- },
- toLower() {
- // 第一次加载排除常用商品
- 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;
- self.showLoading = true;
- self.loadingNow = true;
- self.loadingText = '加载中';
- self.showEmpty = false;
- if(loadMore) {
- self.pageNum += 1;
- }
- authorize.getCode('weixin').then(wechatcode =>{
- let params = {code:wechatcode,searchWord:self.searchInputVal,index:self.pageNum,pageSize:self.pageSize,organizeID:self.userOrganizeID}
- self.$api.lodingGet('/search/product',params,
- response => {
- if(response.code == '1') {
- this.isShowWrapper = true
- const resData = response.data;
- const resList = resData.results;
- if(resList && resList.length > 0){
- self.hasNextPage = resData.hasNextPage;
- self.totalPage = resData.totalPage;
- self.showEmpty = false;
- if(loadMore) {
- self.commodityList = [...self.commodityList,...resList];
- } else {
- self.commodityList =[];
- self.commodityList = [...resList];
- self.showSkeleton = false;
- }
- console.log(self.commodityList)
- // 防上拉暴滑
- 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);
- }
- }
- )
- })
- },
- navToDetailPage(id) {
- this.isModallayer = true;
- this.$api.navigateTo(`/pages/goods/product?id=${id}`);
- this.isModallayer = false;
- }
- }
- }
- </script>
- <style lang="scss">
- page{
- background-color: #F7F7F7 !important;
- }
- .commodity-list-wrapper {
- scroll-view {
- height: 100%;
- }
- .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;
- }
- }
- }
- </style>
|