280 lines
6.0 KiB
JavaScript
Raw Normal View History

2025-06-06 15:17:30 +08:00
const {
creatTask
} = require("../../../utils/serve/team");
// subpackage/team/task-creat/task-creat.js
Page({
/**
* 页面的初始数据
*/
data: {
show: '', //展示弹窗的id
weekList: [{
value: 1,
name: '周一'
},
{
value: 2,
name: '周二'
},
{
value: 3,
name: '周三'
},
{
value: 4,
name: '周四'
},
{
value: 5,
name: '周五'
},
{
value: 6,
name: '周六'
},
{
value: 7,
name: '周日'
}
],
name: '',
checkWeekList: [],
sureWeekList: [],
weekName: '仅一次',
nowDate: '2025-04-01',
nextDate: '2026-04-01',
startTime: '',
endTime: '',
multiArray: [
['定时计数', '定数计时', '团队计数', '团队计时', ],
['1分钟', '2分钟', '3分钟', '4分钟', '5分钟']
],
multiIndex: [0, 0],
selectData: [
['1分钟', '2分钟', '3分钟', '4分钟', '5分钟'],
[100, 200, 300, 400, 500, 600, '自定义输入'],
[1000, 2000, 3000, 4000, 5000, 6000, '自定义输入'],
['10分钟', '20分钟', '30分钟', '40分钟', '50分钟'],
],
number: 0,
mm: '1分钟',
userGroupId: 0,
userGroupName: '',
},
close() {
this.setData({
show: ''
})
},
sure() {
const listName = this.data.checkWeekList.length > 0 ? '每周' + this.data.checkWeekList.join('、').replace('1', '一').replace('2', '二').replace('3', '三').replace('4', '四').replace('5', '五').replace('6', '六').replace('7', '日') : '仅一次'
this.setData({
sureWeekList: this.data.checkWeekList,
weekName: listName,
show: ''
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
if (options.id) {
this.setData({
userGroupId: options.id
})
}
if (options.name) {
this.setData({
userGroupName: options.name
})
}
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
this.setData({
nowDate: year + '-' + month + '-' + day,
nextDate: (year + 1) + '-' + month + '-' + day
})
},
async creat() {
if (this.data.startTime == '' || this.data.endTime == '') return wx.showToast({
title: '请选择起止时间',
icon: 'none'
})
if (this.data.multiIndex == 6 && this.data.number == 0) return wx.showToast({
title: '请输入跳绳个数',
icon: 'none'
})
if (this.data.name == '') return wx.showToast({
title: '请输入任务名称',
icon: 'none'
})
wx.showLoading({
title:'任务创建中'
})
let startTime = this.data.startTime
if (this.data.nowDate == this.data.startTime) {
const now = new Date()
const hours = String(now.getHours()).padStart(2, '0'); // 小时24小时制
const minutes = String(now.getMinutes()).padStart(2, '0'); // 分钟
const seconds = String(now.getSeconds()).padStart(2, '0'); // 秒钟
startTime += ` ${hours}:${minutes}:${seconds}`
}
const data = {
"userGroupId": this.data.userGroupId,
"groupTaskName": this.data.name,
"workModeType": Number(this.data.multiIndex[0]) + 1,
"workModeTypeName": this.data.multiArray[0][this.data.multiIndex[0]],
"isRepeat": this.data.sureWeekList.length > 0,
"weekList": this.data.sureWeekList,
"startTime": startTime,
"endTime": this.data.endTime + ' 23:59:59'
}
if (this.data.multiIndex[0] == 0 || this.data.multiIndex[0] == 3) {
data.duration = Number(this.data.mm[0]) * 60 * (this.data.multiIndex[0] == 0 ? 1 : 10)
} else {
data.amount = this.data.multiIndex == 6 ? this.data.number : this.data.mm
}
console.log('data==============>', data)
console.log('data==============>', data)
console.log('data==============>', data)
console.log('data==============>', data)
const res = await creatTask(data)
console.log(res)
wx.hideLoading()
if (res.success) {
wx.showToast({
title: '创建成功',
})
setTimeout(() => {
wx.navigateBack({
creat: 1
})
}, 500);
}
},
numChange(e) {
// if(e.detail.value == 0) return wx.showToast({
// title: '跳绳个数需要大于0个哦~',
// icon:'none'
// })
this.setData({
number: e.detail.value
})
},
nameChange(e) {
this.setData({
name: e.detail.value
})
},
bindMultiPickerChange(e) {
console.log(e)
this.setData({
multiIndex: e.detail.value,
mm: this.data.multiArray[1][e.detail.value[1]]
})
},
bindColumnChange(e) {
console.log(e)
if (e.detail.column == 0) {
this.setData({
multiArray: [
this.data.multiArray[0],
this.data.selectData[e.detail.value]
]
})
}
},
checkboxChange(e) {
this.setData({
checkWeekList: e.detail.value,
})
},
bindDateStart(e) {
console.log(e)
console.log(this.data.nowDate)
console.log(e.detail.value)
this.setData({
startTime: e.detail.value
})
},
bindDateEnd(e) {
this.setData({
endTime: e.detail.value
})
},
showDialog(e) {
const id = e.currentTarget.id
this.setData({
show: id
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})