2025-06-06 15:17:30 +08:00

280 lines
7.3 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 { getHomeWorkType ,getClassList, creatHomeWork, getStudentList} = require("../../../utils/serve/teacher")
// subpackage/teacher/new-work/new-work.js
Page({
/**
* 页面的初始数据
*/
data: {
homeWorkName:'',
workModeTypeList:[],//项目类型列表
workModeType:{},//项目类型
workTypeList:[{
name:'定时计数',
id:1
},{
name:'定数计时',
id:2
}],
workType:{},
groupList:[1,2,3,4,5,6,7,8,9,10],
group:null,//组数
nowDate:'',
startTime:'', //开始时间
endTime:'',//结束时间
classList:[],
nowClass:{},
clickList:[], //选中学生列表
weekList: [
{value: 1, name: '周一'},
{value: 2, name: '周二'},
{value: 3, name: '周三'},
{value: 4, name: '周四'},
{value: 5, name: '周五'},
{value: 6, name: '周六'},
{value: 7, name: '周日'}
],
weekName:'仅一次',
show:'', //是否展示弹出框
checkWeekList:[], //选中重复列表
sureWeekList:[], //确认的重复列表
studentScope:1,//是否全部学生
multiArray:[
[0,1,2,3,4,5,6,7,8,9],
[0,1,2,3,4,5,6,7,8,9],
[0,1,2,3,4,5,6,7,8,9]
],
num:0, //数量
time:0, //时长
timeList:[
1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
]
},
/**
* 生命周期函数--监听页面加载
*/
async onLoad(options) {
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');
const res = await getHomeWorkType()
const res2 = await getClassList()
this.setData({
workModeTypeList:res.data,
nowDate: year + '-' + month + '-' + day,
classList:res2.data
})
},
showDialog(e){
const id = e.currentTarget.id
this.setData({
show:id
})
},
close(){
this.setData({
show:''
})
},
checkboxChange(e){
this.setData({
checkWeekList:e.detail.value,
})
},
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:''
})
},
all(){
this.setData({
clickList:[]
})
},
//picker改变
bindPickerChange(e){
console.log(e)
if(e.target.id == 'nowClass'){
this.setData({
clickList:[],
studentScope:1
})
}
this.setData({
[e.target.id] : e.target.dataset.list== null ? e.detail.value : this.data[e.target.dataset.list][e.detail.value]
})
},
bindMultiPickerChange: function (e) {
console.log('picker发送选择改变携带值为', e.detail.value)
this.setData({
multiIndex: e.detail.value,
num:Number(e.detail.value.join(''))
})
},
//日期选择
bindDateChange(e){
console.log(e)
this.setData({
[e.target.id] : e.detail.value
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
changeName(e){
console.log(e)
this.setData({
homeWorkName:e.detail.value
})
},
//去选择学生
checkStuent(e){
if(this.data.nowClass.classId == null) return wx.showToast({
title: '请选择正确的班级',
icon:'none'
})
wx.navigateTo({
url: '/subpackage/teacher/check-student/check-student?class='+JSON.stringify(this.data.nowClass),
})
},
//创建作业
async newWork(){
let app = getApp()
if(this.data.homeWorkName == '') return app.showToast('请输入作业名称')
if(this.data.workModeType.id == null) return app.showToast('请选择项目')
if(this.data.startTime == '') return app.showToast('请先选择开始时间')
if(this.data.endTime == '') return app.showToast('请选择结束时间')
if(this.data.nowClass.classId == null) return app.showToast('请选择班级')
if(this.data.workType.id == null) return app.showToast('请选择作业模式')
if(this.data.workType.id == 2 && this.data.num == 0) return app.showToast('请选择个数')
if(this.data.workType.id == 1 && this.data.time == 0) return app.showToast('请选择时长')
if(!this.data.group) return app.showToast('请选择组数')
wx.showLoading('作业创建中...')
let stuList = this.data.clickList
if(stuList.length <= 0 ){//全部学生
const stu =await getStudentList({
pageIndex:1,
pageSize:200,
classId:this.data.nowClass.classId
})
stuList = stu.data.datas
}
let startTime = this.data.startTime
if(this.data.nowDate == this.data.startTime){
const now = new Date()
startTime += ' ' + now.toLocaleTimeString('zh-CN', {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false // 使用24小时制
})
}
let params = {
"workName": this.data.homeWorkName,
"workType": this.data.workModeType.id,
"workModeType": this.data.workType.id,
"workModeTypeName": this.data.workType.name,
"workTypeName": this.data.workModeType.name,
"groupNumber": this.data.group,
"isRepeat": this.data.sureWeekList.length > 0 ? true : false,
"weekList": this.data.sureWeekList,
"studentScope": this.data.studentScope,
"gradeId": this.data.nowClass.gradeId,
"classId": this.data.nowClass.classId,
"gradeName": this.data.nowClass.name.split('-')[0],
"className": this.data.nowClass.name.split('-')[1],
"startTime": startTime,
"endTime": this.data.endTime + ' 23:59:59',
"homeWorkStudents": stuList
}
if(this.data.workType.id == 1){
params.duration = Number(this.data.time) * 60
}else if(this.data.workType.id == 2){
params.amount = this.data.num
}
const res = await creatHomeWork(params)
if(res.success) {
app.showToast('创建成功')
app.globalData.homeWorkRefresh = 1
setTimeout(() => {
wx.navigateBack()
}, 500);
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
console.log(this.data.clickList)
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})