// pages/repairs/repairs.js const app = getApp(); Page({ /** * 页面的初始数据 */ data: { screenHeight: '', //屏幕可视高度 areaID: 0, //区域id value1: 0, //第一个显示什么 option1: [], //区域选项 curPage: 0, //tab切换 【1 已读 0未读】 repairsList: [], //用户反馈列表 page: 1, //页面加载 bgColor: '#efefef' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that = this; that.setData({ screenHeight: app.globalData.screenHeight, option1: wx.getStorageSync('allArea'), }) let curVal = wx.getStorageSync('curVal'); if (curVal) { that.setData({ value1: curVal }) } let areaID = wx.getStorageSync('curId') if (areaID) { that.setData({ areaID }) } else { let id = that.data.option1[0].areaID that.setData({ areaID: id }) } that.menu = that.selectComponent("#menu"); that.menu.changeTitle(that.data.option1[that.data.value1].text); this.lookRepairs(); }, goTop: function (e) { // 一键回到顶部 if (wx.pageScrollTo) { wx.pageScrollTo({ scrollTop: 0 }) } }, choose(e) { //已读未读切换 let idx = e.currentTarget.dataset.idx; this.setData({ curPage: idx, repairsList:[] }) this.lookRepairs(); this.goTop(); }, lookRepairs() { //获取报修列表 wx.showLoading({ title: '加载中...', }) let cur = this.data.curPage; let areaID = this.data.areaID; app.request('user/userRepaired?status=' + cur + '&area_id=' + areaID, '', 'GET').then(res => { wx.hideLoading(); console.log(res, '报修列表') let list = res.data.data; if (list.length == 0) { this.setData({ repairsList: [], bgColor: '#fff' }) } else { this.setData({ repairsList: res.data.data, bgColor: '#efefef' }) } }) }, markRead(e) { //标记为已读 let id = e.currentTarget.dataset.id app.request('user/userRepaired/status?id=' + id, '', 'GET').then(res => { this.lookRepairs(); }) }, morkRepairs() { //上拉加载更多 wx.showLoading({ title: '加载中...', }) let that = this; var page = that.data.page + 1; let state = this.data.curPage; let areaID = this.data.areaID; app.request('user/userRepaired?&status=' + state + '&page=' + page + '&area_id=' + areaID, '', 'GET').then(res => { wx.hideLoading(); let list = res.data.data; if (list.length > 0) { this.setData({ repairsList: that.data.repairsList.concat(list), bgColor: '#efefef', page }) } else { wx.showToast({ title: '到底啦~', icon: 'none' }) } }) }, //选择区域 change: function (e) { let that = this; wx.setStorageSync('curVal', that.data.option1[e.detail].value) wx.setStorageSync('curId', that.data.option1[e.detail].areaID) this.setData({ areaID: that.data.option1[e.detail].areaID }) this.lookRepairs(); this.goTop(); }, //点击可拨打电话 phone(e){ console.log(1111) wx.makePhoneCall({ phoneNumber: e.currentTarget.dataset.phone }) }, //返回键 back() { wx.navigateBack({ delta: 1 }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.morkRepairs(); }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })