zhongshujie
2024-12-12 09e445694a7360893a17152252f2dc5c1b77b2cf
packageBookService/pages/bookServices/detail/index.js
@@ -7,6 +7,7 @@
} from "../../../../assets/js/login";
import FormData from '../../../../utils/formdata/index.js';
const app = getApp();
var pastData = require('../../psychologyAnswer/testdata/index')
Page({
  /**
   * 页面的初始数据
@@ -74,6 +75,8 @@
      residue: 0, // 组卷剩余次数
      mockList: [], // 用户组卷提交信息
    },
    isBuyBank: false,
    bankSaleData: null,
    relatedBookLoading: false,
    noRelatedBookData: false,
    relatedBookPath: "", // 相关图书path
@@ -208,7 +211,9 @@
    fileList: [],
    isShowUp: true,
    protocolShow: false,
    protocolTxt: ''
    protocolTxt: '',
    learnMenu: null,
    md5List: []
  },
  resetTree: function (e) {
@@ -273,7 +278,7 @@
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  onShow(options) {
    if (wx.getStorageSync("paperBookList")) {
      this.setData({
        paperBookList: JSON.parse(wx.getStorageSync("paperBookList")),
@@ -287,6 +292,9 @@
    this.setData({
      num: Number(this.data.paperBookList.length) + Number(this.data.electronicBookList.length),
    });
    if (this.data.bookDetail) {
      this.getBookInfo(this.data.bookDetail.id)
    }
  },
  /**
@@ -524,9 +532,27 @@
      }
    }
    app.MG.store.getProductDetail(query).then((res) => {
      console.log(111, res.datas.cmsDatas[0].datas);
      let isBuyBank = true
      let bankSaleData = null
      // 判断题库是否整体购买
      const bank = res.datas.cmsDatas[0].datas.find((item) => item.refCode == 'questionBank')
      if (bank) {
        if (bank.saleMethod.length) {
          bankSaleData = bank.saleMethod.find((item) => item.SaleType == 'Normal')
          if (bankSaleData) {
            isBuyBank = this.data.buyIdList.includes(bankSaleData.Id)
          }
        }
      }
      this.setData({
        resourceCodeList: res.datas.cmsDatas[0].datas,
        learnTaskData: res.datas.cmsDatas[0].datas.filter((item) => item.refCode == 'jsek_learningTasks')[0]
        learnTaskData: res.datas.cmsDatas[0].datas.filter((item) => item.refCode == 'jsek_learningTasks')[0],
        isBuyBank,
        bankSaleData
      })
      if (res.datas.cmsDatas[0].datas.length) this.setData({
        learnMenu: res.datas.cmsDatas[0].datas.find(item => item.refCode == 'jsek_cloudLearning')
      })
    })
  },
@@ -871,7 +897,7 @@
        }
        // newArr.push(item)
        // 在插入过程中对数据进行排序
        newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item)
        newArr = this.insertAndSortObjectsById(newArr, item)
        // 插进数组后 从原数据中删除
        rootList = rootList.filter(nitem => nitem.id != item.id)
      }
@@ -903,8 +929,8 @@
    return tree
  },
  // 排序数组 按照productLinkPath
  insertAndSortObjectsByProductLinkPath(array, newObj) {
  // 排序数组 按照id
  insertAndSortObjectsById(array, newObj) {
    // 查找新对象应该插入的位置  
    let insertIndex = array.findIndex(obj => newObj.id < obj.id);
    // 如果没有找到合适的位置,则放在数组末尾  
@@ -973,12 +999,13 @@
      },
    }
    app.MG.store.getProductDetailNoChildren(query).then((res) => {
      if (!res.datas.cmsDatas[0].datas.length) {
      if (!res.datas.cmsDatas[0].datas.length || res.datas.cmsDatas[0].datas.length == 0) {
        return this.setData({
          noResources: true,
          loading: false,
        });
      }
      let list = []
      // 判断云学习有无销售方式和有效期
      const cloundSaleMethod =
@@ -990,8 +1017,19 @@
        cloundSaleMethod &&
        new Date().getTime() <= new Date(cloundSaleMethod.EndDate).getTime() &&
        new Date().getTime() >= new Date(cloundSaleMethod.BeginDate).getTime()
      let md5s = []
      res.datas.cmsDatas[0].datas.forEach((item) => {
        // 云学习上有销售方式,去掉云学习下所有销售方式
        if (this.data.tabValue == "jsek_teachingResources") {
          if (item.file || item.freeFile) {
            let md5 = item.file ? item.file : item.freeFile
            md5s.push(md5)
          }
          this.setData({
            md5List: md5s,
          });
        }
        if (flags) item.saleMethod = []
        item.checked = false;
        if (item.sysType == 'CmsItem') {
@@ -1040,9 +1078,9 @@
          new Date(item.saleMethod.find((citem) => citem.SaleType == 'Normal').BeginDate).getTime() <= new Date().getTime()
        ) || (flags && cloundSaleMethod.Price == 0)
        // 判断云学习全部购买按钮是否显示
        let isShowBuyCloundMenu = flags && cloundSaleMethod.Price >= 0
        let isShowBuyCloundMenu = flags && cloundSaleMethod.Price >= 0 && !this.data.buyIdList.includes(cloundSaleMethod.Id)
        // 判断资源购买按钮是否显示
        let isShowBuyCloundBtn = res.datas.cmsDatas[0].datas.some(citem => citem.saleMethod.length != 0) || type.saleMethod.length
        let isShowBuyCloundBtn = !flags && res.datas.cmsDatas[0].datas.some(citem => citem.saleMethod.length != 0)
        // 判断购物车按钮和锁按钮是否显示
        this.handleTreeData(list).forEach(item => {
          item.isbuy = this.resourceIsBuy(item);
@@ -1124,8 +1162,12 @@
              });
            }
          } else {
            if (isTSFW.length > 0) {
              data = res.datas.cmsDatas[0].datas.filter((item) => item.type == 'questionBankFolder' && item.childrenFolderCount > 0)
              data = res.datas.cmsDatas[0].datas.filter((item) => item.type == 'questionBankFolder' && (item.childrenFolderCount > 0 || item.childrenCount > 0) && (item.name !== '填空题' &&
                item.name !== '判断题' &&
                item.name !== '多选题' &&
                item.name !== '简答题'))
              that.setData({
                jslx: false,
              });
@@ -1136,6 +1178,7 @@
              });
            }
            if (data.length > 0) {
              console.log('data', data);
              let list = []
              that.getTreeList(data, list, query.cmsPath)
              list = that.ensureTreeConsistency(list)
@@ -1145,6 +1188,20 @@
                loading: false,
                openTeachids: result,
              });
              //Json赋值
              // const bookId = that.data.bookId
              // if (bookId == 6619) {
              //   const jsonData = {}
              //   jsonData.name = "心理测评"
              //   jsonData.children = [...pastData.postData.list]
              //   var test = that.data.test;
              //   test.push(jsonData);
              //   that.setData({
              //     test: test,
              //   });
              //   console.log(that.data.test, "教学互动");
              // }
            } else {
              that.setData({
                noResources: true,
@@ -1889,6 +1946,42 @@
  },
  handleTrue() {
    // findAndUpdateItemsByIds(this.date.)
  },
  // 题库购买
  async buyBank() {
    console.log(11, this.data.bankSaleData);
    let query = {
      remarks: '云测试',
      requests: [{
        saleMethodId: this.data.bankSaleData.Id,
        count: 1
      }]
    }
    const initOrderRes = await app.MG.store.initOrder(query)
    if (this.data.bankSaleData.Price) {
      // 购买
      const url = "/pages/cart/paymentPage/index?orderNumber=" + initOrderRes.orderNumber + '&onNorderSaleMethod=' + initOrderRes.saleMethodLinks[0].orderSaleMethod.id;
      wx.navigateTo({
        url,
      });
    } else {
      // 免费领取
      app.MG.store
        .confirmOrder({
          orderNum: initOrderRes.orderNumber,
        })
        .then((res) => {
          if (res) {
            wx.showToast({
              title: "领取成功",
              icon: "none",
              duration: 1000,
            });
            this.getBookInfo(this.data.bookDetail.id);
          }
        });
    }
  },
  // 组卷格式化日期显示
  DateFormat(date, fmt) {
@@ -2806,7 +2899,7 @@
    app.MG.ugc.newTopicMessage(query).then((res) => {
      wx.showToast({
        icon: "success",
        title: "请上传资源文件",
        title: "上传成功",
      });
      this.closeDialog()
    })
@@ -2821,5 +2914,10 @@
    this.setData({
      cloundMenuIsBuy: flag
    })
  }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
  onShareTimeline() {}
})