|
|
|
|
const app = getApp<IAppOption>()
|
|
|
|
|
|
|
|
|
|
interface IActivityItem {
|
|
|
|
|
id: number
|
|
|
|
|
name: string
|
|
|
|
|
mainImages: string[]
|
|
|
|
|
startAt: string
|
|
|
|
|
endAt: string
|
|
|
|
|
status: string
|
|
|
|
|
activityStatus: number
|
|
|
|
|
activityStatusName: string
|
|
|
|
|
checkinType: string
|
|
|
|
|
regCount: number
|
|
|
|
|
checkinCount: number
|
|
|
|
|
isRegistered: boolean
|
|
|
|
|
isChecked: boolean
|
|
|
|
|
isReviewed: boolean
|
|
|
|
|
location?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IPagination {
|
|
|
|
|
page: number
|
|
|
|
|
pageSize: number
|
|
|
|
|
pages: number
|
|
|
|
|
count: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
active: 0,
|
|
|
|
|
imageUrl: app.globalData.imageUrl,
|
|
|
|
|
Timestamp: app.globalData.Timestamp,
|
|
|
|
|
|
|
|
|
|
// 我发布的
|
|
|
|
|
createdList: [] as IActivityItem[],
|
|
|
|
|
createdPagination: { page: 1, pageSize: 10, pages: 0, count: 0 } as IPagination,
|
|
|
|
|
createdLoading: false,
|
|
|
|
|
|
|
|
|
|
// 我参与的
|
|
|
|
|
registeredList: [] as IActivityItem[],
|
|
|
|
|
registeredPagination: { page: 1, pageSize: 10, pages: 0, count: 0 } as IPagination,
|
|
|
|
|
registeredLoading: false,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onLoad() {
|
|
|
|
|
app.waitLogin({ type: 1 }).then(() => {
|
|
|
|
|
this.fetchCreatedList()
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 切换 tab
|
|
|
|
|
onChange(e: WechatMiniprogram.CustomEvent) {
|
|
|
|
|
const active = e.detail.name || e.detail.index
|
|
|
|
|
this.setData({ active })
|
|
|
|
|
|
|
|
|
|
if (active === 0 && this.data.createdList.length === 0) {
|
|
|
|
|
this.fetchCreatedList()
|
|
|
|
|
} else if (active === 1 && this.data.registeredList.length === 0) {
|
|
|
|
|
this.fetchRegisteredList()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 获取我发布的活动
|
|
|
|
|
async fetchCreatedList(isRefresh = false) {
|
|
|
|
|
if (this.data.createdLoading) return
|
|
|
|
|
|
|
|
|
|
const { createdPagination } = this.data
|
|
|
|
|
const page = isRefresh ? 1 : createdPagination.page
|
|
|
|
|
|
|
|
|
|
this.setData({ createdLoading: true })
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const res = await wx.ajax({
|
|
|
|
|
url: '/me/my-activities',
|
|
|
|
|
method: 'GET',
|
|
|
|
|
data: { type: 'created', page, pageSize: createdPagination.pageSize },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
const newList = isRefresh ? res.list : [...this.data.createdList, ...res.list]
|
|
|
|
|
this.setData({
|
|
|
|
|
createdList: newList,
|
|
|
|
|
createdPagination: {
|
|
|
|
|
page: res.pagination?.page || page,
|
|
|
|
|
pageSize: res.pagination?.pageSize || createdPagination.pageSize,
|
|
|
|
|
pages: res.pagination?.totalPages || 0,
|
|
|
|
|
count: res.pagination?.total || 0,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('获取我发布的活动失败:', err)
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({ createdLoading: false })
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 获取我参与的活动
|
|
|
|
|
async fetchRegisteredList(isRefresh = false) {
|
|
|
|
|
if (this.data.registeredLoading) return
|
|
|
|
|
|
|
|
|
|
const { registeredPagination } = this.data
|
|
|
|
|
const page = isRefresh ? 1 : registeredPagination.page
|
|
|
|
|
|
|
|
|
|
this.setData({ registeredLoading: true })
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const res = await wx.ajax({
|
|
|
|
|
url: '/me/my-activities',
|
|
|
|
|
method: 'GET',
|
|
|
|
|
data: { type: 'registered', page, pageSize: registeredPagination.pageSize },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
const newList = isRefresh ? res.list : [...this.data.registeredList, ...res.list]
|
|
|
|
|
this.setData({
|
|
|
|
|
registeredList: newList,
|
|
|
|
|
registeredPagination: {
|
|
|
|
|
page: res.pagination?.page || page,
|
|
|
|
|
pageSize: res.pagination?.pageSize || registeredPagination.pageSize,
|
|
|
|
|
pages: res.pagination?.totalPages || 0,
|
|
|
|
|
count: res.pagination?.total || 0,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('获取我参与的活动失败:', err)
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({ registeredLoading: false })
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 删除活动
|
|
|
|
|
async handleDelete(e: WechatMiniprogram.TouchEvent) {
|
|
|
|
|
const { id } = e.currentTarget.dataset
|
|
|
|
|
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '提示',
|
|
|
|
|
content: '确定要删除该活动吗?',
|
|
|
|
|
success: async (res) => {
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
try {
|
|
|
|
|
await wx.ajax({
|
|
|
|
|
url: `/activity/delete?id=${id}`,
|
|
|
|
|
method: 'POST',
|
|
|
|
|
})
|
|
|
|
|
wx.showToast({ title: '删除成功', icon: 'success' })
|
|
|
|
|
this.fetchCreatedList(true)
|
|
|
|
|
} catch (err: any) {
|
|
|
|
|
wx.showToast({ title: err?.message || '删除失败', icon: 'error' })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 编辑活动
|
|
|
|
|
handleEdit(e: WechatMiniprogram.TouchEvent) {
|
|
|
|
|
const { id } = e.currentTarget.dataset
|
|
|
|
|
wx.navigateTo({ url: `/pages/actEdit/index?id=${id}` })
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 查看详情
|
|
|
|
|
handleDetail(e: WechatMiniprogram.TouchEvent) {
|
|
|
|
|
const { id } = e.currentTarget.dataset
|
|
|
|
|
wx.navigateTo({ url: `/pages/actDetail/index?id=${id}` })
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 取消活动
|
|
|
|
|
async handleCancel(e: WechatMiniprogram.TouchEvent) {
|
|
|
|
|
const { id } = e.currentTarget.dataset
|
|
|
|
|
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '提示',
|
|
|
|
|
content: '确定要取消该活动吗?取消后已报名用户将收到通知。',
|
|
|
|
|
success: async (res) => {
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
try {
|
|
|
|
|
await wx.ajax({
|
|
|
|
|
url: `/activity/cancel?id=${id}`,
|
|
|
|
|
method: 'POST',
|
|
|
|
|
})
|
|
|
|
|
wx.showToast({ title: '取消成功', icon: 'success' })
|
|
|
|
|
this.fetchCreatedList(true)
|
|
|
|
|
} catch (err: any) {
|
|
|
|
|
wx.showToast({ title: err?.message || '取消失败', icon: 'error' })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 签到二维码
|
|
|
|
|
handleQrcode(e: WechatMiniprogram.TouchEvent) {
|
|
|
|
|
const { id } = e.currentTarget.dataset
|
|
|
|
|
wx.navigateTo({ url: `/pages/actQrcode/index?id=${id}` })
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 下拉刷新
|
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
const { active } = this.data
|
|
|
|
|
if (active === 0) {
|
|
|
|
|
this.fetchCreatedList(true)
|
|
|
|
|
} else {
|
|
|
|
|
this.fetchRegisteredList(true)
|
|
|
|
|
}
|
|
|
|
|
wx.stopPullDownRefresh()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 上拉加载更多
|
|
|
|
|
onReachBottom() {
|
|
|
|
|
const { active, createdPagination, registeredPagination } = this.data
|
|
|
|
|
|
|
|
|
|
if (active === 0) {
|
|
|
|
|
if (createdPagination.page < createdPagination.pages) {
|
|
|
|
|
this.setData({
|
|
|
|
|
createdPagination: { ...createdPagination, page: createdPagination.page + 1 },
|
|
|
|
|
})
|
|
|
|
|
this.fetchCreatedList()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (registeredPagination.page < registeredPagination.pages) {
|
|
|
|
|
this.setData({
|
|
|
|
|
registeredPagination: { ...registeredPagination, page: registeredPagination.page + 1 },
|
|
|
|
|
})
|
|
|
|
|
this.fetchRegisteredList()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export {}
|