金诚优选前端代码
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.
 
 
 
 
 

1231 lines
48 KiB

<template>
<block v-if="microData && microData.micro_page && microData.micro_page.meta">
<lf-nav title="主页" :spreadOut="false" :bgColor="nav_bg_color" :diy="true">
<view class="lf-nav-capsule" @click="$url('/pages/user/member/code')">
<text class="lf-iconfont icon-nv"></text>
<text class="lf-m-l-4">会员</text>
</view>
<view class="lf-nav-capsule" @click="$msg('敬请期待')">
<text class="lf-iconfont icon-nv"></text>
<text class="lf-m-l-4">停车</text>
</view>
<view class="lf-nav-capsule lf-bg-search" @click="$msg('敬请期待')">
<text class="lf-iconfont icon-nv"></text>
<text class="lf-m-l-4">搜索</text>
</view>
</lf-nav>
<view id="microData" :style="{background: microData.micro_page.meta.background_color}">
<!-- #ifdef MP-WEIXIN -->
<!-- <view class="about-program" @tap="changeAbout" v-if="is_show_init">
<image mode="widthFix" v-if="is_show_about" src="https://cdn.ibrand.cc/%E5%85%B3%E4%BA%8E.png"></image>
</view> -->
<!-- #endif -->
<block v-if="microData && microData.pages && microData.pages.length">
<view v-for="(item, index) in microData.pages" :key="index">
<!-- <view v-if="item.name == 'micro_page_componet_search'">
<view class="banner">
<view class="search">
<div class="menu-box" @tap="jumpMenu"><i class="iconfont icon-fenzu"></i></div>
<view class="search_box" @tap="jumpSearch">
<i class="iconfont icon-sousuo " type="search" size="20"></i>
<input type="text" disabled confirm-type="search" placeholder="搜索"/>
</view>
</view>
</view>
</view> -->
<!--轮播图组件-->
<view v-if="item.name == 'micro_page_componet_slide' && item.value && item.value.length">
<indexBanner :banner-data="item.value" :banner-title="item.title" :screen-width="screenWidth" :show="item.is_show_title" :meta="item.meta"></indexBanner>
</view>
<!--优惠券组件-->
<view v-if="item.name == 'micro_page_componet_coupon' && item.value && item.value.length">
<indexCoupon :index-coupon="item.value" :config="config" @myGetCoupon="getCoupon" :show="item.is_show_title" :meta="item.meta"></indexCoupon>
</view>
<!--套餐-->
<view v-if="item.name == 'micro_page_componet_suit' && item.value && item.value.length">
<indexSuit :suit-data="item.value" :index-data="indexData" :show="item.is_show_title" :meta="item.meta"></indexSuit>
</view>
<!--大咖推荐-->
<view v-if="item.name == 'micro_page_componet_article_-' && item.value && item.value.length">
<bigCoffee :coffee-data="item.value" :coffee-title="item.title" :show="item.is_show_title" :meta="item.meta"></bigCoffee>
</view>
<!--专属方案-->
<view v-if="item.name == 'micro_page_componet_article_|' && item.value && item.value.length">
<exclusivePlan :plan-data="item.value" :plan-title="item.title" :show="item.is_show_title" :meta="item.meta"></exclusivePlan>
</view>
<!--健康美丽Tips-->
<view v-if="item.name == 'micro_page_componet_goods_group_change' && item.value && item.value.length">
<healthTips :health-data="item.value" :title="item.title" :show="item.is_show_title" :meta="item.meta"></healthTips>
</view>
<!--猜你喜欢-->
<view v-if="item.name == 'micro_page_componet_guess_like' && item.value && item.value.length">
<waterfallsFlow :water-data="item.value" :title="item.title" :show="item.is_show_title" :meta="item.meta"></waterfallsFlow>
</view>
<!--拼团-->
<view v-if="item.name == 'micro_page_componet_groupon' && item.value && item.value.length">
<indexGroupon :index-data="item.value" :config="config" :server="microData.server_time" typename="拼团" :meta="item.meta"></indexGroupon>
</view>
<!--秒杀-->
<view v-if="item.name == 'micro_page_componet_seckill' && item.value && item.value.length">
<indexSeckill :index-data="item.value" :config="config" :server="microData.server_time" :big-index="index" @:startevent="isStarts" @:endevent="isEnd"
:meta="item.meta"></indexSeckill>
</view>
<!--打call indexCall-->
<view v-if="item.name == 'micro_page_componet_free_event' && item.value && item.value.length">
<indexCall :call-data="item.value" :config="config" :is-login="isLogin" :server="microData.server_time" :meta="item.meta"></indexCall>
</view>
<!--快捷导航-->
<view v-if="item.name == 'micro_page_componet_nav' && item.value && item.value.length">
<indexNav :nav-data="item.value" :meta="item.meta"></indexNav>
</view>
<!-- 今日头条 TODO 暂时借用快捷导航字段判断 -->
<view class="fuwu-tips" v-if="item.name == 'micro_page_componet_nav' && item.value && item.value.length">
<view class="fuwu-tips-title">今日头条</view>
<view>
<text class="fuwu-tips-desc1">来自太阳的宝石-8月生辰石</text>
<!-- <text class="fuwu-tips-desc1">线上商城全场限时包邮</text>
<text class="fuwu-tips-desc2">(部分品牌满额包邮)</text> -->
</view>
</view>
<!-- 活动页入口 TODO -->
<view class="lf-activity" v-if="item.name == 'micro_page_componet_nav' && item.value && item.value.length" @click="$msg('活动页入口')">
<image src="https://picsum.photos/200" mode="aspectFill"></image>
</view>
<!-- TODO 新做秒杀模块 -->
<view v-if="item.name == 'micro_page_componet_nav' && item.value && item.value.length">
<lf-seckill></lf-seckill>
</view>
<!-- TODO 广告活动模块 -->
<view v-if="item.name == 'micro_page_componet_nav' && item.value && item.value.length">
<lf-multi-column-ad></lf-multi-column-ad>
</view>
<!-- TODO 首页发现推荐模块 -->
<view v-if="item.name == 'micro_page_componet_nav' && item.value && item.value.length">
<lf-index-find></lf-index-find>
</view>
<!-- TODO 大牌不停推模块 - 店铺矩阵 -->
<view v-if="item.name == 'micro_page_componet_nav' && item.value && item.value.length">
<lf-index-shop-matrix></lf-index-shop-matrix>
</view>
<!-- TODO 店铺商品展示模块 -->
<view v-if="item.name == 'micro_page_componet_nav' && item.value && item.value.length">
<view class="lf-module-title" @click="$url('/pages/shop/goodsSpecial')">好物种草间</view>
<lf-shop-goods-card v-for="(d_item,d_index) in 2" :key="d_index"></lf-shop-goods-card>
</view>
<!--图片魔方-->
<view v-if="item.name == 'micro_page_componet_cube' && item.value && item.value.length">
<indexCube :cube-data="item.value" :show-type="item.type" :cube-title="item.title" :show="item.is_show_title" :meta="item.meta" :is-agent="userInfo.is_agent"></indexCube>
</view>
<!--分类商品-->
<view v-if="item.name == 'micro_page_componet_category' && item.value && item.value.length">
<indexCategory :category-data="item.value" :meta="item.meta"></indexCategory>
</view>
<!--商品分组-->
<view v-if="item.name == 'micro_page_componet_goods_group' && item.value && item.value.length">
<indexGrouping :grouping-data="item.value" :meta="item.meta"></indexGrouping>
</view>
<!-- TODO 为你推荐模块 -->
<view v-if="item.name == 'micro_page_componet_nav' && item.value && item.value.length">
<view class="lf-module-title">为你推荐</view>
<view style="padding: 0 11px;">
<lf-waterfall :list="recommend_list"></lf-waterfall>
</view>
</view>
</view>
</block>
<view class="author">
<image mode="widthFix" src="https://cdn.guojiang.club/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20200402115441.png"></image>
</view>
<!-- 生日有礼 -->
<view class="is_birthday" v-if="is_showBirth">
<!-- 生日有礼 -->
<birthday :gift-data="giftData" @close="changeBirthday"></birthday>
</view>
<!--新人礼小图标-->
<view class="new-gift" @tap="showModal" v-if="!isLogin && noLoginGift">
<image src="https://ibrand-miniprogram.oss-cn-hangzhou.aliyuncs.com/%E5%B0%8F%E7%A8%8B%E5%BA%8F/new-gift.png" />
</view>
<view class="index-gift-box" v-if="showNoGift">
<view class="mask">
</view>
<view class="box">
<view class="title">
<!--这是优惠券头头-->
<view class="title-info">
<!--领取成功状态-->
<view class="new-success">
<view class="text">
{{noLoginGift.title}}
</view>
<div class="tips">
数量有限,先到先得
</div>
</view>
</view>
<image src="https://ibrand-miniprogram.oss-cn-hangzhou.aliyuncs.com/%E5%B0%8F%E7%A8%8B%E5%BA%8F/X.png" @tap="close"/>
<!--<i class="iconfont icon-cha-"></i>-->
</view>
<view class="coupon-list">
<!--积分-->
<view class="item point" v-if="noLoginGift.point">
<view class="left">
<view class="lable">
赠送积分
</view>
</view>
<view class="right">
{{noLoginGift.point}}
</view>
</view>
<!--优惠券-->
<view class="item" v-for="(item,index) in noLoginGift.gift" :key="index">
<view class="left">
<view class="lable">
{{item.coupon.title}}
</view>
<view class="time">
{{item.coupon.usestart_at}} - {{item.coupon.useend_at}}
</view>
</view>
<view class="right">
{{item.coupon.label}}
</view>
</view>
</view>
<!--@click="login"-->
<view class="buttom" @tap="login">
<span>我知道了</span>
</view>
</view>
</view>
<view class="index-gift-box" v-if="showGift">
<view class="mask">
</view>
<view class="box">
<view class="title">
<!--这是优惠券头头-->
<view class="title-info">
<!--老用户-->
<!--v-if="!loginGift.activity.is_new_user"-->
<view class="new-success" v-if="!loginGift.activity.is_new_user">
<view class="text">
仅限新人领取
</view>
<view class="tips">
你可是老朋友哦
</view>
</view>
<!--抢光了-->
<!--v-if="loginGift.activity.is_new_user && !loginGift.activity.receive_coupon_num && !loginGift.activity.point_status"-->
<view class="new-success" v-if="(loginGift.activity.is_new_user)&&(!loginGift.activity.receive_coupon_num)&&(!loginGift.activity.point_status)">
<view class="text">
抢光了
</view>
<view class="tips">
祝你下次好运,加油哦
</view>
</view>
<!--领取成功-->
<!--v-if="(loginGift.activity.is_new_user && loginGift.activity.receive_coupon_num) || (loginGift.activity.is_new_user && loginGift.activity.point_status)"-->
<view class="new-success" v-if="(loginGift.activity.is_new_user && loginGift.activity.receive_coupon_num) || (loginGift.activity.is_new_user && loginGift.activity.point_status)" >
<view class="text">
领取成功
</view>
<view class="tips">
<!--已放入你的账户-->
已放入你的账户 {{loginGift.user.mobile}}
</view>
</view>
</view>
<image src="https://ibrand-miniprogram.oss-cn-hangzhou.aliyuncs.com/%E5%B0%8F%E7%A8%8B%E5%BA%8F/X.png" @tap="closeGift"/>
<!--@click="closeGift"-->
<!--<i class="iconfont icon-cha-" ></i>-->
</view>
<!--老用户-->
<!--v-if="!loginGift.activity.is_new_user"-->
<view class="coupon-list" v-if="!loginGift.activity.is_new_user">
<!--积分-->
<!--v-if="loginGift.activity.point_status"-->
<view class="item old point" v-if="loginGift.activity.point_status">
<view class="left">
<view class="lable">
<!--赠送积分-->
赠送 {{loginGift.activity.point}} 积分
</view>
</view>
<view class="right">
</view>
</view>
<!--优惠券-->
<!--v-for="item in loginGift.activity.gift"-->
<view class="item old" v-for="(item,index) in loginGift.activity.gift" :key="index">
<div class="left">
<div class="lable">
<!--111-->
{{item.coupon.title}}
</div>
<view class="time">
<!--222-->
{{item.coupon.usestart_at}} - {{item.coupon.useend_at}}
</view>
</div>
<div class="right">
<!--333-->
{{item.coupon.label}}
</div>
</view>
</view>
<!--抢光了-->
<!--v-if="loginGift.activity.is_new_user && !loginGift.activity.receive_coupon_num && !loginGift.activity.point_status"-->
<view class="coupon-list" v-if="(loginGift.activity.is_new_user) && (!loginGift.activity.receive_coupon_num) && (!loginGift.activity.point_status)">
<!--积分-->
<!--v-if="loginGift.activity.point_status"-->
<view class="item point old" v-if="loginGift.activity.point_status">
<view class="left">
<view class="lable">
<!--赠送积分-->
赠送 {{loginGift.activity.point}} 积分
</view>
</view>
<view class="right">
</view>
</view>
<!--优惠券-->
<!--v-for="item in loginGift.activity.gift"-->
<view class="item old" v-for="(item,index) in loginGift.activity.gift" :key="index">
<view class="left">
<view class="lable">
<!--111-->
{{item.coupon.title}}
</view>
<div class="time">
<!--222-->
{{item.coupon.usestart_at}} - {{item.coupon.useend_at}}
</div>
</view>
<div class="right">
<!--333-->
{{item.coupon.label}}
</div>
</view>
</view>
<!--领取成功-->
<!--v-if="(loginGift.activity.is_new_user && loginGift.activity.receive_coupon_num) || (loginGift.activity.is_new_user && loginGift.activity.point_status)"-->
<view class="coupon-list" v-if="(loginGift.activity.is_new_user && loginGift.activity.receive_coupon_num) || (loginGift.activity.is_new_user && loginGift.activity.point_status)">
<!--积分-->
<!--v-if="loginGift.activity.point_status"-->
<view class="item point" v-if="loginGift.activity.point_status">
<view class="left">
<view class="lable">
<!--2331-->
赠送 {{loginGift.activity.point}} 积分
</view>
</view>
<view class="right">
</view>
</view>
<!--优惠券-->
<!--v-for="item in loginGift.activity.gift" v-show="item.is_receive_coupon"-->
<view class="item" v-for="(item,index) in loginGift.activity.gift" :key="index" v-if="item.is_receive_coupon">
<view class="left">
<view class="lable">
<!--222-->
{{item.coupon.title}}
</view>
<view class="time">
<!--333-->
{{item.coupon.usestart_at}} - {{item.coupon.useend_at}}
</view>
</view>
<view class="right">
<!--444-->
{{item.coupon.label}}
</view>
</view>
</view>
<!--@click="closeGift" -->
<view class="buttom" @tap="closeGift">
<span>我知道了</span>
</view>
</view>
</view>
</view>
<!-- 悬浮购物车入口 -->
<view class="fixed-right">
<view class="fixed-btn" hover-class="lf-opacity" @click="$url('/pages/store/cart/cart')">
<text class="lf-iconfont icon-daishouhuo lf-font-50"></text>
<view class="angle-mark">99+</view>
</view>
</view>
<!-- ad广告弹出组件 TODO 暂时先注释 -->
<!-- <lf-ad-modal :value.sync="show_ad"></lf-ad-modal> -->
<!-- 回到顶部组件 -->
<u-back-top :scrollTop="pageScrollTop"></u-back-top>
<!-- tabbar组件 -->
<lf-tabbar />
</block>
</template>
<script>
import {pageLogin, getUrl,config,isBirthday,autoLogin} from '@/common/js/utils.js';
import indexBanner from '@/components/index-banner/index-banner';
import indexCube from '@/components/index-cube/index-cube';
import indexCoupon from '@/components/index-coupon/index-coupon';
import indexSuit from '@/components/index-suit/index-suit';
import bigCoffee from '@/components/big-coffee/big-coffee';
import exclusivePlan from "@/components/exclusive-plan/exclusive-plan";
import healthTips from "@/components/health-tips/health-tips";
import waterfallsFlow from "@/components/waterfalls-flow/waterfalls-flow";
import indexGroupon from "@/components/index-groupon/index-groupon";
import indexSeckill from "@/components/index-seckill/index-seckill";
import indexCall from "@/components/index-call/index-call";
import indexNav from "@/components/index-nav/index-nav";
import indexCategory from "@/components/index-category/index-category";
import indexGrouping from "@/components/index-grouping/index-grouping";
import birthday from '@/components/birthday/birthday.vue';
import lfNav from '@/components/lf-nav/lf-nav.vue';
import lfTabbar from '@/components/lf-tabbar/lf-tabbar.vue';
import lfAdModal from '@/components/lf-adModal/lf-adModal.vue';
import lfIndexFind from '@/components/lf-indexFind/lf-indexFind.vue';
import lfIndexShopMatrix from '@/components/lf-indexShopMatrix/lf-indexShopMatrix.vue';
import lfShopGoodsCard from '@/components/lf-shopGoodsCard/lf-shopGoodsCard.vue';
import lfWaterfall from '@/components/lf-waterfall-shopdetails/lf-waterfall.vue';
import lfMultiColumnAd from '@/components/lf-multiColumnAd/lf-multiColumnAd.vue';
import lfSeckill from '@/components/lf-seckill/lf-seckill.vue';
var app = getApp();
export default {
data() {
return {
giftData:'',
is_showBirth:false,
is_show_about: true,
is_show_init: false,
banner: [],
indexData: {},
goods_arr: [],
topImage: [],
bestSalesGoods: [],
suit: [],
imgHeight: '',
screenWidth: 0,
currentDesc: 'news',
is_newGiftLogin: false,
isLogin: '',
noLoginGift: '',
// 未登录状态下的新人礼信息
loginGift: '',
// 登录状态下的新人礼信息
showNoGift: false,
// 用户是否关闭弹窗
showGift: false,
// 登录状态下是否弹窗
tapIndex: 0,
isShow: false,
goodsIndex: 0,
goodsList: [],
author: '',
scroll: true,
config: {},
wyBanner: '',
wyGoodsList: '',
userInfo: '',
microData:"",
is_login:'',// 是否是登陆状态
show_ad: true, // 是否显示ad广告
nav_bg_color: 'transparent' ,// 导航背景颜色
recommend_list: [
{
id: 10,
original_price: "4111.00",
picture: "https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png",
pictures: ["https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png"],
price: "2412.00",
product_id: 1008,
sale: 0,
title: "三亚悦榕庄(Banyan Tree Sanya Resort and Spa)"
},
{
id: 10,
original_price: "4111.00",
picture: "https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png",
pictures: ["https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png"],
price: "2412.00",
product_id: 1008,
sale: 0,
title: "三亚悦榕庄(Banyan Tree Sanya Resort and Spa)"
},
{
id: 10,
original_price: "4111.00",
picture: "https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png",
pictures: ["https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png"],
price: "2412.00",
product_id: 1008,
sale: 0,
title: "三亚悦榕庄(Banyan Tree Sanya Resort and Spa)"
},
{
id: 10,
original_price: "4111.00",
picture: "https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png",
pictures: ["https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png"],
price: "2412.00",
product_id: 1008,
sale: 0,
title: "三亚悦榕庄(Banyan Tree Sanya Resort and Spa)"
}
]
};
},
// 注册组件
components: {
indexBanner,
indexCube,
indexCoupon,
indexSuit,
bigCoffee,
exclusivePlan,
healthTips,
waterfallsFlow,
indexGroupon,
indexSeckill,
indexCall,
indexNav,
indexCategory,
indexGrouping,
birthday,
lfNav,
lfTabbar,
lfAdModal,
lfIndexFind,
lfIndexShopMatrix,
lfShopGoodsCard,
lfWaterfall,
lfMultiColumnAd,
lfSeckill
},
onShow(e) {
this.isLogin=!!this.$cookieStorage.get('user_token')
let toekn = this.$cookieStorage.get('user_token');
if (toekn) {
this.getUserInfo();
}
this.is_newGiftLogin = app.globalData.giftLogin;
let is_info = this.$cookieStorage.get('gift_info');
if(!this.isLogin){
this.newPeopleGift();
}
if(this.isLogin && !is_info){
this.getPeopleGift();
}
},
// 生命周期
onLoad(e) {
// 第三方平台配置颜色
var gbConfig = this.$cookieStorage.get('globalConfig') || '';
this.config=gbConfig;
if (!gbConfig) {
let extConfig ={};
if (extConfig) {
this.setData({
config: extConfig,
})
}
}
wx.showLoading();
wx.getSystemInfo({
success: res => {
this.screenWidth = String(res.screenWidth);
}
});
this.queryMicroData();
this.init(e);
},
// 页面滚动
onPageScroll(event){
if(event.scrollTop >= 100){
this.nav_bg_color = '#ffffff';
}else{
this.nav_bg_color = 'transparent';
}
},
//下拉刷新
onPullDownRefresh(){
wx.showLoading();
this.queryMicroData();
},
// 方法,需要将小程序的方法都放到这个里面
methods: {
close(){
this.setData({
showNoGift:false
})
var time = new Date(new Date().setHours(0,0,0,0)).getTime() + 86400000;
this.$cookieStorage.set('new_gift', true, time);
},
login(){
pageLogin(getUrl());
},
showModal(){
this.setData({
showNoGift:true
})
},
changeBirthday(){
this.is_showBirth = false;
var gift= this.$cookieStorage.get("birthday_gift");
gift.flag=true;
this.$cookieStorage.set("birthday_gift",gift);
},
changeAbout() {
this.is_show_about = false;
},
// 请求数据
queryMicroData() {
this.$http
.get({
api: 'api/micro/page/index'
})
.then(res => {
if (res.statusCode == 200) {
res = res.data;
if (res.status) {
this.microData = '';
this.microData = res.data;
this.is_show_init = true;
if (res.data && res.data.micro_page) {
wx.setNavigationBarTitle({
title: res.data.micro_page.name
});
}
uni.stopPullDownRefresh();
} else {
wx.showModal({
content: res.message || '请下拉页面刷新重试',
showCancel: false
});
}
} else {
wx.showModal({
content: '请下拉页面刷新重试',
showCancel: false
});
}
wx.stopPullDownRefresh();
wx.hideLoading();
})
.catch(() => {
wx.stopPullDownRefresh();
wx.hideLoading();
wx.showModal({
content: '请求失败',
showCancel: false
});
});
},
// 获取初始化数据
init(e) {
var token = this.$cookieStorage.get('user_token');
var agent_code = '';
if (e.agent_code) {
agent_code = e.agent_code
}
if (e.scene) {
var scene = decodeURIComponent(e.scene);
var sceneArr = scene.split(',');
if (sceneArr.length > 0) {
agent_code = sceneArr[1]
}
}
this.$http.get({
api: 'api/system/init'
}).then(res => {
if (res.statusCode == 200) {
res = res.data;
if (res.status) {
if (res.data && res.data.other_technical_support) {
this.author = res.data.other_technical_support
}
/*wx.setNavigationBarTitle({
title: res.data.mini_home_title
})*/
this.$cookieStorage.set('init_info', res.data.h5_share);
this.$cookieStorage.set('service_info', res.data.online_service_data);
this.$cookieStorage.set('distribution_valid_time', res.data.distribution_valid_time);
this.$cookieStorage.set('init', res.data);
this.setCode(e);
// #ifdef MP-WEIXIN
if (agent_code && res.data.mini_program_login_type == 'default' && !token) {
wx.showLoading({
title: '正在自动登录',
mask: true
})
wx.login({
success: res => {
if (res.code) {
autoLogin(res.code, agent_code)
.then(res => {
if (res.status) {
if (res.data.access_token) {
var access_token = res.data.token_type + ' ' + res.data.access_token;
this.is_login = access_token
}
if (res.data.open_id) {
wx.reLaunch({
url: '/pages/user/agentlogin/agentlogin?agent_code=' + agent_code + '&open_id=' + res.data.open_id + '&url=' + getUrl() + '&is_tab=true'
})
}
}
wx.hideLoading();
}, err => {
wx.hideLoading();
})
} else {
wx.showToast({
title: '获取code失败',
icon: 'none'
})
}
}
})
}
// #endif
// #ifdef H5
if(agent_code && token == ''){
var env = {
isIPad: /ipad/i.test(window.navigator.userAgent),
isIphone: /iphone|ipad|ipod/i.test(window.navigator.userAgent),
isWechat: /MicroMessenger/i.test(window.navigator.userAgent)
}
if(env.isWechat){
if(e.openid){
this.$cookieStorage.set('openid',e.openid)
}
var openid = this.$cookieStorage.get('openid') || e.openid;
if(openid){
this.postNewQuickLogin(openid,agent_code);
} else{
let origin = window.location.origin;
var url = origin+'/pages/index/index/index?agent_code='+agent_code;
window.location.href = this.$config.GLOBAL.baseUrl+'oauth/wxOauth?redirect_url='+encodeURIComponent(url);
}
} else{
wx.navigateTo({
url:'/pages/user/loginType/loginType'
})
}
}
// #endif
} else {
this.setCode(e);
}
} else {
this.setCode(e);
}
})
},
setCode(e) {
const timeMap = {
y: 31536000000,
m: 2592000000,
d: 86400000,
h: 3600000,
n: 60000,
s: 1000
};
// 默认有效期为7天
var valid_time = "";
var clerk_id = e.clerk_id || "";
var shop_id = e.shop_id || "";
var agent_code = e.agent_code || '';
if (e.scene) {
var scene = decodeURIComponent(e.scene);
var sceneArr = scene.split(',');
if (sceneArr.length > 0) {
agent_code = sceneArr[0]
}
}
var cook_shop_id = this.$cookieStorage.get('shop_id');
if (!this.$cookieStorage.get('distribution_valid_time')) {
valid_time = 10080;
} else {
valid_time = this.$cookieStorage.get('distribution_valid_time');
}
let timeStamp = new Date().getTime();
timeStamp += timeMap.n * valid_time;
// 当url上shop_id与缓存中shop_id不一致时,需要清除clerk_id。以此保证shop_id与clerk_id对应
var cook_clerk_id = this.$cookieStorage.get('clerk_id');
if (cook_shop_id != shop_id && cook_clerk_id) {
this.$cookieStorage.clear('clerk_id');
}
if (agent_code) {
this.$cookieStorage.set('agent_code', agent_code, valid_time + 'n');
// 如果有agent_code就将这次进入的时间缓存
this.$cookieStorage.set('agent_code_time', timeStamp, valid_time + 'n');
// 如果有agent_code并且有coupon_agent_code就将coupon_agent_code清除,保证agent_code为第一位
if (this.$cookieStorage.get('coupon_agent_code')) {
this.$cookieStorage.clear('coupon_agent_code')
}
}
if (clerk_id) {
this.$cookieStorage.set('clerk_id', clerk_id, valid_time + 'n');
}
if (shop_id) {
this.$cookieStorage.set('shop_id', shop_id, valid_time + 'n');
// 如果有shop_id就将这次进入的时间缓存
this.$cookieStorage.set('shop_id_time', timeStamp, valid_time + 'n');
}
const code = agent_code || this.$cookieStorage.get('agent_code');
if (code) {
// this.getCodeUser(code);
}
},
postNewQuickLogin(open_id,agent_code){
wx.showLoading({
title: '正在登录',
mask: true
});
this.$http.post({
api:'api/oauth/newQuickLogin',
data:{
open_id:open_id,
agent_code:agent_code
}
}).then(res=>{
res = res.data;
if(res.status){
if(res.data.access_token){
var access_token = res.data.token_type + ' ' + res.data.access_token;
var expires_in = res.data.expires_in || 315360000;
this.$cookieStorage.set("user_token", access_token, expires_in);
//如果用户没有绑定手机号
if(res.data.has_bind_mobile == 0){
wx.reLaunch({
url:'/pages/user/bindingphone/bindingphone'
})
} else{
this.is_login = this.$cookieStorage.get('user_token');
}
} else{
wx.showModal({
content: res.message || '请求失败,请重试',
showCancel: false
});
}
} else{
wx.showModal({
content: res.message || '请求失败,请重试',
showCancel: false
});
}
wx.hideLoading()
}).catch(rej=>{
wx.showModal({
content: rej.message || '请求失败,请重试',
showCancel: false
});
wx.hideLoading()
})
},
// 根据agent_code获取用户信息
getCodeUser(agent_code) {
this.$http.get({
api: '/api/distribution/getAgentInfo',
data: {
agent_code: agent_code
}
}).then(res => {
if (res.statusCode == 200) {
res = res.data;
if (res.status) {
const title = res.data.name + ' X ' + res.data.home_title || '';
wx.setNavigationBarTitle({
title: title
})
}
}
})
},
// 领取优惠券
getCoupon(e) {
var token = this.$cookieStorage.get('user_token');
console.log(e);
var code = e.code;
var index = e.index;
if (token) {
this.convertCoupon(code, index);
} else {
wx.showModal({
content: '请先登录',
showCancel: false,
success: res => {
if (res.confirm || !res.cancel && !res.confirm) {
pageLogin(getUrl());
}
}
});
}
},
// 领取优惠券接口
convertCoupon(code, index) {
var token = this.$cookieStorage.get('user_token');
wx.showLoading({
title: "正在领取",
mask: true
});
this.$http.post({
api: 'api/coupon/convert',
header: {
Authorization: token
},
data: {
coupon_code: code
}
}).then(res => {
if (res.statusCode == 200) {
res = res.data;
if (res.status) {
var pages = this.microData.pages;
pages.forEach((val, idx) => {
if (val.name == 'micro_page_componet_coupon') {
/* this.setData({
[`microData.pages[${idx}].value[${index}].associate.has_get`]: true
}); */
}
});
wx.showToast({
title: '领取成功'
});
} else {
wx.showToast({
title: res.message || '领取失败',
image: '../../../static/error.png'
});
}
wx.hideLoading();
} else {
wx.showToast({
title: '领取失败',
image: '../../../static/error.png'
});
wx.hideLoading();
}
}).catch(rej => {
wx.showToast({
title: '领取失败',
image: '../../../static/error.png'
});
wx.hideLoading();
});
},
jumpToDetail(e){
var id = e.currentTarget.dataset.id
wx.navigateTo({
url:`/pages/store/detail/detail?id=${id}`
})
},
// 获取用户信息
getUserInfo() {
this.$http.get({
api: 'api/me',
header: {
Authorization: this.$cookieStorage.get('user_token')
},
}).then(res => {
if (res.data.status) {
this.userInfo = res.data.data;
if (res.data.data.agent_code) {
// #ifdef MP-WEIXIN
wx.updateShareMenu();
// #endif
if(!res.data.data.gift_is_receive){
isBirthday().then(()=>{
if(this.$cookieStorage.get("birthday_gift")){
var giftData=this.$cookieStorage.get("birthday_gift").data;
this.giftData = giftData;
this.is_showBirth = true;
}
});
}
}
}
})
},
//跳到搜索页面
jumpSearch() {
console.log(3333);
wx.navigateTo({
url: '/pages/store/search/search'
});
},
jumpMenu(e) {
wx.switchTab({
url: '/pages/index/classification/classification'
});
},
jumpStore(e) {
var id = e.currentTarget.dataset.id;
wx.navigateTo({
url: '/pages/store/detail/detail?id=' + id
});
},
// 新人进店有礼
newPeopleGift(){
this.$http.get({
api:'api/home/gift_new_user'
}).then(res=>{
res=res.data;
if(res.status && res.data){
var cache_no_gift = this.$cookieStorage.get('new_gift');
res.data.gift.forEach(function(val){
val.coupon.usestart_at=val.coupon.usestart_at.replace(/\s.+$/, '')
val.coupon.useend_at=val.coupon.useend_at.replace(/\s.+$/, '');
});
this.setData({
noLoginGift:res.data
});
if(!cache_no_gift){
this.setData({
showNoGift:true
})
}
}
});
},
// 新人进店有礼(已登录)
getPeopleGift(){
this.$http.post({
api:'api/home/gift_new_user',
header:{
Authorization:this.$cookieStorage.get('user_token')
}
}).then(res=>{
res=res.data;
var cache_info = this.$cookieStorage.get('gift_info');
if(res.status && res.data && !cache_info){
// 判断是不是老用户
if(!res.data.activity.is_new_user){
if(this.is_newGiftLogin){
res.data.activity.gift.forEach(function(val){
val.coupon.usestart_at=val.coupon.usestart_at.replace(/\s.+$/, '');
val.coupon.useend_at=val.coupon.useend_at.replace(/\s.+$/, '');
});
this.setData({
showGift:true,
loginGift:res.data
});
}else{
this.closeGift();
}
}
else{
res.data.activity.gift.forEach(function(val){
val.coupon.usestart_at=val.coupon.usestart_at.replace(/\s.+$/, '');
val.coupon.useend_at=val.coupon.useend_at.replace(/\s.+$/, '');
});
this.setData({
showGift:true,
loginGift:res.data
})
}
}
else{
}
})
},
closeGift(){
this.$cookieStorage.set('gift_info',true);
this.setData({
showGift:false
})
},
setData: function (obj) {
let that = this;
let keys = [];
let val, data;
Object.keys(obj).forEach(function (key) {
keys = key.split('.');
val = obj[key];
data = that.$data;
keys.forEach(function (key2, index) {
if (index + 1 == keys.length) {
that.$set(data, key2, val);
} else {
if (!data[key2]) {
that.$set(data, key2, {});
}
}
data = data[key2];
});
});
}
}
};
</script>
<style rel="stylesheet/less" lang="less">
/*@import "index.less";*/
.lf-bg-search{
background-color: rgba(0,0,0,0.5) !important;
}
.lf-nav-capsule{
width: 120rpx;
height: 50rpx;
background-color: #186c6b;
font-size: 24rpx;
display: flex;
align-items: center;
justify-content: center;
color: #FFFFFF;
border-radius: 40rpx;
margin-right: 14rpx;
}
.lf-m-l-4{
margin-left: 4rpx;
}
.fuwu-tips{
width: 686rpx;
height: 70rpx;
background-color: #eff6f7;
margin: 60rpx auto 0;
display: flex;
// justify-content: space-between;
box-sizing: border-box;
align-items: center;
padding: 0 30rpx;
border-radius: 40rpx;
.fuwu-tips-title{
font-size: 36rpx;
color: #186c6b;
margin-right: 15rpx;
font-weight: bold;
font-family: '华文行楷';
}
.fuwu-tips-desc1{
font-size: 28rpx;
color: #222222;
}
.fuwu-tips-desc2{
font-size: 22rpx;
color: #777777;
}
}
.lf-activity{
width: 686rpx;
height: 350rpx;
margin: 60rpx auto 0;
border-radius: 10rpx;
overflow: hidden;
&>image{
width: 100%;
height: 100%;
}
}
.lf-module-title{
font-size: 36rpx;
font-weight: bold;
text-align: center;
color: #222222;
margin-bottom: 30rpx;
margin-top: 60rpx;
}
.fixed-right{
position: fixed;
right: 32rpx;
bottom: 300rpx;
width: max-content;
height: max-content;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
z-index: 9;
.fixed-btn{
width: 100rpx;
height: 100rpx;
border-radius: 50%;
background-color: #15716E;
display: flex;
justify-content: center;
align-items: center;
color: #FFFFFF;
position: relative;
.angle-mark{
position: absolute;
right: 4rpx;
top: 4rpx;
width: 40rpx;
height: 40rpx;
background-color: #007AFF;
border-radius: 50%;
font-size: 20rpx;
display: flex;
justify-content: center;
align-items: center;
}
}
}
</style>