123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664 |
- <template>
- <view class="container" style="padding-bottom: 100rpx">
- <view class="no-login" v-if="!hasLogin">
- <view class="c">
- <text>您还没有注册</text>
- <button open-type="getUserInfo" @getuserinfo="goLogin">点击授权登录</button>
- </view>
- </view>
- <view class="login" v-else>
- <view class="search">
- <navigator url="/pages/category/search/search" class="input">
- <!-- <van-icon name="search" size="16px" /> -->
- <image src="https://mall.zhaijieshi.cc/file/wx-dy/icon-search-grey.png" class="img" mode="aspectFit"></image>
- <text class="txt">商品搜索, 共{{ goodsCount }}款好物</text>
- </navigator>
- </view>
- <view class="catalog">
- <scroll-view class="nav" :scroll-y="true">
- <view
- :class="'item ' + (currentCategory.id == item.id ? 'active' : '')"
- :data-id="item.id"
- :data-index="index"
- :data-name="item.name"
- @tap="switchCate"
- v-for="(item, index) in categoryList"
- :key="index"
- >
- <text class="text">{{ item.name }}</text>
- </view>
- </scroll-view>
- <scroll-view class="cate" :scroll-y="true">
- <navigator url="/pages/servant/servantList/servantList" class="banner" v-if="currentCategory.name == '保姆/月嫂'">
- <image class="category-banner" mode="aspectFill" :src="currentCategory.picUrl"></image>
- </navigator>
- <view v-if="goodsList.length > 0" v-for="(category, idx) in goodsList" :key="idx">
- <view class="hd">
- <text class="txt">{{ category.name }}</text>
- <view class="grey-devide"></view>
- <view class="blue-devide"></view>
- </view>
- <view class="a-section a-popular">
- <view class="b category-line">
- <view class="item" v-for="(item, index) in category.goodsList" :key="index">
- <navigator :url="'/pages/goods/goods?id=' + item.id" class="product-item">
- <image class="img" :src="item.picUrl + '?w=200'" mode="aspectFit"></image>
- <view class="product-name">{{ item.name }}</view>
- </navigator>
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- </view>
- </view>
- </template>
- <script>
- var util = require('../../../utils/util.js');
- var api = require('../../../config/api.js');
- const user = require('../../../utils/user.js');
- const area = require('../../../utils/area.js');
- //获取应用实例
- const app = getApp();
- export default {
- data() {
- return {
- categoryList: [],
- currentCategory: {
- id: '',
- name: '',
- picUrl: ''
- },
- currentSubCategoryList: {},
- scrollLeft: 0,
- scrollTop: 0,
- goodsList: [],
- goodsCount: 0,
- scrollHeight: 0,
- hasLogin: true,
- city: '',
- //当前业务城市
- citys: [],
- cityIndex: 0,
- addressInfo: {},
- category: {
- name: '',
- goodsList: []
- }
- };
- },
- onLoad: function (options) {
- // this.getCatalog();
- },
- onPullDownRefresh() {
- uni.showNavigationBarLoading(); //在标题栏中显示加载
- this.getCatalog();
- uni.hideNavigationBarLoading(); //完成停止加载
- uni.stopPullDownRefresh(); //停止下拉刷新
- },
- onReady: function () {
- // 页面渲染完成
- if (app.globalData.hasLogin) {
- this.setData({
- hasLogin: true
- });
- }
- },
- onShow: function () {
- // 页面显示
- //显示购物车角标
- //user.cartshow();
- //确定业务城市
- var addressInfo = uni.getStorageSync('addressInfo');
- console.info(addressInfo);
- if (addressInfo) {
- this.setData({
- addressInfo: addressInfo
- });
- } else {
- //手机性能慢,可能首页接口没初始化完毕
- let that = this;
- setTimeout(() => {
- var addressInfo = uni.getStorageSync('addressInfo');
- if (addressInfo) {
- that.setData({
- addressInfo: addressInfo
- });
- }
- }, 500);
- }
- this.getCatalog();
- },
- onHide: function () {
- // 页面隐藏
- },
- onUnload: function () {
- // 页面关闭
- },
- methods: {
- listenerCitySelected(e) {
- this.setData({
- cityIndex: e.detail.value,
- city: this.citys[e.detail.value]
- });
- app.globalData.city = this.city;
- },
- getCatalog: function () {
- //CatalogList
- let that = this;
- var addressInfo = uni.getStorageSync('addressInfo');
- that.setData({
- city: addressInfo.city
- });
- uni.showLoading({
- title: '加载中...'
- });
- util.request(api.CatalogList, {
- shopId: addressInfo.shopId,
- city: addressInfo.city
- }).then(function (res) {
- //1036763 写死值 如果地址不是苏州市 隐藏活动专享
- //20220223关闭所有活动合作专区
- //console.info(res.data.categoryList)
- var list = res.data.categoryList;
- that.setData({
- categoryList: list,
- currentCategory: res.data.currentCategory,
- currentSubCategoryList: res.data.currentSubCategory
- });
- that.getCategoryGoods();
- uni.hideLoading();
- });
- util.request(api.GoodsCount).then(function (res) {
- that.setData({
- goodsCount: res.data
- });
- });
- },
- getCategoryGoods() {
- //获取一级类目下所有商品
- let that = this;
- util.request(api.GoodsL1Category, {
- id: that.currentCategory.name == '热销商品' ? '-1' : that.currentCategory.id,
- shopId: that.addressInfo.shopId,
- isHot: that.currentCategory.name == '热销商品' ? true : false,
- city: that.city
- }).then((res) => {
- console.info(res.data);
- that.setData({
- goodsList: res.data
- });
- });
- },
- getCurrentCategory: function (id) {
- let that = this;
- util.request(api.CatalogCurrent, {
- id: id
- }).then(function (res) {
- that.setData({
- currentCategory: res.data.currentCategory,
- currentSubCategoryList: res.data.currentSubCategory
- });
- that.getCategoryGoods();
- });
- },
- goLogin: function (e) {
- if (e.detail.userInfo == null) {
- app.globalData.hasLogin = false;
- util.showErrorToast('微信授权失败');
- return;
- }
- app.globalData.hasLogin = false;
- uni.setStorageSync('userInfo', null);
- user.loginByWeixin(e.detail.userInfo)
- .then((res) => {
- //跳转注册页
- uni.navigateTo({
- url: '/pages/auth/register/register'
- });
- })
- .catch((err) => {
- app.globalData.hasLogin = false;
- });
- },
- switchCate: function (event) {
- var that = this;
- var currentTarget = event.currentTarget;
- if (this.currentCategory.id == event.currentTarget.dataset.id) {
- return false;
- }
- this.getCurrentCategory(event.currentTarget.dataset.id);
- },
- goinviteFriends(e) {
- console.log(app.globalData.hasLogin);
- //跳转到邀请页面
- if (app.globalData.hasLogin) {
- uni.navigateTo({
- url: '/pages/activity/invitefriends/inviteFriends'
- });
- } else {
- uni.navigateTo({
- url: '/pages/auth/login/login'
- });
- }
- }
- }
- };
- </script>
- <style>
- page {
- color: #2A2A2A; /*主要颜色*/
- font-size: 28rpx;
- background:#f5f5f5;
- }
- .container {
- height: 100%;
- width: 100%;
- display: flex;
- flex-direction: column;
- }
- .adv {
- position: fixed;
- left: 0rpx;
- bottom: 0;
- z-index: 100;
- width: 750rpx;
- height: 165rpx;
- display: flex;
- /* border: 1px solid red; */
- }
- .search {
- /* height: 98rpx;
- width: 100%; */
- margin-bottom: 6rpx;
- padding: 0 30rpx;
- display: flex;
- align-items: center;
- width: 750rpx;
- height: 116rpx;
- /* background: #ffffff; */
- box-shadow: 0px 4rpx 8rpx 0px rgba(245, 246, 250, 0.72);
- }
- .search .input {
- width: 690rpx;
- height: 76rpx;
- /* background: #f5f6fa; */
- background: #fff;
- border-radius: 76rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- color: #bec0c5;
- font-size: 26rpx;
- }
- .search .img {
- width: 24rpx;
- height: 24rpx;
- margin-right: 20rpx;
- }
- .search .txt {
- font-size: 24rpx;
- /* padding:0 0 0 14rpx; */
- }
- .login {
- height: 100%;
- /* margin-bottom: 380rpx; */
- }
- .catalog {
- flex: 1;
- width: 100%;
- /* background: #fff; */
- display: flex;
- /* border-top: 1px solid #fafafa; */
- height: 100%;
- /* line-height: 100%; */
- }
- .catalog .nav {
- /* width: 176rpx;
- height: 100%;
- background: #f5f6fa; */
- width: 162rpx;
- height: 100%;
- background:#EDEDED;
- }
- .catalog .nav .item {
- text-align: center;
- line-height: 76rpx;
- width: 176rpx;
- height: 76rpx;
- color: #333;
- font-size: 26rpx;
- /* border-left: 4rpx solid #fff; */
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .catalog .nav .item .text {
- width: 148rpx;
- overflow: hidden;
- text-overflow: ellipsis;
- font-size: 26rpx;
- white-space: nowrap;
- margin-left: 8rpx;
- }
- .catalog .nav .item.active .text {
- flex: 1;
- text-align: center;
- }
- .catalog .nav .item.active {
- /* font-size: 28rpx; */
- /*border-left: 6rpx solid #ab956d;*/
- /* border-left: 4rpx solid #09afff; */
- /* color: #00c0ff;
- background: url('https://mall.zhaijieshi.cc/file/wx-dy/cate-bg.png') no-repeat center center;
- justify-content: flex-start;
- height: 130rpx;
- background-size: 175rpx 130rpx; */
- font-size: 28rpx;
- border-left: 4rpx solid #09afff;
- color: #09afff;
- background:#f5f5f5;
-
- }
- .catalog .cate {
- /* border-left: 1px solid #fafafa; */
- flex: 1;
- height: 100%;
- padding: 0 20rpx 0 10rpx;
- overflow-x: hidden;
- box-sizing: border-box;
- }
- .banner {
- display: block;
- height: 212rpx;
- width: 100%;
- position: relative;
- }
- .banner .category-banner {
- /* position: absolute;
- top: 30rpx;
- left: 0; */
- border-radius: 8rpx;
- height: 212rpx;
- width: 566rpx;
- }
- .banner .txt {
- position: absolute;
- top: 30rpx;
- text-align: center;
- color: #fff;
- font-size: 28rpx;
- left: 0;
- height: 192rpx;
- line-height: 192rpx;
- width: 100%;
- }
- .catalog .hd {
- /* height: 64rpx; */
- width: 568rpx;
- display: flex;
- align-items: center;
- margin:20rpx 0 24rpx ;
- flex-direction: column;
- }
- .grey-devide{
- width:568rpx;
- height:2rpx;
- background: #D3D2C7;
- }
- .blue-devide{
- width:98rpx;
- height:2rpx;
- background: #09AFFF;
- margin-top:-2rpx;
- }
- .catalog .hd .txt {
- font-size: 26rpx;
- padding: 0 6rpx;
- height:30rpx;
- margin-bottom:8rpx;
- line-height: 30rpx;
- }
- .catalog .hd .line {
- width: 100%;
- height: 1px;
- background: #d9d9d9;
- position: absolute;
- z-index: 1;
- }
- .catalog .bd {
- height: auto;
- width: 100%;
- overflow: hidden;
- }
- .catalog .bd .item {
- display: block;
- float: left;
- height: 216rpx;
- width: 144rpx;
- margin-right: 34rpx;
- }
- .catalog .bd .item.last {
- margin-right: 0;
- }
- .catalog .bd .item .icon {
- height: 144rpx;
- width: 144rpx;
- }
- .catalog .bd .item .txt {
- display: block;
- text-align: center;
- font-size: 24rpx;
- color: #333;
- height: 72rpx;
- width: 144rpx;
- }
- .no-login {
- width: 100%;
- height: auto;
- margin: 0 auto;
- background-color: #fff;
- }
- .no-login .c {
- width: 100%;
- height: auto;
- margin-top: 400rpx;
- }
- .no-login .c text {
- margin: 0 auto;
- display: block;
- width: 258rpx;
- height: 59rpx;
- line-height: 29rpx;
- text-align: center;
- font-size: 35rpx;
- }
- .no-login button {
- width: 90%;
- margin: 0 auto;
- color: #fff;
- font-size: 30rpx;
- height: 96rpx;
- line-height: 96rpx;
- right: 0;
- display: flex;
- justify-content: center;
- align-items: center;
- position: flex;
- bottom: 0;
- left: 0;
- border-radius: 0;
- padding: 0;
- margin-left: 5%;
- text-align: center;
- border-top-left-radius: 50rpx;
- border-bottom-left-radius: 50rpx;
- border-top-right-radius: 50rpx;
- border-bottom-right-radius: 50rpx;
- letter-spacing: 3rpx;
- background-image: linear-gradient(to right, #9a9ba1 0%, #9a9ba1 100%);
- }
- .a-popular {
- width: 570rpx;
- height: auto;
- overflow: hidden;
- }
- /* .a-popular .b .item {
- border-bottom: 1px solid #d9d9d9;
- margin: 0 20rpx;
- height: 284rpx;
- width: 588rpx;
- padding-top: 20rpx;
- } */
- .a-popular .b .img {
- width: 170rpx;
- height: 174rpx;
- border-radius: 10rpx;
- margin:0 0 10rpx 0;
- }
- .a-popular .b .right {
- float: left;
- height: 264rpx;
- width: 336rpx;
- display: flex;
- flex-flow: row nowrap;
- }
- .a-popular .b .text {
- display: flex;
- flex-wrap: nowrap;
- flex-direction: column;
- /* justify-content: center; */
- overflow: hidden;
- height: 264rpx;
- width: 280rpx;
- }
- .a-popular .b .name {
- width: 280rpx;
- display: block;
- color: #333;
- line-height: 72rpx;
- font-size: 36rpx;
- }
- .a-popular .b .desc {
- width: 280rpx;
- display: block;
- color: #a98f76;
- line-height: 50rpx;
- font-size: 25rpx;
- height: 120rpx;
- }
- .a-popular .b .price {
- width: 280rpx;
- display: block;
- color: darkred;
- /*color: #a81d28;*/
- line-height: 50rpx;
- font-size: 33rpx;
- }
- .a-popular .b .price span {
- font-size: 24rpx;
- color: gray;
- }
- .a-popular .b .price .btn {
- width: 120rpx;
- border-radius: 30rpx;
- height: 54rpx;
- line-height: 54rpx;
- font-size: 28rpx;
- background-color: #09afff;
- color: #fff;
- text-align: center;
- float: right;
- /* margin-right: 10rpx; */
- margin-top: -10rpx;
- }
- .a-popular .b .brand {
- font-size: 20rpx;
- color: #a98f76;
- display: block;
- line-height: 30rpx;
- padding: 2rpx;
- }
- .category-line {
- display: flex;
- flex-wrap: wrap;
- }
- .product-item{
- display: flex;
- flex-direction: column;
- align-items: center;
- width:170rpx;
- margin:0 20rpx 40rpx 0;
- }
- .product-name{
- width:166rpx;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- text-overflow: ellipsis;
- overflow: hidden;
- font-size: 20rpx;
- text-align: center;
- }
- .nav .active-img {
- width: 8rpx;
- height: 50rpx;
- }
- .nav .hot-img {
- width: 24rpx;
- height: 24rpx;
- margin: 0 0rpx 0 12rpx;
- }
- </style>
|