outputCrowdfund.js 4.72 KB
// packageOutput/pages/summary/components/outputCrowdfund/outputCrowdfund.js
import wxqrcode from '~/utils/lib/wxqrcode'
import { IMG_URL } from '~/utils/constantData'
import outputApi from '~/api/outputApi/index'
const IMAGES = Object.freeze({
  download: `${IMG_URL}/output/download.webp`
})
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    orderObj: {
      type: Object,
      value: () => {},
      observer(n) {
        n && this.dealStaffList()
      }
    }
  },

  options: {
    styleIsolation: 'shared'
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMGURL: IMG_URL,
    IMAGES,
    isShowTip: true,
    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() {}
        })
      })
    },
    handleJumpH5(e) {
      // const { item } = e.currentTarget.dataset
      // wx.$router.jumpH5(item.activityUrl)
    },
    async download(e) {
      const { item } = e.currentTarget.dataset,
        posterObj = this.selectComponent('#poster')
      try {
        let flag = await posterObj.check(item)
        posterObj.setData({
          poster: flag,
          show: true
        })
      } catch (error) {
        wx.$api.showLoading('加载中...')
        outputApi
          .getPosterUrl({
            id: item.activityId
          })
          .then(res => {
            item.posterUrl = res
            this.setData({
              posterItem: item,
              isShowTip: false
            })
          })
          .catch(() => {
            wx.$api.showToast('下载海报失败')
          })
      }
    }
  }
})