123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- // nova-werun/pages/home/medal/index.js
- const Parse = getApp().Parse;
- const company = getApp().globalData.company;
- const uid = Parse.User.current()?.id
- let sev = require('../../../service/getSportData')
- let request = require('../../../../utils/request')
- let dateF = require('../../../../utils/date')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- alreadyList: [],
- MedalList: [],
- show: false,
- title: '',
- user: Parse.User.current(),
-
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- user: Parse.User.current()?.toJSON()
- });
- this.refersh()
- },
- async refersh() {
- await this.getMedal()
- this.getCountSport()
- },
- /**获取勋章 */
- async getMedal() {
- let sql = `SELECT me."objectId",me."name",me."image",me."imageIn",me."condition",
- ml."user",ml."createdAt"
- FROM "Medal" me
- LEFT JOIN "MedalLog" ml ON me."objectId"=ml."medal" AND ml."user"='${uid}'
- WHERE me."company"='${company}'
- AND me."isDeleted" IS NOT TRUE
- ORDER BY me."order" ASC`
- let data = await request.customSQL(sql)
- let medalList = data?.map(item => {
- item.createdAt = dateF.formatTime('YYYY-MM-dd', item.createdAt)
- return item
- })
- this.setData({
- medalList
- });
- },
- /**获取用户累计运动步数-授予勋章 */
- async getCountSport() {
- let {
- medalList
- } = this.data
- let fromTo = {
- from: Parse.User.current()?.get('createdAt'),
- to: new Date()
- }
- let d = await sev.getwalk('distance', '', fromTo) || 0
- console.log(d)
- let logList = medalList?.filter(item => parseInt(item.condition.distance) <= d && !item.user)
- console.log(logList)
- if (logList?.length > 0) {
- wx.showToast({
- title: `太厉害啦!您已累计运动${ (d/1000).toFixed(2) ||0} km,为您解锁${logList?.length}枚勋章。`,
- icon: 'none',
- duration: 5000
- })
- for (let i in logList) {
- let item = logList[i]
- if (parseInt(item.condition.distance) <= d && !item.user) {
- let MedalLog = Parse.Object.extend('MedalLog')
- let log = new MedalLog()
- log.set('company', {
- __type: 'Pointer',
- className: 'Company',
- objectId: company
- })
- log.set('user', {
- __type: 'Pointer',
- className: '_User',
- objectId: uid
- })
- log.set('medal', {
- __type: 'Pointer',
- className: 'Medal',
- objectId: item.objectId
- })
- await log.save()
- }
- }
- this.getMedal()
- }
- this.setData({distance: (d/1000).toFixed(2) ||0})
- },
- /**勋章详情 */
- showPopup(e) {
- let {
- medalList
- } = this.data
- let {
- index
- } = e.currentTarget.dataset
- console.log(medalList[index])
- this.setData({
- chickMedal: medalList[index],
- show: true
- });
- },
- onClose() {
- this.setData({
- show: false
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- })
|