123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944 |
- const dateF = require("../../../../utils/date")
- const Parse = getApp().Parse;
- const company = getApp().globalData.company;
- const uid = Parse.User.current()?.id
- const login = require("../../../../utils/login");
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- attachment: null,
- isAttachment: null,
- showpopup: false,
- name: null,
- mobile: null,
- sex: null,
- idcard: null,
- birthdate: null,
- address: null,
- classType: null,
- centerDesc: null,
- teacher: null,
- tel: null,
- date: '',
- showDate: false,
- storeVal: null,
- active: 0,
- comList: [],
- comCount: 0,
- comVal: null,
- replyObj: {
- placeholder: '你猜我的评论区在等谁?'
- },
- autosize: {
- maxHeight: 100,
- minHeight: 50
- },
- idcard: null,
- teacher: null,
- teacherAdd: null,
- remark: null,
- optionKeyList: [],
- isAttend:false,//当前活动是否可参与(报名时间结束即可参与运动)
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- let userInfo = wx.getStorageSync("userLogin");
- console.log(userInfo)
- let {
- id
- } = options
- this.setData({
- aid: id,
- userInfo
- })
- this.refersh()
- },
- login() {
- let userInfo = wx.getStorageSync("userLogin");
- if (!userInfo || userInfo == '') {
- login.loginNow()
- } else {
- this.setData({
- userInfo
- })
- this.refersh()
- }
- },
- async refersh() {
- await this.getActivity()
- this.getActStatus()
- this.getActRegister()
- this.getArticle()
- },
- /**获取当前活动 */
- async getActivity() {
- let {
- aid
- } = this.data
- let query = new Parse.Query('Activity')
- let data = await query.get(aid)
- let activity = data.toJSON()
- console.log(activity)
- let now = new Date()
- if(activity.signFromTo?.to?.iso){//当前时间大于可签到结束时间-可参与
- let signTo = new Date(activity.signFromTo?.to?.iso)
- if(now > signTo){
- this.setData({isAttend:true})
- }
- }
- if(activity.endDate){//当前时间大于活动结束时间-不可参与
- let end = new Date(activity.endDate)
- if(now > end){
- this.setData({isAttend:false})
- }
- }
- let optionKeyList = Object.keys(activity.limitOptions || {}) || []
- activity.start = dateF.formatTime("YYYY.mm.dd HH:MM", activity.startDate?.iso)
- activity.end = dateF.formatTime("mm.dd HH:MM", activity.endDate?.iso)
- activity.startDate = new Date(activity.startDate?.iso)
- activity.endDate = new Date(activity.endDate?.iso)
-
- if (activity.signFromTo?.from && activity.signFromTo?.to) {
- activity.signFromTo.fromDate = new Date(activity.signFromTo?.from?.iso) || null
- activity.signFromTo.toDate = new Date(activity.signFromTo?.to?.iso) || null
- activity.signFromTo.from = dateF.formatTime("YYYY.mm.dd HH:MM", activity.signFromTo?.from?.iso)
- activity.signFromTo.to = dateF.formatTime("mm.dd HH:MM", activity.signFromTo?.to?.iso)
- }
-
-
- this.setData({
- activity,
- optionKeyList,
- })
- },
- /**预览图片 */
- imagePreview(e) {
- let {
- activity
- } = this.data
- let {
- img
- } = e.currentTarget.dataset
- wx.previewImage({
- current: img, // 当前显示图片的http链接
- urls: activity.cover // 需要预览的图片http链接列表
- })
- },
- /**切换 活动详情/排行榜 */
- async changeTab(e) {
- if (e.detail.name == 1 && !this.data?.comList?.length) {
- // this.getHomeCom()
- }
- this.setData({
- active: e.detail.name
- })
- },
- /**获取报名记录 */
- async getActRegister() {
- let {
- activity
- } = this.data
- let query = new Parse.Query('ActivityRegister')
- query.notEqualTo('isDeleted', true)
- query.equalTo('activity', activity.objectId)
- query.equalTo('isPay', true)
- query.equalTo('isChecked', true)
- query.equalTo('user', uid)
- query.descending('createdAt') //大到小
- query.include('shopStore')
- let req = await query.find()
- let registerList = []
- if (req?.length > 0) {
- registerList = req.map(item => {
- let results = item?.toJSON()
- results.createdAt = dateF.formatTime("YYYY.mm.dd HH:MM", item.get('createdAt'))
- results.booking = dateF.formatTime("YYYY.mm.dd HH:MM", item.get('startDate'))
- results.bookObj = {}
- results.bookObj.from = dateF.formatTime("YYYY.mm.dd HH:MM", item.get('booking')?.from)
- results.bookObj.to = dateF.formatTime("mm.dd HH:MM", item.get('booking')?.to)
- results.shop = results?.shopStore
- return results
- })
- }
- this.setData({
- registerList,
- registerPaseList: req
- })
- },
- /**查看报名记录 */
- lookLog(e) {
- this.setData({
- checkDate: null
- })
- let {
- registerList,
- registerPaseList
- } = this.data
- let {
- index
- } = e.currentTarget.dataset
- console.log(registerList[index])
- this.setData({
- bookObj: registerList[index].bookObj,
- shop: registerList[index].shop,
- aRegister: registerPaseList[index],
- })
- this.onOpen()
- },
- /**判断用户参与活动状态 */
- async getActStatus() {
- let {
- activity
- } = this.data
- let query = new Parse.Query('ActivityRegister')
- query.notEqualTo('isDeleted', true)
- query.equalTo('activity', activity.objectId)
- query.equalTo('isPay', true)
- query.equalTo('isChecked', true)
- let count = await query.count()
- let tips = {
- title: '可报名',
- isCanSign: true,
- isEdit: true, //是否可编辑
- }
- let now = new Date()
- this.setData({
- tips,
- count,
- toYear: now.getFullYear(),
- toMonth: now.getMonth() + 1,
- toDate: now.getDate()
- })
- if (now > activity.endDate) {
- tips = {
- title: '活动已结束',
- isCanSign: false,
- isEdit: false,
- }
- this.setData({
- tips
- })
- return
- }
- if (!activity.isEnabled) {
- tips = {
- title: '活动未开启',
- isCanSign: false,
- isEdit: false,
- }
- this.setData({
- tips
- })
- return
- }
- if (activity.signFromTo?.fromDate && now < activity.signFromTo.fromDate) {
- tips = {
- title: '未到报名时间',
- isCanSign: false,
- isEdit: false,
- }
- this.setData({
- tips
- })
- return
- }
- if (activity.signFromTo?.toDate && now >= activity.signFromTo.toDate) {
- tips = {
- title: '报名时间已过',
- isCanSign: false,
- isEdit: false,
- }
- this.setData({
- tips
- })
- return
- }
- query.equalTo('user', uid)
- query.descending('createdAt') //大到小
- query.include('shopStore')
- let userCount = await query.count()
- if (userCount >= activity?.everyCount) {
- tips = {
- title: '已报名本活动',
- isCanSign: false,
- isCanRevise: false,
- // isEdit: false,
- isEdit: true,
- }
- this.setData({
- tips
- })
- return
- }
- let aRegister = await query.first()
- let aregisterJson = aRegister?.toJSON()
- if (aRegister?.id) {
- tips = {
- title: '已报名本活动',
- isCanSign: true,
- isCanRevise: true,
- // isEdit: false,
- isEdit: true,
- }
- let booking = dateF.formatTime("YYYY.mm.dd HH:MM", aRegister.get('startDate'))
- let bookObj = {}
- bookObj.from = dateF.formatTime("YYYY.mm.dd HH:MM", aRegister.get('booking')?.from)
- bookObj.to = dateF.formatTime("mm.dd HH:MM", aRegister.get('booking')?.to)
- this.setData({
- tips,
- booking,
- bookObj,
- aRegister,
- shop: aregisterJson.shopStore
- })
- return
- }
- if (activity.merber >= 0 && count >= activity.merber) {
- tips = {
- title: '活动人数已满',
- isCanSign: false,
- isEdit: false,
- }
- this.setData({
- tips
- })
- return
- }
- },
- /**前往报名 */
- application() {
- this.setData({
- aRegister: null,
- bookObj: null,
- shop: null
- })
- this.onOpen()
- },
- onOpen() {
- let {
- activity
- } = this.data
- let minDate = Infinity
- let maxDate = 0
- let checkDateList = []
- if (Array.isArray(activity.bookingList) && activity.bookingList.length > 0) {
- activity.bookingList.forEach(item => {
- let from = new Date(item.from.iso)
- let to = new Date(item.to.iso)
- if (minDate > from) minDate = from.getTime()
- if (maxDate < to) maxDate = to.getTime()
- let fromMonth = from.getMonth()
- let fromDate = from.getDate()
- checkDateList.push({
- fromDate: dateF.formatTime("YYYY-mm-dd HH:MM", from),
- toDate: dateF.formatTime("YYYY-mm-dd HH:MM", to),
- month: fromMonth,
- date: fromDate,
- from: dateF.formatTime("HH:MM", from),
- to: dateF.formatTime("mm月dd日 HH:MM", to),
- })
- });
- }
- let formatter = (day) => {
- let month = day.date.getMonth()
- let date = day.date.getDate()
- checkDateList.forEach(item => {
- if (item.month == month && item.date == date) day.bottomInfo = '可预约'
- });
- return day
- }
- this.setData({
- minDate,
- maxDate,
- formatter,
- checkDateList,
- showpopup: true
- })
- let now = new Date()
- let tradeNo = "C" +
- String(now.getFullYear()) +
- (now.getMonth() + 1) +
- now.getDate() +
- now.getHours() +
- now.getMinutes() +
- now.getSeconds() +
- Math.random().toString().slice(-6); //生成六位随机数
- this.setData({
- tradeNo
- })
- this.getUserProfile()
- },
- onClose() {
- this.setData({
- showpopup: false
- })
- },
- /**打开选择位置 */
- openStore() {
- this.getShop()
- this.setData({
- showStorePopup: true
- })
- },
- /**关闭位置选择 */
- closeStore() {
- this.setData({
- showStorePopup: false
- })
- },
- /**获取可选位置 */
- async getShop() {
- let {
- activity
- } = this.data
- let shopList = this.data.shopList || []
- if (shopList?.length > 0) return
- for (let i in activity?.shopStore) {
- let query = new Parse.Query('ShopStore')
- query.equalTo('company', company)
- query.notEqualTo('isDeleted', true)
- query.equalTo('isVerified', true)
- query.equalTo('objectId', activity?.shopStore[i].objectId)
- let req = await query.first()
- shopList.push(req.toJSON())
- }
- this.setData({
- shopList
- })
- },
- /**选择位置 */
- chooseShop(e) {
- let {
- shopList,tips
- } = this.data
- if(!tips.isEdit){
- wx.showToast({
- title:`${tips.title},无法修改`,
- icon:'none'
- })
- this.setData({
- showStorePopup: false
- })
- return
- }
- let {
- index
- } = e.currentTarget.dataset
- this.setData({
- shop: shopList[index],
- showStorePopup: false
- })
- },
- /**获取当前用户和身份 */
- async getUserProfile() {
- let profile
- let query = new Parse.Query('Profile')
- query.notEqualTo("isDeleted", true)
- query.equalTo('user', uid)
- profile = await query.first()
- if (!profile?.id) {
- let Pro = Parse.Object.extend('Profile')
- profile = new Pro()
- } else {
- this.setData({
- name: profile.get('name') || '',
- college: profile.get('college') || '',
- mobile: profile.get('mobile') || '',
- sex: profile.get('sex') || '',
- idcard: profile.get('idcard') || '',
- birthdate: profile.get('birthdate') || '',
- address: profile.get('address') || '',
- classType: profile.get('classType') || '',
- centerDesc: profile.get('centerDesc') || '',
- teacher: profile.get('teacher') || '',
- tel: profile.get('tel') || '',
- })
- }
- this.setData({
- profile
- })
- },
- onChangeSexIsAttachment(event) {
- this.setData({
- isAttachment: event.detail == '同意',
- });
- },
- onChangeSex(event) {
- this.setData({
- sex: event.detail,
- });
- },
- onChangecenterDesc(event) {
- this.setData({
- centerDesc: event.detail,
- });
- },
- /** 立即预约*/
- async enlists(e) {
- let date
- let {
- name,
- isAttachment,
- mobile,
- sex,
- idcard,
- birthdate,
- address,
- classType,
- centerDesc,
- teacher,
- tel,
- aRegister
- } = this.data
- // if (!name || !college || !mobile) {
- console.log(name, isAttachment,
- mobile,
- sex,
- idcard,
- birthdate,
- address,
- classType,
- centerDesc,
- teacher,
- tel, )
- if (!name ||
- !sex || !idcard ||
- !birthdate || !address || !classType || !centerDesc || !teacher
- ) {
- wx.showToast({
- title: '存在未填项',
- icon: 'none',
- duration: 5000
- })
- return
- }
- if (mobile.length != 11 || tel.length != 11) {
- wx.showToast({
- title: '请输入11位手机号',
- icon: 'none',
- duration: 5000
- })
- return
- }
- let {
- shop
- } = this.data
- if (!shop?.objectId) {
- wx.showToast({
- title: '请选择位置',
- icon: 'none',
- duration: 5000
- })
- return
- }
- if (!isAttachment) {
- wx.showToast({
- title: '请阅读并同意《参赛选手免责声明》',
- icon: 'none',
- duration: 5000
- })
- return
- }
- let {
- profile,
- activity
- } = this.data
- profile.set('name', name || '')
- profile.set('mobile', mobile || '')
- profile.set('sex', sex || '')
- profile.set('idcard', idcard || '')
- profile.set('birthdate', birthdate || '')
- profile.set('address', address || '')
- profile.set('classType', classType || '')
- profile.set('centerDesc', centerDesc || '')
- profile.set('teacher', teacher || '')
- profile.set('tel', tel || '')
- profile.set('company', {
- className: 'Company',
- __type: 'Pointer',
- objectId: company
- })
- profile.set('user', {
- className: '_User',
- __type: 'Pointer',
- objectId: uid
- })
- let proSave = await profile.save()
- if (aRegister?.id) {
- this.successPay()
- return
- }
- let {
- from,
- to
- } = e.currentTarget.dataset
- let booking = {}
- if (from && to) {
- booking = {
- from: new Date(from),
- to: new Date(to),
- }
- }
- this.setData({
- showPay: true,
- profileId: proSave?.id,
- date,
- booking
- })
- if (activity.price <= 0) {
- this.successPay()
- }
- },
- /**支付回调 */
- async acceptResult(e) {
- let {
- params,
- no,
- type
- } = e.detail;
- let {
- tradeNo,
- activity,
- aRegister
- } = this.data
- if (aRegister?.id) {
- this.successPay()
- return
- }
- try {
- if (params == 'ok') {
- await this.successPay()
- this.setData({
- showpopup: false
- })
- } else {
- wx.showToast({
- title: "取消支付",
- icon: "error",
- duration: 1500,
- });
- }
- } catch (error) {
- wx.showToast({
- title: "支付失败",
- icon: "error",
- duration: 1500,
- });
- wx.hideLoading()
- }
- },
- async successPay() {
- let {
- profileId,
- activity,
- tradeNo,
- booking,
- shop,
- aRegister
- } = this.data
- wx.showLoading({
- title: "处理中",
- mask: true
- });
- /**当前操作是否编辑 新增报名记录/编辑报名记录 */
- let isEdit = true
- if (!aRegister?.id) {
- isEdit = false
- let query = new Parse.Query('ActivityRegister')
- query.notEqualTo('isDeleted', true)
- query.equalTo('activity', activity.objectId)
- query.notEqualTo('isPay', true)
- query.equalTo('user', uid)
- query.notEqualTo('isChecked', true)
- aRegister = await query.first()
- if (!aRegister?.id) {
- let ActivityRegister = Parse.Object.extend('ActivityRegister')
- aRegister = new ActivityRegister()
- aRegister.set('orderNum', tradeNo)
- aRegister.set('company', {
- className: 'Company',
- __type: 'Pointer',
- objectId: company
- })
- aRegister.set('user', {
- className: '_User',
- __type: 'Pointer',
- objectId: uid
- })
- aRegister.set('activity', {
- className: 'Activity',
- __type: 'Pointer',
- objectId: activity.objectId
- })
- aRegister.set('isPayTpye', 'wx')
- aRegister.set('type', 'daily')
- aRegister.set('price', activity.price)
- aRegister.set('isPay', true)
- aRegister.set('profile', {
- className: 'Profile',
- __type: 'Pointer',
- objectId: profileId
- })
- aRegister.set('isChecked', true)
- }
- }
- if (shop.objectId) {
- aRegister.set('shopStore', {
- className: 'ShopStore',
- __type: 'Pointer',
- objectId: shop.objectId
- })
- }
- if (booking?.from && booking?.to) {
- aRegister.set('startDate', booking.from)
- aRegister.set('booking', booking)
- }
- await aRegister.save()
- await this.getActStatus()
- await this.getActRegister()
- this.setData({
- checkDate: null
- })
- wx.hideLoading()
- wx.showToast({
- title: "报名成功",
- icon: "success",
- duration: 1000,
- });
- this.onClose()
- // if (!isEdit) {
- // setTimeout(() => {
- // wx.navigateTo({
- // url: activity.url,
- // })
- // }, 1000);
- // }
- },
- /**打开时间选择 */
- onDisplay() {
- this.setData({
- showDate: true
- });
- },
- /**关闭时间选择框 */
- onCloseDate() {
- this.setData({
- showDate: false
- });
- },
- /** 日历选中*/
- onConfirm(event) {
- let {
- checkDateList
- } = this.data
- let checkDate = event.detail
- let checkTimeList = checkDateList.filter(item => item.month == checkDate.getMonth() && item.date == checkDate.getDate())
- this.setData({
- checkTimeList,
- checkDate: dateF.formatTime("YYYY年mm月dd日", checkDate),
- showDate: false,
- });
- },
- /**参与活动 */
- involved(){
- },
- async goUrl() {
- let {isAttachment,aRegister}=this.data
- let actQuery = new Parse.Query('ActivityData')
- actQuery.equalTo('company', company)
- actQuery.equalTo('user', uid)
- actQuery.notEqualTo('isDeleted', true)
- actQuery.equalTo('actRegister', aRegister?.id)
- let actDate = await actQuery.first()
- if(actDate?.get('status')=='end'){
- wx.showToast({
- title: '成绩已结算,查看其他预约或参与其他活动吧',
- icon:'none'
- })
- return
- }
- if (!isAttachment) {
- wx.showToast({
- title: '请阅读并同意《参赛选手免责声明》',
- icon: 'none',
- duration: 5000
- })
- return
- }
- let url = `${aRegister?.get('activity')?.get('url')}&a_reg=${aRegister?.id}`
- wx.navigateTo({
- url: url,
- })
- },
- /**隐私协议 */
- async getArticle() {
- let query = new Parse.Query("Article")
- query.equalTo("company", company)
- query.equalTo("type", 'activity')
- query.equalTo("isEnabled", true)
- query.select("title", "attachment")
- let res = await query.first()
- if (res && res.id) {
- let r = res.toJSON()
- if (r.attachment && r.attachment.length > 0) {
- this.setData({
- attachment: r
- })
- }
- }
- },
- //附件下载
- async openFile() {
- await this.getArticle()
- let {
- attachment
- } = this.data
- let url = attachment.attachment[0].url,
- name = attachment.title
- const _this = this
- let rep = this.getFileType(url)
- wx.showLoading({
- title: '加载中',
- })
- wx.downloadFile({
- url: url, //要预览的PDF的地址
- filePath: wx.env.USER_DATA_PATH + `/${name}.${rep}`,
- success: function (res) {
- if (res.statusCode === 200) { //成功
- var Path = res.filePath //返回的文件临时地址,用于后面打开本地预览所用
- wx.openDocument({
- filePath: Path, //要打开的文件路径
- showMenu: true,
- success: function (res) {
- wx.hideLoading()
- },
- fail: function (res) {
- wx.hideLoading()
- }
- })
- }
- },
- fail: function (res) {
- wx.hideLoading()
- },
- })
- },
- //解析文件类型
- getFileType(url) {
- let pdfReg = /^.+(\.pdf)$/
- let txtReg = /^.+(\.txt)$/
- let wordReg = /^.+(\.doc|\.docx)$/
- let excelReg = /^.+(\.xls|\.xlsx)$/
- let jpgPng = /^.+(\.png)$/
- let jpgJpg = /^.+(\.jpg)$/
- let jpgJpeg = /^.+(\.jpeg)$/
- if (pdfReg.test(url)) {
- return 'pdf'
- }
- if (txtReg.test(url)) {
- return 'txt'
- }
- if (wordReg.test(url)) {
- return 'doc'
- }
- if (excelReg.test(url)) {
- return 'xls'
- }
- if (jpgPng.test(url)) {
- return 'png'
- }
- if (jpgJpg.test(url)) {
- return 'jpg'
- }
- if (jpgJpeg.test(url)) {
- return 'jpeg'
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- let userInfo = wx.getStorageSync("userLogin");
- this.setData({
- userInfo
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- })
|