123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- //index.js
- //获取应用实例
- import fetch from '../../utils/http'
-
- const app = getApp()
- const $api = require('../../config/api.js').$api
-
- Page({
- onShow() {
- this.PageReset()
- if (this.data.Type === 1) {
- this.GetProjectDetail()
- } else {
- this.GetActivityDetail()
- this.GetCommentList()
- this.GetSignUpList()
- }
- },
- onLoad(e) {
- console.log(e)
- this.setData({
- Id: e.id,
- Type: e.type - 0,
- FormData: {
- ...this.data.FormData,
- activityId: e.id
- }
- })
- if (e.type - 0 === 1) {
- wx.setNavigationBarTitle({
- title: '项目详情'
- })
- } else {
- wx.setNavigationBarTitle({
- title: '活动详情'
- })
- }
- },
- data: {
- ShowMaxSwiper: false,
- HasSignUp: false,
- UserInfo: app.globalData.UserInfo,
- Id: null,
- Type: null,
- ShowPopup: false,
- FormData: {
- customerName: '',
- phone: '',
- idNum: '',
- activityId: ''
- },
- SubmitOff: true,
- ActivityDetail: {
- Title: '',
- Publisher: '',
- CreateDate: '',
- Content: '',
- BeginDate: '',
- EndDate: '',
- ActivityId: '',
- },
- CommentList: [],
- CurrentImgList: []
- },
- onReady() {
-
- },
- CloseMaxSwiper() { // 关闭大图
- this.setData({
- ShowMaxSwiper: false,
- CurrentIndex: 0
- })
- },
- PageReset() { // 页面数据重置
- this.setData({
- ActivityDetail: {
- Title: '',
- Publisher: '',
- CreateDate: '',
- Content: '',
- BeginDate: '',
- EndDate: ''
- },
- CommentList: [],
- SubmitOff: true,
- ShowPopup: false,
- CurrentIndex: 0
- })
- },
- GetSignUpList() { // 获取报名情况
- fetch({
- url: $api.user.signUpList.url.replace(':openid', app.globalData.UserInfo.openid) + '?pageNum=1&pageSize=10000',
- method: $api.user.signUpList.method
- }).then((res) => {
- if (res.code === 200) {
- res.data.records.map((item) => {
- if (item.activityId === this.data.FormData.activityId) {
- this.setData({
- HasSignUp: true
- })
- return
- }
- })
- }
- })
- },
- AddComment() { // 添加评论
- if (app.globalData.UserInfo.hasReg - 0 !== 1) {
- wx.navigateTo({
- url: '/pages/index/index?index=3'
- })
- } else {
- wx.navigateTo({
- url: '/pages/ActivityDetail/comment?id=' + this.data.Id
- })
- }
- },
- ShowSignUpPopup() { // 打开报名弹窗
- if (app.globalData.UserInfo.hasReg - 0 !== 1) {
- wx.navigateTo({
- url: '/pages/index/index?index=3'
- })
- } else {
- if (!this.data.HasSignUp) {
- this.setData({
- ShowPopup: true
- })
- }
- }
- },
- ClosePopup() { // 关闭报名弹窗
- this.setData({
- ShowPopup: false,
- FormData: {
- customerName: '',
- phone: '',
- idNum: '',
- activityId: this.data.FormData.activityId
- }
- })
- },
- FormInput(e) { // 输入form数据
- this.setData({
- FormData: {
- ...this.data.FormData,
- [e.target.dataset.name]: e.detail.value
- }
- })
- },
- Submit() { // 提交报名信息
- if (new Date(this.data.ActivityDetail.BeginDate).getTime() < Date.now() && new Date(this.data.ActivityDetail.EndDate).getTime() > Date.now()) {
- if (this.data.FormData.customerName === '') {
- wx.showToast({
- title: '姓名不能为空!',
- icon: 'none'
- })
- return false
- }
- if (this.data.FormData.phone === '') {
- wx.showToast({
- title: '手机号不能为空!',
- icon: 'none'
- })
- return false
- }
- if (this.data.FormData.idNum === '') {
- wx.showToast({
- title: '身份证号不能为空!',
- icon: 'none'
- })
- return false
- }
- if (this.data.SubmitOff) {
- this.setData({
- SubmitOff: false
- })
- fetch({
- url: $api.activity.signUp.url.replace(':openid', app.globalData.UserInfo.openid),
- method: $api.activity.signUp.method,
- data: {
- ...this.data.FormData
- }
- }).then((res) => {
- // console.log(res)
- if (res.code === 200) {
- wx.showToast({
- title: '报名成功!',
- icon: 'success'
- })
- this.setData({
- ShowPopup: false
- })
- } else {
- wx.showToast({
- title: res.message,
- icon: 'none'
- })
- this.setData({
- SubmitOff: true
- })
- }
- })
- }
- } else {
- if (new Date(this.data.ActivityDetail.BeginDate).getTime() > Date.now()) {
- wx.showToast({
- title: '报名时间未开始!',
- icon: 'none'
- })
- } else if (new Date(this.data.ActivityDetail.EndDate).getTime() < Date.now()) {
- wx.showToast({
- title: '报名已结束!',
- icon: 'none'
- })
- }
- }
- },
- GetCommentList() { // 获取评论列表
- fetch({
- url: $api.comment.list.url + '?pageNum=1&pageSize=10000&commentType=activity&mainId=' + this.data.Id,
- method: $api.comment.list.method
- }).then((res) => {
- if (res.code === 200) {
- // console.log(res.data.records)
- let CommentList = []
- res.data.records.map((item, index) => {
- CommentList.push({
- FloorUserIcon: item.avatar,
- FloorUserName: item.customerName,
- CreateDate: item.createDate,
- Content: item.commentContent,
- ImgList: item.commentImgList || [],
- LikeNum: '0',
- ParentId: item.parentId,
- Childs: []
- })
- let aChild = []
- item.childComment.map((subItem) => {
- aChild.push({
- Name: subItem.customerName,
- CreateDate: subItem.createDate,
- Content: subItem.commentContent,
- LikeNum: '0',
- ImgList: subItem.commentImgList || []
- })
- })
- CommentList[index].Childs = aChild
- })
- let aArr = []
- CommentList.map((item, index) => {
- if (item.ParentId !== '') {
- aArr.unshift(index)
- }
- })
- aArr.map((item) => {
- CommentList.splice(item - 0, 1)
- })
- this.setData({
- CommentList: CommentList
- })
- console.log(this.data.CommentList)
- }
- })
- },
- CheckBigImg(e) { // 查看大图
- // console.log(e.target.dataset)
- if (e.target.dataset.type - 0 === 1) { // 评论大图
- // console.log(this.data.CommentList[e.target.dataset.mainindex].ImgList)
- this.setData({
- CurrentImgList: this.data.CommentList[e.target.dataset.mainindex].ImgList,
- CurrentIndex: e.target.dataset.index,
- ShowMaxSwiper: true
- })
- } else { // 回复大图
- this.setData({
- CurrentImgList: this.data.CommentList[e.target.dataset.mainindex].Childs[e.target.dataset.subindex].ImgList,
- CurrentIndex: e.target.dataset.index,
- ShowMaxSwiper: true
- })
- }
- },
- GetActivityDetail() { // 获取活动详情
- fetch({
- url: $api.activity.detail.url.replace(':id', this.data.Id),
- method: $api.activity.detail.method
- }).then((res) => {
- if (res.code === 200) {
- this.setData({
- ActivityDetail: {
- Title: res.data.title,
- Publisher: '江北公司',
- CreateDate: res.data.publicDate,
- Content: res.data.context,
- BeginDate: res.data.beginDate,
- EndDate: res.data.endDate,
- ActivityId: res.data.activityId
- }
- })
- }
- })
- },
- GetProjectDetail() { // 获取项目详情
- fetch({
- url: $api.dynamic.detail.url.replace(':id', this.data.Id),
- method: $api.dynamic.detail.method
- }).then((res) => {
- if (res.code === 200) {
- this.setData({
- ActivityDetail: {
- Title: res.data.title,
- Publisher: '江北公司',
- CreateDate: res.data.publishDate,
- Content: res.data.url,
- BeginDate: '',
- EndDate: ''
- }
- })
- }
- })
- },
- onShareAppMessage: function () {
- var shareImg = app.globalData.ActivityImg
-
- if (this.data.Type == 1) {
- shareImg = app.globalData.DongtaiImg
- }
- return {
- title: this.data.ActivityDetail.Title,
- path: '/pages/ActivityDetail/index?id=' + this.data.Id + '&type='+this.data.Type,
- imageUrl: shareImg
- }
- }
- })
|