yiming
2024-04-28 04acf6421dded7b6f6eef9d2cf41d0b4a0e8dd0d
pages/bibliographyList/index.js
@@ -1,4 +1,5 @@
// pages/bibliographyList/index.js
import Toast from 'tdesign-miniprogram/toast/index';
const app = getApp()
const config =
  Page({
@@ -7,6 +8,15 @@
     * 页面的初始数据
     */
    data: {
      hiddenmodalput: false,
      name: "",
      phoneNum: '',
      input: '',
      dialogKey: '',
      showWithInput: false,
      showTextAndTitleWithInput: false,
      downloadLoadin: false,
      isMore: null,
      higherList: [],
      vocationalList: [],
      teacherList: [],
@@ -16,13 +26,23 @@
      value: '',
      BarHeight: '',
      navBarHeight: '',
      start: 1,
      tabValue: '',
      keyword: '',
      Md5: '',
      emailError: false,
      loading: true, //开启骨架屏加载
      hidden: true, //是否展示内容
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      this.higherGet()
      this.vocationalGet()
      this.teacherGet()
@@ -35,7 +55,13 @@
        barHeight: systInfo.statusBarHeight,
      })
      let event = {
        detail: {
          value: "0"
        }
      }
      this.onTabsChange(event)
@@ -92,14 +118,34 @@
    },
    onTabsChange(event) {
      console.log(`Change tab, tab-panel value is ${event.detail.value}.`);
      const value = event.detail.value
      if (value === '0') {
        console.log(value);
        this.setData({
          tabValue: value,
          isMore: false
        })
      } else if (value === '1') {
        console.log(value);
        this.setData({
          tabValue: value,
          isMore: false
        })
      } else if (value === '2') {
        console.log(value);
        this.setData({
          tabValue: value,
          isMore: false
        })
      }
    },
    onTabsClick(event) {
      console.log(`Click tab, tab-panel value is ${event.detail.value}.`);
    },
    //高等教育
    higherGet(keyword) {
      console.log(keyword, 'keyword');
      let searchObj = {
        'Name*': keyword,
        '||author*': keyword,
@@ -112,7 +158,7 @@
        queryType: '*',
        paging: {
          start: '0',
          size: '999'
          size: this.data.start * 9
        },
        coverSize: {
          width: 260
@@ -138,7 +184,12 @@
          higherTotal: res.total
        })
        console.log(this.data.higherList, '5555');
        this.setData({
          loading: false, //开启骨架屏加载
          hidden: false, //是否展示内容
        })
      })
      wx.stopPullDownRefresh()
    },
@@ -156,7 +207,7 @@
        queryType: '*',
        paging: {
          start: '0',
          size: '999'
          size: this.data.start * 9
        },
        coverSize: {
          width: 260
@@ -181,6 +232,7 @@
        })
      })
      wx.stopPullDownRefresh()
    },
    // 职业教育
    teacherGet(keyword) {
@@ -195,7 +247,7 @@
        queryType: '*',
        paging: {
          start: '0',
          size: '999'
          size: this.data.start * 9
        },
        coverSize: {
          width: 260
@@ -207,6 +259,8 @@
          fileType: [],
          jsek_resource: [],
          freeFile: [],
          bookshelf_freeEpub: [], //epub试读百分比
          bookshelf_probationPage: [], //pdf试读页数
          ...searchObj
        },
        SysType: 'CmsItem'
@@ -218,41 +272,80 @@
          teacherList: res.datas,
          teacherTotal: res.total
        })
      })
      wx.stopPullDownRefresh()
    },
    // downloadData(event) {
    //   this.setData({
    //     downloadLoadin: true
    //   })
    //   console.log(111);
    //   const item = event.currentTarget.dataset.item;
    //   // console.log(item.datas.freeFile.Value);
    //   const URL = app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.datas.freeFile.Value
    //   item.determine = false
    //   console.log(URL, 'URL');
    //   setTimeout(() => {
    //     if (URL) {
    //       item.determine = true
    //     }
    //   }, 600)
    //   wx.downloadFile({
    //     url: URL,
    //     success: function (res) {
    //       const filePath = res.tempFilePath;
    //       wx.openDocument({
    //         filePath: filePath,
    //         success: function (res) {
    //           console.log('打开文档成功');
    //         },
    //         fail: function (res) {
    //           console.log('打开文档失败', res);
    //         }
    //       });
    //     },
    //     fail: function (res) {
    //       console.log('下载文件失败', res);
    //     }
    //   });
    //   setTimeout(() => {
    //     this.setData({
    //       downloadLoadin: false
    //     });
    //   }, 2000);
    // },
    downloadData(event) {
      console.log(111);
      const item = event.currentTarget.dataset.item;
      // console.log(item.datas.freeFile.Value);
      const URL = app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.datas.freeFile.Value
      item.determine = false
      console.log(URL, 'URL');
      setTimeout(() => {
        if (URL) {
          item.determine = true
        }
      }, 600)
      wx.downloadFile({
        url: URL,
        success: function (res) {
          const filePath = res.tempFilePath;
          wx.openDocument({
            filePath: filePath,
            success: function (res) {
              console.log('打开文档成功');
            },
            fail: function (res) {
              console.log('打开文档失败', res);
            }
          });
        },
        fail: function (res) {
          console.log('下载文件失败', res);
        }
      });
      const item = event.currentTarget.dataset.item
      console.log(item);
      if (item.fileType == "pdf") {
        wx.navigateTo({
          url: "/packageBookService/pages/components/webView/index?md5=" +
            item.freeFile +
            "&fileName=" +
            item.name +
            "&fileType=" +
            item.fileType + "&bookBuy=true"
          // "&freePage=" +
          // this.data.fileInfo.freePage +
          // +
          // "&bookId=" +
          // this.data.bookDetail.id,
        });
      } else {
        Toast({
          context: this,
          selector: '#t-toast',
          message: '此书不能查看',
          theme: 'warning',
          direction: 'column',
        });
        console.log(456);
      }
    },
    onSearchSubmit: function (e) {
      const keyword = e.detail.value;
@@ -267,5 +360,197 @@
    goBack() {
      wx.navigateBack();
    },
    onReachBottom(e) {
      if (this.data.tabValue == 0) {
        console.log(0);
        if (this.data.higherList.length < this.data.higherTotal) {
          this.setData({
            isMore: true,
            start: this.data.start + 1
          })
          this.higherGet()
        } else {
          this.setData({
            isMore: true,
          })
          setTimeout(() => {
            this.setData({
              isMore: false
            })
          }, 100)
        }
      } else if (this.data.tabValue == 1) {
        if (this.data.teacherList.length < this.data.teacherTotal) {
          this.setData({
            isMore: true,
            start: this.data.start + 1
          })
          this.teacherGet()
        } else {
          this.setData({
            isMore: true,
          })
          setTimeout(() => {
            this.setData({
              isMore: false
            })
          }, 100)
        }
        console.log(2);
      } else if (this.data.tabValue == 2) {
        if (this.data.vocationalList.length < this.data.vocationalTotal && this.data.vocationalList.length > 9) {
          this.setData({
            isMore: true,
            start: this.data.start + 1
          })
          this.vocationalGet()
        } else {
          this.setData({
            isMore: true,
          })
          setTimeout(() => {
            this.setData({
              isMore: false
            })
          }, 100)
        }
        console.log(2);
      }
    },
    onPullDownRefresh() {
      let keyword = this.data.value
      this.setData({
        start: 1,
      })
      this.higherGet(keyword)
      this.vocationalGet(keyword)
      this.teacherGet(keyword)
    },
    // 邮箱点击
    mailbox(e) {
      const key = e.currentTarget.dataset.key;
      const item = e.currentTarget.dataset.item;
      this.setData({
        // [key]: true,
        // dialogKey: key,
        hiddenmodalput: true,
        input: '',
        Md5: item.datas.freeFile.FileList[0].Md5
      });
    },
    onEmailInput(e) {
      const isEmailValid = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(e.detail.value);
      this.setData({
        emailError: !isEmailValid,
        "input": e.detail.value,
      });
    },
    //弹窗确认
    onConfirm() {
      if (!this.data.emailError && this.data.input) {
        const {
          dialogKey
        } = this.data;
        this.setData({
          [dialogKey]: false
        });
        console.log(this.data.input);
        console.log(this.data.Md5);
        if (this.data.input) {
          let query = {
            eMail: this.data.input,
            md5s: [this.data.Md5]
          }
          app.MG.file.sendFileWithEmail(query).then(res => {
            console.log(res);
          })
        }
      } else {
        // 校验不通过,给出错误提示
        wx.showToast({
          title: '邮箱格式不正确',
          icon: 'none',
        });
      }
    },
    // 弹窗取消
    closeDialog() {
      const {
        dialogKey
      } = this.data;
      this.setData({
        [dialogKey]: false
      });
      console.log(111);
    },
    //取消弹框
    cancelM: function (e) {
      this.setData({
        hiddenmodalput: false,
      })
    },
    //提交
    confirmM: function (e) {
      console.log("姓名:" + this.data.name + "  电话:" + this.data.phoneNum);
      if (!this.data.emailError && this.data.name) {
        if (this.data.name) {
          let query = {
            eMail: this.data.name,
            md5s: [this.data.Md5]
          }
          app.MG.file.sendFileWithEmail(query).then(res => {
            console.log(res);
            this.setData({
              hiddenmodalput: false,
            })
          })
        }
      } else {
        // 校验不通过,给出错误提示
        wx.showToast({
          title: '邮箱格式不正确',
          icon: 'none',
        });
      }
    },
    iName: function (e) {
      this.setData({
        name: e.detail.value
      })
      // console.log(this.data.name);
    },
    iPhoneNum: function (e) {
      this.setData({
        phoneNum: e.detail.value
      })
    },
  })