'use strict';

import React, { Component } from 'react';
import resList from '../../resconfig/resList';
import API from '../../api';
import './pagesharep.less';
import { SHARE_JOIN_URL } from '../../constant';
class Pagesharep extends Component {
  constructor(props) {
    super(props);
    let {success,message,data} = API.buriedPoint({pageBizId:507})

    this.state = this.state || { resList: resList };
  }
  //获取连接上参数
  // getUrlParam(name) {
  //   const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  //   const r = window.location.search.substr(1).match(reg);
  //   if (r != null) {
  //       return unescape(r[2]);
  //   }
  //   return null;
  // }
  getUrlParam(name) {
    const search = window.location.search;
    const matched = search
    .slice(1)
    .match(new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'));
    return search.length ? matched && matched[2] : null;
  }
  componentDidMount(){
    let data = {
      ...window.projectData.wxShareConfig,
      url:CFG.shareUrlHead+encodeURIComponent(CFG.shareUrl+"&avatar="+ this.getUrlParam("avatar")+"&nickname="+this.getUrlParam("nickname")+"&shareCode="+this.getUrlParam("shareCode"))
    }
    console.log(data);
    
    // window['invokeWX'](data)
    window['postMsgToMini'](data);
  }
  //

  render() {
    let nickName = decodeURIComponent(this.getUrlParam("nickname")) || "迈克";//获取连接上用户拼接的昵称
    let avatar = decodeURIComponent(this.getUrlParam("avatar")) || "http://yun.duiba.com.cn/spark/assets/e818694f1c7f121d1583a779569f7ab2919bafee.png";
    //获取连接上用户拼接的头像
    return (
      <section className="page-home">
        <div className="sharep">
          <img className="bg" src={this.state.resList['3557ca56-60fa-45c5-b3ec-152ce8479320'].url} />
          {/* <img className="sharetips" src={this.state.resList['a88eeca7-66ff-4824-9cac-0fac481b7412'].url} />
          <label className="sharemessage">你的好友{nickName},邀请你参与兑换好礼</label>
          <img className="headimg" src={resList['ed6e5aa4-5a70-4e30-aee9-d00091ed462e'].url} />
          <img className="headimg" src={avatar} /> */}
          <img className="joinbtn point6" onClick={() => { setTimeout(()=>{window.location.href = CFG.deepLink + "&shareCode=" + this.getUrlParam("shareCode")},500)  }} src={this.state.resList['75c91ede-a6c1-4815-b56a-0b63529219a3'].url} />
          {/* <img className="img" src={this.state.resList['0e6c663d-9c74-4573-97eb-af2c1862cdce'].url} /> */}
        </div>
      </section>
    ); 
  }
}
export default Pagesharep;
