index.js 25 KB

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