litian
2024-07-11 57ba8e29b5cfdd3fc5b0b9b631a26ff095d1ac5d
pages/digitalCourses/digitalCoursesDetails/index.js
@@ -1,7 +1,13 @@
// pages/digitalCourses/digitalCoursesDetails/index.js
const app = getApp()
import {
  worksDataBytool
} from "../../../assets/js/toolClass.js";
import moment from 'moment'
import Toast from "tdesign-miniprogram/toast";
import {
  loginInfo
} from '../../../assets/js/login';
Page({
  /**
@@ -62,6 +68,20 @@
    notePage: 1,
    noteLimit: 6,
    noteTotalCount: 0,
    images: [],
    visible: false,
    showIndex: false,
    closeBtn: false,
    deleteBtn: false,
    bookId: '',
    playerList: [],
    worksInfo: [],
    isCertificate: {},
    isLearn: false,
    isTest: false,
    userInfo: {
      fullName: '' //名称
    }
  },
  formatDate(dateString) {
    if (!dateString) {
@@ -113,9 +133,13 @@
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
    this.setData({
      bookId: options.id
    })
    this.digitalCoursesDetailsGet(options.id)
    this.getPlayerList()
    this.getType()
    this.getCertificateList()
  },
  /**
@@ -165,6 +189,22 @@
   */
  onShareAppMessage() {
  },
  //获取视频学习
  getPlayerList() {
    app.MG.identity
      .getUserKey({
        domain: 'videoPlayer',
        keys: [this.data.bookId]
      })
      .then((res) => {
        if (res.length > 0) {
          this.setData({
            playerList: JSON.parse(res[0].value)
          })
          console.log(this.data.playerList, "playerList")
        }
      })
  },
  digitalCoursesDetailsGet(digitalTextId) {
    let query = {
@@ -310,17 +350,27 @@
      }
    }
    app.MG.store.getProductDetail(query).then((res) => {
      console.log(res.datas, 1111)
      let test = []
      let learn = []
      let learnItemList = []
      if (res.datas.cmsDatas[0].datas.length > 0) {
        res.datas.cmsDatas[0].datas.forEach((item) => {
          if (item.type == 'questionBankFolder' || item.type == 'questionBankItem') {
            test.push(item)
          } else if (item.type != "resourceItem") {
            this.data.playerList.forEach(pItem => {
              if (pItem.cmsItemId == item.id) {
                item.progress = pItem.progress
              }
            })
            learn.push(item)
          }
          if (item.type == 'productItem') {
            learnItemList.push(item)
          }
        })
        if (this.data.selectActive === 'learn') {
          let list = []
          // 测试 6位// 正式 5位//  测试调用传20,内部7  正式调用传17 内部传6
@@ -357,6 +407,24 @@
              openTeachids: result,
            });
          }
        }
        //判断资源是否学习完成
        if (learnItemList.length == this.data.playerList.length) {
          let data = this.data.playerList.filter((ditem) => ditem.progress != '100')
          if (data) {
            this.setData({
              isLearn: false,
            });
          } else {
            this.setData({
              isLearn: true,
            });
          }
        } else {
          this.setData({
            isLearn: false,
          });
        }
      }
    })
@@ -584,7 +652,67 @@
    });
  },
  //申请证书
  //获取字段
  getType() {
    app.MG.resource.getCmsTypeByRefCode({
      refCodes: ['jsek_courseCertificate']
    }).then((res) => {
      this.setData({
        worksInfo: res[0].cmsTypeLinks[0].children,
      })
    })
  },
  getCertificateList() {
    const data = {
      start: 0,
      size: 9999,
      topicIdOrRefCode: 'applyCourseCertificate',
      appRefCode: app.config.appRefCode,
      sort: {
        type: 'Desc',
        field: 'CreateDate'
      }
    }
    app.MG.ugc.getTopicMessageList(data).then((res) => {
      res.datas.map((item) => {
        item.content = JSON.parse(item.content)
        if (item.content.id == this.data.bookId) {
          this.setData({
            isCertificate: item
          })
        }
      })
    })
  },
  onCertificate() {
    // if (!this.data.isBuy) {
    //   wx.showToast({
    //     title: "请先购买,体验完整服务",
    //     icon: "none",
    //     duration: 1000,
    //   });
    //   return false
    // }
    // if (!this.data.isLearn) {
    //   wx.showToast({
    //     title: "您的学习任务还未完成,暂不能申请证书,加油哦!",
    //     icon: "none",
    //     duration: 1000,
    //   });
    //   return false
    // }
    // if (this.data.isCertificate && this.data.isCertificate.state == 'WaitAudit') {
    //   wx.showToast({
    //     title: "您申请的证书正在审核中",
    //     icon: "none",
    //     duration: 1000,
    //   });
    //   return false
    // }
    var page = getCurrentPages().pop(); // 获取当前页面实例
    page.setData({
      // 动态设置禁止滚动的样式
@@ -601,11 +729,52 @@
      scrollJudge: true
    })
  },
  confirmM() {
  //姓名
  onFullNameInput(e) {
    this.setData({
      dialogBox: false,
      scrollJudge: true
    })
      "userInfo.fullName": e.detail.value,
    });
  },
  confirmM() {
    if (this.data.userInfo.fullName) {
      let data = {}
      data = {
        topicIdOrRefCode: 'applyCourseCertificate',
        name: this.data.userInfo.fullName,
        content: JSON.stringify(this.data.digitalsData),
        state: 'WaitAudit',
        cmsTypeRefCode: 'jsek_courseCertificate',
        type: 'applyCourse',
        newDataListRequest: worksDataBytool(this.data.worksInfo, this.data.userInfo)
      }
      app.MG.ugc
        .newTopicMessage(data)
        .then((res) => {
          wx.showToast({
            title: "已提交申请",
            icon: "none",
            duration: 1000,
          });
          this.setData({
            "userInfo.fullName": "",
            dialogBox: false,
            scrollJudge: true
          })
          this.getCertificateList()
        })
        .catch(() => {
          this.setData({
            "userInfo.fullName": "",
          })
        })
    } else {
      wx.showToast({
        title: "姓名不能为空",
        icon: "none",
        duration: 1000,
      });
    }
  },
  setCoolect() {
    // 首页测试登录功能,后续注释
@@ -666,4 +835,29 @@
      }
    }
  },
  //证书查看
  onClick1() {
    this.setData({
      images: ['/static/images/certificate/cbzs.jpg'],
      showIndex: true,
      visible: true,
    })
  },
  onClick2() {
    this.setData({
      images: ['/static/images/certificate/rzzs.jpg'],
      showIndex: true,
      visible: true,
    })
  },
  onClose(e) {
    const {
      trigger
    } = e.detail;
    console.log(trigger);
    this.setData({
      visible: false,
    });
  },
})