123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552 |
- import {
- ilogin,
- ihome,
- iactivity,
- icommunity,
- imine,
- answer
- } from '../../api/api.js'
- const app = getApp()
- Page({
- loadMyinformation() {
- let id = wx.getStorageSync('id')
- imine.loadMyinformation({reqdata: {id}},r => {
- console.log(r);
- this.setData({
- user: Object.assign(this.data.user, r.object)
- })
- wx.setStorageSync('user', this.data.user)
- this.data.linkState && this.toLinkR()
- })
- },
- loadMyActivities() {
- imine.loadMyActivities(this.data.mine.pagination, r => {
- this.setData({
- ['mine.curNav']: 3,
- ['mine.list']: this.data.mine.list.concat(r.list),
- ['mine.pagination.page']: r.list.length > 0 ? this.data.mine.pagination.page : --this.data.mine.pagination.page
- })
- })
- },
- loadMyComments() {
- imine.loadMyComments(this.data.mine.pagination, r => {
- for (let c of r.list) {
- c.showtime = new Date(c.comment_addtime).getDateName('hh:mm')
- }
- this.setData({
- ['mine.curNav']: 2,
- ['mine.list']: this.data.mine.list.concat(r.list),
- ['mine.pagination.page']: r.list.length > 0 ? this.data.mine.pagination.page : --this.data.mine.pagination.page
- })
- })
- },
- loadMyPubarticles() {
- imine.loadMyPubarticles(this.data.mine.pagination, r => {
- this.setData({
- ['mine.curNav']: 0,
- ['mine.list']: this.data.mine.list.concat(r.list),
- ['mine.pagination.page']: r.list.length > 0 ? this.data.mine.pagination.page : --this.data.mine.pagination.page
- })
- })
- },
- loadMyCollectedarticles() {
- imine.loadMyCollectedarticles(this.data.mine.pagination, r => {
- this.setData({
- ['mine.curNav']: 1,
- ['mine.list']: this.data.mine.list.concat(r.list).map(item => {
- item.status_attend = Date.now() < new Date(item.applyStartTime).valueOf() ? '未开始' : Date.now() > new Date(item.applyEndTime).valueOf() ? '已结束' :''
- return item
- }),
- ['mine.pagination.page']: r.list.length > 0 ? this.data.mine.pagination.page : --this.data.mine.pagination.page
- })
- })
- },
- data: {
- showAuthPanel: false,
- curNav: 0,
- user: {},
- imgUrl: app.globalData.imgUrl,
- navs: [{
- key: 'home',
- name: '首页'
- }, {
- key: 'activity',
- name: '活动动态'
- }, {
- key: 'community',
- name: '社区'
- }, {
- key: 'mine',
- name: '个人中心'
- }],
- searchOn: false,
- home: {},
- activity: {
- list: [],
- pagination: {
- page: 1,
- rows: 10,
- reqdata: {
- keyword: ''
- }
- }
- },
- community: {
- showAddtidings: false,
- acts: [{
- favorite: true
- }],
- list: [],
- pagination: {
- page: 1,
- rows: 10,
- reqdata: {
- keyword: ''
- }
- }
- },
- mine: {
- list: [],
- curNav: 0,
- pagination: {
- page: 1,
- rows: 10
- }
- },
- linkState: false //判断执行 toLinkR 的条件
- // isRegister: wx.getStorageSync('user')?wx.getStorageSync('user').isRegister:null
- },
- loadArticles() {
- icommunity.loadArticles(this.data.community.pagination, r => {
- this.setData({
- ['community.list']: this.data.community.list.concat(r.list),
- ['community.pagination.page']: r.list.length > 0 ? this.data.community.pagination.page : --this.data.community.pagination.page
- })
- wx.stopPullDownRefresh()
- })
- },
- loadActivities() {
- iactivity.loadActivities(this.data.activity.pagination, r => {
- this.setData({
- ['activity.list']: this.data.activity.list.concat(r.list),
- ['activity.pagination.page']: r.list.length > 0 ? this.data.activity.pagination.page : --this.data.activity.pagination.page,
- })
- wx.stopPullDownRefresh()
- })
- },
- loadHome() {
- let count = 3
- ihome.loadBanners({},r => {
- console.log(r);
- this.setData({
- ['home.banners']: r.list
- })
- if (count == 1) {
- wx.stopPullDownRefresh()
- } else {
- count--
- }
- })
- ihome.loadPartners({},r => {
- this.setData({
- ['home.partners']: r.list
- })
- if (count == 1) {
- wx.stopPullDownRefresh()
- } else {
- count--
- }
- })
- ihome.loadHotnews({},r => {
- this.setData({
- ['home.hotnews']: r.list
- })
- if (count == 1) {
- wx.stopPullDownRefresh()
- } else {
- count--
- }
- })
- },
- onLoad(args) {
- this.loadHome()
- // this.loadConfig()
- },
- clickRemoveArticle(e) {
- console.log(e)
- wx.showModal({
- title: '确定删除?',
- content: '是否删除此动态?',
- confirmColor: '#f64f5f',
- success: r => {
- let {id,minenav,i} = e.currentTarget.dataset
- if (r.confirm) {
- icommunity[minenav==0?'loadDeleteArticle':'loadDeleteCollect']({
- reqdata:{id}
- }, r => {
- wx.showToast({
- title: '删除成功'
- })
- this.data.mine.list.splice(i, 1)
- this.setData({
- mine: this.data.mine
- })
- })
- }
- }
- })
- },
- clickFavorite(e) {
- let {id,isCollect} = e.currentTarget.dataset
- let scope = this.data.curNav == 2 ? 'community' : 'mine'
- let item = this.data[scope].list[e.currentTarget.dataset.i]
- icommunity[isCollect?'loadDeleteCollect':'loadAddArticle']({
- reqdata:{
- [isCollect?'id':'collectProjectId']:id,
- ['collectType']: isCollect?null:1
- }
- }, r => {
- item.isCollect = !item.isCollect
- item.collectNumber =item.isCollect? parseInt(item.collectNumber) + 1: parseInt(item.collectNumber) - 1
- this.setData({
- [scope + '.list[' + e.currentTarget.dataset.i + ']']: item
- })
- })
- },
- clickActivity(e) {
- if (!this.data.user || !this.data.user.id) {
- return this.setData({
- showAuthPanel: true
- })
- }
- app.data.nav.activityDetails = this.data.activity.list[e.currentTarget.dataset.i]
- wx.navigateTo({
- url: '../activities/activityDetails/activityDetails?id=' + e.currentTarget.dataset.id
- })
- },
- clickArticle(e) {
- console.log(e)
- app.data.nav.newsDetails = this.data.home.hotnews[e.currentTarget.dataset.i]
- wx.navigateTo({
- url: '../hotnews/newsDetails/newsDetails?id=' + e.currentTarget.dataset.id
- })
- },
- clickHotnewsMore() {
- wx.navigateTo({
- url: '../hotnews/hotnews/hotnews'
- })
- },
- clickMyinfo() {
- wx.navigateTo({
- url: '../mine/myinfo/edit/edit'
- })
- },
- clickCommunityArticle(e) {
- app.data.nav.communityArticle = e.currentTarget.dataset.item
- wx.navigateTo({
- url: e.currentTarget.dataset.item.fileType == 2 ? '../community/videoDetails/videoDetails' : '../community/articleDetails/articleDetails'
- })
- },
- clickUploadpics() {
- wx.navigateTo({
- url: '../community/uploadPics/uploadPics'
- })
- this.setData({
- ['community.showAddtidings']: false
- })
- },
- clickUploadvideos() {
- wx.navigateTo({
- url: '../community/uploadVideos/uploadVideos'
- })
- this.setData({
- ['community.showAddtidings']: false
- })
- },
- clickClosetidings() {
- this.setData({
- ['community.showAddtidings']: false
- })
- },
- clickAddtidings() {
- if (!this.data.user || !this.data.user.id) {
- return this.setData({
- showAuthPanel: true
- })
- }
- this.setData({
- ['community.showAddtidings']: true
- })
- },
- inputSearch(e) {
- if (this.data.curNav == 1) {
- this.setData({
- ['activity.pagination.reqdata.keyword']: e.detail.value,
- ['activity.pagination.page']: 1,
- ['activity.list']: [],
- })
- this.loadActivities()
- } else {
- this.setData({
- ['community.pagination.reqdata.keyword']: e.detail.value,
- ['community.pagination.page']: 1,
- ['community.list']: []
- })
- this.loadArticles()
- }
- },
- clickSearch() {
- this.setData({
- searchOn: true
- })
- },
- blurSearch(e) {
- if (!e.detail.value) {
- this.setData({
- searchOn: false
- })
- }
- },
- clickMinenav(e) {
- this.data.mine.pagination.page = 1
- this.data.mine.list = []
- switch (e.currentTarget.dataset.cur) {
- case '1':
- {
- this.loadMyCollectedarticles()
- };
- break;
- case '2':
- {
- this.loadMyComments()
- };
- break;
- case '3':
- {
- this.loadMyActivities()
- };
- break;
- default:
- {
- this.loadMyPubarticles()
- }
- }
- },
- clickNav(e) {
- switch (e.currentTarget.dataset.cur) {
- case '1':
- this.data.activity.pagination.page = 1
- this.data.activity.list = []
- this.loadActivities()
- break;
- case '2':
- this.data.community.pagination.page = 1
- this.data.community.list = []
- this.loadArticles()
- break;
- case '3':
- if (!this.data.user || !this.data.user.id) {
- return this.setData({
- showAuthPanel: true
- })
- }
- this.data.mine.pagination.page = 1
- this.data.mine.list = []
- this.loadMyinformation()
- // if (this.data.config.open_space == 1) {
- // this.loadMyPubarticles()
- // } else {
- // this.loadMyCollectedarticles()
- // }
- // this.loadMyCollectedarticles()
- this.setData({
- ['mine.curNav']: 0
- },()=>{
- this.loadMyPubarticles()
- })
- break;
- }
- this.setData({
- curNav: e.currentTarget.dataset.cur
- })
- wx.setNavigationBarTitle({
- title: this.data.navs[e.currentTarget.dataset.cur].name
- })
- },
- clickHideAuthPanel() {
- this.setData({
- showAuthPanel: false
- })
- },
- toLink (e) {
- if (!this.data.user || !this.data.user.id) {
- return this.setData({
- showAuthPanel: true
- })
- }
- wx.navigateTo({
- url: e.currentTarget.dataset.url,
- })
- },
- toLinkR() {
- if (!this.data.user || !this.data.user.id) {
- return this.setData({
- showAuthPanel: true,
- linkState: true
- })
- }
- this.setData({
- linkState: false
- })
-
- answer.checkPermission({reqdata:{
- userId: this.data.user.id
- }},r => {
- (r.object && r.object.status)
- ? this.data.user.isRegister
- ? wx.showModal({
- title: '答题须知:',
- content: '1.比赛期间每人最多答题三次\n\n 2.排行榜以得分情况计算',
- confirmColor: '#ff0000',
- cancelText: '返回',
- success (res) {
- if (res.confirm) {
- wx.navigateTo({
- url: '/pages/contest/answer/answer'
- })
- }
- }
- })
- : wx.navigateTo({
- url: '/pages/contest/info/info'
- })
- : wx.showToast({
- title: r.msg,
- icon:'none'
- })
- })
-
- },
- clickStudy () {
- wx.showToast({
- title: '精彩视频,即将呈现~',
- icon: 'none'
- })
- },
- getUserInfo (e) {
- wx.login({
- success: r => {
- wx.getUserInfo({
- success: e => {
- let {encryptedData,iv} = e
- ilogin.loadAT({
- reqdata: {
- code: r.code,
- encryptedData,
- iv
- }
- }, r => {
- wx.setStorageSync('id', r.object.id)
- wx.setStorageSync('openId', r.object.openId)
- this.loadMyinformation()
- this.clickHideAuthPanel()
- })
- },
- })
- // ilogin.loadAT({
- // reqdata: {
- // code: r.code,
- // encryptedData,
- // iv
- // }
- // }, r => {
- // console.log(r)
- // })
- }
- })
- },
- onShow() {
- wx.getStorage({
- key: 'user',
- complete: r => {
- if (r.data) {
- this.setData({
- user: r.data
- })
- }
- }
- })
- },
- onPullDownRefresh() {
- switch (this.data.curNav) {
- case 1:
- case '1':
- this.data.activity.pagination.page = 1
- this.data.activity.list = []
- this.loadActivities()
- break;
- case 2:
- case '2':
- this.data.community.pagination.page = 1
- this.data.community.list = []
- this.loadArticles()
- break;
- case 3:
- case '3':
- wx.stopPullDownRefresh()
- break;
- default:
- this.loadHome()
- }
- },
- onReachBottom() {
- if (this.data.curNav == 1) {
- this.data.activity.pagination.page += 1
- this.loadActivities()
- }
- if (this.data.curNav == 2) {
- this.data.community.pagination.page += 1
- this.loadArticles()
- }
- if (this.data.curNav == 3) {
- this.data.mine.pagination.page += 1
- switch (this.data.mine.curNav) {
- case 1:
- case '1':
- this.loadMyCollectedarticles();
- break;
- case 2:
- case '2':
- this.loadMyComments()
- break;
- case 3:
- case '3':
- this.loadMyActivities()
- break;
- default:
- this.loadMyPubarticles()
- }
- }
- },
- loadConfig() {
- ilogin.loadConfig({},r => {
- app.config = r
- this.setData({
- config: r
- })
- })
- },
- onShareAppMessage() {
- return {
- title: '冰雪小程序',
- path: '/pages/home/home',
- imageUrl: '../../imgs/share2.jpg',
- success: function(res) {},
- fail: function(res) {
- console.log(res, '失败')
- }
- }
- }
- })
|