index.js 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  1. const dateF = require("../../../../utils/date")
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. const uid = Parse.User.current()?.id
  5. const login = require("../../../../utils/login");
  6. let getSportData = require('../../../service/getSportData')
  7. let request = require('../../../../utils/request')
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. attachment: null,
  14. isAttachment: null,
  15. showpopup: false,
  16. name: null,
  17. mobile: null,
  18. sex: null,
  19. idcard: null,
  20. birthdate: null,
  21. address: null,
  22. classType: null,
  23. centerDesc: null,
  24. teacher: null,
  25. tel: null,
  26. date: '',
  27. showDate: false,
  28. active: 0,
  29. idcard: null,
  30. teacher: null,
  31. optionKeyList: [],
  32. isAttend: false, //当前活动是否可参与(报名时间结束即可参与运动)
  33. rank: 'DESC',
  34. rankType:'',
  35. rankList: [], //排行榜
  36. meRank: [], //我的排行
  37. checkRank:'steps',//排行关键字
  38. showCheckRank:false,//选择排行关键字弹框
  39. fixedNum:null,//指定数值
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. let userInfo = wx.getStorageSync("userLogin");
  46. console.log(userInfo)
  47. let {
  48. id
  49. } = options
  50. this.setData({
  51. aid: id,
  52. userInfo
  53. })
  54. this.refersh()
  55. // this.refersh02()
  56. },
  57. login() {
  58. let userInfo = wx.getStorageSync("userLogin");
  59. if (!userInfo || userInfo == '') {
  60. login.loginNow()
  61. } else {
  62. this.setData({
  63. userInfo
  64. })
  65. this.refersh()
  66. }
  67. },
  68. async refersh() {
  69. await this.getActivity()
  70. this.getActStatus()
  71. this.getActRegister()
  72. this.getArticle()
  73. },
  74. /**获取当前活动 */
  75. async getActivity() {
  76. let {
  77. aid
  78. } = this.data
  79. let query = new Parse.Query('Activity')
  80. let data = await query.get(aid)
  81. let activity = data.toJSON()
  82. console.log(activity)
  83. let now = new Date()
  84. if (activity.signFromTo?.to?.iso) { //当前时间大于可签到结束时间-可参与
  85. let signTo = new Date(activity.signFromTo?.to?.iso)
  86. if (now > signTo) {
  87. this.setData({
  88. isAttend: true
  89. })
  90. }
  91. }
  92. if (activity.endDate) { //当前时间大于活动结束时间-不可参与
  93. let end = new Date(activity.endDate)
  94. if (now > end) {
  95. this.setData({
  96. isAttend: false
  97. })
  98. }
  99. }
  100. let optionKeyList = Object.keys(activity.limitOptions || {}) || []
  101. activity.start = dateF.formatTime("YYYY.mm.dd HH:MM", activity.startDate?.iso)
  102. activity.end = dateF.formatTime("mm.dd HH:MM", activity.endDate?.iso)
  103. activity.startDate = new Date(activity.startDate?.iso)
  104. activity.endDate = new Date(activity.endDate?.iso)
  105. if (activity.signFromTo?.from && activity.signFromTo?.to) {
  106. activity.signFromTo.fromDate = new Date(activity.signFromTo?.from?.iso) || null
  107. activity.signFromTo.toDate = new Date(activity.signFromTo?.to?.iso) || null
  108. activity.signFromTo.from = dateF.formatTime("YYYY.mm.dd HH:MM", activity.signFromTo?.from?.iso)
  109. activity.signFromTo.to = dateF.formatTime("mm.dd HH:MM", activity.signFromTo?.to?.iso)
  110. }
  111. this.setData({
  112. activity,
  113. optionKeyList,
  114. })
  115. },
  116. /**预览图片 */
  117. imagePreview(e) {
  118. let {
  119. activity
  120. } = this.data
  121. let {
  122. img
  123. } = e.currentTarget.dataset
  124. wx.previewImage({
  125. current: img, // 当前显示图片的http链接
  126. urls: activity.cover // 需要预览的图片http链接列表
  127. })
  128. },
  129. /**切换 活动详情/排行榜 */
  130. async changeTab(e) {
  131. if (e.detail.name == 1) {
  132. // this.getHomeCom()
  133. this.refersh02()
  134. }
  135. this.setData({
  136. active: e.detail.name
  137. })
  138. },
  139. async refersh02() {
  140. this.confirmCheckRank()
  141. this.getMeRank()
  142. },
  143. /** 正序逆序*/
  144. async changeup() {
  145. if (this.data.rank == 'DESC') {
  146. await this.setData({
  147. rank: 'ASC'
  148. })
  149. } else {
  150. await this.setData({
  151. rank: 'DESC'
  152. })
  153. }
  154. this.confirmCheckRank()
  155. },
  156. /**打开排序弹框 */
  157. onChangeRank(e){
  158. this.setData({
  159. checkRank:e.detail,
  160. showCheckRank:true,
  161. })
  162. },
  163. /**关闭排序弹框 */
  164. onCloseCheckRank(){
  165. this.setData({
  166. showCheckRank:false
  167. })
  168. },
  169. /**确认排序 */
  170. async confirmCheckRank(){
  171. let {fixedNum,checkRank,aid,rank}=this.data
  172. fixedNum = parseFloat(fixedNum)
  173. let startNum = 0
  174. let endNum = 0
  175. //查找此跨度内最接近 fixedNum 的记录
  176. if(checkRank=='steps'){
  177. startNum = fixedNum-35//成人5秒可运动35步
  178. endNum = fixedNum+35
  179. }else{
  180. startNum = fixedNum-5//每5秒记录运动状况
  181. endNum = fixedNum+5
  182. }
  183. let sql = `WITH d1 AS (
  184. 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",
  185. al."steps" AS "al_steps",al."distance" AS "al_distance",al."burnCalories" AS "al_burnCalories",al."sportDate" AS "al_sportDate",
  186. ar."booking",
  187. u."nickname",u."avatar"
  188. FROM "ActivityData" ad
  189. LEFT JOIN "ActivityRunLog" al ON al."actData" = ad."objectId"
  190. LEFT JOIN "ActivityRegister" ar ON ar."objectId" = ad."actRegister"
  191. LEFT JOIN "_User" u ON u."objectId"=ad."user"
  192. WHERE ad."isDeleted" IS NOT TRUE
  193. AND ad."activity"='${aid}'
  194. AND ad."company"='${company}'
  195. ${fixedNum?`AND al."${checkRank}" >= ${startNum}
  196. AND al."${checkRank}" <= ${endNum}`:''}
  197. ),
  198. rank_t AS(
  199. SELECT *, ROW_NUMBER() OVER (PARTITION BY d1."ad_objectId" ORDER BY ABS(d1."ad_${checkRank}" - ${fixedNum||0})) AS rn
  200. FROM d1
  201. ),
  202. d2 AS(
  203. SELECT * FROM rank_t
  204. WHERE rank_t."rn"=1
  205. )
  206. SELECT * FROM d2
  207. ORDER BY d2."al_${checkRank=='steps'?'sportDate':'steps'}" ${rank}
  208. LIMIT 200 OFFSET 0`
  209. // console.log(sql)
  210. let data = await request.customSQL(sql)
  211. // console.log(data)
  212. let rankList = data?.map(item => {
  213. let obj = item
  214. if (item?.booking?.from?.iso) obj.booking = dateF.formatTime("YYYY-mm-dd HH:MM", item?.booking?.from?.iso)
  215. return obj
  216. })
  217. this.setData({
  218. rankList,
  219. });
  220. this.onCloseCheckRank()
  221. },
  222. /**获取我的成绩 */
  223. async getMeRank() {
  224. let {
  225. aid,
  226. meRank
  227. } = this.data
  228. let mesql = `WITH d1 AS (
  229. 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",
  230. al."steps" AS "al_steps",al."distance" AS "al_distance",al."burnCalories" AS "al_burnCalories",al."sportDate" AS "al_sportDate",
  231. ar."booking",
  232. u."nickname",u."avatar"
  233. FROM "ActivityData" ad
  234. LEFT JOIN "ActivityRunLog" al ON al."actData" = ad."objectId"
  235. LEFT JOIN "ActivityRegister" ar ON ar."objectId" = ad."actRegister"
  236. LEFT JOIN "_User" u ON u."objectId"=ad."user"
  237. WHERE ad."isDeleted" IS NOT TRUE
  238. AND ad."activity"='${aid}'
  239. AND ad."user"='${uid}'
  240. AND al."steps" > 43
  241. AND al."steps" <109),
  242. rank_t AS(
  243. SELECT *, ROW_NUMBER() OVER (PARTITION BY d1."ad_objectId" ORDER BY ABS(d1."ad_steps" - 70)) AS rn
  244. FROM d1
  245. ),
  246. d2 AS(
  247. SELECT * FROM rank_t
  248. WHERE rank_t."rn"=1
  249. )
  250. SELECT * FROM d2
  251. ORDER BY d2."al_sportDate" ASC
  252. LIMIT 200 OFFSET 0`
  253. let medata = await request.customSQL(mesql)
  254. // console.log(medata)
  255. meRank = medata?.map(item => {
  256. let obj = item
  257. if (item?.booking?.from?.iso) obj.booking = dateF.formatTime("YYYY-mm-dd HH:MM", item?.booking?.from?.iso)
  258. return obj
  259. })
  260. // console.log(meRank)
  261. this.setData({
  262. meRank,
  263. });
  264. },
  265. /**获取报名记录 */
  266. async getActRegister() {
  267. let {
  268. activity
  269. } = this.data
  270. let query = new Parse.Query('ActivityRegister')
  271. query.notEqualTo('isDeleted', true)
  272. query.equalTo('activity', activity.objectId)
  273. query.equalTo('isPay', true)
  274. query.equalTo('isChecked', true)
  275. query.equalTo('user', uid)
  276. query.descending('createdAt') //大到小
  277. query.include('shopStore')
  278. let req = await query.find()
  279. let registerList = []
  280. if (req?.length > 0) {
  281. registerList = req.map(item => {
  282. let results = item?.toJSON()
  283. results.createdAt = dateF.formatTime("YYYY.mm.dd HH:MM", item.get('createdAt'))
  284. results.booking = dateF.formatTime("YYYY.mm.dd HH:MM", item.get('startDate'))
  285. results.bookObj = {}
  286. results.bookObj.from = dateF.formatTime("YYYY.mm.dd HH:MM", item.get('booking')?.from)
  287. results.bookObj.to = dateF.formatTime("mm.dd HH:MM", item.get('booking')?.to)
  288. results.shop = results?.shopStore
  289. return results
  290. })
  291. }
  292. this.setData({
  293. registerList,
  294. registerPaseList: req
  295. })
  296. },
  297. /**查看报名记录 */
  298. lookLog(e) {
  299. this.setData({
  300. checkDate: null
  301. })
  302. let {
  303. registerList,
  304. registerPaseList
  305. } = this.data
  306. let {
  307. index
  308. } = e.currentTarget.dataset
  309. console.log(registerList[index])
  310. this.setData({
  311. bookObj: registerList[index].bookObj,
  312. shop: registerList[index].shop,
  313. aRegister: registerPaseList[index],
  314. })
  315. this.onOpen()
  316. },
  317. /**判断用户参与活动状态 */
  318. async getActStatus() {
  319. let {
  320. activity
  321. } = this.data
  322. let query = new Parse.Query('ActivityRegister')
  323. query.notEqualTo('isDeleted', true)
  324. query.equalTo('activity', activity.objectId)
  325. query.equalTo('isPay', true)
  326. query.equalTo('isChecked', true)
  327. let count = await query.count()
  328. let tips = {
  329. title: '可报名',
  330. isCanSign: true,
  331. isEdit: true, //是否可编辑
  332. }
  333. let now = new Date()
  334. this.setData({
  335. tips,
  336. count,
  337. toYear: now.getFullYear(),
  338. toMonth: now.getMonth() + 1,
  339. toDate: now.getDate()
  340. })
  341. if (now > activity.endDate) {
  342. tips = {
  343. title: '活动已结束',
  344. isCanSign: false,
  345. isEdit: false,
  346. }
  347. this.setData({
  348. tips
  349. })
  350. return
  351. }
  352. if (!activity.isEnabled) {
  353. tips = {
  354. title: '活动未开启',
  355. isCanSign: false,
  356. isEdit: false,
  357. }
  358. this.setData({
  359. tips
  360. })
  361. return
  362. }
  363. if (activity.signFromTo?.fromDate && now < activity.signFromTo.fromDate) {
  364. tips = {
  365. title: '未到报名时间',
  366. isCanSign: false,
  367. isEdit: false,
  368. }
  369. this.setData({
  370. tips
  371. })
  372. return
  373. }
  374. if (activity.signFromTo?.toDate && now >= activity.signFromTo.toDate) {
  375. tips = {
  376. title: '报名时间已过',
  377. isCanSign: false,
  378. isEdit: false,
  379. }
  380. this.setData({
  381. tips
  382. })
  383. return
  384. }
  385. query.equalTo('user', uid)
  386. query.descending('createdAt') //大到小
  387. query.include('shopStore')
  388. let userCount = await query.count()
  389. if (userCount >= activity?.everyCount) {
  390. tips = {
  391. title: '已报名本活动',
  392. isCanSign: false,
  393. isCanRevise: false,
  394. // isEdit: false,
  395. isEdit: true,
  396. }
  397. this.setData({
  398. tips
  399. })
  400. return
  401. }
  402. let aRegister = await query.first()
  403. let aregisterJson = aRegister?.toJSON()
  404. if (aRegister?.id) {
  405. tips = {
  406. title: '已报名本活动',
  407. isCanSign: true,
  408. isCanRevise: true,
  409. // isEdit: false,
  410. isEdit: true,
  411. }
  412. let booking = dateF.formatTime("YYYY.mm.dd HH:MM", aRegister.get('startDate'))
  413. let bookObj = {}
  414. bookObj.from = dateF.formatTime("YYYY.mm.dd HH:MM", aRegister.get('booking')?.from)
  415. bookObj.to = dateF.formatTime("mm.dd HH:MM", aRegister.get('booking')?.to)
  416. this.setData({
  417. tips,
  418. booking,
  419. bookObj,
  420. aRegister,
  421. shop: aregisterJson.shopStore
  422. })
  423. return
  424. }
  425. if (activity.merber >= 0 && count >= activity.merber) {
  426. tips = {
  427. title: '活动人数已满',
  428. isCanSign: false,
  429. isEdit: false,
  430. }
  431. this.setData({
  432. tips
  433. })
  434. return
  435. }
  436. },
  437. /**前往报名 */
  438. application() {
  439. this.setData({
  440. aRegister: null,
  441. bookObj: null,
  442. shop: null
  443. })
  444. this.onOpen()
  445. },
  446. onOpen() {
  447. let {
  448. activity
  449. } = this.data
  450. let minDate = Infinity
  451. let maxDate = 0
  452. let checkDateList = []
  453. if (Array.isArray(activity.bookingList) && activity.bookingList.length > 0) {
  454. activity.bookingList.forEach(item => {
  455. let from = new Date(item.from.iso)
  456. let to = new Date(item.to.iso)
  457. if (minDate > from) minDate = from.getTime()
  458. if (maxDate < to) maxDate = to.getTime()
  459. let fromMonth = from.getMonth()
  460. let fromDate = from.getDate()
  461. checkDateList.push({
  462. fromDate: dateF.formatTime("YYYY-mm-dd HH:MM", from),
  463. toDate: dateF.formatTime("YYYY-mm-dd HH:MM", to),
  464. month: fromMonth,
  465. date: fromDate,
  466. from: dateF.formatTime("HH:MM", from),
  467. to: dateF.formatTime("mm月dd日 HH:MM", to),
  468. })
  469. });
  470. }
  471. let formatter = (day) => {
  472. let month = day.date.getMonth()
  473. let date = day.date.getDate()
  474. checkDateList.forEach(item => {
  475. if (item.month == month && item.date == date) day.bottomInfo = '可预约'
  476. });
  477. return day
  478. }
  479. this.setData({
  480. minDate,
  481. maxDate,
  482. formatter,
  483. checkDateList,
  484. showpopup: true
  485. })
  486. let now = new Date()
  487. let tradeNo = "C" +
  488. String(now.getFullYear()) +
  489. (now.getMonth() + 1) +
  490. now.getDate() +
  491. now.getHours() +
  492. now.getMinutes() +
  493. now.getSeconds() +
  494. Math.random().toString().slice(-6); //生成六位随机数
  495. this.setData({
  496. tradeNo
  497. })
  498. this.getUserProfile()
  499. },
  500. onClose() {
  501. this.setData({
  502. showpopup: false
  503. })
  504. },
  505. /**打开选择位置 */
  506. openStore() {
  507. this.getShop()
  508. this.setData({
  509. showStorePopup: true
  510. })
  511. },
  512. /**关闭位置选择 */
  513. closeStore() {
  514. this.setData({
  515. showStorePopup: false
  516. })
  517. },
  518. /**获取可选位置 */
  519. async getShop() {
  520. let {
  521. activity
  522. } = this.data
  523. let shopList = this.data.shopList || []
  524. if (shopList?.length > 0) return
  525. for (let i in activity?.shopStore) {
  526. let query = new Parse.Query('ShopStore')
  527. query.equalTo('company', company)
  528. query.notEqualTo('isDeleted', true)
  529. query.equalTo('isVerified', true)
  530. query.equalTo('objectId', activity?.shopStore[i].objectId)
  531. let req = await query.first()
  532. shopList.push(req.toJSON())
  533. }
  534. this.setData({
  535. shopList
  536. })
  537. },
  538. /**选择位置 */
  539. chooseShop(e) {
  540. let {
  541. shopList,
  542. tips
  543. } = this.data
  544. if (!tips.isEdit) {
  545. wx.showToast({
  546. title: `${tips.title},无法修改`,
  547. icon: 'none'
  548. })
  549. this.setData({
  550. showStorePopup: false
  551. })
  552. return
  553. }
  554. let {
  555. index
  556. } = e.currentTarget.dataset
  557. this.setData({
  558. shop: shopList[index],
  559. showStorePopup: false
  560. })
  561. },
  562. /**获取当前用户和身份 */
  563. async getUserProfile() {
  564. let profile
  565. let query = new Parse.Query('Profile')
  566. query.notEqualTo("isDeleted", true)
  567. query.equalTo('user', uid)
  568. profile = await query.first()
  569. if (!profile?.id) {
  570. let Pro = Parse.Object.extend('Profile')
  571. profile = new Pro()
  572. } else {
  573. this.setData({
  574. name: profile.get('name') || '',
  575. college: profile.get('college') || '',
  576. mobile: profile.get('mobile') || '',
  577. sex: profile.get('sex') || '',
  578. idcard: profile.get('idcard') || '',
  579. birthdate: profile.get('birthdate') || '',
  580. address: profile.get('address') || '',
  581. classType: profile.get('classType') || '',
  582. centerDesc: profile.get('centerDesc') || '',
  583. teacher: profile.get('teacher') || '',
  584. tel: profile.get('tel') || '',
  585. })
  586. }
  587. this.setData({
  588. profile
  589. })
  590. },
  591. onChangeSexIsAttachment(event) {
  592. this.setData({
  593. isAttachment: event.detail == '同意',
  594. });
  595. },
  596. onChangeSex(event) {
  597. this.setData({
  598. sex: event.detail,
  599. });
  600. },
  601. onChangecenterDesc(event) {
  602. this.setData({
  603. centerDesc: event.detail,
  604. });
  605. },
  606. /** 立即预约*/
  607. async enlists(e) {
  608. let date
  609. let {
  610. name,
  611. isAttachment,
  612. mobile,
  613. sex,
  614. idcard,
  615. birthdate,
  616. address,
  617. classType,
  618. centerDesc,
  619. teacher,
  620. tel,
  621. aRegister
  622. } = this.data
  623. // if (!name || !college || !mobile) {
  624. console.log(name, isAttachment,
  625. mobile,
  626. sex,
  627. idcard,
  628. birthdate,
  629. address,
  630. classType,
  631. centerDesc,
  632. teacher,
  633. tel, )
  634. if (!name ||
  635. !sex || !idcard ||
  636. !birthdate || !address || !classType || !centerDesc || !teacher
  637. ) {
  638. wx.showToast({
  639. title: '存在未填项',
  640. icon: 'none',
  641. duration: 5000
  642. })
  643. return
  644. }
  645. if (mobile.length != 11 || tel.length != 11) {
  646. wx.showToast({
  647. title: '请输入11位手机号',
  648. icon: 'none',
  649. duration: 5000
  650. })
  651. return
  652. }
  653. let {
  654. shop
  655. } = this.data
  656. if (!shop?.objectId) {
  657. wx.showToast({
  658. title: '请选择位置',
  659. icon: 'none',
  660. duration: 5000
  661. })
  662. return
  663. }
  664. if (!isAttachment) {
  665. wx.showToast({
  666. title: '请阅读并同意《参赛选手免责声明》',
  667. icon: 'none',
  668. duration: 5000
  669. })
  670. return
  671. }
  672. let {
  673. profile,
  674. activity
  675. } = this.data
  676. profile.set('name', name || '')
  677. profile.set('mobile', mobile || '')
  678. profile.set('sex', sex || '')
  679. profile.set('idcard', idcard || '')
  680. profile.set('birthdate', birthdate || '')
  681. profile.set('address', address || '')
  682. profile.set('classType', classType || '')
  683. profile.set('centerDesc', centerDesc || '')
  684. profile.set('teacher', teacher || '')
  685. profile.set('tel', tel || '')
  686. profile.set('company', {
  687. className: 'Company',
  688. __type: 'Pointer',
  689. objectId: company
  690. })
  691. profile.set('user', {
  692. className: '_User',
  693. __type: 'Pointer',
  694. objectId: uid
  695. })
  696. let proSave = await profile.save()
  697. if (aRegister?.id) {
  698. this.successPay()
  699. return
  700. }
  701. let {
  702. from,
  703. to
  704. } = e.currentTarget.dataset
  705. let booking = {}
  706. if (from && to) {
  707. booking = {
  708. from: new Date(from),
  709. to: new Date(to),
  710. }
  711. }
  712. this.setData({
  713. showPay: true,
  714. profileId: proSave?.id,
  715. date,
  716. booking
  717. })
  718. if (activity.price <= 0) {
  719. this.successPay()
  720. }
  721. },
  722. /**支付回调 */
  723. async acceptResult(e) {
  724. let {
  725. params,
  726. no,
  727. type
  728. } = e.detail;
  729. let {
  730. tradeNo,
  731. activity,
  732. aRegister
  733. } = this.data
  734. if (aRegister?.id) {
  735. this.successPay()
  736. return
  737. }
  738. try {
  739. if (params == 'ok') {
  740. await this.successPay()
  741. this.setData({
  742. showpopup: false
  743. })
  744. } else {
  745. wx.showToast({
  746. title: "取消支付",
  747. icon: "error",
  748. duration: 1500,
  749. });
  750. }
  751. } catch (error) {
  752. wx.showToast({
  753. title: "支付失败",
  754. icon: "error",
  755. duration: 1500,
  756. });
  757. wx.hideLoading()
  758. }
  759. },
  760. async successPay() {
  761. let {
  762. profileId,
  763. activity,
  764. tradeNo,
  765. booking,
  766. shop,
  767. aRegister
  768. } = this.data
  769. wx.showLoading({
  770. title: "处理中",
  771. mask: true
  772. });
  773. /**当前操作是否编辑 新增报名记录/编辑报名记录 */
  774. let isEdit = true
  775. if (!aRegister?.id) {
  776. isEdit = false
  777. let query = new Parse.Query('ActivityRegister')
  778. query.notEqualTo('isDeleted', true)
  779. query.equalTo('activity', activity.objectId)
  780. query.notEqualTo('isPay', true)
  781. query.equalTo('user', uid)
  782. query.notEqualTo('isChecked', true)
  783. aRegister = await query.first()
  784. if (!aRegister?.id) {
  785. let ActivityRegister = Parse.Object.extend('ActivityRegister')
  786. aRegister = new ActivityRegister()
  787. aRegister.set('orderNum', tradeNo)
  788. aRegister.set('company', {
  789. className: 'Company',
  790. __type: 'Pointer',
  791. objectId: company
  792. })
  793. aRegister.set('user', {
  794. className: '_User',
  795. __type: 'Pointer',
  796. objectId: uid
  797. })
  798. aRegister.set('activity', {
  799. className: 'Activity',
  800. __type: 'Pointer',
  801. objectId: activity.objectId
  802. })
  803. aRegister.set('isPayTpye', 'wx')
  804. aRegister.set('type', 'daily')
  805. aRegister.set('price', activity.price)
  806. aRegister.set('isPay', true)
  807. aRegister.set('profile', {
  808. className: 'Profile',
  809. __type: 'Pointer',
  810. objectId: profileId
  811. })
  812. aRegister.set('isChecked', true)
  813. }
  814. }
  815. if (shop.objectId) {
  816. aRegister.set('shopStore', {
  817. className: 'ShopStore',
  818. __type: 'Pointer',
  819. objectId: shop.objectId
  820. })
  821. }
  822. if (booking?.from && booking?.to) {
  823. aRegister.set('startDate', booking.from)
  824. aRegister.set('booking', booking)
  825. }
  826. await aRegister.save()
  827. await this.getActStatus()
  828. await this.getActRegister()
  829. this.setData({
  830. checkDate: null
  831. })
  832. wx.hideLoading()
  833. wx.showToast({
  834. title: "报名成功",
  835. icon: "success",
  836. duration: 1000,
  837. });
  838. this.onClose()
  839. // if (!isEdit) {
  840. // setTimeout(() => {
  841. // wx.navigateTo({
  842. // url: activity.url,
  843. // })
  844. // }, 1000);
  845. // }
  846. },
  847. /**打开时间选择 */
  848. onDisplay() {
  849. this.setData({
  850. showDate: true
  851. });
  852. },
  853. /**关闭时间选择框 */
  854. onCloseDate() {
  855. this.setData({
  856. showDate: false
  857. });
  858. },
  859. /** 日历选中*/
  860. onConfirm(event) {
  861. let {
  862. checkDateList
  863. } = this.data
  864. let checkDate = event.detail
  865. let checkTimeList = checkDateList.filter(item => item.month == checkDate.getMonth() && item.date == checkDate.getDate())
  866. this.setData({
  867. checkTimeList,
  868. checkDate: dateF.formatTime("YYYY年mm月dd日", checkDate),
  869. showDate: false,
  870. });
  871. },
  872. async goUrl() {
  873. let {
  874. isAttachment,
  875. aRegister
  876. } = this.data
  877. let actQuery = new Parse.Query('ActivityData')
  878. actQuery.equalTo('company', company)
  879. actQuery.equalTo('user', uid)
  880. actQuery.notEqualTo('isDeleted', true)
  881. actQuery.equalTo('actRegister', aRegister?.id)
  882. let actDate = await actQuery.first()
  883. if (actDate?.get('status') == 'end') {
  884. wx.showToast({
  885. title: '成绩已结算,查看其他预约或参与其他活动吧',
  886. icon: 'none'
  887. })
  888. return
  889. }
  890. if (!isAttachment) {
  891. wx.showToast({
  892. title: '请阅读并同意《参赛选手免责声明》',
  893. icon: 'none',
  894. duration: 5000
  895. })
  896. return
  897. }
  898. let url = `${aRegister?.get('activity')?.get('url')}&a_reg=${aRegister?.id}`
  899. wx.navigateTo({
  900. url: url,
  901. })
  902. },
  903. /**隐私协议 */
  904. async getArticle() {
  905. let query = new Parse.Query("Article")
  906. query.equalTo("company", company)
  907. query.equalTo("type", 'activity')
  908. query.equalTo("isEnabled", true)
  909. query.select("title", "attachment")
  910. let res = await query.first()
  911. if (res && res.id) {
  912. let r = res.toJSON()
  913. if (r.attachment && r.attachment.length > 0) {
  914. this.setData({
  915. attachment: r
  916. })
  917. }
  918. }
  919. },
  920. //附件下载
  921. async openFile() {
  922. await this.getArticle()
  923. let {
  924. attachment
  925. } = this.data
  926. let url = attachment.attachment[0].url,
  927. name = attachment.title
  928. const _this = this
  929. let rep = this.getFileType(url)
  930. wx.showLoading({
  931. title: '加载中',
  932. })
  933. wx.downloadFile({
  934. url: url, //要预览的PDF的地址
  935. filePath: wx.env.USER_DATA_PATH + `/${name}.${rep}`,
  936. success: function (res) {
  937. if (res.statusCode === 200) { //成功
  938. var Path = res.filePath //返回的文件临时地址,用于后面打开本地预览所用
  939. wx.openDocument({
  940. filePath: Path, //要打开的文件路径
  941. showMenu: true,
  942. success: function (res) {
  943. wx.hideLoading()
  944. },
  945. fail: function (res) {
  946. wx.hideLoading()
  947. }
  948. })
  949. }
  950. },
  951. fail: function (res) {
  952. wx.hideLoading()
  953. },
  954. })
  955. },
  956. //解析文件类型
  957. getFileType(url) {
  958. let pdfReg = /^.+(\.pdf)$/
  959. let txtReg = /^.+(\.txt)$/
  960. let wordReg = /^.+(\.doc|\.docx)$/
  961. let excelReg = /^.+(\.xls|\.xlsx)$/
  962. let jpgPng = /^.+(\.png)$/
  963. let jpgJpg = /^.+(\.jpg)$/
  964. let jpgJpeg = /^.+(\.jpeg)$/
  965. if (pdfReg.test(url)) {
  966. return 'pdf'
  967. }
  968. if (txtReg.test(url)) {
  969. return 'txt'
  970. }
  971. if (wordReg.test(url)) {
  972. return 'doc'
  973. }
  974. if (excelReg.test(url)) {
  975. return 'xls'
  976. }
  977. if (jpgPng.test(url)) {
  978. return 'png'
  979. }
  980. if (jpgJpg.test(url)) {
  981. return 'jpg'
  982. }
  983. if (jpgJpeg.test(url)) {
  984. return 'jpeg'
  985. }
  986. },
  987. /**
  988. * 生命周期函数--监听页面初次渲染完成
  989. */
  990. onReady: function () {
  991. },
  992. /**
  993. * 生命周期函数--监听页面显示
  994. */
  995. onShow: function () {
  996. let userInfo = wx.getStorageSync("userLogin");
  997. this.setData({
  998. userInfo
  999. })
  1000. },
  1001. /**
  1002. * 生命周期函数--监听页面隐藏
  1003. */
  1004. onHide: function () {
  1005. },
  1006. /**
  1007. * 生命周期函数--监听页面卸载
  1008. */
  1009. onUnload: function () {
  1010. },
  1011. /**
  1012. * 页面相关事件处理函数--监听用户下拉动作
  1013. */
  1014. onPullDownRefresh: function () {
  1015. },
  1016. /**
  1017. * 页面上拉触底事件的处理函数
  1018. */
  1019. onReachBottom: function () {
  1020. },
  1021. /**
  1022. * 用户点击右上角分享
  1023. */
  1024. onShareAppMessage: function () {
  1025. },
  1026. })