// pages/article/index.js import {ArticeModel} from '../../models/artice.js' import dayjs from '../../utils/dayjs/index.js' let artice = new ArticeModel() Page({ /** * 页面的初始数据 */ data: { nodes: '', isStar: true, // 是否 showBtn: true, aId: '', title: '', date: '', origin: '', unStar: '/images/common/star.png', star: '/images/common/star_light.png', disable: true, }, onClickCollect () { // 收藏功能 this.addOrRemoveCollectionApi() }, onlineSubmit () { console.log('在线报名') this.onlineSignApi() // 在线报名 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(options) const {id} = options this.setData({ aId: id }) this.fetchArticeApi() }, fetchArticeApi () { artice.getDetail(this.data.aId, (res) => { console.log('artice detail') console.log(res) const data = res.result const date = dayjs(data.createTime).format('MM月DD日') this.setData({ nodes: data.content, title: data.title, date: date, origin: data.source, isStar: data.isCollection ? true : false, showBtn: data.typeFlag >= 2 ? true : false, disable: data.typeFlag == 3 ? true : false, }) }) }, addOrRemoveCollectionApi () { artice.addOrRemoveCollect(this.data.aId, res => { console.log(res) this.setData({ isStar: !this.data.isStar }) if (res.code == 200) { wx.showToast({ title: res.message, icon: 'none' }) } }) }, onlineSignApi () { artice.onlineSign(this.data.aId, res => { console.log(res) wx.showToast({ title: res.message, icon: 'none' }) this.setData({ disable: true }) // this.fetchArticeApi() }) }, })