111
QYF-GitLab1
2025-01-03 2ee8ddb1ecac7df4198e54e08ec7f22daf4b07c0
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({
  /**
   * 页面的初始数据
@@ -50,10 +51,12 @@
    resourceClassList: [], // 资源所属分类
    applyState: "", // 教学资源申请状态
    deadline: "", // 教学资源申请有效日期,
    isShowBuyCloundBtn: false,
    isshowDrawBtn: true, // 云学习领取查看按钮是否显示
    isShowBuyCloundMenu: false, //   云学习全部购买按钮是否显示
    isCloundHaveSaleMethod: false, // 云学习是否有销售方式 
    cloundMenuIsBuy: false,
    learnTaskData: {},
    rejectCause: "", // 下载拒绝原因
    buyIdList: [],
    shoppingCartGetId: [], // 已购买id列表
@@ -72,6 +75,9 @@
      residue: 0, // 组卷剩余次数
      mockList: [], // 用户组卷提交信息
    },
    isBuyBank: false, // 题库是否购买
    isShoppingBank: false, // 题库是否加入购物车
    bankSaleData: null,
    relatedBookLoading: false,
    noRelatedBookData: false,
    relatedBookPath: "", // 相关图书path
@@ -206,7 +212,10 @@
    fileList: [],
    isShowUp: true,
    protocolShow: false,
    protocolTxt: ''
    protocolTxt: '',
    learnMenu: null,
    md5List: [],
    editDialog: false
  },
  resetTree: function (e) {
@@ -263,15 +272,13 @@
      this.setData({
        tabValue: options.tabValue,
      });
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  onShow(options) {
    if (wx.getStorageSync("paperBookList")) {
      this.setData({
        paperBookList: JSON.parse(wx.getStorageSync("paperBookList")),
@@ -285,6 +292,9 @@
    this.setData({
      num: Number(this.data.paperBookList.length) + Number(this.data.electronicBookList.length),
    });
    if (this.data.bookDetail.id) {
      this.getBookInfo(this.data.bookDetail.id)
    }
  },
  /**
@@ -422,10 +432,14 @@
        protectedEpub: [],
        probationPage: [], //pdf试读页数
        freeEpubPage: [], //epub试读百分比
        bookEditor: [], //图书编辑
        contactInformation: [], //联系方式
      },
    };
    app.MG.store.getProductDetail(query).then(async (res) => {
      this.getResourceCode(id, res.datas.rootCmsItemId)
      res.datas.bookEditor = res.datas.bookEditor ? res.datas.bookEditor : '-'
      res.datas.contactInformation = res.datas.contactInformation ? res.datas.contactInformation : '-'
      this.setData({
        bookDetail: res.datas,
        buyIdList: res.datas.purchasedSaleMethodIdList,
@@ -459,6 +473,16 @@
          }
          await this.getBookClass(classData);
        }
      }
      // 扫码从题库跳转回图书详情
      const localData = wx.getStorageSync('tabValue')
      if (localData) {
        this.setData({
          tabValue: localData
        })
        wx.removeStorage({
          key: 'tabValue',
        })
      }
      if (this.data.tabValue == 'questionBank' || this.data.tabValue == 'jsek_cloudLearning' || this.data.tabValue == 'jsek_teachingResources') {
        const checkData = this.data.cmsDatas.find(
@@ -497,13 +521,12 @@
        }
      }
      this.setData({
        "bookDetail.publicationDate": moment(this.data.bookDetail.publicationDate).format("YYYY年MM月"),
        "bookDetail.publicationDate": this.data.bookDetail.publicationDate ? moment(this.data.bookDetail.publicationDate).format("YYYY年MM月") : '',
        "bookDetail.price": this.numFormat(this.data.bookDetail.price),
        "bookDetail.oldPrice": this.numFormat(this.data.bookDetail.oldPrice),
        "bookDetail.paperPrice": this.numFormat(
          this.data.bookDetail.paperPrice
        ),
      });
    });
  },
@@ -522,10 +545,30 @@
      }
    }
    app.MG.store.getProductDetail(query).then((res) => {
      let isBuyBank = true
      let isShoppingBank = 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)
            isShoppingBank = this.data.buyIdList.includes(bankSaleData.Id) ? true : this.data.shoppingCartGetId.includes(bankSaleData.Id)
          }
        }
      }
      this.setData({
        resourceCodeList: res.datas.cmsDatas[0].datas,
        learnTaskData: res.datas.cmsDatas[0].datas.filter((item) => item.refCode == 'jsek_learningTasks')[0],
        isBuyBank,
        isShoppingBank,
        bankSaleData
      })
      console.log('refcode', this.data.resourceCodeList);
      if (res.datas.cmsDatas[0].datas.length) this.setData({
        learnMenu: res.datas.cmsDatas[0].datas.find(item => item.refCode == 'jsek_cloudLearning')
      })
    })
  },
  //请求子商品的文件
@@ -716,6 +759,14 @@
      }
    }
  },
  // 联系
  editPhone() {
    this.setData({
      editDialog: true
    })
  },
  // 我要建议
  suggestBtn() {
    // 检查登录状态
@@ -869,7 +920,7 @@
        }
        // newArr.push(item)
        // 在插入过程中对数据进行排序
        newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item)
        newArr = this.insertAndSortObjectsById(newArr, item)
        // 插进数组后 从原数据中删除
        rootList = rootList.filter(nitem => nitem.id != item.id)
      }
@@ -901,8 +952,8 @@
    return tree
  },
  // 排序数组 按照productLinkPath
  insertAndSortObjectsByProductLinkPath(array, newObj) {
  // 排序数组 按照id
  insertAndSortObjectsById(array, newObj) {
    // 查找新对象应该插入的位置  
    let insertIndex = array.findIndex(obj => newObj.id < obj.id);
    // 如果没有找到合适的位置,则放在数组末尾  
@@ -949,7 +1000,6 @@
    let query = {
      path: '*',
      queryType: '*',
      // storeInfo: this.data.options.storeInfo,
      productId: this.data.bookDetail.id,
      cmsPath: type.productLinkPath,
      cmsType: '*',
@@ -962,10 +1012,9 @@
        file: [],
        protectedFile: [],
        resourcesClassification: [],
        isDownload: [],
        // isDownload: [],
        jsek_resourceBrief: [],
        jsek_link: [],
        jsek_questionBank: []
      },
      pading: {
        start: 0,
@@ -973,13 +1022,13 @@
      },
    }
    app.MG.store.getProductDetailNoChildren(query).then((res) => {
      console.log('未处理资源', res.datas.cmsDatas[0].datas);
      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 =
@@ -991,8 +1040,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') {
@@ -1041,7 +1101,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 = !flags && res.datas.cmsDatas[0].datas.some(citem => citem.saleMethod.length != 0)
        // 判断购物车按钮和锁按钮是否显示
        this.handleTreeData(list).forEach(item => {
          item.isbuy = this.resourceIsBuy(item);
@@ -1051,6 +1113,7 @@
        this.setData({
          isshowDrawBtn,
          isShowBuyCloundMenu,
          isShowBuyCloundBtn,
          isCloundHaveSaleMethod: flags,
          learn: list,
          loading: false,
@@ -1123,17 +1186,22 @@
            }
          } 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.refCode != 'jsek_interaction' && (item.childrenFolderCount > 0 || item.childrenCount > 0) && (item.name !== '填空题' &&
                item.name !== '判断题' &&
                item.name !== '多选题' &&
                item.name !== '简答题') && item.name !== '单选题')
              that.setData({
                jslx: false,
              });
            } else {
              data = res.datas.cmsDatas[0].datas.filter((item) => item.type == 'questionBankFolder')
              // && item.refCode != 'jsek_interaction'
              that.setData({
                jslx: true,
              });
            }
            if (data.length > 0) {
              console.log('data', data);
              let list = []
              that.getTreeList(data, list, query.cmsPath)
              list = that.ensureTreeConsistency(list)
@@ -1143,6 +1211,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,
@@ -1836,6 +1918,31 @@
      });
    }
  },
  // 云学习全部购买
  async buyCloudLearnClass() {
    const cloundMenu = this.data.resourceCodeList.find((item) => item.refCode == 'jsek_cloudLearning')
    let query = {
      remarks: '云学习',
      requests: [{
        saleMethodId: cloundMenu.saleMethod.find((eitem) => eitem.SaleType == 'Normal').Id,
        count: 1
      }]
    }
    const initOrderRes = await app.MG.store.initOrder(query)
    // 检查订单号是否存在
    if (initOrderRes.orderNumber) {
      // bookService: orderNumber.value,  少传这个 ,暂时不知道有什么用
      wx.navigateTo({
        url: `/pages/cart/paymentPage/index?&bookId=${this.data.bookDetail.id}&bookName=${this.data.bookDetail.name}&orderNumber=${initOrderRes.orderNumber}`,
      });
    } else {
      // 订单号不存在,显示警告消息
      wx.showToast({
        icon: "error",
        title: "请重试",
      });
    }
  },
  // 云学习字段购买
  async buyCloundMenu() {
    const cloundData = this.data.resourceCodeList.find(item => item.refCode == 'jsek_cloudLearning')
@@ -1861,6 +1968,59 @@
  },
  handleTrue() {
    // findAndUpdateItemsByIds(this.date.)
  },
  // 题库购买
  async buyBank() {
    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);
          }
        });
    }
  },
  // 题库加入购物车
  handleShoppingBank() {
    let query = {
      requests: [{
        saleMethodId: this.data.bankSaleData.Id,
        storeEventId: null,
        agentCode: "云测试",
      }, ],
    };
    app.MG.store.addShoppingCart(query).then(res => {
      wx.showToast({
        icon: 'success',
        title: '加入成功',
      })
      this.getShoppingCartProductGet();
      this.getBookInfo(this.data.bookDetail.id)
    })
  },
  // 组卷格式化日期显示
  DateFormat(date, fmt) {
@@ -2544,6 +2704,11 @@
    return childrenList
  },
  uploadFile(e) {
    const userInfo = JSON.parse(wx.getStorageSync(app.config.userInfoKey))
    if (userInfo.role != 'Teacher') return wx.showToast({
      icon: 'error',
      title: '请先进行教师认证',
    })
    this.setData({
      dialogBox: true,
      isShowUp: true
@@ -2773,7 +2938,7 @@
    app.MG.ugc.newTopicMessage(query).then((res) => {
      wx.showToast({
        icon: "success",
        title: "请上传资源文件",
        title: "上传成功",
      });
      this.closeDialog()
    })
@@ -2788,5 +2953,10 @@
    this.setData({
      cloundMenuIsBuy: flag
    })
  }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
  onShareTimeline() {}
})