bug
litian
2024-09-10 99dfeb5fc86bce593a5d3f43f45c26eedc00ab0a
packageBookService/pages/bookServices/detail/index.js
@@ -1,6 +1,7 @@
// pages/bookServices/detail/index.js
import Toast from "tdesign-miniprogram/toast";
import tool from "../../../../assets/js/toolClass";
import moment from 'moment'
import {
  loginInfo
} from "../../../../assets/js/login";
@@ -11,6 +12,9 @@
   * 页面的初始数据
   */
  data: {
    // 进页面默认切换  展开的id
    // defaultactiveTeachid  教学资源
    // defaultactiveLearnid  云学习
    bookId: "",
    barHeight: "",
    navBarHeight: "",
@@ -165,6 +169,37 @@
      description: '',
      agree: false
    },
    resourceVisible: false,
    resourceValue: [],
    fileTypeList: [{
        label: '音频',
        value: '音频'
      },
      {
        label: '视频',
        value: '视频'
      },
      {
        label: '图片',
        value: '图片'
      },
      {
        label: 'PDF',
        value: 'PDF'
      },
      {
        label: '资源包',
        value: '资源包'
      },
      {
        label: '文档',
        value: '文档'
      },
      {
        label: '其他',
        value: '其他'
      }
    ],
    fileList: [],
    isShowUp: true,
    protocolShow: false,
@@ -189,20 +224,24 @@
      bookId: options.id + "",
      barHeight: systInfo.statusBarHeight,
      navBarHeight: navBarHeight,
    });
    this.setData({
      options: {
        id: options.id,
        name: options.name,
        name: decodeURI(options.name),
        storeInfo: options.storeInfo,
      },
    });
    wx.setNavigationBarTitle({
      title: options.name,
      title: decodeURI(options.name),
    })
    let token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        if (data) {} else {}
      })
    }
    this.getBookInfo(options.id);
    // this.getResourceClass(); // 获取资源所属分类
    const token = wx.getStorageSync(app.config.tokenKey);
    token = wx.getStorageSync(app.config.tokenKey)
    if (token) {
      this.getShoppingCartProductGet();
      this.getApplyInfo(options.id);
@@ -216,6 +255,13 @@
      // 获取申请次数
      this.getSelectPaperBookCount();
      this.getSelectBookCount();
    }
    if (options.tabValue) {
      this.setData({
        tabValue: options.tabValue,
      });
    }
  },
@@ -435,6 +481,16 @@
          await this.getBookClass(classData);
        }
      }
      if (this.data.tabValue == 'questionBank' || this.data.tabValue == 'jsek_cloudLearning' || this.data.tabValue == 'jsek_teachingResources') {
        const checkData = this.data.cmsDatas.find(
          (item) => item.refCode == this.data.tabValue
        );
        if (this.data.tabValue == "questionBank") {
          this.getResourceData(checkData)
        } else {
          this.getResourceDataList(checkData)
        }
      }
      // 获取组卷销售id
      if (res.datas.saleMethod && res.datas.saleMethod.length) {
@@ -462,9 +518,7 @@
        }
      }
      this.setData({
        "bookDetail.publicationDate": this.formatDate(
          this.data.bookDetail.publicationDate
        ),
        "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(
@@ -700,7 +754,7 @@
      link
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/packageBookService/pages/bookServices/webpage/index?url=${link}`,
      url: `/packageBookService/pages/bookServices/linkPage/index?path=${link}`,
    });
  },
  // tag切换
@@ -716,7 +770,7 @@
      e.detail.label == "云测试"
    ) {
      const checkData = this.data.cmsDatas.find(
        (item) => item.refCode == e.detail.value
        (item) => item.refCode == this.data.tabValue
      );
      if (!this.data.resourceClassList.length) this.getResourceClass()
      if (checkData) {
@@ -819,7 +873,7 @@
  },
  // 扁平化数据转换tree
  getTreeList(rootList, pathLength, newArr, path, addNum) {
  getTreeList(rootList, pathLength, newArr, path) {
    for (const item of rootList) {
      // 此处原本 item.productLinkPath.length == pathLength 但 productLinkPath 长度个别书存在4、5位交错
      if ((pathLength - item.productLinkPath.length >= 0 && pathLength - item.productLinkPath.length <= 3) && item.productLinkPath.includes(path)) {
@@ -837,7 +891,7 @@
        }
        // newArr.push(item)
        // 在插入过程中对数据进行排序
        newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item, addNum)
        newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item)
        // 插进数组后 从原数据中删除
        rootList = rootList.filter(nitem => nitem.id != item.id)
      }
@@ -847,7 +901,7 @@
    for (const i of newArr) {
      i.children = []
      let addnum1 = i.productLinkPath.length - path.length == 6 ? 6 : 7
      this.getTreeList(rootList, pathLength + addnum1, i.children, i.productLinkPath, addnum1)
      this.getTreeList(rootList, pathLength + addnum1, i.children, i.productLinkPath)
      if (i.children.length == 0) {
        delete i.children
      }
@@ -872,9 +926,9 @@
  },
  // 排序数组 按照productLinkPath
  insertAndSortObjectsByProductLinkPath(array, newObj, addNum) {
  insertAndSortObjectsByProductLinkPath(array, newObj) {
    // 查找新对象应该插入的位置  
    let insertIndex = array.findIndex(obj => Number(newObj.productLinkPath.substring(newObj.productLinkPath.length - addNum, newObj.productLinkPath.length)) < Number(obj.productLinkPath.substring(obj.productLinkPath.length - addNum, obj.productLinkPath.length)));
    let insertIndex = array.findIndex(obj => Number(newObj.productLinkPath.substring(newObj.productLinkPath.lastIndexOf('\\') + 1, newObj.productLinkPath.length)) < Number(obj.productLinkPath.substring(obj.productLinkPath.lastIndexOf('\\') + 1, obj.productLinkPath.length)));
    // 如果没有找到合适的位置,则放在数组末尾  
    if (insertIndex === -1) {
      insertIndex = array.length;
@@ -884,10 +938,10 @@
    // 测试6 正式5
    // 对数组进行排序  
    array.sort((a, b) => {
      if (Number(a.productLinkPath.substring(a.productLinkPath.length - addNum, a.productLinkPath.length)) < Number(b.productLinkPath.substring(b.productLinkPath.length - addNum, b.productLinkPath.length))) {
      if (Number(a.productLinkPath.substring(a.productLinkPath.lastIndexOf('\\') + 1, a.productLinkPath.length)) < Number(b.productLinkPath.substring(b.productLinkPath.lastIndexOf('\\') + 1, b.productLinkPath.length))) {
        return -1;
      }
      if (Number(a.productLinkPath.substring(a.productLinkPath.length - addNum, a.productLinkPath.length)) > Number(b.productLinkPath.substring(b.productLinkPath.length - addNum, b.productLinkPath.length))) {
      if (Number(a.productLinkPath.substring(a.productLinkPath.lastIndexOf('\\') + 1, a.productLinkPath.length)) > Number(b.productLinkPath.substring(b.productLinkPath.lastIndexOf('\\') + 1, b.productLinkPath.length))) {
        return 1;
      }
      // a must be equal to b  
@@ -987,7 +1041,7 @@
        }
        const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 13 ? 8 : 6
        const num = query.cmsPath.length + addNum
        this.getTreeList(res.datas.cmsDatas[0].datas, num, list, '\\', addNum)
        this.getTreeList(res.datas.cmsDatas[0].datas, num, list, '\\')
        list = this.ensureTreeConsistency(list)
        list = this.changeResourceChildren(list)
        let result = [];
@@ -995,7 +1049,7 @@
          this.findChildIds(list, result);
          // const newUSeList = this.deleteTreeData(list, result)
          // console.log('树剔除', result, newUSeList);
          // console.log('树加一', this.increaseTreeData(list, newUSeList, 16094));
          this.setData({
            openTeachids: result,
            loading: false,
@@ -1101,7 +1155,7 @@
              const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 13 ? 8 : 6
              const num = query.cmsPath.length + addNum
              that.getTreeList(data, num, list, '\\', addNum)
              that.getTreeList(data, num, list, '\\')
              list = that.ensureTreeConsistency(list)
              that.findChildIds(list[0].children, result);
              that.setData({
@@ -2567,7 +2621,6 @@
    return childrenList
  },
  uploadFile(e) {
    console.log(123)
    this.setData({
      dialogBox: true,
      isShowUp: true
@@ -2576,6 +2629,12 @@
  closeDialog() {
    this.setData({
      dialogBox: false,
      resourceInfo: {
        resourceName: '',
        fileType: '',
        description: '',
        agree: false
      },
    });
  },
  onCloseProtocol() {
@@ -2619,9 +2678,24 @@
      'resourceInfo.resourceName': e.detail.value,
    });
  },
  onFileTypeInput(e) {
  onResourcePicker(e) {
    this.setData({
      'resourceInfo.fileType': e.detail.value,
      resourceVisible: true,
    });
  },
  onPickerChange(e) {
    const {
      value
    } = e.detail;
    this.setData({
      resourceVisible: false,
      resourceValue: value,
      'resourceInfo.fileType': value.join(' '),
    });
  },
  onPickerCancel(e) {
    this.setData({
      resourceVisible: false,
    });
  },
  textareaChange(e) {
@@ -2662,6 +2736,7 @@
        const pdfData = ['pdf']
        const Compression = ['rar', 'zip']
        const pictureData = ['jpg', 'png']
        const documentData = ['doc', 'docx', 'xls', 'xlsx', "ppt", "pptx"]
        if (audioData.indexOf(Extension) > -1) {
          medioType = '音频'
        } else if (videoData.indexOf(Extension) > -1) {
@@ -2672,6 +2747,8 @@
          medioType = '资源包'
        } else if (pictureData.indexOf(Extension) > -1) {
          medioType = '图片'
        } else if (documentData.indexOf(Extension) > -1) {
          medioType = '文档'
        } else {
          medioType = '其他'
        }
@@ -2715,6 +2792,7 @@
                    that.setData({
                      "resourceInfo.resourceName": FileName,
                      "resourceInfo.fileType": medioType,
                      fileList: file,
                      isShowUp: false
                    })
@@ -2729,15 +2807,9 @@
  },
  handleRemove(e) {
    console.log(e)
    let md5 = e.currentTarget.dataset.md5
    for (let i = 0; i < this.data.fileList.length; i++) {
      if (this.data.fileList.md5 == md5) {
        this.data.fileList.splice(i, 1)
      }
    }
    this.setData({
      isShowUp: true,
      fileList: []
    });
  },
  confirmM() {
@@ -2750,7 +2822,7 @@
    if (this.data.resourceInfo.fileType == '') {
      return wx.showToast({
        icon: "error",
        title: "请填写资源类型",
        title: "请选择资源类型",
      });
    }
@@ -2780,9 +2852,7 @@
        icon: "success",
        title: "请上传资源文件",
      });
      this.setData({
        dialogBox: false,
      });
      this.closeDialog()
    })
  }
})