import { request, throttle } from "../../utils/api" import { createStoreBindings } from "mobx-miniprogram-bindings" import { store } from "../../store/index" import { env } from "../../env" Page({ /** * 页面的初始数据 */ data: { // 作业路径 workPath: '', // 作业名 workPathName: '', // 作业列表 workList: [], // vh页面高度 vh: 0, // 搜索内容 valueSearch: '', // 过滤器显示 filterShow: false, // 新增 showDialog: false, // 显示过滤器 showSheet: true, // 搜索项 作业名 workName: '', // 期号 issue: "", // 学员班级 classIds: [], // 开始时间 startTime: "", // 结束时间 endTime: "", // 期号列表 // issusList: [], minHour: 10, maxHour: 20, // 显示的时间类型 timeType: false, //开始true // 期号列表 issusList: [{ text: '20230311', value: 0 }, { text: '20230312', value: 1 }, { text: '20230313', value: 2 }, ], // 选中班级 activeTab: 0, showTimeAttr: false, // 期号信息 showIssus: false, // 发布作业 // 作业名称 formWorkName: "", // 任务班级 formClass: "", // 作业要求 formWorkDetail: "", // 上传文件 formTem: "", // pageNo: 1, pageSize: 10, total: 0, // 班级id filterClassId: "", // 班级列表 classList: [], optionType: { value: "id", label: "className" }, // 临时期号 arrIssue: '', // 最小时间 minDate: new Date(2019, 10, 1).getTime(), // 临时存储时间 timeArrStart: "", timeArrEnd: "", optionTypeIssue: { value: "homeworkNumber", label: "homeworkNumber" }, AllWorkList: [] }, // 点击班级 onClassID(e) { this.setData({ filterClassId: e.target.dataset.id }) }, // 期号选择 selectChange(e) { console.log(e.detail) this.setData({ classIds: e.detail }) }, //开始 时间变化 startTimeChange(e) { }, // 选择班级 onChangeTab(e) { this.setData({ activeTab: e.detail }) }, //显示过滤器 showFilter() { this.setData({ filterShow: !this.data.filterShow }) }, // 重置数据 reSetData() { this.setData({ startTime: "", endTime: "", workName: "", issue: "", filterClassId: '' }) }, // 确认搜索 onSearchFilter() { this.showFilter() this.setData({ pageNo: 1 }) this.getWorkList() }, // 点击搜索 触发 goSearch(e) { console.log(e.detail) this.setData({ workName: e.detail, pageNo: 1 }) this.getWorkList() }, // 关闭过滤项 onCloseSheet() { this.setData({ showSheet: !this.data.showSheet }) }, // 区分时间选择类型 onShowTimeAttr(e) { let active = e.target.dataset.active this.setData({ timeType: active }) console.log(this.data.timeType) if (active) { // 开始时间 } else { // 结束时间 } this.setData({ showTimeAttr: true }) }, // 取消更改时间选择 onCloseTimeAttr() { this.setData({ showTimeAttr: false, }) // wx.nextTick(() => { if (this.data.timeType) { this.setData({ startTime: "" }) } else { this.setData({ endTime: "" }) } console.log(this.data.startTime) // }) }, onTimeAttr() { this.setData({ showTimeAttr: false, }) if (this.data.timeType) { this.setData({ startTime: this.data.timeArrStart }) } else { this.setData({ endTime: this.data.timeArrEnd }) } }, // 时间变化 startTimeChange(e) { this.setData({ timeArrStart: e.detail }) }, endTimeChange(e) { this.setData({ timeArrEnd: e.detail }) }, // 选择期号 onIssusChange(e) { console.log(e.detail.value.homeworkNumber) this.setData({ arrIssue: e.detail.value.homeworkNumber }) }, // 关闭期号选择 onCloseIssus() { this.setData({ showIssus: !this.data.showIssus, // showFilter: true }) }, // 确认 onIssus() { if (this.data.arrIssue == "" && this.data.workList.length !== 0) { this.setData({ issue: this.data.workList[0].homeworkNumber, showIssus: false, }) } else { this.setData({ showIssus: false, issue: this.data.arrIssue }) } }, // 新增表单 onCloseDialog() { }, // 开启 onShowDialog() { this.setData({ showDialog: true }) }, // 获取班级信息 async getClassesList() { const res = await request("/app-api/tutor/h5/getClassPage", "GET", { pageNo: 1, pageSize: 99 }) this.setData({ classList: res.data.list }) console.log(res.data.code) }, // 提交作业 submitWork: throttle(async function () { let ids = "" ids = this.data.classIds.join(",") console.log(ids) let { formWorkName, formWorkDetail, workPath } = this.data console.log(ids, formWorkName, formWorkDetail) if (this.data.classIds.length == 0) { wx.showToast({ title: '请选择发布班级', icon: "error" }) return } if (this.data.formWorkName == "") { wx.showToast({ title: '请输入作业名称', icon: "error" }) return } if (this.data.workPath == "") { wx.showToast({ title: '请上传作业', icon: "error" }) return } let userInfo = wx.getStorageSync('userInfo') let res = await request("/app-api/tutor/h5/addHomework", "POST", { classIds: ids, homeworkName: formWorkName, // 文件地址 homeworkPath: workPath, reserve: formWorkDetail, // 获取老师信息 subject: userInfo.subject, }) console.log(res) if (res?.code == 0) { wx.showToast({ title: '发布成功', icon: "success" }) } this.setData({ showDialog: false }) this.getWorkList() }), // 取消提交 closeSubmit() { this.setData({ showDialog: false, formWorkDetail: '', formWorkName: "", classIds: [], }) }, getWorkList: throttle(async function () { let { pageNo, pageSize, total, startTime, endTime, workName, issue, filterClassId } = this.data let userInfo = wx.getStorageSync('userInfo') let primary = { pageNo, pageSize, beginCreateTime: startTime == "" ? '' : new Date(startTime).toISOString().slice(0, 9) + ' 00:00:00', endCreateTime: endTime == "" ? '' : new Date(endTime).toISOString().slice(0, 9) + ' 00:00:00', homeworkName: workName, homeworkNumber: issue, subject: userInfo.subject, classId: filterClassId } console.log(primary) const res = await request("/app-api/tutor/h5/getHomeworkPage", "GET", primary) this.getWorkListAll() console.log(res) if (res.code == 0) { if (pageNo === 1) { this.setData({ workList: res.data.list, total: res.data.total, subject: "" }) return } } if (pageNo * pageSize < total) { this.setData({ total: res.data.total }) } }), // async getWorkListAll() { const res = await request("/app-api/tutor/h5/getHomeworkPage", "GET", { pageNo: 1, pageSize: 99, }) this.setData({ AllWorkList: res.data.list }) }, // 前往详情页 toWorkPushDetail(e) { console.log(e) wx.navigateTo({ url: '/teacher/pages/workPushDetail/workPushDetail?workId=' + e.currentTarget.dataset.index, }) }, // 上传作业 chooseUpload() { var that = this wx.chooseMessageFile({ count: 1, type: 'file', success(res) { console.log(res, "res") const tempFilePaths = res.tempFiles that.setData({ workPathName: tempFilePaths[0].name }) for (var i in tempFilePaths) { wx.uploadFile({ url: env.baseUrl + '/app-api/tutor/h5/addHomeworkUpload', //上传的服务器地址 filePath: tempFilePaths[i].path, name: 'file', formData: { 'file': tempFilePaths[i].path }, success: function (resp) { console.log(resp) var data = JSON.parse(resp.data) let workPath = data.data.replace('/www/wwwroot/', 'https://') that.setData({ workPath }) console.log(workPath) if (data.code == 0) { wx.showToast({ title: '上传成功', icon: 'none', duration: 1300 }) } else { wx.showToast({ title: "上传失败", icon: 'none', duration: 2000 }) } }, fail: function (err) { console.log(err) } }) } } }) }, // 触底 scrolltolower(){ let {pageSize,pageNo,total} = this.data if (pageNo*pageSize { console.log(res) this.setData({ vh: res.windowHeight - 50 - res.statusBarHeight }) } }) this.getWorkList() }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { this.reSetData() this.setData({ pageNo: 1, workListL:[] }) this.getWorkList() }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { let { pageNo, pageSize, total } = this.data if (pageNo * pageSize < total) { this.setData({ pageNo: pageNo += 1, }) } }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })