sharePopup.js 4.64 KB
// components/sharePopup/sharePopup.js
import {imgUrlMixin} from '~/mixins/index'
import index_const from "~/pages/tab/index/index_const"
import { IMG_URL } from '~/utils/constantData'
import Draw from '~/utils/Draw'
Component({
  /**
   * 组件的属性列表
   */
  behaviors: [imgUrlMixin],
  properties: {
    data: {
      type: Object,
      observer(val) {
        let thisPage = wx.$router.getPageInstance()
        this.setData({
          navHeight: thisPage.data.navHeight
				})
        if (val.showSharePopup) {
					wx.$util.getViewInfo('.user-box', res => {
						this.setData({
							boxImageHeight: res.height,
						})
						val.boxImageHeight = res.height
							// 计算弹窗图片区域最大高度
						wx.$util.getViewInfo('.layout', res => {
							this.setData({
								postersBoxHeight: res.height * 0.7,
								postersImageHeight: res.height * 0.7 - this.data.boxImageHeight - 20
							})
							val.postersBoxHeight = res.height * 0.7,
							val.postersImageHeight = res.height * 0.7 - this.data.boxImageHeight - 20
							this.init(val)
							// this.init(val)
						})
					}, this)
				
					
				}
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    USERINFO: wx.$storage.get('userInfo'),
    activityTypList: index_const.data.activityTypList
  },

  /**
   * 组件的方法列表
   */
  methods: {
    async init(n) {
			wx.$api.showLoading()
      const drawfun = new Draw({
        width: 280,
        height: 560 + n.boxImageHeight
      }, this),
      {
        userInfo
      } = wx.$storage.get(),
      res = await drawfun.begin({
        imageList: [{
            x: 0,
            y: 0,
            width: 279,
            height: n.boxImageHeight,
            url: `${this.data.IMGURL}taskDetail_bg.png`
          },
          // {
          //   x: 12,
          //   y: 12,
          //   width: 20,
          //   height: 20,
          //   url: `${userInfo.weChatAvatarUrl ? userInfo.weChatAvatarUrl : this.data.IMGURL}order_person_default.png`
          // },
          {
            x: 16,
            y: n.boxImageHeight + 10,
            width: 247,
            height: 500,
            url: n.posterImg
          },
          // {
          //   x: 204,
          //   y: n.postersImageHeight / 2 + boxImageHeight + 20,
          //   width: 60,
          //   height: 60,
          //   url: n.imagePath
          // }
        ],
        textList: [{
            x: 44,
            y: 14,
            fontSize: 14,
            color: '#2D2D33',
            text: userInfo.name,
            textBaseline: 'top'
          },
          {
            x: 44 + drawfun.getTextWidth(userInfo.name, 14),
            y: 15,
            fontSize: 12,
            color: '#6E6E7A',
            text: '邀请你参加',
            textBaseline: 'top'
          },
          {
            x: 44,
            y: 36,
            fontSize: 14,
            color: '#1B233D',
            text: n.activityName,
            textBaseline: 'top',
            fontWeight: 500
          },
          {
            x: 44 + drawfun.getTextWidth(n.activityName, 14) + 9,
            y: 39,
            fontSize: 10,
            color: '#4466F0',
            text: '众筹',
            border: {
              width: 1,
              color: '#8FA5FF',
              radius: 2,
              padding: [5, 5]
            }
          },
          // {
          //   x: 16,
          //   y: (n.postersImageHeight / 2) + boxImageHeight + 30,
          //   fontSize: 13,
          //   color: '#1B233D',
          //   text: userInfo.merchantName
          // },
          // {
          //   x: 16,
          //   y: n.postersImageHeight / 2 + boxImageHeight + 50,
          //   fontSize: 11,
          //   color: '#6E6E7A',
          //   text: n.address,
          //   lineNum: 3,
          //   width: 193
          // }
        ],
			})
      wx.hideLoading()
      this.setData({
        poster: res.path
      })
    },
    close() {
      let thisPage = wx.$router.getPageInstance()
      thisPage.setData({
        sharePopupData: {
          showSharePopup: false
        }
      })
    },
    saveImage(e) {
      const filePath = this.data.poster,
			_this = this
      wx.saveImageToPhotosAlbum({
          filePath,
          success(){
            wx.$api.showToast('保存成功')
          },
          fail(err) {
            if(err.errMsg=='saveImageToPhotosAlbum:fail auth deny'){
              _this.triggerEvent('showAuth',true)
            }
            // const auth = _this.selectComponent('#auth')
            // auth.check()
          }
        }
      )
    },
    noScroll() {},
    authFail(e) {
      this.setData({
        showAuth: true
      })
    }
  }
})