387 lines
8.8 KiB
JavaScript
387 lines
8.8 KiB
JavaScript
// pages/center/center.js
|
|
const app = getApp()
|
|
const md5 = require('../../utils/md5.js')
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
token: app.globalData.token,
|
|
sourceUrl: app.baseUrls.sourceUrl,
|
|
userIcon: '',
|
|
userName: '',
|
|
curCommunityName: '',
|
|
gridList: [],
|
|
serviceUrl: app.baseUrls.serviceUrl,
|
|
baseImgUrl: app.baseUrls.baseImgUrl,
|
|
userNameText: '',
|
|
userPassword: '',
|
|
showAuthentication:false,
|
|
isLoading: false
|
|
},
|
|
// 获取头像
|
|
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',
|
|
})
|
|
}
|
|
})
|
|
},
|
|
// 获取邻里统计-求助
|
|
getHelpCount: function () {
|
|
var self = this
|
|
app.restAjax.get(app.restAjax.path(app.apis.getHelpCount, [app.baseUrls.requestUrl]), {
|
|
problemTypeId: 'b99f796f-b3a0-4d52-b10e-6e387ebbcc1b',
|
|
areaCode: wx.getStorageSync('areaCode')
|
|
}, {
|
|
headers: {
|
|
token: self.data.token
|
|
}
|
|
}, function (code, data) {
|
|
self.setData({
|
|
helpCount: data.data
|
|
})
|
|
}, function (code, data) {
|
|
console.log(data)
|
|
})
|
|
},
|
|
// 获取邻里统计-交友
|
|
getFriendCount: function () {
|
|
var self = this
|
|
app.restAjax.get(app.restAjax.path(app.apis.getHelpCount, [app.baseUrls.requestUrl]), {
|
|
problemTypeId: '99cf4a4e-22a2-49b2-9274-4519cd47cefd'
|
|
}, {
|
|
headers: {
|
|
token: self.data.token
|
|
}
|
|
}, function (code, data) {
|
|
self.setData({
|
|
friendCount: data.data
|
|
})
|
|
}, function (code, data) {
|
|
console.log(data)
|
|
})
|
|
},
|
|
// 获取邻里统计-其他
|
|
getOtherCount: function () {
|
|
var self = this
|
|
app.restAjax.get(app.restAjax.path(app.apis.getHelpCount, [app.baseUrls.requestUrl]), {
|
|
problemTypeId: '02a11dc0-9656-4504-8c11-030a28914ff3'
|
|
}, {
|
|
headers: {
|
|
token: self.data.token
|
|
}
|
|
}, function (code, data) {
|
|
self.setData({
|
|
otherCount: data.data
|
|
})
|
|
}, function (code, data) {
|
|
console.log(data)
|
|
})
|
|
},
|
|
// 网格员认证
|
|
checkGrid: function () {
|
|
this.setData({
|
|
showAuthentication: true
|
|
})
|
|
wx.hideTabBar({
|
|
animation: false,
|
|
})
|
|
},
|
|
// 获取网格员列表
|
|
getGridList: function () {
|
|
var self = this
|
|
app.restAjax.get(app.restAjax.path(app.apis.getGridListPage, [app.baseUrls.requestUrl]), {
|
|
page: 1,
|
|
rows: 3,
|
|
areaCode: wx.getStorageSync('areaCode')
|
|
}, {
|
|
headers: {
|
|
token: self.data.token
|
|
}
|
|
}, function (code, data) {
|
|
if (code == '200') {
|
|
self.setData({
|
|
gridList: data.rows
|
|
})
|
|
}
|
|
}, function (code, data) {
|
|
console.log(data)
|
|
})
|
|
},
|
|
// 提交网格员认证
|
|
doAuthentication: function () {
|
|
var self = this
|
|
if (!self.data.isLoading) {
|
|
var info = {
|
|
userName: self.data.userNameText,
|
|
passWord: md5.hexMD5(md5.hexMD5(md5.hexMD5(self.data.userPassword)))
|
|
}
|
|
self.setData({
|
|
isLoading: true
|
|
})
|
|
app.restAjax.get(app.restAjax.path(app.apis.checkGrid, [app.baseUrls.requestUrl]), info, {
|
|
headers: {
|
|
token: self.data.token
|
|
}
|
|
}, function (code, data) {
|
|
wx.hideLoading()
|
|
if (data.data == true) {
|
|
wx.showToast({
|
|
title: '认证成功!',
|
|
icon: 'success'
|
|
})
|
|
self.setData({
|
|
showAuthentication: false,
|
|
userNameText: '',
|
|
userPassword: '',
|
|
isLoading: false
|
|
})
|
|
wx.showTabBar({
|
|
animation: false,
|
|
})
|
|
self.getGridList()
|
|
} else {
|
|
wx.showToast({
|
|
title: '认证失败!',
|
|
icon: 'error'
|
|
})
|
|
self.setData({
|
|
isLoading: false
|
|
})
|
|
}
|
|
}, function (code, data) {
|
|
console.log(data)
|
|
wx.showToast({
|
|
title: data.msg,
|
|
icon: 'error'
|
|
})
|
|
self.setData({
|
|
isLoading: false
|
|
})
|
|
})
|
|
}
|
|
},
|
|
// 关闭认证
|
|
closeAuthentication: function () {
|
|
this.setData({
|
|
showAuthentication: false,
|
|
userNameText: '',
|
|
userPassword: ''
|
|
})
|
|
wx.showTabBar({
|
|
animation: false,
|
|
})
|
|
},
|
|
// 快速反馈-更多
|
|
checkGridMore: function () {
|
|
wx.navigateTo({
|
|
url: './contact',
|
|
})
|
|
},
|
|
checkMoreCase: function () {
|
|
wx.navigateTo({
|
|
url: './case/caseList',
|
|
})
|
|
},
|
|
checkCaseStatus: function (e) {
|
|
var status = e.currentTarget.dataset.status
|
|
var search = ''
|
|
if (status == '2') {
|
|
search = '?handleStatus=2'
|
|
} else {
|
|
search = '?isAccept=' + status
|
|
}
|
|
wx.navigateTo({
|
|
url: './case/caseList' + search,
|
|
})
|
|
},
|
|
// 联系网格员
|
|
contactGrid: function (e) {
|
|
var id = e.currentTarget.dataset.id
|
|
wx.navigateTo({
|
|
url: './contact/contactDetail?gridMiniId=' + id,
|
|
})
|
|
},
|
|
// 获取头像
|
|
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({
|
|
userName: 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.getHelpCount()
|
|
this.getFriendCount()
|
|
this.getOtherCount()
|
|
if (!wx.getStorageSync('userIcon')) {
|
|
this.checkPermission()
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
this.getGridList()
|
|
this.setData({
|
|
userIcon: wx.getStorageSync('userIcon'),
|
|
userName: wx.getStorageSync('name'),
|
|
curCommunityName: wx.getStorageSync('curCommunityName')
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |