锦水志愿者去哪小程序
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.

753 lines
21 KiB

// pages/heartNew/heartNew.js
const app = getApp()
var api = require("../../utils/activity.js")
import {
getTimestamp
} from "../../utils/common"
import checkoutVersion from "../../utils/checkVersion"
Page({
/**
* 页面的初始数据
*/
data: {
statusHeight: 0, // 自定义头部状态栏高度
navigationHeight: 0, // 自定义头部导航栏高度
selectedTab: "tab0",
// banner 相关
banner: [],
indicatorDots: false, //指示点
autoplay: true, //true false,//自动播放
circular: true, //衔接滑动
interval: 4000, //自动播放间隔时长(ms)
duration: 500, //幻灯片切换时长(ms)
currentSwiper: 0,
// banner 相关end
// 列表相关
loadMoreVisible: false, //false
loadMoreType: "none", //loading none
dingdan: false,//判断订单列表隐藏
jingcai: true,//判断精彩列表隐藏
indexPage: 1,
pageSize: 10,
qkdat: false,//判断是否清空数据
actId: "",//判断返回以后是否需要刷新列表
volunteerlist:[],//志愿者列表
volunteerCount: 0, //志愿者注册数
listLength:0,//数据长度判断是否需要加载
getImgUrl:"",
ifClickImage:false,//因为志友多多点击图片查看大图,会出现列表刷新的bug,所以加这个字段进行控制
tabFixed: false,
searchName: '',
infoCompleted: 0, //是否完善了用户信息
completeInfoDialogVisible: false,
tabRightList: [], //拼团购和顺道捎
volunteerTagId: '',//志愿者标签id
tagList: [
{
tagName: '全部',
id: ''
}
],
isLoading: false, //防止标签切换加载数据时点击切换标签
btnTop: 0,
btnLeft: 0,
sceneFrom:'', // indexNew通过扫码进入,跳转到?
fromprogram: '', // indexNew来自工作端=work 或者 数据分析端=leader 的跳转,
gid: "", // indexNew
isVolunteer: false, // 通过接口获取判断是否已注册过志愿者
defaultGridId: '', // 默认网格id 用于默认注册未注册的用户
detailId: '', // 通过分享进入 团购详情的id
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.indexNew(options)
},
onLoadConfig () {
this.getVolunteerVerify()
this.bannerListV2()
this.getVolunteerTags()
this.getImgUrl()//获取配置图片
this.setData({
statusHeight: app.globalData.deviceInfo.statusHeight,
navigationHeight: app.globalData.deviceInfo.navigationHeight,
infoCompleted: app.globalData.infoCompleted
})
let parms = {
pageIndex: this.data.indexPage,
pageSize: this.data.pageSize,
timestamp: getTimestamp(),
actType: 0,
qkdat: true,
selectedTab:this.data.selectedTab
}
this.selectComponent("#state-0").getActivityList(parms)
this.setData({
btnTop: app.globalData.screen.height * 2 * 0.75,
btnLeft: (app.globalData.screen.width * 2 - 200) * 0.5
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
if (app.globalData.volunteerChange) {
app.globalData.volunteerChange = false
this.getUserState()
return
}
if(this.data.selectedTab == "tab1"){//刷新志友
if(this.data.ifClickImage){//如果为true就不可以刷新,判断完成以后重新置为false
this.setData({
ifClickImage: false
})
}else{
this.setData({
loadMoreVisible: false,
loadMoreType: "none",
indexPage: 1,
})
this.setData({
dingdan: true,
jingcai: true,
volunteerlist:[],//列表置空
listLength:0
})
let parms = {
pageIndex: this.data.indexPage,
pageSize: this.data.pageSize,
nickname: this.data.searchName,
volunteerTagId: this.data.volunteerTagId
}
this.volunteerlist(parms)
}
} else if (this.data.selectedTab == "tab3") {
this.setData({
dingdan: false,
jingcai: true,
selectedTab: 'tab0'
})
let parms = {
pageIndex: this.data.indexPage,
pageSize: this.data.pageSize,
timestamp: getTimestamp(),
actType: 0,//活动列表类型(0-招募令,1-精彩活动)
qkdat: true,
selectedTab:this.data.selectedTab
}
this.selectComponent("#state-0").getActivityList(parms)
}
if (this.data.actId) {
this.setData({
loadMoreVisible: false,
loadMoreType: "none",
indexPage: 1,
})
this.updateActivityList()
}
},
// tab 切换
tabBarChange (e) {
this.setData({
loadMoreVisible: false,
loadMoreType: "none",
indexPage: 1,
})
if (e.currentTarget.dataset.tab == "tab0") {
this.setData({
dingdan: false,
jingcai: true,
})
let parms = {
pageIndex: this.data.indexPage,
pageSize: this.data.pageSize,
timestamp: getTimestamp(),
actType: 0,//活动列表类型(0-招募令,1-精彩活动)
qkdat: true,
selectedTab:e.currentTarget.dataset.tab
}
this.selectComponent("#state-0").getActivityList(parms)
} else if (e.currentTarget.dataset.tab == "tab1") {
this.setData({
dingdan: true,
jingcai: true,
volunteerlist:[],//列表置空
listLength:0,
searchName: ''
})
let parms = {
pageIndex: this.data.indexPage,
pageSize: this.data.pageSize,
nickname: this.data.searchName,
volunteerTagId: this.data.volunteerTagId
}
this.volunteerlist(parms)
} else if (e.currentTarget.dataset.tab == "tab2") {
this.setData({
dingdan: true,
jingcai: false,
})
let parms = {
pageIndex: this.data.indexPage,
pageSize: this.data.pageSize,
timestamp: getTimestamp(),
actType: 1,//活动列表类型(0-招募令,1-精彩活动)
qkdat: true,
selectedTab:e.currentTarget.dataset.tab
}
this.selectComponent("#state-2").getActivityList(parms)
} else if (e.currentTarget.dataset.tab == "tab3") {
this.setData({
dingdan: true,
jingcai: true,
})
wx.navigateTo({
url: "/subpages/heart/pages/leaderboardNew/leaderboardNew"
})
}
this.setData({
selectedTab: e.currentTarget.dataset.tab
})
},
// 返回以后刷新列表
updateActivityList () {
if ((this.data.selectedTab === "tab0")) {
let params = {
pageIndex: 1,
pageSize: 10,
timestamp: getTimestamp(),
actType: 0,
actId: this.data.actId,
selectedTab:this.data.selectedTab
}
this.selectComponent("#state-0").updateActivityList(params)
} else if (this.data.selectedTab === "tab2") {
let params = {
pageIndex: 1,
pageSize: 10,
timestamp: getTimestamp(),
actType: 1,
actId: this.data.actId,
selectedTab:this.data.selectedTab
}
this.selectComponent("#state-2").updateActivityList(params)
}
this.setData({
actId: ""
})
},
// 志愿者列表
volunteerlist (params){
let that = this
api.volunteerV2list(params).then(function (res) {
if (res.data.volunteerList.length !== that.data.pageSize) {
that.setData({
loadMoreVisible: true,
loadMoreType: "none",
})
}
that.setData({
listLength:res.data.volunteerList.length,
volunteerlist:that.data.volunteerlist.concat(res.data.volunteerList),
volunteerCount: res.data.volunteerCount,
isLoading: false
})
})
},
//返回上一级
goback () {
wx.navigateBack({
delta: 1
})
},
// banner 切换
swiperChange: function (e) {
this.setData({
currentSwiper: e.detail.current
})
},
// 通过判断列表的长度断定是否显示加载中
toActDetailDown (e) {
if (e.detail.listLength !== this.data.pageSize) {
this.setData({
loadMoreVisible: true,
loadMoreType: "none",
})
}
this.setData({
actId: e.detail.actId,
listLength: e.detail.listLength
})
},
clickImage (e){
this.setData({
ifClickImage: e.detail,
})
},
bindInputValue (e) {
this.setData({
searchName: e.detail.value
})
},
searchName () {
console.log(this.data.searchName)
if(!this.data.searchName) {
wx.showToast({
title: '请输入搜索的昵称',
icon: 'none',
duration: 2000
})
return;
}
this.setData({
volunteerlist: [],
indexPage: 1
})
let parms = {
pageIndex: this.data.indexPage,
pageSize: this.data.pageSize,
nickname: this.data.searchName,
volunteerTagId: this.data.volunteerTagId
}
this.volunteerlist(parms)
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.bannerListV2()
},
bannerListV2: function () {
let that = this
let params = {
bannerType:"0"
}
api.bannerList(params).then(function (res) {
that.setData({
banner: res.data
})
wx.stopPullDownRefresh();
})
},
// 获取志愿者标签列表
getVolunteerTags () {
api.getVolunteerTags().then(res => {
if (res.code == 0 && res.msg == 'success') {
const tagList = this.data.tagList.concat(res.data)
console.log('志愿者标签列表: ', tagList)
this.setData({
tagList
})
}
}).catch(err => {
console.log(err)
})
},
// 获取配置图片
getImgUrl:function (){//0:咨询热线
let that = this
api.getImgUrl("0").then(function (res) {
that.setData({
getImgUrl: res.data[0]
})
})
// 2021.05.08
api.getImgUrl("5").then(function (res) {
that.setData({
tabRightList: res.data
})
})
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if (this.data.listLength !== this.data.pageSize) {
this.setData({
loadMoreVisible: true,
loadMoreType: "none",
})
} else {
this.setData({
loadMoreVisible: true,
loadMoreType: "loading",
})
}
if (this.data.selectedTab == "tab0") {
this.setData({
indexPage: this.data.indexPage + 1
})
let parms = {
pageIndex: this.data.indexPage,
pageSize: this.data.pageSize,
timestamp: getTimestamp(),
actType: 0,
selectedTab:this.data.selectedTab
}
this.selectComponent("#state-0").getActivityList(parms)
}else if(this.data.selectedTab == "tab1"){
this.setData({
indexPage: this.data.indexPage + 1
})
let parms = {
pageIndex: this.data.indexPage,
pageSize: this.data.pageSize,
nickname: this.data.searchName,
volunteerTagId: this.data.volunteerTagId
}
this.volunteerlist(parms)
} else if (this.data.selectedTab == "tab2") {
this.setData({
indexPage: this.data.indexPage + 1
})
let parms = {
pageIndex: this.data.indexPage,
pageSize: this.data.pageSize,
timestamp: getTimestamp(),
actType: 1,
selectedTab:this.data.selectedTab
}
this.selectComponent("#state-2").getActivityList(parms)
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
//跳转志愿者认证页面
govolunteer () {
wx.navigateTo({
url: "/subpages/heart/pages/volunteer/volunteer"
})
},
//拨打电话
getPhone (e) {
// return false
wx.showModal({
title: "拨打电话",
content: "",
cancelColor: "#29B9A5",
confirmColor: "#29B9A5",
success: (res) => {
if (res.confirm) {
console.log("用户点击确定")
wx.makePhoneCall({
phoneNumber: e.currentTarget.dataset.number
})
} else if (res.cancel) {
console.log("用户点击取消")
}
}
})
},
onPageScroll: function (ev) {
var _this = this;
if (ev.scrollTop <= 0) {
ev.scrollTop = 0;
} else if (ev.scrollTop > wx.getSystemInfoSync().windowHeight) {
ev.scrollTop = wx.getSystemInfoSync().windowHeight;
}
if (ev.scrollTop > 210 || ev.scrollTop == wx.getSystemInfoSync().windowHeight) {
//向下滚动
this.setData({
tabFixed: true
})
} else {
//向上滚动
this.setData({
tabFixed: false
})
}
},
//跳转到我要提交页面
myApply () {
if (this.data.infoCompleted == 0) {
this.setData({
completeInfoDialogVisible: !this.data.completeInfoDialogVisible
})
return false
}
wx.navigateTo({
url: "/subpages/heart/pages/myApply/myApply"
})
},
//banner跳转到详情
toBannerDetail (e) {
wx.navigateTo({
url: `/subpages/heart/pages/bannerDetail/bannerDetail?id=${e.currentTarget.dataset.id}`
})
},
// 跳转 拼团购顺道捎 入口移至首页
toJumpPage (e) {
if (e.currentTarget.dataset.code == 'ptg') {
wx.navigateTo({
url: `/subpages/heart/pages/groupBuyList/groupBuyList?title=${e.currentTarget.dataset.title}`
})
} else if (e.currentTarget.dataset.code == 'sds') {
wx.navigateTo({
url: `/subpages/heart/pages/dropByList/dropByList?title=${e.currentTarget.dataset.title}`
})
}
},
//选择志愿者标签筛选
changeTag (e) {
if (this.data.isLoading) {
wx.showToast({
title: '正在加载...',
icon: 'loading',
})
return
}
const id = e.currentTarget.dataset.id
this.setData({
volunteerTagId: id,
volunteerlist: [],
indexPage: 1,
isLoading: true
})
let parms = {
pageIndex: this.data.indexPage,
pageSize: this.data.pageSize,
nickname: this.data.searchName,
volunteerTagId: this.data.volunteerTagId
}
this.volunteerlist(parms)
},
//扫描签到码
scanCode () {
wx.scanCode({
onlyFromCamera: false,
scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
success: res => {
if (res.errMsg == 'scanCode:ok') {
wx.navigateTo({
url: `/subpages/heart/pages/scanCodeSignin/scanCodeSignin?id=${res.result}`
})
}
},
fail: res => {
// 接口调用失败
// wx.showToast({
// icon: 'none',
// title: '接口调用失败!'
// })
},
complete: res => {
// 接口调用结束
console.log(res)
}
});
},
//2021.04.07 志愿者独立小程序 indexNew
indexNew (options) {
this.getResidentConfig()
if (options.shareType) {
const para = {
shareType: options.shareType,
// id: options.id,
detailId: options.detailId,
// type: options.type ? options.type : "",
// defaultGridId: options.defaultGridId ? options.defaultGridId : "",
}
wx.setStorageSync("shareObj", JSON.stringify(para))
}
// if (options.scene) {
// if (options.scene == 'module_ma_code_zyzqn' || options.scene == 'module_ma_code_lbzx') {
// this.setData({
// sceneFrom: options.scene
// })
// } else {
// this.setData({
// gridId: options.scene,
// fromprogram: options.from,
// gid: decodeURIComponent(options.scene)
// })
// }
// }
setTimeout(() => {
this.getUserState()
}, 700)
// 检查版本更新
checkoutVersion()
},
// indexNew根据微信code查询用户当前状态
getUserState: function () {
let that = this
wx.login({
success (res) {
if (res.code) {
let code = res.code
api.getToken(code).then(function (res) {
let state = res.data.userState
// console.log(state)
// console.log('date', Date.parse(new Date()))
app.globalData.infoCompleted = state
wx.removeStorageSync("topGridName")
wx.setStorageSync("topGridName", res.data.grid)
wx.removeStorageSync("token")
wx.setStorageSync("token", res.data.token)
// that.setData({
// departmentName: res.data.grid
// })
// 优化注册流程
// if (that.data.gid && !that.data.fromprogram) {
// if (that.data.gid == "gridLeader") {
// wx.redirectTo({
// url: "/pages/gridLeaderRegister/gridLeaderRegister"
// })
// } else {
// wx.redirectTo({
// url: "/pages/formid/formid?gid=" + that.data.gid
// })
// }
// } else {
if (state == "4") {
// if (wx.getStorageSync("shareObj")) {
// const para = JSON.parse(wx.getStorageSync("shareObj"))
// wx.redirectTo({
// url: "/pages/formid/formid?gid=" + para.defaultGridId
// })
// } else if (that.data.sceneFrom!='') {
// if (that.data.sceneFrom == 'module_ma_code_zyzqn') {
// wx.redirectTo({
// url: "/pages/formid/formid?gid=" + that.data.zyzqnGridId+'&module=module_ma_code_zyzqn'
// })
// } else if (that.data.sceneFrom == 'module_ma_code_lbzx') {
// wx.redirectTo({
// url: "/pages/formid/formid?gid=" + that.data.lbzxGridId+'&module=module_ma_code_lbzx'
// })
// }
// } else if (that.data.fromprogram) {
// wx.redirectTo({
// url: "/pages/formid/formid?gid=" + that.data.gid
// })
// } else if (app.globalData.tempGridId == "") {
// wx.redirectTo({
// url: "/pages/toRegister/toRegister"
// })
// } else {
// wx.redirectTo({
// url: "/pages/formid/formid?gid=" + that.data.gid
// })
// }
that.registDefaultGrid()
} else {
// if (that.data.sceneFrom == 'module_ma_code_zyzqn') {
// wx.navigateTo({
// url: "/pages/heartNew/heartNew"
// })
// } else if (that.data.sceneFrom == 'module_ma_code_lbzx') {
// //that.toLaoBingZaiXian(1)
// }
if (wx.getStorageSync("shareObj")) {
const para = JSON.parse(wx.getStorageSync("shareObj"))
// if (para.shareType === "heartDetail") {
// wx.navigateTo({
// url: `/subpages/heart/pages/heartDetail/heartDetail?id=${para.id}`
// })
// } else if (para.shareType === 'newsDetail') {
// wx.navigateTo({
// url: `/subpages/home/pages/newsDetail/newsDetail?id=${para.detailId}`
// })
// }
if (para.shareType === 'groupBuyDetail') {
wx.navigateTo({
url: `/subpages/heart/pages/groupBuyDetail/groupBuyDetail?id=${para.detailId}`
})
}
wx.removeStorageSync("shareObj")
}
that.onLoadConfig()
}
// }
})
} else {
console.log("登录失败" + res.errMsg)
}
}
})
},
getVolunteerVerify () {
api.getVolunteerVerify().then(res => {
if (res.code == 0) {
if (res.data && res.data.id) {
this.setData({
isVolunteer: true
})
}
}
})
},
//未注册过的用户直接默认绑定默认网格
registDefaultGrid () {
let that = this
wx.login({
success (res) {
if (res.code) {
console.log("微信CODE: " + res.code)
const para = {
inviteUserId: "",
gridId: that.data.defaultGridId,
wxCode: res.code
}
api.getTokenV2(para).then(function (res) {
let state = res.data.userState
app.globalData.infoCompleted = state
wx.removeStorageSync("token")
wx.setStorageSync("token", res.data.token)
that.getUserState()
})
}
}
})
},
// 获取默认网格
getResidentConfig (){
let that = this
api.getResidentConfig().then(res => {
if (res.code === 0 && res.msg === "success") {
res.data.forEach(item => {
if (item.residentType === "default_grid" && item.residentCode === "default_grid") {
that.setData({
defaultGridId:item.residentValue
})
}
})
}
}).catch(err => {
console.log(err)
})
},
})