345 lines
7.7 KiB
JavaScript
345 lines
7.7 KiB
JavaScript
const app = getApp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
token: app.globalData.token,
|
|
page: {
|
|
page: 1,
|
|
rows: 5,
|
|
newsTypeId: '52baf515-304c-46f2-911a-355d889346f2',
|
|
showArea: '6dcbb862-4b48-4dca-aee1-d78fd76adc05'
|
|
},
|
|
noticeList: [],
|
|
serviceUrl: app.baseUrls.serviceUrl,
|
|
// serviceUrl: app.baseUrls.requestUrl,
|
|
baseImgUrl: app.baseUrls.baseImgUrl,
|
|
cardInfo: {},
|
|
curCommunity: wx.getStorageSync('curCommunityName'),
|
|
sourceUrl: app.baseUrls.sourceUrl
|
|
},
|
|
// 切换社区
|
|
changeCommunity: function () {
|
|
wx.navigateTo({
|
|
url: '../community/changeCommunity',
|
|
})
|
|
},
|
|
// 加入社区
|
|
joinCommunity: function () {
|
|
wx.navigateTo({
|
|
url: '../community/joinCommunity',
|
|
})
|
|
},
|
|
// 党员报到
|
|
doCheckIn: function () {
|
|
if (wx.getStorageSync('curCommunityId')) {
|
|
if (wx.getStorageSync('areaLevel') < 4) {
|
|
wx.showToast({
|
|
title: '请选择至社区级',
|
|
icon: 'error'
|
|
})
|
|
} else {
|
|
wx.navigateTo({
|
|
url: '../checkIn/checkIn',
|
|
})
|
|
}
|
|
} else {
|
|
wx.showToast({
|
|
title: '请先选择社区',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
},
|
|
// 微事我言
|
|
goTalk: function () {
|
|
if (wx.getStorageSync('curCommunityId')) {
|
|
if (wx.getStorageSync('areaLevel') < 4) {
|
|
wx.showToast({
|
|
title: '请选择至社区级',
|
|
icon: 'error'
|
|
})
|
|
} else {
|
|
wx.navigateTo({
|
|
url: '../talk/talk',
|
|
})
|
|
}
|
|
} else {
|
|
wx.showToast({
|
|
title: '请先选择社区',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
},
|
|
// 事件上报
|
|
goReport: function () {
|
|
if (wx.getStorageSync('curCommunityId')) {
|
|
if (wx.getStorageSync('areaLevel') < 4) {
|
|
wx.showToast({
|
|
title: '请选择至社区级',
|
|
icon: 'error'
|
|
})
|
|
} else {
|
|
wx.navigateTo({
|
|
url: '../report/report',
|
|
})
|
|
}
|
|
} else {
|
|
wx.showToast({
|
|
title: '请先加入并选择社区',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
},
|
|
// 生活服务
|
|
goServe: function () {
|
|
if (wx.getStorageSync('curCommunityId')) {
|
|
if (wx.getStorageSync('areaLevel') < 4) {
|
|
wx.showToast({
|
|
title: '请选择至社区级',
|
|
icon: 'error'
|
|
})
|
|
} else {
|
|
wx.navigateTo({
|
|
url: '../serve/serve',
|
|
})
|
|
}
|
|
} else {
|
|
wx.showToast({
|
|
title: '请先加入并选择社区',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
},
|
|
// 更多新闻
|
|
checkMoreNews: function () {
|
|
wx.navigateTo({
|
|
url: '../news/newsList',
|
|
})
|
|
},
|
|
// 获取通知公告
|
|
getNotice: function () {
|
|
var self = this
|
|
app.restAjax.get(app.restAjax.path(app.apis.getNewsList, [app.baseUrls.requestUrl]), self.data.page, {
|
|
headers: {
|
|
token: self.data.token
|
|
}
|
|
}, function (code, data) {
|
|
self.setData({
|
|
noticeList: data.rows
|
|
})
|
|
}, function (code, data) {
|
|
console.log(data)
|
|
})
|
|
},
|
|
// 查看通知公告详情
|
|
checkNewsDetail: function (e) {
|
|
var id = e.currentTarget.dataset.id
|
|
wx.navigateTo({
|
|
url: '../news/newsDetail?newsId=' + id,
|
|
})
|
|
},
|
|
|
|
// 登录
|
|
doLogin: function () {
|
|
var self = this
|
|
wx.login({
|
|
success: function (res) {
|
|
app.restAjax.post(app.restAjax.path(app.apis.doLogin, [app.baseUrls.serviceUrl]), {
|
|
jsCode: res.code
|
|
}, {}, function (code, data) {
|
|
console.log(data)
|
|
}, function (code, data) {
|
|
console.log(data)
|
|
})
|
|
}
|
|
})
|
|
},
|
|
// 获取字典
|
|
getDictionary: function () {
|
|
var self = this
|
|
app.restAjax.get(app.restAjax.path(app.apis.getDictionary, [app.baseUrls.serviceUrl, '5879c4fc-d357-44a1-9126-394af36ffe63']), {}, {
|
|
headers: {
|
|
token: self.data.token
|
|
}
|
|
}, function (code, data) {
|
|
console.log(data)
|
|
}, function (code, data) {
|
|
console.log(data)
|
|
})
|
|
},
|
|
// 扫码获取名片
|
|
getCard: function () {
|
|
var self = this
|
|
app.restAjax.get(app.restAjax.path(app.apis.getCardDetail, [app.baseUrls.requestUrl, self.data.cardId]), {}, {
|
|
headers: {
|
|
token: self.data.token
|
|
}
|
|
}, function (code, data) {
|
|
self.setData({
|
|
cardInfo: data
|
|
})
|
|
wx.setStorage({
|
|
data: data.areaCode,
|
|
key: 'areaCode'
|
|
})
|
|
}, function (code, data) {
|
|
console.log(data)
|
|
})
|
|
},
|
|
// 获取默认名片
|
|
getDefaultCard: function () {
|
|
var self = this
|
|
app.restAjax.get(app.restAjax.path(app.apis.getDefaultCard, [app.baseUrls.requestUrl]), {}, {
|
|
headers: {
|
|
token: self.data.token
|
|
}
|
|
}, function (code, data) {
|
|
self.setData({
|
|
cardInfo: data
|
|
})
|
|
// wx.setStorage({
|
|
// data: data.areaCode,
|
|
// key: 'areaCode'
|
|
// })
|
|
}, function (code, data) {
|
|
console.log(data)
|
|
})
|
|
},
|
|
// 获取头像
|
|
checkPermission() {
|
|
var _self = this
|
|
try {
|
|
var names = wx.getStorageSync('name')
|
|
var icon = wx.getStorageSync('userIcon')
|
|
|
|
if (names) {
|
|
this.setData({
|
|
name: names,
|
|
userIcon: icon
|
|
})
|
|
} else {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '小程序需要您微信头像以及昵称用于展示,请授权.',
|
|
showCancel: false,
|
|
success(res) {
|
|
if (res.confirm) {
|
|
_self.getUserProfile(3)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
} catch (error) {
|
|
wx.showToast({
|
|
title: '获取信息失败',
|
|
icon: 'error'
|
|
})
|
|
}
|
|
},
|
|
getUserProfile(e) {
|
|
let _self = this
|
|
wx.getUserProfile({
|
|
desc: '获取微信头像以及昵称用于展示',
|
|
success: (res) => {
|
|
wx.setStorage({
|
|
data: res.userInfo.nickName,
|
|
key: 'name',
|
|
})
|
|
wx.setStorage({
|
|
data: res.userInfo.avatarUrl,
|
|
key: 'userIcon',
|
|
})
|
|
_self.setData({
|
|
name: res.userInfo.nickName,
|
|
userIcon: res.userInfo.avatarUrl
|
|
})
|
|
app.globalData.userIcon = res.userInfo.avatarUrl
|
|
app.globalData.userInfo = res.userInfo
|
|
// _self.selectComponent('#head').refreshCart()
|
|
},
|
|
fail(err) {
|
|
//判断是否绑定手机号
|
|
wx.showToast({
|
|
title: '获取个人信息失败',
|
|
icon: 'error',
|
|
})
|
|
}
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
// this.doLogin()
|
|
this.getNotice()
|
|
this.checkPermission()
|
|
wx.setStorage({
|
|
data: '1',
|
|
key: 'gridMiniId'
|
|
})
|
|
if (options.id) {
|
|
this.setData({
|
|
cardId: options.id
|
|
})
|
|
this.getCard()
|
|
} else {
|
|
this.getDefaultCard()
|
|
}
|
|
// this.getDictionary()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
this.setData({
|
|
curCommunityName: wx.getStorageSync('curCommunityName') ? wx.getStorageSync('curCommunityName'): '切换社区',
|
|
curCommunityId: wx.getStorageSync('curCommunityId') ? wx.getStorageSync('curCommunityId') : '',
|
|
curCommunity: wx.getStorageSync('curCommunityName')
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |