123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559 |
- 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<total) {
- this.setData({
- pageNo: pageNo+=1
- })
- this.getWorkList()
- }
- },
- // 触顶
- scrolltoupper(){
- this.reSetData()
- this.setData({
- pageNo: 1,
- workListL:[]
- })
- // this.getWorkList()
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- wx.hideHomeButton()
- this.store = createStoreBindings(this, {
- store,
- filedfs: ["userInfo"]
- })
- this.getClassesList()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- let data = wx.getSystemInfo({
- success: (res) => {
- 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() {
- }
- })
|