377 lines
9.0 KiB
JavaScript
377 lines
9.0 KiB
JavaScript
var app = getApp();
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
randomName: true,
|
|
showPhone: true,
|
|
gotCode: false,
|
|
restTime: 120,
|
|
timer: '',
|
|
indicatorDots: true,
|
|
autoplay: true,
|
|
token: '',
|
|
news: {
|
|
newsUrl: app.newsUrl,
|
|
bannerList: [],
|
|
newsList: []
|
|
},
|
|
venue: {
|
|
venueUrl: app.venueUrl,
|
|
venueList: []
|
|
},
|
|
activity: {
|
|
activityUrl: app.activityUrl,
|
|
activityList: []
|
|
},
|
|
live: {
|
|
liveUrl: app.liveUrl,
|
|
liveList: []
|
|
},
|
|
usercenterUrl: app.usercenterUrl,
|
|
isConfirm: false
|
|
},
|
|
doLogin: function () {
|
|
var self = this;
|
|
wx.login({
|
|
success(res) {
|
|
if (res.code) {
|
|
app.restAjax.post(app.restAjax.path('{url}/wxminiapp/auth/login', [app.loginUrl]), {
|
|
jsCode: res.code
|
|
}, null, function (code, data) {
|
|
var tokenArray = data.data.split('_');
|
|
var token = tokenArray[0];
|
|
var isRandomUsername = tokenArray[1];
|
|
self.setData({
|
|
token: token
|
|
})
|
|
wx.setStorageSync('token', token);
|
|
wx.setStorageSync('isRandomUsername', isRandomUsername)
|
|
}, function (code, data) {
|
|
app.dialog.msg(data.msg);
|
|
});
|
|
} else {
|
|
app.dialog.msg('登录失败!'+ res.errMsg);
|
|
}
|
|
}
|
|
})
|
|
},
|
|
doGetBanner: function() {
|
|
var self = this;
|
|
app.restAjax.get(app.restAjax.path('{newsUrl}/app/newscontent/listpagenewscontentrelease', [self.data.news.newsUrl]), {
|
|
newsDirectoriesId: 'eab0ca3c-d35d-4c02-9397-ace2bdd10fc1',
|
|
page: 1,
|
|
rows: 5
|
|
}, null, function(code, data) {
|
|
self.setData({
|
|
'news.bannerList': data.rows
|
|
})
|
|
}, function(code, data) {
|
|
app.dialog.msg(data.msg);
|
|
});
|
|
},
|
|
doGetVenueList: function() {
|
|
var self = this;
|
|
app.restAjax.get(app.restAjax.path('{venueUrl}/app/venuesinfo/listpagevenuesinforelease', [self.data.venue.venueUrl]), {
|
|
page: 1,
|
|
rows: 3
|
|
}, null, function(code, data) {
|
|
for(var i = 0, item; item = data.rows[i++];) {
|
|
item.venuePanoramaArray = item.venuePanorama.split(',');
|
|
}
|
|
self.setData({
|
|
'venue.venueList': data.rows
|
|
});
|
|
}, function(code, data) {
|
|
app.dialog.msg(data.msg);
|
|
});
|
|
},
|
|
doGetActivityList: function() {
|
|
var self = this;
|
|
app.restAjax.get(app.restAjax.path('{activityUrl}/app/activitylibrary/listpageactivitylibraryrelease', [self.data.activity.activityUrl]), {
|
|
page: 1,
|
|
rows: 3
|
|
}, null, function(code, data) {
|
|
for(var i = 0, item; item = data.rows[i++];) {
|
|
item.activityImageArray = item.activityImage.split(',');
|
|
}
|
|
self.setData({
|
|
'activity.activityList': data.rows
|
|
});
|
|
}, function(code, data) {
|
|
app.dialog.msg(data.msg);
|
|
});
|
|
},
|
|
doGetNewsList: function() {
|
|
var self = this;
|
|
app.restAjax.get(app.restAjax.path('{newsUrl}/app/newscontent/listpagenewscontentrelease', [self.data.news.newsUrl]), {
|
|
newsDirectoriesParentId: 'f497904b-7727-4832-891c-604c36ae4167',
|
|
page: 1,
|
|
rows: 5
|
|
}, null, function(code, data) {
|
|
self.setData({
|
|
'news.newsList': data.rows
|
|
})
|
|
}, function(code, data) {
|
|
app.dialog.msg(data.msg);
|
|
});
|
|
},
|
|
doGetLiveList: function() {
|
|
var self = this;
|
|
app.restAjax.get(app.restAjax.path('{liveUrl}/app/liveplan/listpageliveplanrelease', [self.data.live.liveUrl]), {
|
|
page: 1,
|
|
rows: 4
|
|
}, null, function(code, data) {
|
|
self.setData({
|
|
'live.liveList': data.rows
|
|
})
|
|
}, function(code, data) {
|
|
app.dialog.msg(data.msg);
|
|
});
|
|
},
|
|
goNewsDetail: function (event) {
|
|
wx.navigateTo({
|
|
url: '../newsDetail/newsDetail?templateRecordUrl='+ event.currentTarget.dataset.templateRecordUrl,
|
|
})
|
|
},
|
|
goNewsList: function(event) {
|
|
wx.navigateTo({
|
|
url: '../newsList/newsList?type='+ event.currentTarget.dataset.type,
|
|
})
|
|
},
|
|
goVolunteer: function () {
|
|
wx.navigateTo({
|
|
url: '../volunteer/volunteer',
|
|
})
|
|
},
|
|
goBroadcast: function () {
|
|
wx.navigateTo({
|
|
url: '../broadcast/broadcast',
|
|
})
|
|
},
|
|
goVenue: function () {
|
|
wx.switchTab({
|
|
url: '../venue/venue',
|
|
})
|
|
},
|
|
goVenueDetail: function(event) {
|
|
wx.navigateTo({
|
|
url: '../venueDetail/venueDetail?venuesInfoId=' + event.currentTarget.dataset.venuesInfoId,
|
|
})
|
|
},
|
|
goBroadcastDetail: function (event) {
|
|
wx.navigateTo({
|
|
url: '../broadcastDetail/broadcastDetail?livePlanId='+ event.currentTarget.dataset.livePlanId,
|
|
})
|
|
},
|
|
goActivity: function () {
|
|
wx.switchTab({
|
|
url: '../activity/activity',
|
|
})
|
|
},
|
|
goActivityDetail: function(event) {
|
|
wx.navigateTo({
|
|
url: '../activityDetail/activityDetail?id=' + event.currentTarget.dataset.activityLibraryId
|
|
})
|
|
},
|
|
goHeritage: function () {
|
|
wx.switchTab({
|
|
url: '../heritage/heritage',
|
|
})
|
|
},
|
|
goCultureDetail: function(event) {
|
|
wx.navigateTo({
|
|
url: '../cultureDetail/cultureDetail?libraryId='+ event.currentTarget.dataset.libraryId,
|
|
})
|
|
},
|
|
// 获取输入的手机号
|
|
phoneNum: function (res) {
|
|
this.setData({
|
|
phone: res.detail.value
|
|
})
|
|
},
|
|
// 校验手机号
|
|
testPhone: function () {
|
|
var self = this
|
|
if (self.data.phone) {
|
|
if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(self.data.phone)) {
|
|
wx.showToast({
|
|
title: '请输入正确的手机号',
|
|
icon: 'none',
|
|
duration: 1500
|
|
})
|
|
} else {
|
|
self.getCode()
|
|
}
|
|
} else {
|
|
wx.showToast({
|
|
title: '手机号不能为空',
|
|
icon: 'none',
|
|
duration: 1500
|
|
})
|
|
}
|
|
},
|
|
// 获取验证码
|
|
getCode: function () {
|
|
var self = this;
|
|
self.setData({
|
|
gotCode: true
|
|
})
|
|
self.data.timer = setInterval(function () {
|
|
var cur = self.data.restTime - 1
|
|
if (cur == 0) {
|
|
clearInterval(self.data.timer)
|
|
self.setData({
|
|
restTime: 120,
|
|
gotCode: false
|
|
})
|
|
} else {
|
|
self.setData({
|
|
restTime: cur
|
|
})
|
|
}
|
|
}, 1000)
|
|
app.restAjax.get(app.restAjax.path('{usercenterUrl}/api/sms/getverificationcode/' + self.data.phone, [app.usercenterUrl]), {}, null,
|
|
function (code, data) {},
|
|
function (code, data) {
|
|
wx.showToast({
|
|
title: data.msg,
|
|
icon: 'none',
|
|
duration: 1500
|
|
})
|
|
})
|
|
},
|
|
// 提交绑定手机
|
|
submitPhone: function () {
|
|
var self = this;
|
|
self.setData({
|
|
isConfirm: true
|
|
})
|
|
app.restAjax.put(app.restAjax.path('{usercenterUrl}/app/user/updateminiappdefaultusername', [app.usercenterUrl]), {
|
|
phone: self.data.phone,
|
|
verificationCode: self.data.code
|
|
}, {
|
|
headers: {
|
|
token: self.data.token
|
|
}
|
|
}, function (code, data) {
|
|
wx.setStorageSync('token', data.data);
|
|
wx.setStorageSync('isRandomUsername', 0)
|
|
clearInterval(self.data.timer)
|
|
self.setData({
|
|
showPhone: false
|
|
})
|
|
wx.showTabBar();
|
|
self.getUserInfo()
|
|
}, function (code, data) {
|
|
app.dialog.msg(data.msg);
|
|
self.setData({
|
|
isConfirm: false
|
|
})
|
|
})
|
|
},
|
|
// 验证码
|
|
inputCode: function (e) {
|
|
this.setData({
|
|
code: e.detail.value
|
|
})
|
|
},
|
|
// 判断用户是否为随机名称
|
|
isRandomName: function () {
|
|
var self = this
|
|
wx.getStorage({
|
|
key: 'isRandomUsername',
|
|
success: function (res) {
|
|
if (res.data == 1) {
|
|
wx.hideTabBar()
|
|
self.setData({
|
|
randomName: true
|
|
})
|
|
} else {
|
|
wx.hideTabBar()
|
|
self.setData({
|
|
randomName: false
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
// 获取用户信息
|
|
getUserInfo: function () {
|
|
var self = this
|
|
app.restAjax.get(app.restAjax.path('{usercenterUrl}/app/user/getappuser', [app.usercenterUrl]), {}, {
|
|
headers: {
|
|
token: self.data.token
|
|
}
|
|
}, function (code, data) {
|
|
self.setData({
|
|
userInfo: data
|
|
})
|
|
}, function (code, data) {
|
|
app.dialog.msg(data.msg);
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
var self = this;
|
|
self.doLogin();
|
|
self.doGetBanner();
|
|
self.doGetNewsList();
|
|
self.doGetLiveList();
|
|
self.doGetVenueList();
|
|
self.doGetActivityList();
|
|
self.isRandomName();
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |