CrowdfundPoster.js 3.34 KB
// packageOutput/pages/summary/components/CrowdfundPoster/CrowdfundPoster.js
import Draw from '~/utils/Draw'

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item: {
      // type: Object,
      type: null,
      observer(n) {
        console.log(n, '=================')
        this.getImageInfo(n)
      },
    }
  },

  /**
   * 组件的初始数据
   */
  data: {},

  /**
   * 组件的方法列表
   */
  methods: {
    getImageInfo(n) {
      let that = this
      wx.getImageInfo({
        src: `${n.posterUrl}?v=${Date.now()}`,
        success: function (res) {
          console.log(res)
          // w = res.width
          // h = res.height
          that.init(n, res.width, res.height)
        }
      })
    },
    async init(n, ImgWidth, ImgHeight) {
      let proportion = ImgWidth / 279
      let actualHeight = ImgHeight / proportion
      console.log(actualHeight)
      wx.$api.showLoading()

      const drawfun = new Draw(
          {
            width: 279,
            // height: 554
            height: actualHeight
          },
          this
        ),
        { userInfo } = wx.$storage.get(),
        merchantName = userInfo.merchantName.length > 12 ? `${userInfo.merchantName.substring(0, 12)}...` : userInfo.merchantName,
        res = await drawfun.begin({
          imageList: [
            // {
            //   x: 0,
            //   y: 0,
            //   width: 279,
            //   height: 66,
            //   url: 'https://img02.glsx.com.cn/weapp/resource/saas/business-assistant/output/poster-bg.png'
            // },
            {
              x: 0,
              y: 0,
              width: 279,
              height: actualHeight,
              url: n.posterUrl
            }
          ]
          // textList: [
          //   {
          //     x: 12,
          //     y: 14,
          //     fontSize: 14,
          //     color: '#2D2D33',
          //     text: merchantName,
          //     textBaseline: 'top'
          //   },
          //   {
          //     x: 12,
          //     y: 36,
          //     fontSize: 14,
          //     color: '#1B233D',
          //     text: n.activityName,
          //     textBaseline: 'top',
          //     fontWeight: 500
          //   },
          //   {
          //     x: 14 + drawfun.getTextWidth(n.activityName, 14) + 9,
          //     y: 37,
          //     fontSize: 10,
          //     color: '#4466F0',
          //     text: '众筹',
          //     textBaseline: 'top',
          //     border: {
          //       width: 1,
          //       color: '#4466F0',
          //       radius: 2,
          //       padding: [2, 5],
          //       opacity: 0.5
          //     }
          //   }
          // ]
        })
      console.log(res)
      wx.hideLoading()
      this.setData({
        poster: res.path,
        show: true
      })
    },
    download() {
      const filePath = this.data.poster,
        _this = this
      wx.saveImageToPhotosAlbum({
        filePath,
        success() {
          wx.$api.showToast('保存成功')
        },
        fail(err) {
          const auth = _this.selectComponent('#auth')
          auth.check()
        }
      })
    },
    hide() {
      this.setData({
        show: false,
        poster: ''
      })
    },
    noScroll() {},
    authFail(e) {
      this.setData({
        showAuth: true
      })
    }
  }
})