// pages/admin/index.js import { ajax } from "../../utils/util"; Page({ /** * 页面的初始数据 */ data: { list: [] }, page: 1, size: 2, total: 0, T: undefined, goBack(){ wx.navigateBack(); }, conclusion(e) { if (this.T) clearTimeout(this.T); setTimeout(() => { if (this.T) clearTimeout(this.T); if (!e.currentTarget.dataset.conclusion) { wx.showModal({ title: '请输入评语', editable: true, complete: (res) => { if (res.confirm) { this.uploadConclusion(e.currentTarget.dataset.id, e.currentTarget.dataset.conclusion, res.content, e.currentTarget.dataset.index) } } }) } else { this.uploadConclusion(e.currentTarget.dataset.id, e.currentTarget.dataset.conclusion, "", e.currentTarget.dataset.index); } }, 200); }, uploadConclusion(articleId, ok, message, index) { ajax({ urlType: "apiurl", api: "/article/audit", method: "post", data: { articleId, ok, message } }).then(res => { if (res.code !== 0) return wx.showToast({ title: res.message || '审核失败', icon: "none" }) const { list } = this.data; if (ok) { list.splice(index, 1); this.setData({ list }) } else { list[index].message = message; } if (index >= list.length - 2) this.getData(); wx.showToast({ title: '审核成功', icon: "success" }) }) }, getData() { ajax({ urlType: "apiurl", api: "/article/list-audit", method: "post", data: { page: this.page, size: this.size } }).then(res => { if (res.code !== 0) return wx.showToast({ title: '请求失败', icon: "none" }) const data = res.data || {}; data.data.length && (this.page += 1); this.total = data.total; this.setData({ list: [...this.data.list, ...data.data] }) }) }, change(e) { const T = setTimeout(() => { clearTimeout(T); if (e.detail.current >= this.data.list.length - 1) this.getData(); }, 500); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getData() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { return { title: __wxConfig.accountInfo.nickname, path: "/pages/index/index" } } })