// dispatcher/pages/home/home.js import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js' import { DispatcherIndex, DispatcherAudit } from '../../../utils/api.js' const { navigateTo, redirectTo, navigateBack } = routers() const { globalData } = getApp() const { baseImgUrl } = globalData Page({ /** * 页面的初始数据 */ data: { baseImgUrl, isLoaded: 0, pageNo: 1, pageSize: 10, isAll: 0, list: [ // { // "order_num": "1", // "username": "12154545", // "league_name": "福建师大雷锋精神连接方式垃圾分类是就发了是家乐福", // "reg_time": "1436864169", // "wish_num": "0", // } ] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getData(res => { this.setData({ isLoaded: 1 }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { const obj = { navigateTo, redirectTo, navigateBack, viewImage } for (const i in obj) { this[i] = obj[i] } }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { this.setData({ pageNo: 1 }) this.getData(res => { wx.stopPullDownRefresh() }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { const { isAll = false } = this.data if (isAll) return this.getData() }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { if (isFn(sharePage)) return sharePage() }, /** * 获取数据 */ getData: function (cb) { const continuousFn = { fn: this.getData, param: { ...arguments } } const { content, pageNo, pageSize, list } = this.data DispatcherIndex({ data: { content, pageNo, pageSize }, continuousFn }).then(res => { const newList = res.data.list let listTemp = [] if (pageNo > 1) { listTemp = [].concat(list, newList) } else { listTemp = [].concat(newList) } this.setData({ list: listTemp, pageNo: newList.length == pageSize ? pageNo + 1 : pageNo, isAll: newList.length < pageSize }) cb && cb(res) }).catch(res => { cb && cb(res) }) }, /** * 选择调度馆 */ selectLiCtl: function (e) { const { index } = e.currentTarget.dataset const { list } = this.data const libId = list[index].id || '' if (libId) { getApp().globalData.dispatchLibId = libId wx.setStorageSync(`dispatchLibId_${getGlobalVal('userId')}`, libId) redirectTo({ url: 'dispatcher/pages/dispatch_go/dispatch_go', paras: { libId }, zindex: 3 }) } else { wx.showToast({ title: '该馆无效,请换一个馆', icon: 'none' }) } }, /** * 输入搜索值 */ inputSearchCtl: function (e) { const { value } = e.detail const { content } = this.data if (content == value) return this.setData({ content: value }) }, /** * 清除搜索值 */ clearSearchCtl: function () { this.setData({ content: '' }) }, /** * 提交搜索值 */ submitSearchCtl: function () { this.setData({ pageNo: 1 }) this.getData() }, /** * 确认拒绝校长馆申请 */ commitDispatcherAuditCtl: function (e) { const continuousFn = { fn: this.commitDispatcherAuditCtl, param: { ...arguments } } const { type = 0, index = 0 } = e.currentTarget.dataset const { list = [] } = this.data const { id = '' } = list[index] if (!type || !id) return DispatcherAudit({ data: { type, libId: id }, continuousFn }).then(res => { // wx.showToast({ // title: res.msg || '调度员已确认你馆调书申请,请等待调度员与你联系!', // icon: 'none', // duration: 5000 // }) this.getData() cb && cb(res) }).catch(res => { // wx.showToast({ // title: res.data.msg || '你馆阅读会员数量还不足35名,请继续加油达到目标哦~', // icon: 'none', // duration: 5000 // }) cb && cb(res) }) } })