litian
2024-12-24 6df96b3e7a7da1985ee875e84711e9f15c5fbff0
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
// packageCourse/pages/studentClass/index.js
import {
  getPublicImage
} from '../../../assets/js/middleGround/tool'
import moment from 'moment'
const app = getApp()
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    searchKey: '',
    visible: false,
    refCode: '',
    classDetail: null,
    classList: [],
    page: 1,
    pageSize: 10,
    totalSize: 0,
    // 加载参数
    bottomLoading: false,
    isMoreData: false,
    // 返回顶部
    isBackTop: false,
    setScrollValue: 0,
    skeletonLoding: true
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getCurrentClassList()
  },
 
  onCourseNameInput(e) {
    this.setData({
      refCode: e.detail.value
    })
  },
 
  // 通过code查询班级
  getClassDetail() {
    if (this.data.refCode == '') {
      wx.showToast({
        title: '请输入邀请码',
        duration: 1000,
        icon: "none",
      })
      return false
    }
    const data = {
      classIdOrRefCode: this.data.refCode
    }
    app.MG.edu
      .getCourseClass(data)
      .then(res => {
        if (res) {
          res.classTime = moment(res.beginDate).format('YYYY-MM-DD') + '--' + moment(res.endDate).format('YYYY-MM-DD')
          this.setData({
            classDetail: res
          })
        }
      })
      .catch(err => {
        console.log(err)
      })
  },
 
  // 打开新建班级
  newClass() {
    this.setData({
      visible: true,
    })
  },
 
  // 关闭申请
  cancle() {
    this.setData({
      visible: false
    })
  },
 
  // 申请提交班级
  submitClass() {
    if (!this.data.refCode) {
      wx.showToast({
        title: '请输入邀请码',
        duration: 1000,
        icon: "none",
      })
      return false
    }
    const data = {
      refCode: this.data.refCode
    }
    app.MG.identity.joinGroupByRefCode(data).then(res => {
      if (res == '组不存在') {
        wx.showToast({
          title: '班级不存在',
          duration: 1000,
          icon: "none",
        })
      }
      if (res == '组成员数量已最大,不能加入') {
        wx.showToast({
          title: '已满员',
          duration: 1000,
          icon: "none",
        })
      }
      if (res == '已经申请过加入此组') {
        wx.showToast({
          title: '已申请',
          duration: 1000,
          icon: "none",
        })
      }
      this.getCurrentClassList()
    })
  },
 
  // 获取当前班级列表
  getCurrentClassList(isReachBottom) {
    const data = {
      start: (this.data.page - 1) * this.data.pageSize,
      size: this.data.pageSize,
      sort: {
        type: 'Desc',
        field: 'CreateDate',
        subSorts: []
      },
      filterList: [],
      searchList: this.data.searchKey ? [{
        keywords: this.data.searchKey,
        field: 'Name',
        compareType: 'Contains'
      }] : []
    }
    app.MG.identity.joinedGroupByList(data).then(res => {
      const {
        datas,
        totalSize
      } = res
      if (datas) {
        let list = res.datas.map(item => {
          return {
            ...item,
            classTime: moment(item.beginDate).format('YYYY.MM.DD') +
              '--' +
              moment(item.endDate).format('YYYY.MM.DD'),
            bookName: item.linkProductDto.product.name,
            bookIcon: getPublicImage(item.linkProductDto.product.icon, 100)
          }
        }) //触底加载新数据并保留老数据
        if (isReachBottom) {
          list = [...this.data.classList, ...list] //将新数据加入老数据中
        }
        this.setData({
          classList: list,
          totalSize: totalSize,
          visible: false,
          skeletonLoding: false,
          bottomLoading: false
        })
      }
    })
  },
 
  // 获取教材详情
  async getBookDetail(shopId, path) {
    let query = {
      path,
      queryType: '*',
      productId: String(shopId),
      storeInfo: path,
      coverSize: {
        height: 300,
        width: 210
      },
      fields: {
        author: [],
        isbn: []
      }
    }
    const res = await app.MG.store.getProductDetail(query)
    return res.datas ?? null
  },
 
  // 班级详情
  async todetail(e) {
    const {
      classId,
      item
    } = e.currentTarget.dataset
    const bookRefCode = item.linkProductDto?.product?.refCode
    const path = bookRefCode ? 'jsek_digitalTextbooks' : 'defaultGoodsStore3'
    const bookData = await this.getBookDetail(item.linkProductDto?.product?.id, path)
    if (item.userState == 'WaitValid' || item.userState == 'Reject') {
      wx.showToast({
        title: item.userState == 'WaitValid' ? '审核中' : '未通过',
        duration: 1000,
        icon: 'none',
      })
      return false
    }
    wx.navigateTo({
      url: '/packageCourse/pages/teachClass/index?classId=' + classId + '&bookId=' + bookData.id + '&author=' + bookData.author + '&isbn=' + bookData.isbn + '&rootCmsItemId=' + bookData.rootCmsItemId + '&bookRefCode=' + bookRefCode,
    })
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    if (this._freshing) return
    this.setData({
      page: 1,
      bottomLoading: false,
      isMoreData: false
    })
    setTimeout(() => {
      this._freshing = true;
      this.setData({
        triggered: false,
      })
      this.getCurrentClassList();
      this._freshing = false
    }, 500);
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.totalSize > this.data.classList.length) {
      this.setData({
        page: this.data.page + 1,
        bottomLoading: true,
        isMoreData: false
      })
    } else {
      this.setData({
        bottomLoading: false,
        isMoreData: true
      })
      return false;
    }
    this.getCurrentClassList(true);
  },
 
  // 监听滚动距离
  onPageScroll(e) {
    if (e && e.scrollTop >= 1000) {
      this.setData({
        isBackTop: true
      })
    } else {
      this.setData({
        isBackTop: false
      })
    }
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
 
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
 
  }
})