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.

200 lines
4.0 KiB

5 years ago
// pages/activity/huawei/list/index.js
import commonApi from "../../../../utils/https/common"
Page({
/**
* 页面的初始数据
*/
data: {
id:null,
types:[],
typeIndex:0,
list:[],
detail:{},
showRuleFlag:false,
user_id:null,
isReg:false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
id:options.id
})
if(options.user_id){
let user_id = wx.getStorageSync('jstrip_userid');
if(user_id!=options.user_id){
this.setData({
user_id:options.user_id
})
}
}
commonApi.user_post("actonline/act_online/isSign",{id:options.id}).then(res=>{
if(res.code==1){
this.setData({
isReg:res.data
})
}
})
commonApi.user_post("actonline/act_online/getActDetail",{id:options.id}).then(res=>{
this.setData({
detail:res.data
})
})
commonApi.user_post("actonline/act_online/getActTypeList",{
act_id:this.data.id
}).then(res=>{
this.setData({
types:res.data
})
if(res.data.length>0){
this.getList()
}
})
},
showRule:function(){
this.setData({
showRuleFlag:!this.data.showRuleFlag
})
},
reUpload:function(){
let that = this;
wx.showModal({
title:"提示",
content:"一个分类的作品多次提交,平台只保留最近上传的作品。",
cancelText:"否",
confirmText:"是",
success:function(res){
if(res.confirm){
that.gotoUpload()
}
}
})
},
changeType:function(e){
this.setData({
typeIndex:e.currentTarget.dataset.type,
list:[]
})
this.getList()
},
getList:function(){
commonApi.user_post("actonline/act_online/myWork",{
type_id:this.data.types[this.data.typeIndex].id,
id:this.data.id,
page:1,
limit:100,
user_id:this.data.user_id || null
}).then(res=>{
if(this.data.user_id && res.data.data[0].status!=1){
res.data.data = []
}
this.setData({
list:res.data.data
})
this.onShareAppMessage()
})
},
gotoUpload:function(){
if(this.data.isReg){
wx.navigateTo({
url: '../upload/index?id='+this.data.id
})
}
else {
wx.navigateTo({
url: '../index?id='+this.data.id
})
}
},
vote:function(e){
let that = this
commonApi.user_post("actonline/act_online/vote",{
id:this.data.list[0].id
}).then(res=>{
if(res.code==1){
wx.showToast({
title: '投票成功',
icon:'success'
})
let list = this.data.list;
list[0].votes = Number(list[0].votes) + 1;
}
else if(res.code==-1){
wx.showModal({
title:"提示",
content:res.msg,
confirmText:"关闭",
cancelText:"前往报名",
success:function(res){
if(!res.confirm){
wx.navigateTo({
url: '/pages/activity/huawei/index?id='+that.data.id
})
}
}
})
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
if(this.data.list.length>0){
return {
title:"帮我投一票吧~",
path:"/pages/activity/huawei/list/index?id="+this.data.id+"&user_id="+this.data.list[0].user.id,
imageUrl:this.data.list[0].img
}
}
}
})