榆山居民端
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.
 

661 lines
17 KiB

const app = getApp()
const api = require('../../utils/api')
const homeApi = require('../../utils/home')
const global = require('../../utils/config')
import { getTimestamp } from '../../utils/common'
import checkoutVersion from '../../utils/checkVersion'
import home from '../../utils/home'
Page({
data: {
statusHeight: 0, // 自定义头部状态栏高度
navigationHeight: 0, // 自定义头部导航栏高度
bannerList: [], // banner列表
projectList: [], // 项目列表
infoList: [], // 消息列表
noticeList: [], // 通知公告列表
unReadNum: 0, // 未读数量
timestamp: '', // 时间戳
sudokuState: {
// 九宫格显隐状态
consultAvailable: '0', // 网格专员
appraiseAvailable: '0', // 请您监督
},
completeInfoDialogVisible: false, // 完善信息弹框显隐
gridId: '', // 网格id
departmentName: '', // 所在网格
isCarryLoad: false,
vaccinationSwitch: false, // 疫苗入口开关
griderList: [],
communityNewsList: [],
currentIndex: 0,
moduleList: [
{
icon:
'https://epdc-yushan.elinkservice.cn/files-pro/20211009/db9d4408de344c419bb22be21ba163b9.png',
tip: '积分排名',
module: 'pointRank',
},
{
icon:
'https://epdc-yushan.elinkservice.cn/files-pro/20220324/118ea106d9ed40978f3e23cc51b43119.png',
// 'https://epdc-yushan.elinkservice.cn/files-pro/20211009/59b127e9fc8042969334c31fe0272c3f.png', // 蓝色
tip: '指尖榆山',
module: 'fingerYushan',
},
{
icon:
'https://epdc-yushan.elinkservice.cn/files-pro/20211009/db945b5cc30147df80923f6c5928074f.png',
tip: '志愿服务',
module: 'volunteerService',
},
{
icon:
'https://epdc-yushan.elinkservice.cn/files-pro/20220324/1083316800d948b4a8a4206dcb857722.png',
tip: '个人中心',
module: 'personalCenter',
},
// {
// icon:
// 'https://epdc-yushan.elinkservice.cn/files-pro/20211009/ccbab2a8a4a847548a72972770009576.png',
// tip: '网格队伍',
// module: 'gridArmy',
// },
// {
// icon:
// 'https://epdc-yushan.elinkservice.cn/files-pro/20211009/47c5baebb4d54987b4faebfeadd92a25.png',
// tip: '社会组织',
// module: 'societyOrg',
// },
],
serviceImgUrl: '',
servicePhone: '',
tabList: [],
currentTab: '',
loadMoreType: 'none',
loadMoreVisible: false,
newsList: [],
pageNo: 1,
pageSize: 10,
currentView: 'item',
phoneSlideState: 'close',
signMsg: '',
signCode: 0,
isSignUp: 0,
visible: false,
},
onLoad(options) {
if (options.scene) {
if (options.scene.indexOf('RP') > -1) {
this.setData({
statusHeight: app.globalData.deviceInfo.statusHeight,
navigationHeight: app.globalData.deviceInfo.navigationHeight,
gridId: options.scene.substring(0, options.scene.length - 2),
})
wx.setStorageSync(
'redirectToAddIssue',
options.scene.substr(options.scene.length - 2, 2)
)
} else {
this.setData({
statusHeight: app.globalData.deviceInfo.statusHeight,
navigationHeight: app.globalData.deviceInfo.navigationHeight,
gridId: options.scene,
})
}
} else {
this.setData({
statusHeight: app.globalData.deviceInfo.statusHeight,
navigationHeight: app.globalData.deviceInfo.navigationHeight,
})
}
this.getUserState()
this.data.isCarryLoad = true
this.getResidentConfig()
},
onTabItemTap() {
this.getUserState()
},
onShow() {
this.getUnreadNum() // 实时获取有无未读消息
// 检查版本更新
checkoutVersion()
},
onReachBottom() {
this.setData({
loadMoreVisible: true,
})
if (this.data.loadMoreType === 'loading') {
this.data.pageNo += 1
this.contentList()
}
},
swiperChange: function (e) {
if (e.detail.source === 'touch') {
this.setData({
currentIndex: e.detail.current,
})
}
},
// 根据微信code查询用户当前状态
getUserState() {
let that = this
wx.login({
success(res) {
if (res.code) {
let code = res.code
api.getToken(code).then((res) => {
const state = res.data.userState
app.globalData.infoCompleted = state
wx.setStorageSync('topGridName', res.data.grid)
wx.setStorageSync('token', res.data.token)
that.setData({
departmentName: res.data.grid,
})
// 扫码进入
if (that.data.gridId !== '') {
// 扫的是网格长码
if (that.data.gridId == 'gridLeader') {
wx.redirectTo({
url: '/pages/gridLeaderRegister/gridLeaderRegister',
})
// 扫的是网格码
} else {
wx.redirectTo({
url: '/pages/formid/formid?gid=' + that.data.gridId,
})
}
} else {
if (state == '4') {
// 非扫码进入,通过搜索小程序直接进入的情况
wx.redirectTo({
url: '/pages/toRegister/toRegister',
})
} else {
if (wx.getStorageSync('redirectToAddIssue')) {
wx.navigateTo({
url: '/subpages/discussion/pages/addIssue/addIssue',
})
} else {
that.initLoad()
}
}
}
})
} else {
console.log('登录失败' + res.errMsg)
}
},
})
},
// 获取banner列表
getBannerList() {
api
.bannerList('0')
.then((res) => {
console.log('首页banner列表', res)
this.setData({
bannerList: res.data,
})
})
.catch(() => {
console.log('获取banner列表失败')
this.setData({
bannerList: [],
})
})
},
// 获取项目列表
getProjectList() {
const para = {
pageIndex: 1,
pageSize: 10,
timestamp: this.data.timestamp,
searchContent: '',
firstCategoryCode: '',
}
api
.getProjectList(para)
.then((res) => {
console.log('项目列表', res)
this.setData({
projectList: res.data,
})
})
.catch(() => {
console.log('获取项目列表失败')
this.setData({
projectList: [],
})
})
},
// 获取最新一条消息-主要获取消息未读数
getUnreadNum() {
api
.getFirstInfo()
.then((res) => {
console.log('获取消息未读数', res)
this.setData({
unReadNum: res.data.amount,
})
})
.catch(() => {
console.log('获取消息未读数失败')
})
},
// 获取消息列表
getInfoList() {
let para = {
pageIndex: 1,
pageSize: 10,
timestamp: this.data.timestamp,
}
homeApi
.getInfoList(para)
.then((res) => {
console.log('消息列表', res)
this.setData({
infoList: res.data,
})
})
.catch((err) => {
console.log('获取消息列表失败')
})
},
// 获取通知公告列表
getNoticeList() {
let para = {
pageIndex: 1,
pageSize: 10,
timestamp: this.data.timestamp,
}
homeApi
.getNoticeList(para)
.then((res) => {
this.setData({
noticeList: res.data,
})
})
.catch((err) => {
console.log(err)
})
},
// 获取 网格员
gridmanList() {
const params = {
pageIndex: 1,
pageSize: 10,
}
api
.gridmanList(params)
.then((res) => {
console.log('网格员列表', res)
this.setData({
griderList: res.data,
})
})
.catch((err) => {
console.error('网格员列表', err)
})
},
// 初始化加载
initLoad() {
this.setData({
pageNo: 1,
pageSize: 10,
timestamp: getTimestamp(),
newsList: [],
loadMoreType: 'loading',
loadMoreVisible: false,
})
this.getBannerList()
this.getProjectList()
this.getInfoList()
this.getNoticeList()
this.getUnreadNum()
this.gridmanList()
this.getImgUrl()
this.contentList()
this.contentModuleList()
this.getUserInfo() // 获取签到状态isSignUp
},
// 切换网格,跳转到网格列表
changeGrid() {
wx.navigateTo({ url: '/subpages/changegrid/pages/changeGrid/changeGrid' })
},
// 跳转到通知公告列表
navigateToInfoList() {
wx.navigateTo({
url: '/subpages/home/pages/notice/notice',
})
},
// 消息没有数据
noMore() {
wx.showToast({
title: '暂无更多消息~',
icon: 'none',
duration: 1000,
})
},
// 跳转到消息页面
navigateToNotice() {
wx.navigateTo({ url: '/subpages/home/pages/info/info' })
},
// 跳转到banner详情
navigatetoBannerDetail(e) {
const { id, url, newsflag } = e.currentTarget.dataset
if (newsflag == '0') {
wx.navigateTo({
url: `/subpages/home/pages/webview/webview?url=${url}`,
})
} else if (newsflag == '1') {
wx.navigateTo({
url: `/subpages/home/pages/newsDetail/newsDetail?id=${id}`,
})
}
},
//积分排行
navigateToIntegral() {
api
.getUserInfo()
.then((res) => {
// console.log('用户信息', res)
wx.navigateTo({
url:
'/subpages/integralCentre/pages/index/index?points=' +
res.data.points,
})
})
.catch((err) => {
console.log(err)
})
},
//社区教育
navigateToEducation() {
wx.navigateTo({
url: '/subpages/education/pages/index/index',
})
},
navigateToSynthetical() {
wx.navigateTo({
url: '/subpages/education/pages/healthyLife/healthyLife?page=zhfw',
})
},
// 获取疫苗配置
getResidentConfig() {
homeApi
.getResidentConfig()
.then((res) => {
if (res.code === 0 && res.msg === 'success') {
res.data.forEach((item) => {
if (
item.residentType === 'vaccination_config' &&
item.residentCode === 'vaccination_switch'
) {
this.setData({
vaccinationSwitch: item.residentValue === 'on',
})
}
})
}
})
.catch((err) => {
console.log(err)
})
},
//疫苗接种
toVaccines() {
wx.navigateTo({
url: '/subpages/extend/pages/epidemicControl/epidemicControl',
// url: '/subpages/extend/pages/vaccines/vaccines'
})
},
// 绑定家庭入口
toFamily() {
wx.navigateTo({
url: '/subpages/family/pages/index/index',
})
},
// 获取最新社区资讯
contentList() {
const params = {
pageIndex: 1,
pageSize: 5,
typeId: '',
}
homeApi
.contentList(params)
.then((res) => {
console.log('社区最新资讯', res)
this.setData({
communityNewsList: res.data,
})
})
.catch((err) => {
console.error(err)
})
},
// 模块列表跳转
navigateToModule(e) {
const { module } = e.currentTarget.dataset
if (module === 'gridArmy') {
wx.navigateTo({
url: '/subpages/gridArmy/pages/communityList/communityList',
})
} else if (module === 'pointRank') {
wx.navigateTo({
url: '/subpages/integralCentre/pages/index/index',
})
} else if (module === 'volunteerService') {
wx.navigateTo({
url: '/pages/heart/heart',
})
} else if (module === 'societyOrg') {
wx.navigateTo({
url: '/subpages/societyOrg/pages/orgList/orgList',
})
} else if (module === 'fingerYushan') {
wx.navigateTo({
url: '/subpages/fingertipYushan/pages/index/index',
})
} else if (module === 'personalCenter') {
wx.navigateTo({
url: '/pages/mine/mine'
})
}
},
// 我有事要说跳转
navigateToDiscussion() {
if (app.globalData.infoCompleted == 0) {
this.setData({
completeInfoDialogVisible: !this.data.completeInfoDialogVisible,
})
return false
}
wx.navigateTo({
url: '/pages/discussion/discussion',
})
// wx.navigateTo({
// url: '/subpages/discussion/pages/addIssue/addIssue'
// })
},
navigateToWork() {
if (app.globalData.infoCompleted == 0) {
this.setData({
completeInfoDialogVisible: !this.data.completeInfoDialogVisible,
})
return false
}
wx.navigateTo({
url: '/subpages/workTodo/pages/index/index',
})
},
navigateToSumbit() {
if (app.globalData.infoCompleted == 0) {
this.setData({
completeInfoDialogVisible: !this.data.completeInfoDialogVisible,
})
return false
}
wx.navigateTo({
url: '/subpages/submitAdvise/pages/activeApply/activeApply',
})
},
// 获取服务电话
getImgUrl() {
const imgType = '3'
api
.getImgUrl(imgType)
.then((res) => {
console.log('服务电话', res)
this.setData({
serviceImgUrl: res.data[0].imgUrl,
servicePhone: res.data[0].remark,
})
})
.catch((err) => {
console.error(err)
})
},
// 拨打便民服务电话
callPhone(e) {
const { phone } = e.currentTarget.dataset
wx.showModal({
title: `拨打${phone}`,
content: '',
cancelColor: '#29B9A5',
confirmColor: '#29B9A5',
success: (res) => {
if (res.confirm) {
console.log('用户点击确定')
wx.makePhoneCall({
phoneNumber: phone,
})
} else if (res.cancel) {
console.log('用户点击取消')
}
},
})
},
changeTab(e) {
const { tab } = e.currentTarget.dataset
this.setData({
currentTab: tab,
loadMoreType: 'none',
loadMoreVisible: false,
newsList: [],
currentView: `item${tab}`,
})
this.data.pageNo = 1
wx.showLoading({
title: '加载中...',
})
this.contentList()
},
// 获取资讯列表
contentList() {
const params = {
pageIndex: this.data.pageNo,
pageSize: this.data.pageSize,
typeId: this.data.currentTab,
}
homeApi
.contentList(params)
.then((res) => {
console.log('社区最新资讯', res)
this.setData({
newsList: this.data.newsList.concat(res.data),
loadMoreType:
res.data.length === this.data.pageSize ? 'loading' : 'none',
})
wx.hideLoading()
})
.catch((err) => {
console.error(err)
wx.hideLoading()
})
},
// 获取栏目列表
contentModuleList() {
homeApi
.contentModuleList()
.then((res) => {
console.log('栏目列表', res)
const tabList = []
res.data.forEach((item) => {
tabList.push({ label: item.typeName, value: item.id })
})
this.setData({
tabList: [...[{ label: '最新资讯', value: '' }], ...tabList],
})
})
.catch((err) => {
console.error('', err)
})
},
navigateToDetail(e) {
const { id } = e.currentTarget.dataset
wx.navigateTo({
url: `/subpages/communityNews/pages/detail/detail?id=${id}`,
})
},
openPhonePannel() {
this.setData({
phoneSlideState: this.data.phoneSlideState === 'open' ? 'close' : 'open',
})
},
pageTouchEnd() {
this.setData({
phoneSlideState: 'close',
})
},
// 获取用户信息
getUserInfo () {
api.getUserInfo().then(res => {
console.log("用户信息", res)
this.setData({
isSignUp: res.data.isSignUp
})
}).catch(err => {
this.setData({
isSignUp: 0
})
console.log(err)
})
},
//签到
toSignIn () {
if (app.globalData.infoCompleted == 0) {
this.setData({
completeInfoDialogVisible: !this.data.completeInfoDialogVisible,
})
return false
}
if (this.data.isSignUp == 1) {
return
}
api.userInfoSignUp().then(res => {
console.log(res.data)
if (res.code === 0) {
// 显示提醒
this.setData({
signCode: res.code,
signMsg: res.data,
visible: true
});
} else {
this.setData({
signCode: res.code,
signMsg: res.msg,
visible: true
});
}
})
},
// 关闭签到提醒
onClose() {
this.getUserInfo()
this.setData({
visible: false
});
},
})