litian
2024-12-24 6df96b3e7a7da1985ee875e84711e9f15c5fbff0
packageCourse/pages/course/index.js
@@ -31,6 +31,10 @@
      total: 999,
      loading: false
    },
    updateCourse: false,
    currentCourse: null,
    submitLoading: false,
    showContentOnly: false,
    // 加载参数
    bottomLoading: false,
    isMoreData: false,
@@ -47,6 +51,18 @@
    this.getData()
  },
  showDialog() {
    this.setData({
      showContentOnly: true,
    });
  },
  closeDialog() {
    this.setData({
      showContentOnly: false
    });
  },
  // 课程详情
  todetail(e) {
    const {
@@ -54,14 +70,15 @@
      item
    } = e.currentTarget.dataset
    const refCode = item.linkProduct.refCode ? item.linkProduct.refCode : ''
    if (item.applyState == 'WaitAudit' || item.applyState == 'Reject') {
    if (item.applyState == 'WaitAudit') {
      wx.showToast({
        title: item.applyState == 'WaitAudit' ? '审核中' : '未通过',
        title: '审核中',
        duration: 1000,
        icon: 'none',
      })
      return false
    }
    if (item.applyState == 'Reject') return false
    wx.navigateTo({
      url: '/packageCourse/pages/course/detail/index?courseId=' + courseId + "&bookRefCode=" + refCode,
    })
@@ -114,9 +131,9 @@
            ...item,
            name: item.name,
            id: item.id,
            icon: item.icon && item.icon != 'default' ? getPublicImage(item.icon, 80) : '',
            icon: item.icon && item.icon != 'default' ? getPublicImage(item.icon, 200) : '',
            introduction: item.description,
            reason: item.applyReturnMsg ? JSON.parse(item.applyReturnMsg).reason : '-'
            reason: item.applyReturnMsg ? JSON.parse(item.applyReturnMsg).reason ? JSON.parse(item.applyReturnMsg).reason : '-' : '-'
          }
        })
        //触底加载新数据并保留老数据
@@ -162,7 +179,7 @@
        const list = res.datas.map((item) => {
          return {
            ...item,
            icon: item.product.icon ? getPublicImage(item.product.icon, 80) : ''
            icon: item.product.icon ? getPublicImage(item.product.icon, 200) : ''
          }
        })
        this.setData({
@@ -209,8 +226,11 @@
  // 单选选择课本
  onChange(e) {
    const {
      index
    } = e.currentTarget.dataset
    this.setData({
      radioVal: e.detail.value
      radioVal: index
    });
  },
@@ -238,48 +258,111 @@
    })
  },
  // 重新申请
  replayCourse(e) {
    const {
      item
    } = e.currentTarget.dataset
    if (!item.linkProduct.icon) {
      item.linkProduct.icon = ''
    }
    const data = {
      product: item.linkProduct
    }
    this.setData({
      currentCourse: item,
      courseName: item.name,
      courseDesc: item.description,
      selectedBook: data,
      updateCourse: true,
      visible: true
    })
    this.getTextBook()
  },
  // 新建课程
  submitCourse() {
    if (!this.data.courseName) {
      wx.showToast({
        title: '请填写课程名称',
        duration: 1000,
        icon: 'none',
    if (this.data.updateCourse) {
      this.setData({
        submitLoading: true
      })
      return false
      app.MG.edu
        .updateCourse({
          courseId: this.data.currentCourse.id,
          name: this.data.courseName,
          description: this.data.courseDesc,
        })
        .then((res) => {
          app.MG.edu
            .updateCourseApply({
              courseId: this.data.currentCourse.id,
              applyData: JSON.stringify({
                textBookId: this.data.selectedBook.product.id,
                textBookName: this.data.selectedBook.product.name
              })
            })
            .then((ares) => {
              if (ares) {
                this.setData({
                  visible: false,
                  selectedBook: null,
                  courseDesc: '',
                  courseName: '',
                  submitLoading: false
                })
                this.getData()
              }
            })
        })
    } else {
      if (!this.data.courseName) {
        wx.showToast({
          title: '请填写课程名称',
          duration: 1000,
          icon: 'none',
        })
        return false
      }
      if (!this.data.selectedBook) {
        wx.showToast({
          title: '请选择关联教材',
          duration: 1000,
          icon: 'none',
        })
        return false
      }
      this.setData({
        submitLoading: true
      })
      app.MG.edu
        .applyNewCourse({
          name: this.data.courseName,
          description: this.data.courseDesc,
          content: '',
          icon: this.data.selectedBook.product.icon,
          type: 'course',
          config: '',
          applyData: JSON.stringify({
            textBookId: this.data.selectedBook.product.id,
            textBookName: this.data.selectedBook.product.name
          }),
          linkProductId: this.data.selectedBook.product.id,
          maxClassCount: 999,
          payPrice: 0
        })
        .then((res) => {
          if (res) {
            this.setData({
              visible: false,
              selectedBook: null,
              courseDesc: '',
              courseName: '',
              submitLoading: false
            })
            this.getData()
          }
        })
    }
    if (!this.data.selectedBook) {
      wx.showToast({
        title: '请选择关联教材',
        duration: 1000,
        icon: 'none',
      })
      return false
    }
    app.MG.edu
      .applyNewCourse({
        name: this.data.courseName,
        description: this.data.courseDesc,
        content: '',
        icon: this.data.selectedBook.product.icon,
        type: 'course',
        config: '',
        applyData: JSON.stringify({
          textBookId: this.data.selectedBook.product.id,
          textBookName: this.data.selectedBook.product.name
        }),
        linkProductId: this.data.selectedBook.product.id,
        maxClassCount: 999,
        payPrice: 0
      })
      .then((res) => {
        if (res) {
          this.setData({
            visible: false
          })
          this.getData()
        }
      })
  },
  // 返回顶部