index.js 27 KB

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