12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073 |
- 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");
- let getSportData = require('../../../service/getSportData')
- let request = require('../../../../utils/request')
- 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,
- active: 0,
- idcard: null,
- teacher: null,
- optionKeyList: [],
- isAttend: false, //当前活动是否可参与(报名时间结束即可参与运动)
- rank: 'DESC',
- rankType:'',
- rankList: [], //排行榜
- meRank: [], //我的排行
- checkRank:'steps',//排行关键字
- showCheckRank:false,//选择排行关键字弹框
- fixedNum:null,//指定数值
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- let userInfo = wx.getStorageSync("userLogin");
- console.log(userInfo)
- let {
- id
- } = options
- this.setData({
- aid: id,
- userInfo
- })
- this.refersh()
- // this.refersh02()
- },
- 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.getHomeCom()
- this.refersh02()
- }
- this.setData({
- active: e.detail.name
- })
- },
- async refersh02() {
- this.confirmCheckRank()
- this.getMeRank()
- },
- /** 正序逆序*/
- async changeup() {
- if (this.data.rank == 'DESC') {
- await this.setData({
- rank: 'ASC'
- })
- } else {
- await this.setData({
- rank: 'DESC'
- })
- }
- this.confirmCheckRank()
- },
- /**打开排序弹框 */
- onChangeRank(e){
- this.setData({
- checkRank:e.detail,
- showCheckRank:true,
- })
- },
- /**关闭排序弹框 */
- onCloseCheckRank(){
- this.setData({
- showCheckRank:false
- })
- },
- /**确认排序 */
- async confirmCheckRank(){
- let {fixedNum,checkRank,aid,rank}=this.data
- fixedNum = parseFloat(fixedNum)
- let startNum = 0
- let endNum = 0
- //查找此跨度内最接近 fixedNum 的记录
- if(checkRank=='steps'){
- startNum = fixedNum-35//成人5秒可运动35步
- endNum = fixedNum+35
- }else{
- startNum = fixedNum-5//每5秒记录运动状况
- endNum = fixedNum+5
- }
- let sql = `WITH d1 AS (
- SELECT ad."objectId" AS "ad_objectId",ad."steps" AS "ad_steps",ad."distance" AS "ad_distance",ad."burnCalories" AS "ad_burnCalories",ad."sportDate" AS "ad_sportDate",
- al."steps" AS "al_steps",al."distance" AS "al_distance",al."burnCalories" AS "al_burnCalories",al."sportDate" AS "al_sportDate",
- ar."booking",
- u."nickname",u."avatar"
- FROM "ActivityData" ad
- LEFT JOIN "ActivityRunLog" al ON al."actData" = ad."objectId"
- LEFT JOIN "ActivityRegister" ar ON ar."objectId" = ad."actRegister"
- LEFT JOIN "_User" u ON u."objectId"=ad."user"
- WHERE ad."isDeleted" IS NOT TRUE
- AND ad."activity"='${aid}'
- AND ad."company"='${company}'
- ${fixedNum?`AND al."${checkRank}" >= ${startNum}
- AND al."${checkRank}" <= ${endNum}`:''}
- ),
- rank_t AS(
- SELECT *, ROW_NUMBER() OVER (PARTITION BY d1."ad_objectId" ORDER BY ABS(d1."ad_${checkRank}" - ${fixedNum||0})) AS rn
- FROM d1
- ),
- d2 AS(
- SELECT * FROM rank_t
- WHERE rank_t."rn"=1
- )
- SELECT * FROM d2
- ORDER BY d2."al_${checkRank=='steps'?'sportDate':'steps'}" ${rank}
- LIMIT 200 OFFSET 0`
- // console.log(sql)
- let data = await request.customSQL(sql)
- // console.log(data)
- let rankList = data?.map(item => {
- let obj = item
- if (item?.booking?.from?.iso) obj.booking = dateF.formatTime("YYYY-mm-dd HH:MM", item?.booking?.from?.iso)
- return obj
- })
- this.setData({
- rankList,
- });
- this.onCloseCheckRank()
- },
- /**获取我的成绩 */
- async getMeRank() {
- let {
- aid,
- meRank
- } = this.data
- let mesql = `WITH d1 AS (
- SELECT ad."objectId" AS "ad_objectId",ad."steps" AS "ad_steps",ad."distance" AS "ad_distance",ad."burnCalories" AS "ad_burnCalories",ad."sportDate" AS "ad_sportDate",
- al."steps" AS "al_steps",al."distance" AS "al_distance",al."burnCalories" AS "al_burnCalories",al."sportDate" AS "al_sportDate",
- ar."booking",
- u."nickname",u."avatar"
- FROM "ActivityData" ad
- LEFT JOIN "ActivityRunLog" al ON al."actData" = ad."objectId"
- LEFT JOIN "ActivityRegister" ar ON ar."objectId" = ad."actRegister"
- LEFT JOIN "_User" u ON u."objectId"=ad."user"
- WHERE ad."isDeleted" IS NOT TRUE
- AND ad."activity"='${aid}'
- AND ad."user"='${uid}'
- AND al."steps" > 43
- AND al."steps" <109),
- rank_t AS(
- SELECT *, ROW_NUMBER() OVER (PARTITION BY d1."ad_objectId" ORDER BY ABS(d1."ad_steps" - 70)) AS rn
- FROM d1
- ),
- d2 AS(
- SELECT * FROM rank_t
- WHERE rank_t."rn"=1
- )
- SELECT * FROM d2
- ORDER BY d2."al_sportDate" ASC
- LIMIT 200 OFFSET 0`
- let medata = await request.customSQL(mesql)
- // console.log(medata)
- meRank = medata?.map(item => {
- let obj = item
- if (item?.booking?.from?.iso) obj.booking = dateF.formatTime("YYYY-mm-dd HH:MM", item?.booking?.from?.iso)
- return obj
- })
- // console.log(meRank)
- this.setData({
- meRank,
- });
- },
- /**获取报名记录 */
- 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,
- });
- },
- 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 () {
- },
- })
|