QYF-GitLab1
4 天以前 b55024ee2f42aa93e0ecaa3113bdeb286f6e59ac
packageBookService/pages/bookServices/detail/index.js
@@ -212,9 +212,20 @@
    protocolTxt: '',
    learnMenu: null,
    md5List: [],
    editDialog: false
    editDialog: false,
    scrollTop: 0, // 扫码进资源滚动
    source: '',
    activeId: '',
    qrTabValue: '',
    cacheData: [], // 云学习初始数据
  },
  // 扫码到资源列表,滚动到该资源位置
  handleScrollTop(e) {
    if (this.data.tabValue == this.data.qrTabValue)
      this.setData({
        scrollTop: e.detail.top
      })
  },
  resetTree: function (e) {
    this.setData({
      currentCheck: e.detail.checkedItem,
@@ -258,7 +269,11 @@
        name: decodeURI(options.name),
        storeInfo: options.storeInfo,
      },
      source: options.source,
      activeId: options.resourceId,
      qrTabValue: options.tabValue
    });
    console.log('传参', this.data);
    wx.setNavigationBarTitle({
      title: decodeURI(options.name),
    })
@@ -301,6 +316,7 @@
    }
    this.setData({
      num: Number(this.data.paperBookList.length) + Number(this.data.electronicBookList.length),
      editDialog: false
    });
    if (this.data.bookDetail.id) {
      this.getBookInfo(this.data.bookDetail.id)
@@ -444,9 +460,11 @@
        freeEpubPage: [], //epub试读百分比
        bookEditor: [], //图书编辑
        contactInformation: [], //联系方式
        IsTextbook: [] // 是否为教材 如果是教材禁止显示所有购买按钮
      },
    };
    app.MG.store.getProductDetail(query).then(async (res) => {
      res.datas.IsTextbook = res.datas.IsTextbook == '1' ? true : false
      this.getResourceCode(id, res.datas.rootCmsItemId)
      res.datas.bookEditor = res.datas.bookEditor ? res.datas.bookEditor : '-'
      res.datas.contactInformation = res.datas.contactInformation ? res.datas.contactInformation : '-'
@@ -771,7 +789,11 @@
      editDialog: true
    })
  },
  closeEditDialog() {
    this.setData({
      editDialog: false
    })
  },
  // 我要建议
  suggestBtn() {
    // 检查登录状态
@@ -971,23 +993,40 @@
    // 返回更新后的数组  
    return array;
  },
  // 递归树结构,如果父级有销售方式(有效期),去掉所有子集的销售方式
  clearTreeSealmethod(clearSaleMethod, tree) {
  // 递归树结构
  handleSalmethodBtn(tree, data, parent) {
    for (let item of tree) {
      const saleData = item.saleMethod &&
        item.saleMethod.length ?
        item.saleMethod.find((citem) => citem.SaleType == 'Normal') : null
      if (
        ((saleData && new Date(saleData.EndDate).getTime() >= new Date().getTime() && new Date(saleData.BeginDate).getTime() <= new Date().getTime()) ||
          clearSaleMethod) && item.children && item.children.length
      ) {
        item.children.forEach((ditem) => (ditem.saleMethod = []))
      // 是否显示按钮
      item.isShowIcon = false;
      if (item.sysType == 'CmsItem') {
        // 查找目录下资源销售方式,目录下资源没有销售方式
        if (item.saleMethod?.length == 0) {
          // 查看其父级是否有销售方式
          if (parent.saleMethod?.length > 0) {
            // 父级是有销售方式直接显示按钮
            // const index = data.findIndex(i => i.id == parent.id)
            parent.isShowIcon = true
          }
          //  else {
          //   // 父级没有销售方式,查找该资源父级
          //   const arr = parent.productLinkPath.split('\\')
          //   const linkData = arr[arr.length - 1] // arr[arr.length - 1] 排除自己
          //   linkData.reverse()
          //   const dataList = linkData.map(ritem => {
          //     const parentData = data.find(citem => citem.id == ritem);
          //     if (parentData) return parentData;
          //   })
          //   if (dataList?.length > 0) {
          //     const index = data.findIndex(i => i.id == dataList[0].id)
          //     data[index].isShowIcon = true
          //   }
          // }
        } else {
          item.isShowIcon = true
        }
      } else {
        this.handleSalmethodBtn(item.children, data, item)
      }
      if (item.children && item.children.length)
        this.clearTreeSealmethod(
          saleData && new Date(saleData.EndDate).getTime() >= new Date().getTime() && new Date(saleData.BeginDate).getTime() <= new Date().getTime(),
          item.children
        )
    }
    return tree
  },
@@ -1028,6 +1067,9 @@
          loading: false,
        });
      }
      this.setData({
        cacheData: res.datas.cmsDatas[0].datas
      })
      let list = []
      // 判断云学习有无销售方式和有效期
      const cloundSaleMethod =
@@ -1081,15 +1123,19 @@
      }
      let result = [];
      if (type.refCode == "jsek_teachingResources") {
        this.findChildIds(list, result);
        if (this.data.activeId) {
          result = this.findChildIdsByCode(res.datas.cmsDatas[0].datas)
        } else {
          this.findChildIds(list, result);
        }
        this.setData({
          openTeachids: result,
          loading: false,
          teach: list,
        });
      } else if (type.refCode == "jsek_cloudLearning") {
        // 云学习上无销售方式,走目录 资源 销售方式去除方法
        if (!flags) list = this.clearTreeSealmethod(false, list)
        // 控制按钮显示
        list = this.handleSalmethodBtn(list, list, null)
        // 判断领取查看是否显示(云学习,或资源目录,有售价为0)
        let isshowDrawBtn = res.datas.cmsDatas[0].datas.some(
          (item) =>
@@ -1099,15 +1145,22 @@
          new Date(item.saleMethod.find((citem) => citem.SaleType == 'Normal').BeginDate).getTime() <= new Date().getTime()
        ) || (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)
        let isShowBuyCloundMenu = flags && cloundSaleMethod.Price > 0 && !this.data.buyIdList.includes(cloundSaleMethod.Id) && !this.data.bookDetail.IsTextbook
        // 判断资源购买按钮是否显示 (云学习无销售方式,资源和目录中有销售方式,且售价大于0)
        let isShowBuyCloundBtn = !flags && res.datas.cmsDatas[0].datas.some(item => item.saleMethod.length &&
          item.saleMethod.find((citem) => citem.SaleType == 'Normal').Price > 0 &&
          new Date(item.saleMethod.find((citem) => citem.SaleType == 'Normal').EndDate).getTime() >= new Date().getTime() &&
          new Date(item.saleMethod.find((citem) => citem.SaleType == 'Normal').BeginDate).getTime() <= new Date().getTime()) && !this.data.bookDetail.IsTextbook
        // 判断购物车按钮和锁按钮是否显示
        this.handleTreeData(list).forEach(item => {
          item.isbuy = this.resourceIsBuy(item);
          item.isShopCar = this.isShoppingCart(item);
        })
        this.findChildIds(list, result);
        if (this.data.activeId) {
          result = this.findChildIdsByCode(res.datas.cmsDatas[0].datas)
        } else {
          this.findChildIds(list, result);
        }
        this.setData({
          isshowDrawBtn,
          isShowBuyCloundMenu,
@@ -1119,7 +1172,6 @@
          learnPath: type.productLinkPath
        });
      }
      console.log('1', this.data.teach);
    })
  },
  //  获取 云测试
@@ -1200,7 +1252,7 @@
              });
            }
            if (data.length > 0) {
              console.log('data', data);
              console.log('data01', data);
              let list = []
              that.getTreeList(data, list, query.cmsPath)
              list = that.ensureTreeConsistency(list)
@@ -1268,6 +1320,17 @@
          break
        }
      }
  },
  // 获取目录扫码展开项
  findChildIdsByCode(list) {
    let arr = []
    const data = list.find(item => item.id == this.data.activeId)
    if (data) {
      const ids = data.productLinkInfo.find(item => item.CmsItemId == data.id).LinkPath.split('\\')
      arr = [data.id, ...ids].map(item => Number(item))
    }
    return arr
  },
  // 图书添加购物车
@@ -1674,28 +1737,55 @@
  },
  // 判断资源是否购买
  resourceIsBuy(data) {
    if (data.saleMethod && data.saleMethod.length) {
      const saleData = data.saleMethod.find((item) => item.SaleType == 'Normal')
      if (saleData.State == 'Disable') return false
      const isShow = this.data.buyIdList.some(
        (item) => item == saleData.Id
      );
      // 已经购买
      if (isShow || saleData.Price == 0) return false
      // 未购买,查看销售方式是否过期
      if (!isShow) {
        const flag = new Date(saleData.EndDate).getTime() >= new Date().getTime() &&
          new Date(saleData.BeginDate).getTime() <= new Date().getTime()
        if (flag) {
          // 为过期 ,需要购买
          return true
        } else {
          // 已过期 无需购买
          return false
    // if (data.saleMethod && data.saleMethod.length) {
    //   const saleData = data.saleMethod.find((item) => item.SaleType == 'Normal')
    //   if (saleData.State == 'Disable') return false
    //   const isShow = this.data.buyIdList.some(
    //     (item) => item == saleData.Id
    //   );
    //   // 已经购买
    //   if (isShow || saleData.Price == 0) return false
    //   // 未购买,查看销售方式是否过期
    //   if (!isShow) {
    //     const flag = new Date(saleData.EndDate).getTime() >= new Date().getTime() &&
    //       new Date(saleData.BeginDate).getTime() <= new Date().getTime()
    //     if (flag) {
    //       // 为过期 ,需要购买
    //       return true
    //     } else {
    //       // 已过期 无需购买
    //       return false
    //     }
    //   }
    // } else {
    //   return false;
    // }
    let linkData = data.productLinkPath.split("\\");
    linkData.reverse()
    let dataList = linkData.map(item => {
      let data = this.data.cacheData.find(citem => citem.id == item);
      if (data) return data;
    })
    let isBuy = 1;
    for (let i = 0; i < dataList.length; i++) {
      const dataItem = dataList[i];
      if (dataItem) {
        if (dataItem.saleMethod.length > 0) {
          isBuy = 2;
          if (this.data.bookDetail.purchasedSaleMethodIdList.indexOf(dataItem.saleMethod[0].Id) > -1 || dataItem.saleMethod[0].Price == 0) {
            isBuy = 3;
            break;
          } else {
            break;
          }
        }
      }
    }
    if (isBuy == 2) {
      // 未购买
      return false
    } else {
      return false;
      return true
    }
  },
  // 云学习资源是否显示锁图标(未购买,且资源售价大于零)
@@ -2099,12 +2189,6 @@
  },
  // 购买组卷
  buyMock() {
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      buyMockFun()
    } else {
      this.logInFun(() => {})
    }
    const buyMockFun = async () => {
      let res;
      if (!this.data.mockData.id)
@@ -2153,6 +2237,13 @@
        console.log(error);
      }
    }
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      buyMockFun()
    } else {
      this.logInFun(() => {})
    }
  },
  // 记录购买组卷时间
  recordBuyMock() {
@@ -2679,9 +2770,14 @@
  //去样书申请单
  goApply() {
    wx.navigateTo({
      url: "/packageDomain/pages/sampleBookList/applicationForm/index",
    });
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      wx.navigateTo({
        url: "/packageDomain/pages/sampleBookList/applicationForm/index",
      });
    } else {
      this.logInFun(() => {})
    }
  },
  handleTree() {
    // const child = this.selectComponent('#teach-tree')
@@ -3023,6 +3119,17 @@
      cloundMenuIsBuy: flag
    })
  },
  // 显示ISBN
  showISBN() {
    wx.showModal({
      title: '',
      content: this.data.bookDetail.isbn,
      showCancel: false,
      confirmText: '关闭',
      success: (res) => {}
    })
  },
  /**
   * 用户点击右上角分享
   */