var app = getApp(); var netUtil = require("../../utils/requestUtil.js"); //require引入 Page({ data: { PageCur: "basics", cardCur: 0, swiperList: null, iconList: [{ icon: 'homefill', color: 'green', badge: 0, url: '/pages/house/list/index', name: '房源列表' }, { icon: 'card', color: 'olive', badge: 0, url: '/pages/house/room/index', name: '房间列表' } // { // icon: 'my', // color: 'blue', // badge: 0, // url: '/pages/login/subaccount', // name: '子账号登录' // } ], gridCol: 3, skin: false, detailUrl: '/pages/house/share', data: [], page: 1, pages: 0, expire_num: 0, house_expire_num: 0, region: ['安徽省', '合肥市', '蜀山区'], search: '', latitude: 31.860026, longitude: 117.256507, num:100 }, onLoad() { //this.towerSwiper('swiperList'); // 初始化towerSwiper 传已有的数组名即可 //获取列表 this.getList(1, true); }, onReady: function() { const _this = this; wx.getLocation({ type: 'wgs84', success(res) { console.log(res) _this.setData({ latitude: res.latitude, longitude: res.longitude }) } }) }, /** * 生命周期函数--监听页面显示 */ onShow: function() { this.getBanner(); }, //获取广告列表 getBanner: function() { var self = this; var url = app.globalData.requestUrl + 'index/ad/index?page=1&pagesize=6'; netUtil.sendGet(url) .then((res) => { this.setData({ swiperList: res.data }) }) }, //导航切换 NavChange: function(e) { this.setData({ PageCur: e.currentTarget.dataset.cur }) }, // towerSwiper // 初始化towerSwiper towerSwiper(name) { let list = this.data[name]; for (let i = 0; i < list.length; i++) { list[i].zIndex = parseInt(list.length / 2) + 1 - Math.abs(i - parseInt(list.length / 2)) list[i].mLeft = i - parseInt(list.length / 2) } this.setData({ swiperList: list }) }, RegionChange: function(e) { var region = e.detail.value; //重置搜索默认 this.setData({ region: region }) //重置搜索数据 this.getList(1, true); }, formSubmit: function(e) { const params = e.detail.value this.setData({ search: params.search }) //执行搜索查询 this.getList(1, true, params.search) }, /** * 根据公里搜索 */ searchKilometre: function(e) { var num = e.currentTarget.dataset.num; //执行搜索查询 this.setData({ num:e.currentTarget.dataset.num }) this.getList(1, true, '', num) }, /** * 同小区搜索 */ searchName: function(e) { var name = e.currentTarget.dataset.name; //执行搜索查询 this.getList(1, true,name) }, //获取数据列表 getList: function(pageNum, override, search, num) { this.loading = true; var self = this; var url = app.globalData.requestUrl + 'index/index/index?pagesize=10&page=' + pageNum if (search != undefined) { url += '&search=' + search } if(num == undefined){ var num = this.data.num; } if (num != undefined) { //根据经伟度获取公里数 if (this.data.latitude != '') { url += '&latitude=' + this.data.latitude } if (this.data.longitude != '') { url += '&longitude=' + this.data.longitude } url += '&num=' + num; } //根据省市区获取数据 var region = self.data.region if (region.length > 0) { url += '&province=' + region[0] + '&city=' + region[1] + '&area=' + region[2] } return netUtil.sendGet(url) .then((res) => { this.setData({ pages: res.data.data.room.pages, page: pageNum, expire_num: res.data.data.expire_num, house_expire_num: res.data.data.house_expire_num, //override 为true 则直接覆盖 否则上拉追加数据 data: override ? res.data.data.room.list : self.data.data.concat(res.data.data.room.list) }) }).then(() => { this.loading = false; }) }, //上拉加载数据 onReachBottom: function() { // 下拉触底,先判断是否有请求正在进行中 // 以及检查当前请求页数是不是小于数据总页数,如符合条件,则发送请求 if (!this.loading && this.data.page < this.data.pages && this.data.pages != 1) { this.getList(this.data.page + 1, false, this.data.search); } }, //下拉刷新 onPullDownRefresh: function() { if (!this.loading) { this.getList(1, true).then(() => { wx.stopPullDownRefresh() }) } }, //点击详情 toDetail: function(e) { var id = e.currentTarget.dataset.id; wx.navigateTo({ url: this.data.detailUrl + '?id=' + id, }) }, //点击详情 toLink: function(e) { var id = e.currentTarget.dataset.id; console.log(id); wx.navigateTo({ url: id }) }, //拨打电话 phoneCall: function(e) { var phone = e.currentTarget.dataset.phone; wx.makePhoneCall({ phoneNumber: phone, }) }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { return { imageUrl: app.globalData.requestUrl + 'upload/share/1.png' } } })