市北人才赋能平台 --小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.1 KiB

6 years ago
// pages/article/index.js
6 years ago
import {ArticeModel} from '../../models/artice.js'
import dayjs from '../../utils/dayjs/index.js'
import { store } from '../../utils/store.js'
6 years ago
let artice = new ArticeModel()
6 years ago
Page({
/**
* 页面的初始数据
*/
data: {
6 years ago
nodes: '',
isStar: true, // 是否
showBtn: false,
6 years ago
image: '',
6 years ago
aId: '',
title: '',
date: '',
origin: '',
6 years ago
unStar: '/images/common/star.png',
star: '/images/common/star_light.png',
disable: true,
6 years ago
},
onClickCollect () {
// 收藏功能
6 years ago
this.addOrRemoveCollectionApi()
6 years ago
},
6 years ago
onlineSubmit () {
console.log('在线报名')
if (store.hasPhone()) {
this.onlineSignApi() // 在线报名
} else {
wx.redirectTo({
url: `/pages/register/index`,
})
}
6 years ago
},
6 years ago
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
6 years ago
console.log(options)
const {id} = options
this.setData({
aId: id
})
this.fetchArticeApi()
6 years ago
},
6 years ago
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,
6 years ago
image: data.titlePic,
6 years ago
origin: data.source,
isStar: data.isCollection ? true : false,
showBtn: data.typeFlag >= 2 ? true : false,
disable: data.typeFlag == 3 ? true : false,
6 years ago
})
})
6 years ago
},
6 years ago
addOrRemoveCollectionApi () {
artice.addOrRemoveCollect(this.data.aId, res => {
console.log(res)
if (res.code == 200) {
6 years ago
this.setData({
isStar: !this.data.isStar
})
6 years ago
wx.showToast({
6 years ago
title: this.data.isStar ? '收藏成功' : '取消收藏成功',
6 years ago
icon: 'none'
})
}
})
6 years ago
},
6 years ago
onlineSignApi () {
artice.onlineSign(this.data.aId, res => {
console.log(res)
wx.showToast({
title: res.message,
icon: 'none'
})
this.setData({
disable: true
})
// this.fetchArticeApi()
6 years ago
})
6 years ago
},
6 years ago
6 years ago
})