const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {} let ifStoreApp = extConfig.attr.ifStoreApp; const navigationBarHeight = (getApp().statusBarHeight + 60) + 'px' const Http = require("../utils/HttpBasics"); const imgurl = require("../utils/imgurl"); const config = require("../config/config"); const QR = require("../utils/memberqrcode.js"); const util = require("../utils/util"); const bgColor = require("../utils/bgColor.js") let app = getApp(); Page({ data: { showLocationIf: true, ifStoreApp: ifStoreApp, navigationBarTitle: '首页', navigationBarHeight, chengzhangBox: bgColor.colorFirst.main.chengzhangBox, activeColor: bgColor.colorFirst.main.activeColor, qg: bgColor.colorFirst.main.qg, newUrl: "", cover: "", kanjia: imgurl.kanjia.url, pintuan: imgurl.pintuan.url, xiaofeika: imgurl.xiaofeika.url, xingyun: imgurl.xingyun.url, jfshangcheng: imgurl.jfshangcheng.url, toutiao: imgurl.toutiao.url, more: imgurl.more.url, giftHr: imgurl.giftHr.url, giftHr: imgurl.giftHr.url, next: imgurl.next.url, usergift: imgurl.usergift.url, guanbi1: imgurl.guanbi1.url, icon0001: imgurl.icon0001.url, icon0002: imgurl.icon0002.url, icon0003: imgurl.icon0003.url, icon0004: imgurl.icon0004.url, icon0005: imgurl.icon0005.url, icon0006: imgurl.icon0006.url, icon0007: imgurl.icon0007.url, icon0008: imgurl.icon0008.url, barcode: imgurl.barcode.url, leftarrows: imgurl.leftarrows.url, newcard: imgurl.newcard.url, newseckill: imgurl.newseckill.url, newbargain: imgurl.newbargain.url, newgroup: imgurl.newgroup.url, product: imgurl.product.url, barginicon: imgurl.barginicon.url, pintuan: imgurl.pintuan.url, live: imgurl.live.url, duihuan: imgurl.duihuan.url, market: app.globalData.market, list: [], xslist: [], loading: true, fistLogin: null, alphaData: null, alphaData1: null, swiperCurrent: 0, title: null, weappShareTitle: '', //分享标题 weappShareCoverImg: '', //分享图片 desc: null, scrollTop: 0, showGame: false, showTopic: false, showQg: false, gamedata: {}, couponId: '', //游戏返回时传回的字段 played: false, //从游戏页面跳回首页返回true havePlayEd: app.globalData.havePlayEd, havePlayEd1: app.globalData.havePlayEd1, staticGamedata: {}, showIf: false, showPages: false, display: 'none', display1: 'none', optionsData: null, page: 1, // 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载 openId: '', showGg: false, ggdata: {}, liveFlag: 0, //直播按钮显隐标志位 squareName: "", //当前广场 isShowSqare: false, }, //获取当前广场名 //跳转到其他广场列表 goSquareList() { wx.navigateTo({ url: '/pages/location/location', }) }, goLive() { wx.navigateTo({ url: '/pages2/live/livelist/index', }) }, alphaClick1: function(even) { var animation = wx.createAnimation({}) animation.opacity(0).step({ duration: 2000 }) this.setData({ alphaData: animation.export() }) }, alphaClick: function(even) { var animation = wx.createAnimation({}) animation.opacity(0).step({ duration: 2000 }) this.setData({ alphaData1: animation.export() }) }, // 我的卡包 mycard: function() { wx.navigateTo({ url: '/pages/cardorder/index/index', }) }, //我的券包 mycoupon: function() { wx.navigateTo({ url: '/pages/couponorder/index/index', }) }, gotoSpellGroup: function() { wx.navigateTo({ url: '/pages/spellGroup/spellGroup', }) }, qrcode: function() { var that = this; let memberId = that.data.memberId; if (memberId) { wx.navigateTo({ url: '/pages/specialcourtesy/specialcourtesy' }) } }, //跳往限时秒杀 gotoRushBuy: function() { wx.navigateTo({ url: '/pages/rushToBuy/index', }) }, swiperChange: function(e) { this.setData({ swiperCurrent: e.detail.current }); }, gotogame: function() { let that = this; if (!that.data.showIf) { wx.showToast({ title: '暂无游戏频道', icon: "none", duration: 3000 }) } else { Http.get({ url: config.api.checkPhoneStatus, data: {} }) .then(res => { var data = { couponChannelId: "" + that.data.couponChannelId, couponId: "" + that.data.couponId }; if (that.data.couponChannelId == null) { var data = { couponId: "" + that.data.couponId }; } wx.redirectTo({ url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId, }) }) .catch(err => { if (err.code == 11005) { // 用户手机未授权 /** * 将值传到用户手机号授权的页面 * */ wx.redirectTo({ url: "/pages/getphoneInfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId, }); } else if (err.code == 11006) { // 用户手机已加密 wx.redirectTo({ url: "/pages/phoneinput/phoneinput?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId, }); } else { wx.showToast({ title: err.message, icon: 'none', duration: 2000, mask: false }); } }) } }, mySpecial: function() { console.log("special"); wx.navigateTo({ url: '/pages/specialcourtesy/specialcourtesy', }) }, //是否属于集团 ifShowSqare() { if (wx.getStorageSync("squareList")) { this.setData({ isShowSqare: true }) } else { this.setData({ isShowSqare: false }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onLoad: function(options) { this.getLocation(); let that = this; let optionss; let openId = wx.getStorageSync('openId') if (openId) { that.setData({ openId: openId }) } if (wx.getStorageSync('options')) { optionss = JSON.parse(wx.getStorageSync('options')); } if (options.played == "true") { that.setData({ played: true }) } if (optionss && optionss.couponChannelId || optionss && optionss.orderId) { that.setData({ optionsData: optionss }) that.getWeapNote(optionss.couponChannelId, optionss.orderId); } else { that.getWeapNote() } //获取条形码 // util.barcode("barcode", optionss.quancode, 510, 100); // console.log(Http.headers.token, "?") }, /** * 获得经纬度 */ getLocation() { let that = this; wx.getLocation({ type: "wgs84", success: function(res) { console.log(res, 9999) if (res && res.longitude && res.latitude) { Http.post({ url: config.api.updateLBS, data: { latitude: res.latitude, longitude: res.longitude } }).then(res => { console.log(res, 9999) }) } }, fail: error => { console.log(error); } }) }, onUnload() { wx.removeStorageSync('squareList') }, onShow: function() { this.ifShowSqare(); if (wx.getStorageSync("squareList")) { var temp = wx.getStorageSync("squareList").filter(item => item.tenantId == wx.getStorageSync("selectedMall"))[0].name this.setData({ squareName: temp }) } if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 0 }) } let that = this; that.setData({ havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false, havePlayEd1: app.globalData.havePlayEd1 ? app.globalData.havePlayEd1 : false }) /** * couponNum 是否有普通的优惠券购买 * couponNum2 是否有新买的消费卡 */ let num = wx.getStorageSync('couponNum'); let num1 = wx.getStorageSync('couponNum2'); if (num == 'couponNum' || num1 == 'couponNum2') { wx.showTabBarRedDot({ index: 3 }) } else { wx.hideTabBarRedDot({ index: 3 }) } if (app.globalData.score) { that.setData({ fistLogin: app.globalData.score }) } // 如果有游戏 setTimeout(function() { that.alphaClick(); }, 8000) // 如果有广告 setTimeout(function() { // debugger that.alphaClick1(); }, 8000) }, getmemberId: function(token) { let that = this; Http.get({ url: config.api.getScore, data: { token: token } }).then(res => { that.setData({ levelName: res.data.levelName, upgradePercent: res.data.upgradePercent, upgradeScore: res.data.upgradeScore, memberId: res.data.id, }) }) .catch(err => { wx.showModal({ title: '提示', content: err.message, showCancel: false }) }) }, gotoChengzhangzhi: function() { wx.navigateTo({ url: '/pages/czdetail/czdetail', }) }, gotoBargain: function() { wx.navigateTo({ url: '/pages/bargain/bargain', }) }, gotoSpellGroup: function() { wx.navigateTo({ url: '/pages/spellGroup/spellGroup', }) }, gotoCard: function() { wx.navigateTo({ url: '/pages/discountCardList/discountCardList', }) }, // gotoGame: function () { // wx.navigateTo({ // url: '/pages/game/index', // }) // }, gotoJfsc: function() { wx.navigateTo({ url: '/pages/integralmall/index', }) }, /** * * @param {code,page} * 子组件向父组件传值 */ onGetCode: function(e) { this.setData({ code: e.detail.val, page: e.detail.pageNum, }); console.log(e.detail.val) console.log(e.detail.pageNum) }, getWeapNote: function(couponChannelId, couponId, orderId) { var that = this; if (app.globalData.token){ // 登录 console.log(app.globalData.token) that.getmemberId(app.globalData.token); that.getBannerlist(); that.topicShow(); that.getxsList(); that.getMallInfo(app.globalData.token); if (app.couponChannelListCallback) { app.couponChannelListCallback(app.globalData.token); } if (app.couponListCallback) { app.couponListCallback(app.globalData.token); } if (app.businessListCallback) { app.businessListCallback(app.globalData.token); } Http.get({ url: config.api.getWeapNote, data: { appId: config.weapp.AppId, } }) .then(res => { console.log(33333333333) console.log(app.globalData.token) console.log(res) console.log(33333333333) // that.getGameOne(app.globalData.token) that.getStaticGame(app.globalData.token) that.getGg(app.globalData.token) let weapNote = JSON.parse(res.data.weapNote); that.setData({ desc: weapNote.firstpage.desc, title: weapNote.firstpage.title }) }) .catch(err => { // that.getGameOne(app.globalData.token) that.getStaticGame(app.globalData.token) that.getGg(app.globalData.token) wx.showModal({ title: "提示", content: err.errMsg, showCancel: false }); }); }else{ app.tokenCallback = token => { // 登录 console.log(app.globalData.token) that.getmemberId(app.globalData.token); that.getBannerlist(); that.topicShow(); that.getxsList(); that.getMallInfo(app.globalData.token); if (app.couponChannelListCallback) { app.couponChannelListCallback(app.globalData.token); } if (app.couponListCallback) { app.couponListCallback(app.globalData.token); } if (app.businessListCallback) { app.businessListCallback(app.globalData.token); } Http.get({ url: config.api.getWeapNote, data: { appId: config.weapp.AppId, } }) .then(res => { console.log(33333333333) console.log(app.globalData.token) console.log(res) console.log(33333333333) // that.getGameOne(app.globalData.token) that.getStaticGame(app.globalData.token) that.getGg(app.globalData.token) let weapNote = JSON.parse(res.data.weapNote); that.setData({ desc: weapNote.firstpage.desc, title: weapNote.firstpage.title }) }) .catch(err => { // that.getGameOne(app.globalData.token) that.getStaticGame(app.globalData.token) that.getGg(app.globalData.token) wx.showModal({ title: "提示", content: err.errMsg, showCancel: false }); }); } } }, getStaticGame(token) { let _this = this; Http.get({ url: config.api.getGame, data: { triggleAction: 2, // 固定入口 token: token } }).then(res => { if (res.data.id) { _this.setData({ showIf: true, newUrl: res.data.imgUrl }) } else { _this.setData({ showIf: false }) } _this.setData({ staticGamedata: res.data }) }) .catch(err => { _this.setData({ showIf: false }) console.log(err) }) }, getGameOne: function(token) { let _this = this; Http.get({ url: config.api.getGame, data: { triggleAction: 1, // 登录触发 token: token } }).then(res => { if (res.data.id) { _this.setData({ showGame: true, }) } else { _this.setData({ showGame: false }) } _this.setData({ gamedata: res.data }) }) .catch(err => { _this.setData({ showGame: false }) this.alphaClick(); }) }, /** * mallinfo */ getMallInfo: function(token) { let that = this; Http.get({ url: config.api.getMallInfo, data: { token: token, } }).then(res => { that.setData({ liveFlag: res.data.liveSupport, weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null, weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null, }); console.log(that.data.liveFlag, "||||") }) .catch(err => { // 不需要错误提示 }); }, //获取限时抢购列表 getxsList() { let that = this; Http.get({ url: config.api.couponChannelList, data: { pageNum: 1, pageSize: 3, targetAd: 2 } }).then(res => { if (res && res.data.total > 0) { that.setData({ xslist: res.data.list, showQg: true }); } else { that.setData({ showQg: false }) } }) .catch(err => { console.log(err) wx.showToast({ title: err.errMsg, icon: 'none', duration: 2000, mask: false }); }) }, /** * banner */ getBannerlist: function() { let that = this; Http.get({ url: config.api.bannerlist, data: { pageNum: 1, pageSize: 7 } }).then(res => { that.getmemberId(app.globalData.token); // that.checkUserCarStatus(); that.setData({ list: res.data.list }); }) .catch(err => { that.getmemberId(app.globalData.token); // that.checkUserCarStatus(); }); }, // 专题显示 topicShow: function() { let that = this; Http.get({ url: config.api.topicShow, data: { token: app.globalData.token } }).then(res => { if (res && res.data) { that.setData({ name: res.data.name, cover: res.data.cover, id: res.data.id, showTopic: true }) } else { that.setData({ showTopic: false }) } }) .catch(err => { console.log(err); }) }, gotoTopic() { wx.navigateTo({ url: `/pages/topicDetail/index?id=${this.data.id}` }) }, /** * 检查用户是否有车 */ // checkUserCarStatus: function() { // var that = this; // Http.get({ // url: config.api.userCarCount, // data: {} // }).then(res => { // if (res.data > 0) { // // 用户名下有车 // app.globalData.phone = res.data.phone; // app.globalData.supportCar = true; // // 共同登录 // that.userCarLogin(); // } // }); // }, /** * car共同登录 */ // userCarLogin: function() { // var that = this; // if (!app.globalData.carLogin) { // // 共同登录 // Http.post({ // url: config.api.carInit, // data: { // phone: app.globalData.phone // } // }).then(res => { // app.globalData.carLogin = true; // app.globalData.parkVendor = res.data.vendor; // if (res.data.token != "undefined") { // app.globalData.etcpToken = res.data.token; // } // }); // } // }, /** * 获取用户信息 */ // getUserInfo: function() { // // 获取用户信息 // wx.getSetting({ // success: res => { // if (res.authSetting["scope.userInfo"]) { // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 // wx.getUserInfo({ // success: res => { // // 可以将 res 发送给后台解码出 unionId // } // }); // } // } // }); // }, gotoBargain: function() { wx.navigateTo({ url: '/pages/bargain/bargain' }) }, //限时抢购的详情页面 gotodetail: function(e) { wx.navigateTo({ url: `/pages/coupon/detail/index?couponChannelId=${ e.currentTarget.dataset.couponchannelid }&couponId=${e.currentTarget.dataset.couponid}` }); }, //浮层广告 getGg: function(token) { let that = this Http.get({ url: config.api.getGg, data: { token: token, appId: config.weapp.AppId, openId: that.data.openId } }).then(res => { console.log(res) if (res.data.id) { that.setData({ showGg: true, }) console.log(that.data.showGg, 1111111111111) } else { that.setData({ showGg: false }) that.getGameOne(app.globalData.token) console.log(that.data.showGg, 222222222222222222) } that.setData({ ggdata: res.data }) }) .catch(err => { this.setData({ showGg: false }) that.getGameOne(app.globalData.token) that.alphaClick1(); }) }, /** * 刷新 */ onPullDownRefresh: function(e) { let that = this; that.getWeapNote(); that.setData({ page: 1 }) if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) { this.getWeapNote(this.data.optionsData.couponChannelId, this.data.optionsData.orderId); } else { this.getWeapNote() } if (that.data.code == 0 || that.data.code == undefined) { that.selectComponent("#lists").getList(0, 1, "refresh"); wx.stopPullDownRefresh(); } else { that.selectComponent("#lists").getList(that.data.code, 1, "refresh"); wx.stopPullDownRefresh(); }; // 砍价下拉刷新 // that.selectComponent("#bargain").getList(); // that.selectComponent("#spellGroup").getList(); // that.selectComponent("#rushtobyCard").getList(); wx.stopPullDownRefresh(); //爆款专区下拉刷新 that.selectComponent("#hot").getList(); that.getxsList(); that.topicShow(); }, //加载更多 onReachBottom: function() { let that = this; that.data.page++; that.setData({ page: that.data.page }); console.log("加载更多页数" + that.data.page); console.log("加载更多key" + that.data.code); //父组件获得子组件的方法 //如果code == 0 if (that.data.code == 0 || that.data.code == undefined) { that.selectComponent("#lists").getList(0, that.data.page); } else { that.selectComponent("#lists").getList(that.data.code, that.data.page); } }, // 用户点击右上角分享 onShareAppMessage: function() { return { title: this.data.weappShareTitle, imageUrl: this.data.weappShareCoverImg, // desc: this.data.desc, success: function(res) { wx.showToast({ title: "分享成功", duration: 1000, icon: "success" }); } }; } });