// pages/guide/index.js require('regenerator-runtime'); import { login } from '../../utils/request'; import { judgeMyApi } from '../../utils/util/index' import {getBanner,getRecommend} from '../../utils/api/index' Page({ data: { isLogin: false, background: [ 'https://unpkg.com/@vant/assets/apple-1.jpeg', 'https://unpkg.com/@vant/assets/apple-2.jpeg', 'https://unpkg.com/@vant/assets/apple-2.jpeg', ], gridList: [ { id: 'manage', name: '户号管理' }, { id: 'pay', name: '燃气缴费' }, { id: 'history', name: '历史账单' }, { id: 'analyze', name: '用气分析' }, { id: 'place', name: '服务网点' }, { id: 'subsidy', name: '采暖补贴' }, ], RecommendList:[],//推荐列表 gridTwoList: [ { id: 'kefu', name: '客服电话', icon: '../../static/index/kefu.png' }, { id: 'qiangxiu', name: '抢修电话', icon: '../../static/index/weixiu.png' }, ] }, onLoad: async function (options) { await this.wxLogin(); const baseUrl = 'https://kitchen.smartlog.work' //获取到轮播图 const getBannerList = await getBanner({bannerName:'',bannerModule:''}) //获取到推荐列表 const getRecommendList = await getRecommend({recommendTitle:'',recommendType:''}) //拼接轮播图url let backgroundList = getBannerList.rows.map(item=>{ if(item.bannerPicture !== ''){ item.bannerPicture = `${baseUrl}/static/${item.bannerPicture}` } return item }) //对没有图片的数据筛选掉 backgroundList = backgroundList.filter(item=>item.bannerPicture !== '') let RecommendList = getRecommendList.rows.map(item=>{ if(item.recommendPicture !== ''){ item.recommendPicture = `${baseUrl}/static/${item.recommendPicture}` } return item }) RecommendList = RecommendList.filter(item=>item.recommendPicture !== '') this.setData({ isLogin: true, background:backgroundList, RecommendList }); let access_token = await wx.getStorageSync('access_token'); if(!access_token) return; }, onShow: async function () { if(!this.data.isLogin) { await this.wxLogin(); } wx.getStorageSync('access_token') && this.setData({ isLogin: true }); }, onClickHide: function () { this.setData({ show: false }); }, wxLogin: async function () { let canIuse = await judgeMyApi({myApi:'getUserProfile',myVersion:'2.24.0'}); if(!canIuse) return false; wx.showLoading({ title: '正在登陆', }) const res = await login(); wx.hideLoading(); if (res) { wx.showToast({ title: '登录成功', duration: 1000 }) this.setData({ isLogin: true }) return true; } let timer = setTimeout(() => { wx.showToast({ title: '登录失败', icon: 'error', duration: 1000 }) clearTimeout(timer); return false; }, 1800); }, // gotoOtherage: function (event) { // const { // dataset: { // url // } // } = event.currentTarget; // if (url == 'navigateToMiniProgram') { // this.setData({ // show: true // }); // } else { // wx.navigateTo({ // url // }); // } // }, //拨打电话 call(event) { let phone = '010-96777'; console.log('打电话',value); const { dataset: { value } } = event.currentTarget; if(value === 'kefu') { phone: '010-96777'; } else { phone: '010-96777'; } wx.makePhoneCall({ phoneNumber: phone }) }, //跳转页面 gotoUserManage(event) { const { dataset: { gopage } } = event.currentTarget; if(gopage === 'manage') { wx.navigateTo({ url: '/packageB/userManagement/userManagement', }) } else if(gopage === 'pay') { wx.navigateTo({ url: '/packageB/pay/pay', }) }else if(gopage === 'history') { wx.navigateTo({ url: '/packageB/historical/historical', }) }else if(gopage === 'analyze') { wx.navigateTo({ url: '/packageB/consumption/consumption', }) }else if(gopage === 'place') { wx.navigateTo({ url: '/packageB/serviceNetwork/serviceNetwork', }) }else if(gopage === 'subsidy') { wx.navigateTo({ url: '/packageB/subsidy/subsidy', }) } } });