const app = getApp() import { news_type } from '../../utils/dict'; Page({ /** * 页面的初始数据 */ data: { frameStyle: { useTop: true, name: '资讯信息管理', leftArrow: true, useBar: false }, searchInfo: {}, list: [], total: 0, limit: 5, page: 0, skip: 0, typeList: news_type, }, // 跳转菜单 back(e) { wx.navigateBack({ delta: 1 }); }, //查询 onSearch: function (e) { const that = this; that.setData({ skip: 0, page: 0, list: [] }) that.setData({ 'searchInfo.title': e.detail.value }); that.watchLogin() }, // 添加 toAdd() { const that = this; that.setData({ skip: 0, page: 0, list: [] }) wx.navigateTo({ url: '/pages/news/add' }) }, // 修改 toEdit: function (e) { const that = this; that.setData({ skip: 0, page: 0, list: [] }) let { id } = e.currentTarget.dataset; wx.navigateTo({ url: `/pages/news/add?id=${id}` }) }, // 删除 toDel: async function (e) { const that = this; const { id } = e.currentTarget.dataset; wx.showModal({ title: '提示', content: '是否确认删除该条数据?', async success(res) { if (res.confirm) { const arr = await app.$delete(`/newCourt/api/news/${id}`); if (arr.errcode == '0') { wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 }) that.setData({ skip: 0, page: 0, list: [] }) that.watchLogin() } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) } } } }) }, toPage: function () { const that = this; let list = that.data.list; let limit = that.data.limit; if (that.data.total > list.length) { wx.showLoading({ title: '加载中', mask: true }) let page = that.data.page + 1; that.setData({ page: page }) let skip = page * limit; that.setData({ skip: skip }) that.watchLogin(); wx.hideLoading() } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, // 监听用户是否登录 watchLogin: async function () { const that = this; let searchInfo = that.data.searchInfo; wx.getStorage({ key: 'user', success: async res => { let info = { skip: that.data.skip, limit: that.data.limit }; if (searchInfo && searchInfo.title) info.title = searchInfo.title; let arr; arr = await app.$get(`/newCourt/api/news`, { ...info }); if (arr.errcode == '0') { that.setData({ list: [...that.data.list, ...arr.data] }) that.setData({ total: arr.total }) } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) } }, fail: async res => { wx.redirectTo({ url: '/pages/index/index' }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { const that = this; // 监听用户是否登录 that.watchLogin(); }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })