2026-07-01 15:10:17 +08:00

224 lines
4.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const tabService = require("../../../utils/tab-serve");
const util = require("../../../utils/utils")
const { sportKeyObj, sportDes } = require('../../../utils/soprt-key')
import {getAreaList} from "../../../utils/serve/train"
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
tabName: 'time', //time num nothing
isPopupVisible: false,
time: 60, //计时 单位:s
number: 100, //计数
timeStr:'01:00',
theme:'small',
sportKey: '',
sportName: '',
sportDesc: '',
videoUrl: '',
gradeList:[
'一年级',
'二年级',
'三年级',
'四年级',
'五年级',
'六年级',
],
areaList:[],
grade:'',
areaId:'',
sexList:['男','女'],
sex:1
},
/**
* 生命周期函数--监听页面加载
*/
async onLoad(options) {
this.setData({
theme: options.type
})
if (options.sportKey) {
this.setData({
sportKey: options.sportKey,
sportName: sportKeyObj[options.sportKey] || '',
sportDesc: sportDes[options.sportKey] || '',
videoUrl: 'https://yuedong-wechatapplet.oss-cn-shanghai.aliyuncs.com/static/train/video/new/' + options.sportKey + '.mp4',
})
}
if(options.type == 'mid'){
const res = await getAreaList()
this.setData({
areaList:res.data
})
}
},
gradeChange(e){
console.log(e)
const {value} = e.detail
this.setData({
grade:Number(value) + 1,
})
app.globalData.gradeId = Number(value) + 1
},
areaChange(e){
console.log(e)
const {value} = e.detail
this.setData({
areaId:Number(value) + 1,
timeStr:util.formatTimeStr(this.data.areaList[Number(value)].duration)
})
app.globalData.areaId = Number(value) + 1
console.log(app.globalData.areaId)
},
sexChange(e){
console.log(e)
const {id} = e.currentTarget
this.setData({
sex:Number(id),
})
app.globalData.sex = Number(id)
},
//步进器
setup(e) {
if (this.data.tabName == 'time') {//计数
//添加
if (e.currentTarget.id == 'add') {
this.setData({
time:this.data.time + 15,
timeStr:util.formatTimeStr(this.data.time + 15)
})
}else{
if(this.data.time <= 30) return wx.showToast({
title: '最少训练30秒哦~~',
icon:'none'
})
if(this.data.time >= 3600) return wx.showToast({
title: '最多训练60分钟哦~~',
icon:'none'
})
this.setData({
time:this.data.time - 15,
timeStr:util.formatTimeStr(this.data.time - 15)
})
}
} else {//计数
//添加
if (e.currentTarget.id == 'add') {
this.setData({
number:this.data.number + (this.data.number < 50? 10 : 50)
})
}else{
if(this.data.number <= 10) return wx.showToast({
title: '最少10个哦~~',
icon:'none'
})
this.setData({
number:this.data.number - (this.data.number <= 50? 10 : 50)
})
}
}
},
//跳转设置页面
goSetting(){
wx.navigateTo({
url: '/subpackage/train/setting/setting?type='+this.data.theme,
})
},
changeTab(e) {
const value = e.currentTarget.id
this.setData({
tabName: value
})
},
showPopup() {
if(this.data.sex == '' && this.data.theme != 'fit') return app.showToast('请选择性别')
if(this.data.theme == 'small' && this.data.grade == '') return app.showToast('请选择年级')
if(this.data.theme == 'mid' && this.data.areaId == '') return app.showToast('请选择省份')
const sportKey = this.data.sportKey || 'Rope-Skipping'
const data = `&type=${this.data.tabName}&time=${this.data.time}&number=${this.data.number}&theme=myself`
if(this.data.sportKey == 'Rope-Skipping' ){
wx.navigateTo({
url: '/subpackage/train/check-type/check-page?sportKey=' + this.data.sportKey + data,
})
}else{
wx.navigateTo({
url: '/module-sport/pages/sport-full-screen?sportKey=' + this.data.sportKey + data,
})
}
},
handleCancel() {
this.setData({
isPopupVisible: false
});
},
handleConfirm() {
this.setData({
isPopupVisible: false
});
// 处理确认逻辑
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
tabService.updateIndex(this, 0)
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})