123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- // pages/home/index.js
- const app = getApp()
- const util = require('../../utils/util.js')
- const url = require('../../utils/url.js')
- const call = require("../../utils/net.js")
- var QQMapWX = require('../../libs/qqmap-wx-jssdk.js');
- var qqmapsdk;
- Page({
- //查看详情要进行授权
- getUserInfo(e){
- //console.log(e)
- let ids = e.currentTarget.dataset.ids;
- let title = e.currentTarget.dataset.title;
- var userId = wx.getStorageSync('userId');
- if (userId) {
- wx.navigateTo({
- url: '/pages/home/detail/detail?id=' + ids + '&title=' + title,
- })
- } else {
-
- if (e.detail.errMsg == 'getUserInfo:ok') {
- let reqData = {
- 'signature': e.detail.signature,
- 'rawData': e.detail.rawData
- }
- wx.login({
- success(res) {
- if (res.code) {
- let code = res.code
- reqData['code'] = code
- call.request(url.host + url.login,
- { code: res.code },
- res => {
- //console.log(res.data)
- wx.setStorageSync('userId', res.data.data); //将userId存入本地缓存
- if (res.data.code == 200) {
- call.request(url.host + url.getuserinfo,
- reqData,
- res => {
- wx.navigateTo({
- url: '/pages/home/detail/detail?id=' + ids + '&title=' + title,
- })
- //console.log(res)
- },
- res => {
- //console.log(res)
- })
- } else {
- wx.showToast({
- icon: 'none',
- title: res.data.msg,
- })
- }
- },
- res => {
- //console.log(res)
- })
- } else {
- console.log('登录失败!' + res.errMsg)
- }
- }
- })
- } else if (e.detail.errMsg == 'getUserInfo:fail auth deny') {
- wx.showToast({
- icon: 'none',
- title: '授权失败!',
- })
- }
- }
- },
- /**
- * 页面的初始数据
- */
- data: {
- collegeTips: "点击'添加到我的小程序'",
- showShopPopup: false, // 是否显示收藏提示层
- animationData: {}, // 动画数据
- host: url.host,
- city: '',
- search: {
- pla: "搜索 社保/公积金/身份证"
- },
- currentSwiper: 0,
- banner:[
- // { img: '../../icon/ad/banner1.png', link:"https://www.wodeshebao.com/tax/index.html"},
- ],
- menu:[
- // { imgPath: '../../icon/menu/shebao.png', typeName: '社保', id:"1" },
- // { imgPath: '../../icon/menu/gongjijin.png', typeName: '公积金', id: "1" },
- // { imgPath: '../../icon/menu/xingshijiashi.png', typeName: '行驶驾驶', id: "1" },
- // { imgPath: '../../icon/menu/shuiwu.png', typeName: '税务', id: "1" },
- // { imgPath: '../../icon/menu/huzheng.png', typeName: '户政', id: "1" },
- // { imgPath: '../../icon/menu/huzheng.png', typeName: '户政', id: "1" },
- ],
- region: ['便民查询', '新鲜服务', '常见问题'],
- convenience:[
- { img: '../../icon/ad/shebaodaijiao.png', name: '社保代缴' ,id:'1'},
- { img: '../../icon/ad/geshuijisuanqi.png', name: '个税计算器' ,id:'2'},
- { img: '../../icon/ad/yaolaojisuanqi.png', name: '养老金计算器',id: '3'}
- ],
- service:[
- // { img: '../../icon/ad/lala.png', title: '啦啦队签证旅游', msg: '签证 旅游 住宿', id: '5' },
- { img: '../../icon/ad/nearjob.png', title: '附近的工作', msg: '走路上班回家吃饭', id: '3' },
- { img: '../../icon/ad/banruoshangcheng.png', title: '般若商城', msg: '招财 姻缘 风水', id: '4' }
- ],
- question:{
- range:null
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var that = this;
- if (options.city){
- this.setData({
- city: options.city
- })
- app.globalData.city = options.city;
- }else{
- // 实例化API核心类
- qqmapsdk = new QQMapWX({
- key: 'UPWBZ-LYEK2-FFUUS-CVJFM-X26WO-DFBWF'
- });
- this.getUserLocation();//授权后进行定位
- }
- //获取首页数据
- call.getData(url.host + url.getIndex,
- res=>{
- //console.log(res)
- that.setData({
- banner: res.data.data.ads,
- menu:res.data.data.types
- })
- },
- res=>{
- console.log(res)
- });
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.setData({
- city: app.globalData.city
- })
- if (typeof this.getTabBar === 'function' &&
- this.getTabBar()) {
- this.getTabBar().setData({
- selected: 0
- })
- }
- var that = this;
- this.showModal();
- //请求城市的热门话题的标题列表
- call.request(url.host + url.getCityHotTitle,
- { city: app.globalData.city },
- res => {
- //console.log(res)
- let range = "question.range"
- that.setData({
- [range]: res.data.data
- })
- },
- res => {
- console.log(res)
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- //当前轮播
- swiperChange: function (e) {
- //console.log(e.detail.source)
- if (e.detail.source == 'touch'){
- this.setData({
- currentSwiper: e.detail.current
- })
- }else{
- this.setData({
- currentSwiper: e.detail.current
- })
- }
- },
- //请求授权地理位置
- getUserLocation: function () {
- let that = this;
- wx.getSetting({
- success: (res) => {
- //console.log(res)
- // res.authSetting['scope.userLocation'] == undefined 表示 初始化进入该页面
- // res.authSetting['scope.userLocation'] == false 表示 非初始化进入该页面,且未授权
- // res.authSetting['scope.userLocation'] == true 表示 地理位置已授权
- if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {
- wx.showModal({
- title: '请求授权当前位置',
- content: '需要获取您的地理位置,请确认授权',
- success: function (res) {
- if (res.cancel) {
- wx.showToast({
- title: '拒绝授权',
- icon: 'none',
- duration: 1000
- })
- } else if (res.confirm) {
- wx.openSetting({
- success: function (dataAu) {
- if (dataAu.authSetting["scope.userLocation"] == true) {
- wx.showToast({
- title: '授权成功',
- icon: 'success',
- duration: 1000
- })
- //再次授权,调用wx.getLocation的API
- that.getLocation();
- } else {
- wx.showToast({
- title: '授权失败',
- icon: 'none',
- duration: 1000
- })
- }
- }
- })
- }
- }
- })
- } else if (res.authSetting['scope.userLocation'] == undefined) {
- //调用wx.getLocation的API
- that.getLocation();
- }
- else {
- //调用wx.getLocation的API
- that.getLocation();
- }
- }
- })
- },
- // 微信获得经纬度
- getLocation: function () {
- let that = this;
- wx.getLocation({
- type: 'wgs84',
- success: function (res) {
- //console.log(res)
- var latitude = res.latitude
- var longitude = res.longitude
- that.getLocal(latitude, longitude)
- },
- fail: function (res) {
- console.log(res)
- }
- })
- },
- // 获取当前地理位置
- getLocal: function (latitude, longitude) {
- let that = this;
- qqmapsdk.reverseGeocoder({
- location: {
- latitude: latitude,
- longitude: longitude
- },
- success: function (res) {
- // console.log(res)
- let city = res.result.ad_info.city
- city = city.replace('市','')
- app.globalData.city = city
- that.setData({
- city: city
- })
- },
- fail: function (res) {
- console.log(res);
- },
- complete: function (res) {
- // console.log(res);
- }
- });
- },
- //菜单搜索
- menusearch:function(e){
- let ids = e.currentTarget.dataset.ids;
- let title = e.currentTarget.dataset.title;
- wx.navigateTo({
- url: '/pages/home/problem/problem?ids=' + ids + '&title=' + title,
- })
- },
- //便民查询
- towxchat:function(e){
- let id = e.currentTarget.dataset.id;
- switch (id) {
- case "1": {
- wx.navigateToMiniProgram({
- appId: 'wxbf3f03f8a7d0cdcf',
- extraData: {
- },
- success(res) {
- console.log("跳转小程序成功")
- }
- });
- break
- }
- case "2": {
- wx.navigateToMiniProgram({
- appId: 'wx7379ad24baaaf660',
- extraData: {
- },
- success(res) {
- console.log("跳转小程序成功")
- }
- });
- break
- }
- case "3": {
- wx.navigateToMiniProgram({
- appId: 'wxcb0ec6ae8c422c3b',
- extraData: {
- },
- success(res) {
- console.log("跳转小程序成功")
- }
- });
- break
- }
- }
- },
- //新鲜服务-跳转小程序
- goAdWx(e) {
- let id = e.currentTarget.dataset.id
- switch (id) {
- case "3": {
- wx.navigateToMiniProgram({
- appId: 'wx0fdd65237732c014',
- extraData: {
- },
- success(res) {
- // 打开成功
- wx.reportAnalytics('click_service', {
- service_title: '职友集',
- });
- }
- });
- break
- }
- case "4": {
- wx.navigateToMiniProgram({
- appId: 'wx7ab08191e61478c5',
- extraData: {
- },
- success(res) {
- // 打开成功
- wx.reportAnalytics('click_service', {
- service_title: '般若商城',
- });
- }
- });
- break
- }
- // case "5": {
- // wx.navigateToMiniProgram({
- // appId: 'wxab59d3c94759d509',
- // extraData: {
- // },
- // success(res) {
- // // 打开成功
- // wx.reportAnalytics('click_service', {
- // service_title: '啦啦队签证旅游',
- // });
- // }
- // });
- // break
- // }
- }
- },
- //跳转城市地点
- positioning:function(){
- wx.navigateTo({
- url: '/pages/home/location/location',
- })
- },
- //常见问题跳详情
- toproblem: function (e) {
- let ids = e.currentTarget.dataset.ids;
- let title = e.currentTarget.dataset.title;
- wx.navigateTo({
- url: '/pages/home/detail/detail?id=' + ids + '&title=' + title,
- })
- },
- //搜索按钮
- confirm: util.throttle(function (e) {
- let word = e.detail.value;
- //查询接口
- if (word.match(/^\s*$/) || word == null || word == undefined || word == '') {
- wx.showToast({
- icon: 'none',
- title: '请输入搜索关键词!',
- })
- }else{
- wx.navigateTo({
- url: './search/search?word=' + word,
- })
- }
- }, 1000),
- toWeb:function(e){
- let link = e.currentTarget.dataset.link;
- wx.navigateTo({
- url: '/pages/home/webView/webView?link='+link,
- })
- },
- //显示提示
- showModal() {
- // 创建动画
- var animation = wx.createAnimation({
- duration: 1000,
- timingFunction: "ease-in-out",
- delay: 0
- })
- this.animation = animation
- animation.translateX(0).step()
- this.setData({
- animationData: animation.export(), // export 方法每次调用后会清掉之前的动画操作。
- showShopPopup: true
- })
- animation.translateX(-202).step()
- this.setData({
- animationData: animation.export(), // export 方法每次调用后会清掉之前的动画操作。
- showShopPopup: true
- })
- setTimeout(() => {
- animation.translateX(0).step()
- this.setData({
- animationData: animation.export(), // export 方法每次调用后会清掉之前的动画操作。
- showShopPopup: true
- })
- }, 2500)
- },
- })
|