let util = require('../../../utils/util') // let apiArr = require('../../../packages/doorToDoor/data/doorToDoor') import {apiArr} from '../../../api/community' import apiAddr from '../../../api/base'; import {apiArr as apiArr2} from '../../../api/doorToDoor' const app = getApp({allowDefault:true}) // pages/index/newIndex/newIndex.js Page({ /** * 页面的初始数据 */ data: { s: app.system.statusBarHeight, // 状态栏高度 n: (app.menu.top - app.system.statusBarHeight) * 2 + app.menu.height, // 导航栏高度 t: app.menu.top, // 胶囊局顶部距离 h: app.menu.height, // 胶囊高度 picUrl: util.img_url, city:"", qqmap_key: '', tabList:[ { img:"https://wechat-img-file.oss-cn-beijing.aliyuncs.com/tabItem_img1.png", name:"社区列表", url:"/packages/community/communityList/index?title=社区列表&types=2" }, { img:"https://wechat-img-file.oss-cn-beijing.aliyuncs.com/tabItem_img2.png", name:"社区服务", url:"/packages/doorToDoor/pages/doorToDoor/doorToDoor" }, { img:"https://wechat-img-file.oss-cn-beijing.aliyuncs.com/tabItem_img3.png", name:"周边商家", url:"/packages/roundMechant/pages/roundMechant/roundMechant" }, // { // img:"https://wechat-img-file.oss-cn-beijing.aliyuncs.com/tabItem_img4.png", // name:"社区团购", // // url:"/packages/GropBuy/pages/GropBuy" // }, // { // img:"https://wechat-img-file.oss-cn-beijing.aliyuncs.com/tabItem_img5.png", // name:"餐饮美食", // url:"/packages/food/pages/food/food" // }, { img:"https://wechat-img-file.oss-cn-beijing.aliyuncs.com/tabItem_img6.png", name:"智慧康养", url:"/packages/health/pages/health/health" }, { img:"https://wechat-img-file.oss-cn-beijing.aliyuncs.com/tabItem_img11.png", name:"我的预约", url:"/packages/myReservation/pages/myReservation/myReservation" }, { img:"https://wechat-img-file.oss-cn-beijing.aliyuncs.com/tabItem_img8.png", name:"便民服务", url:"/packages/ConvenServer/ConvenServer/pages/ConvenServer/ConvenServer" }, // { // img:"https://wechat-img-file.oss-cn-beijing.aliyuncs.com/tabItem_img9.png", // name:"积分兑换", // // url:"/packages/indexSubcontract/pointExchange/index" // }, // { // img:"https://wechat-img-file.oss-cn-beijing.aliyuncs.com/tabItem_img10.png", // name:"官方商城", // url:"/packages/official/index/index" // }, ], current:0, flag:false, page_num:1, page_size:10, serverList:[],//服务列表 CommunityList:[], //小区列表 iptMsg:"", bannerList:[], currentIdx:0, currentCity:"", }, swipers(e){ let that = this that.setData({ currentIdx:e.detail.current }) }, getBanner(){ let that = this util.postUrl(apiArr2.getBanner,{},res=>{ that.setData({ bannerList:res.list }) }) }, //输入框 iptChange(e){ let that = this that.setData({ iptMsg:e.detail.value }) }, //输入按钮 searchCurrent(){ let that = this that.setData({ flag:false, page_num:1, serverList:[], current:1 }) that.getServerList() }, opMap(){ wx.chooseAddress({ success(res){ console.log(res); } }) }, map(){ if(wx.getStorageSync('ctoken')){ wx.navigateTo({ url: '../shopcity', }) }else{ wx.navigateTo({ url: '/pages/login/login', }) } }, NotOpen(){ wx.showModal({ title: '提示', content: '此功能暂未开通!', showCancel:false, complete: (res) => { if (res.cancel) { } } }) }, adds(e){ wx.openLocation({ latitude: e.currentTarget.dataset.axis.lat, longitude: e.currentTarget.dataset.axis.log, name:e.currentTarget.dataset.axis.addr, scale:18 }) }, phone(e){ wx.makePhoneCall({ phoneNumber: e.currentTarget.dataset.phone, }) }, changeCurrent(e){ let that = this that.setData({ current:e.currentTarget.dataset.idx, flag:false, page_num:1, serverList:[], CommunityList:[], iptMsg:'' }) if(e.currentTarget.dataset.idx == '0'){ that.getCommunityList() }else if(e.currentTarget.dataset.idx == '1'){ that.getServerList() } }, //获取服务列表 getServerList(){ let that = this wx.showLoading({ title: '加载中...', mask:true }) util.postUrl(apiArr2.getServerById,{ page_num:that.data.page_num, page_size:that.data.page_size, title:that.data.iptMsg, },res=>{ wx.hideLoading() if(!res.rows){ return } let flag = false if(res.rows && res.rows.length == that.data.page_size){ flag =true }else{ flag =false } res.rows.forEach(item=>{ item.photo = util.img_url + item.photo }) that.setData({ serverList:that.data.serverList.concat(res.rows || []), flag, page_num:that.data.page_num + 1 }) }) }, getCommunityList(){ let that = this util.postUrl(apiArr.list,{ page_num:that.data.page_num, page_size:that.data.page_size },res=>{ let flag = false if(res.rows && res.rows.length == that.data.page_size){ flag =true }else{ flag =false } that.setData({ CommunityList:that.data.CommunityList.concat(res.rows || []), flag, page_num:that.data.page_num + 1 }) console.log(that.data.CommunityList); }) }, // 网站配置信息 getHostInfo() { const that = this; wx.request({ url: apiAddr.get_host_info, method: 'post', header: { 'Content-type': 'application/x-www-form-urlencoded' }, dataType: 'json', success: (result) => { console.log(result,'result'); let wxapp = result.data.all.wxapp; if(wxapp){ this.setData({ qqmap_key: wxapp.qqmap_key, }, () => { this.getUserLocation() }) } }, }) }, getUserLocation(){ const that = this; const {qqmap_key} = this.data; let userlocat = wx.getStorageSync('userlocat'); wx.getLocation({ type: 'wgs84', success (res) { const latitude = res.latitude const longitude = res.longitude // const speed = res.speed // const accuracy = res.accuracy wx.request({ url: 'https://apis.map.qq.com/ws/geocoder/v1/?location='+res.latitude+','+res.longitude+'&key=' + qqmap_key + '&get_poi=0', success: function(res) { console.log(res,'rerrrrr'); var city = res.data.result.address_component.city; if(city){ // that.setData({ // city // }) // let area = that.data.shopArea; // console.log(area); // if(typeof area[city] !== 'undefined'){ // // setData(that,'area_id',area[city]['area_id']); // } } userlocat = { userlat: latitude, userlng: longitude, // overtime: overtime, city:city, }; that.setData({ city: userlocat }) wx.setStorageSync('userlocat', userlocat); // wx.setStorageSync('city', city); wx.setStorageSync('Usercity', city); }, fail(err){ console.log(err); } }) } }) }, desc(e){ // 本期便民服务暂时不上 if(!e.currentTarget.dataset.url){ this.NotOpen(); return } if(!wx.getStorageSync('ctoken')){ wx.navigateTo({ url: '/pages/login/login', }) return } if(e.currentTarget.dataset.url == '/packages/doorToDoor/pages/doorToDoor/doorToDoor'){ if(!wx.getStorageSync('city')){ wx.showModal({ title: '提示', content: '请先选择您的城市', confirmText:"去选择", complete: (res) => { if (res.cancel) { } if (res.confirm) { wx.navigateTo({ url: '/pages/index/shopcity', }) } } }) return } } if(e.currentTarget.dataset.url == '/packages/roundMechant/pages/roundMechant/roundMechant'){ wx.getLocation({ type:"gcj02", success(res){ wx.navigateTo({ url: `${e.currentTarget.dataset.url}?lat=${res.latitude}&log=${res.longitude}`, }) } }) return; } wx.navigateTo({ url: e.currentTarget.dataset.url, }) }, // 榴园厨房 cf(){ let that = this wx.navigateTo({ url: '/packages/kitchen/pages/kitchen/kitchen', }) }, //物业报修 wybx(){ let that= this if(!wx.getStorageSync('ctoken')){ wx.navigateTo({ url: '/pages/login/login', }) return } wx.navigateTo({ url: '/packages/OneRepair/pages/OneRepair/OneRepair', }) }, //商家入驻 shopEnter(){ wx.navigateTo({ url: '/packages/indexSubcontract/shopEnter/index', }) }, //人人爱净水 water_filter(){ if(!wx.getStorageSync('ctoken')){ wx.navigateTo({ url: '/pages/login/login', }) return } wx.navigateTo({ url: '/packages/WaterPurifier/pages/water_filter/water_filter', }) }, //进入小区 dwelling(){ wx.navigateTo({ url: '/packages/community/dwelling/index', }) }, //服务更多 ServerMore(){ wx.navigateTo({ url: '/packages/doorToDoor/pages/ServiceMore/ServiceMore', }) }, //服务详情 ServerDesc(e){ wx.navigateTo({ url: `/packages/doorToDoor/pages/reservation/reservation?appid=${e.currentTarget.dataset.appid}`, }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let that = this that.getCommunityList(); that.getBanner(); that.getHostInfo(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { // let that = this // that.setData({ // city:wx.getStorageSync('userlocat') // }) let that = this if(wx.getStorageSync('city')){ console.log(123,wx.getStorageSync('city')); let obj = {city:wx.getStorageSync('city')} that.setData({ currentCity:obj }) }else{ wx.setStorageSync('city', wx.getStorageSync('Usercity')) } }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { let that = this if(that.data.current == 0){ if(that.data.flag){ that.getCommunityList(); } }else if(that.data.current == 1){ if(that.data.flag){ that.getServerList(); } } }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })