// pages/heartNew/heartNew.js const app = getApp() var api = require("../../utils/activity.js") import { getTimestamp } from "../../utils/common" 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, shouye: {}, }, /** * 生命周期函数--监听页面加载 */ onLoad: function () { this.getModuleList() 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 }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ 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.trim('') }) }, 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.03.31 拼团购顺道捎移至首页 // 2021.04.28 拼团购顺道捎移回... 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) } }); }, // 志愿者信息变更,更新用户当前状态 getUserState: function () { let that = this wx.login({ success (res) { if (res.code) { api.getToken(res.code).then((res) => { let state = res.data.userState app.globalData.infoCompleted = state wx.removeStorageSync("topGridName") wx.setStorageSync("topGridName", res.data.grid) wx.removeStorageSync("token") wx.setStorageSync("token", res.data.token) that.setData({ infoCompleted: app.globalData.infoCompleted }) }) } else { console.log("登录失败" + res.errMsg) } } }) }, // 获取模块信息 getModuleList: function () { let params = { pageIndex: 1, pageSize: 10, pid: '0' } api.moduleCategory(params).then(res => { console.log('获取模块列表',res.data) res.data.forEach( item => { if (item.categoryCode == 'shouye') { this.data.shouye = { ...item } this.setData({ shouye: this.data.shouye }) } }) }).catch(err => { console.log(err) }) }, //跳转到 页面 toShouye () { //如果是 详情样式,直接跳转详情页面 if (this.data.shouye.moduleStyle == '4') { wx.navigateTo({ url: `/subpages/oneKeyService/pages/noticeDetail/noticeDetail?pid=${this.data.shouye.pid}&bannerflag=${this.data.shouye.bannerFlag}&categorycode=${this.data.shouye.categoryCode}&modulestyle=${this.data.shouye.moduleStyle}&categoryname=${this.data.shouye.categoryName}` }) } else { wx.navigateTo({ url: `/subpages/oneKeyService/pages/moduleList/moduleList?pid=${this.data.shouye.id}&bannerflag=${this.data.shouye.bannerFlag}&categorycode=${this.data.shouye.categoryCode}&modulestyle=${this.data.shouye.moduleStyle}&categoryname=${this.data.shouye.categoryName}` }) } }, })