

export default class InviteFriends {
  palette(posterImg, qrcodeImg, userName, avatarUrl, options, explain) {
    //获取图片的长宽
    let posterImgWidth = 0, posterImgHeight = 280;
    let windowWidth = options.windowWidth;
    let windowHeight = options.windowHeight;
    if(options){
      posterImgWidth = options.posterImgWidth ? options.posterImgWidth : 0;
      posterImgHeight = options.posterImgHeight ? options.posterImgHeight : 0;
      if (posterImgHeight > windowHeight){
        posterImgHeight = windowHeight - 200;
      }
    }

    // explain = ['妍希送你很多豪礼的静安寺到就看', '很好三等奖啊可是很好三等奖啊可是','数据库大吉点击奥斯卡数据库大吉点击奥斯卡'];

    let textOneBottom = '', textTwoBottom = '' , textThreeBottom = '';
    if(explain.length == 1){
      textOneBottom = '80rpx';
      if (explain[0].length > 11){
        explain[0] = explain[0].substr(0,10) + '..';
      }
    }
    else if (explain.length == 2){
      textOneBottom = '100rpx';
      textTwoBottom = '70rpx';
      if (explain[0].length > 11) {
        explain[0] = explain[0].substr(0, 9) + '..';
      }

      if (explain[1].length > 15) {
        explain[1] = explain[1].substr(0, 14) + '..';
      }
    }
    else if (explain.length == 3){
      textOneBottom = '108rpx';
      textTwoBottom = '78rpx';
      textThreeBottom  = '50rpx';
      if (explain[0].length > 11) {
        explain[0] = explain[0].substr(0, 9) + '..';
      }

      if (explain[1].length > 15) {
        explain[1] = explain[1].substr(0, 14) + '..';
      }
      
      if (explain[2].length > 15) {
        explain[2] = explain[2].substr(0, 14) + '..';
      }
    }

    return ({
      width: '750rpx',
      height: windowHeight - 100 + 'px',
      background: '#fff',
      views: [
        {
          type: 'image',
          url: posterImg,
          css: {
            width: windowWidth + 'px',
            height: posterImgHeight + 'px'
          }
        },
        {
          type: 'image',
          url: qrcodeImg,
          css: {
            width: '140rpx',
            height: '140rpx',
            right: '28rpx',
            bottom: '33rpx',
          }
        },
        {
          type: 'image',
          url: avatarUrl,
          css: {
            width: '80rpx',
            height: '80rpx',
            left: '28rpx',
            bottom: '53rpx',
            borderRadius: '40rpx'
          }
        },
         {
          type: 'text',
          text: userName + explain[0],
          css: {
            width: '320rpx',
            left: '120rpx',
            bottom: textOneBottom,
            fontSize: '28rpx',
            color: '#000000'
          },
        },
        {
          type: 'text',
          text: explain[1],
          css: {
            width: '320rpx',
            left: '120rpx',
            bottom: textTwoBottom,
            fontSize: '18rpx',
            color: '#666666'
          },

        },
        {
          type: 'text',
          text: explain[2],
          css: {
            width: '320rpx',
            left: '120rpx',
            bottom: textThreeBottom,
            fontSize: '18rpx',
            color: '#666666'
          },

        },
      ],
    });
  }
}
