const { getTaskDeatil, postTaskResult } = require("../../../utils/serve/team") const { postUserTrain, postParentTrain } = require("../../../utils/serve/user") const { getSmallScore, getMidScore } = require("../../../utils/serve/train") const utils = require("../../../utils/utils") const { getHomeWorkType } = require("../../../utils/serve/teacher") const { getHomeWorkDetail } = require("../../../utils/serve/parent") // subpackage/train/result/result.js Page({ /** * 页面的初始数据 */ data: { type: '', sportType: '跳绳', count: 0, time: 0, isAi: true, timeStr: '00:00', speed: 0, theme: '', calorie:0, group:1 }, /** * 生命周期函数--监听页面加载 */ async onLoad(options) { const { type, sportType, count, time, isAi, theme } = options const who = wx.getStorageSync('theme') this.setData({ type, sportType, count, time, theme, timeStr: utils.formatTimeStr(Number(time)), speed: ((Number(count) / Number(time)) * 60).toFixed(0), isAi: isAi == 'true' }) if (who == 'user') { //用户端仅有跳绳====================================================================================== if (theme == 'team') { //2.添加团队任务成绩 const { data } = await getTaskDeatil(options.taskId) console.log('叔叔叔叔', data) const res = await postTaskResult({ "groupTaskId": options.taskId, "workModeType": data.workModeType, "workModeTypeName": data.workModeTypeName, "duration": time, "amount": count, "dataSourceType": isAi == 'true' ? 2 : 1 }) console.log('数据数据数据', res) } else { //1.添加个人目标成绩 const app = getApp() console.log(app) let params = { "personalGoalName": this.data.theme == 'small' ? '小学体测' : this.data.theme == 'fit' ? '健身减肥' : '中学考试', "workModeType": 1, "workModeTypeName": this.data.theme == 'small' ? '小学体测' : this.data.theme == 'fit' ? '健身减肥' : '中学考试', "duration": time, "amount": count, "PersonalGoalType": this.data.theme == 'small' ? 2 : this.data.theme == 'fit' ? 1 : 2, "dataSourceType": isAi == 'true' ? 2 : 1 } if (this.data.theme == 'small') { const dd = await getSmallScore({ GradeId: app.globalData.gradeId, Sex: app.globalData.sex, Amount: count }) params.Score = dd.data.score this.setData({ scoreObj: dd.data }) } if (this.data.theme == 'mid') { const dd = await getMidScore({ AreaId: app.globalData.areaId, Sex: app.globalData.sex, Amount: count }) params.Score = dd.data.score this.setData({ scoreObj: dd.data }) } const res = await postUserTrain(params) } } else if (who == 'parent') { //家长端 ====================================================================================== //自由训练 跳绳 if (theme == 'myself') { console.log('自由训练') let params = { "workType": 1, "workTypeName": "跳绳", "workModeType": 1, "workModeTypeName": this.data.type == 'time' ? '定时计数' : this.data.type == 'num' ? '定数计时' : '自由训练', "duration": time, "amount": count, "homeWorkId":0, "dataSourceType": isAi == 'true' ? 2 : 1, "calorie":(count*0.1).toFixed(1), "startTime":this.getCurrentDateTime(), "endTime":this.getCurrentDateTime(), "groupNumber":1 } const res = await postParentTrain(params) } else { //未知运动类型 //1、获取卡路里 //2、获取运动详情 //3、提交作业 const homeWorkList = await getHomeWorkType() const {data:{workType,workTypeName,workModeType,workModeTypeName,duration,amount,id,startTime,endTime,groupNumber}} = await getHomeWorkDetail(options.homeWorkId) const sportObj = homeWorkList.data.filter(item => item.name == options.sportType) console.log(sportObj) let isTime = options.type == 'time' let calorie = isTime ? options.count * sportObj[0].kcalIndex : amount * sportObj[0].kcalIndex * groupNumber calorie = calorie.toFixed(1) this.setData({ calorie, group:groupNumber, timeStr:isTime ? utils.formatTimeStr(Number(duration* groupNumber)) : utils.formatTimeStr(Number(time)), speed:isTime ? ((Number(count) / Number(duration* groupNumber)) * 60).toFixed(0) : ((Number(amount* groupNumber) / Number(time)) * 60).toFixed(0), count:isTime ? count : amount * groupNumber }) let params = { calorie,workType,workTypeName,workModeType,workModeTypeName,duration,amount,startTime,endTime,groupNumber, "homeWorkId":id, "dataSourceType": isAi == 'true' ? 2 : 1, } if(type == 'time'){ //定时计数 params.amount = options.count }else { params.duration = options.time } console.log(params) const res = await postParentTrain(params) } } }, getCurrentDateTime:()=> { const now = new Date(); // 获取各个时间组件 const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以加1 const day = String(now.getDate()).padStart(2, '0'); const hours = String(now.getHours()).padStart(2, '0'); const minutes = String(now.getMinutes()).padStart(2, '0'); const seconds = String(now.getSeconds()).padStart(2, '0'); // 格式化日期和时间 const formattedDate = `${year}-${month}-${day}`; const formattedTime = `${hours}:${minutes}:${seconds}`; return `${formattedDate} ${formattedTime}`; }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })