liukangdong
2024-07-24 0cd3a666af34e28eaf50ed1392b5d219a9d2b1cf
wechat_staff/pages/promotion/index.js
@@ -1,4 +1,5 @@
import { newsPage } from '../../api/index'
import moment from "moment";
Page({
  /**
@@ -6,7 +7,7 @@
   */
  data: {
    capacity: 10,
    page: 0,
    page: 1,
    list: [],
    total: 0,
  },
@@ -15,10 +16,22 @@
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getList()
  },
  getList() {
    newsPage()
    newsPage({capacity:this.data.capacity,
      page:this.data.page,
      model:{type:0}})
      .then(res =>{
        if(this.data.page == res.data.page){
          res.data.records.forEach(element => {
            element.createDate = moment(element.createDate).format("yyyy/MM/DD")
          })
          this.setData({list: [...this.data.list, ...res.data.records || []],
            total:res.data.total})
        }
        console.log(this.data)
    })
  },
  onReady() {
@@ -30,7 +43,126 @@
  onShow() {
  },
  onReachBottom() {
    console.log('触底事件');
    const { total, list, page } = this.data
    if(total > list.length){
      this.setData({ page: page + 1 })
      this.getList()
    }else{
      wx.showToast({
        title: '暂无更多数据',
        icon: 'none'
      })
    }
  },
  downfile(e){
    const item =  e.currentTarget.dataset.index;
    const files = []
    if(item.fileType ==1 && item.fileList && item.fileList.length && item.fileList[0].fileurlFull  ){
      files.push(item.fileList[0].fileurlFull)
    }
    if(item.fileType !=1 && item.fileList && item.fileList.length  ){
      item.fileList.forEach(ee => {
         if(ee.fileurlFull){
           files.push(ee.fileurlFull)
         }
      })
    }
    if(item.fileType ==1){
      this.downloadVideoFileDo(files,item.title)
    }else{
      this.downloadImageFileDo(files,item.title)
    }
  },
  downloadImageFileDo(files,title){
    wx.showLoading({
      title: '正在下载',
    })
   let temp = 0;
    if(files.length){
      for(let i = 0;i<files.length;i++){
        let filePath = wx.env.USER_DATA_PATH + '/' + new Date().valueOf()+i + '.jpg'  ;
        wx.downloadFile({
          url: files[i],
          filePath: filePath,
          timeout:180000,
          success: function (res) {
            var tempFp = res.filePath
            wx.saveImageToPhotosAlbum({
              filePath: tempFp,
              success(result) {
                temp ++;
                console.log(result)
                if(temp == files.length){
                    wx.hideLoading();
                    wx.setClipboardData({
                      data:  title,
                      success: function (res) {
                        wx.getClipboardData({
                          success: function (res) {
                            wx.showToast({
                              title: '文案已复制成功,去分享吧'
                            })
                          }
                        })
                      }
                  })
                }
              }, fail(err) {
                wx.showToast({
                  title: '图片下载失败哦'
                })
              }
            })
          } , fail(err) {
            wx.showToast({
              title: '图片下载失败哦'
            })
          }
        })
      }
    }
  },
  downloadVideoFileDo(files,title){
    wx.showLoading({
      title: '正在下载',
    })
    if(files.length){
      let filePath = wx.env.USER_DATA_PATH + '/' + new Date().valueOf() + '0.mp4';
      wx.downloadFile({
        url: files[0],
        filePath: filePath,
        timeout:180000,
        success: function (res) {
          var tempFp = res.filePath
          wx.saveVideoToPhotosAlbum({
            filePath: tempFp,
            success(result) {
              console.log(result)
                  wx.hideLoading();
                  wx.setClipboardData({
                    data:  title,
                    success: function (res) {
                      wx.getClipboardData({
                        success: function (res) {
                          wx.showToast({
                            title: '文案已复制成功,去分享吧'
                          })
                        }
                      })
                    }
                })
            }, fail(err) {
              wx.showToast({
                title: '视频下载失败哦'
              })
            }
          })
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
@@ -51,14 +183,7 @@
  onPullDownRefresh() {
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
  },
  /**
   * 用户点击右上角分享
   */