outputCrowdfund.js 3.63 KB
// packageOutput/pages/summary/components/outputCrowdfund/outputCrowdfund.js
import wxqrcode from '~/utils/lib/wxqrcode'
import { IMG_URL } from '~/utils/constantData'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    orderObj: {
      type: Object,
      value: () => { },
      observer(n) {
        n && this.dealStaffList()
      }
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMGURL: IMG_URL,
    orderFormList: [{
      label: '总场次',
      name: 'totalNum'
    }, {
      label: '总订单',
      name: 'totalOrderCount'
    }, {
      label: '成交金额',
      name: 'totalAmount',
      prefix: '¥'
    }],
    merchantFormList: [{
      label: '活动时间',
      name: 'time'
    }, {
      label: '订单数',
      name: 'orderCount'
    }, {
      label: '产值',
      name: 'realAmount',
      className: 'red',
      prefix: '¥'
    }, {
      label: '预估产值',
      name: 'predictAmount',
      prefix: '¥'
    }],
    tableHeadList: [{
      label: '',
      width: '',
      width: '28rpx'
    }, {
      label: '业务员',
      name: 'shareName',
    }, {
      label: '转发',
      name: 'shareCount',
    }, {
      label: '浏览',
      name: 'browseCount'
    }, {
      label: '成交',
      name: 'dealCount',
      width: '92rpx'
    }, {
      label: '产值',
      name: 'totalAmount',
      prefix: '¥'
    }]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    dealStaffList() {
      var list = this.data.orderObj
      list && list.activityList?.forEach(item => {
        // 0-未开始;1-活动中;2-已结束
        let sliceNum = item.actStatus == 2 ? 3 : 10
        item.showStaffList = item.staffList.length > sliceNum ? item.staffList.slice(0, sliceNum) : item.staffList
        item.staffList = item.staffList.length > sliceNum ? item.staffList.slice(sliceNum) : []
      })
      this.setData({
        orderObj: list
      })
    },
    handleMore(e) {
      var { idx } = e.currentTarget.dataset
      var list = this.data.orderObj
      var item = list.activityList[idx]
      list.activityList[idx].showStaffList = list.activityList[idx].showStaffList.concat(item.staffList.length > 10 ? item.staffList.slice(0, 10) : item.staffList)
      list.activityList[idx].staffList = item.staffList.length > 10 ? item.staffList.slice(10) : []
      this.setData({
        orderObj: list
      })
    },
    handleCopy(e) {
      var { idx } = e.currentTarget.dataset
      var currentItem = this.data.orderObj.activityList[idx]
      var qr = wxqrcode.createQrCodeImg(currentItem.activityUrl)
      const base64src = function (base64data) {
        return new Promise((resolve, reject) => {
          const [a, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || []
          if (!format) reject(new Error('ERROR_BASE64SRC_PARSE'))
          const filePath = `${wx.env.USER_DATA_PATH}/tmp_base64src.${format}`
          const buffer = wx.base64ToArrayBuffer(bodyData)
          wx.getFileSystemManager().writeFile({
            filePath,
            data: buffer,
            encoding: 'binary',
            success() {
              resolve(filePath)
            },
            fail() {
              reject(new Error('ERROR_BASE64SRC_WRITE'))
            }
          })
        })
      }
      base64src(qr).then(res => {
        wx.getImageInfo({
          src: res,
          success(obj) {
            wx.showShareImageMenu({
              path: obj.path
            })
          },
          fail() {
          }
        })
      })
    },
    download(e){
      const {item} = e.currentTarget.dataset
      this.setData({
        posterItem: item
      })
    }
  }
})