import { Component } from 'react'
import { View, Text, Button, Image, scrollView, Input } from '@tarojs/components'
import Taro, { } from '@tarojs/taro'
import tool from '../../common/tool'
import * as api from '../../service/index'
import './index.less'

export default class Mine extends Component {

  state = {
    userInfo: {},

  }

  componentDidShow () {
    console.log('111');
    this.getUserInfo()
  }
  onShareAppMessage = (res) => {
    let path = `/pages/index/index?c=${Taro.getStorageSync('user_id')}&s=rightTap`
    if (process.env.TARO_ENV == 'tt') {
      path = `/pages/index/index?c=channel_name&s=douyinguazai`
    }
    let shareData = {
      title: tool.shareTitle,
      path: path,
      imageUrl: tool.shareImg
    }
    return shareData;
  }
  getUserInfo () {
    api.getUserInfo().then(res => {
      if (res.code == 200) {
        this.setState({
          userInfo: res.data
        })
      }
    })
  }

  getEarnPoints () {
    Taro.navigateTo({
      url: `/pages/earnPoints/index`
    })
  }
  wallet () {
    Taro.navigateTo({
      url: `/pages/wallet/index`
    })
  }
  toDetail (index) {
    switch (index) {
      case 0:
        Taro.navigateTo({
          url: `/pages/imageWorks/index`
        })
        break;
      case 1:
        Taro.navigateTo({
          url: `/pages/like/index`
        })
        break;
      case 2:
        Taro.navigateTo({
          url: `/pages/invite/index`
        })
        break;
      case 3:
        Taro.navigateTo({
          url: `/pages/shareCnt/index`
        })
        break;
      case 4:
        Taro.previewImage({
          current: this.state.userInfo.kf_img, // 当前显示图片的http链接  
          urls: [`${this.state.userInfo.kf_img}`] // 需要预览的图片http链接列表  
        })
        break;
    }
  }

  componentDidMount () { }

  render () {
    return (
      <View className='mine'>
        <View className='user-info'>
          <View className='user-bag'>
            <View className='user-top'>
              <Image className='user-img' src={this.state.userInfo.head_img}></Image>
              <View className='user-info-text'>
                <View className='info-top'>
                  <View className='user-name'>{this.state.userInfo.user_name}</View>
                </View>
                <View className='info-bottom' >
                  <View className='integral'>点券：{this.state.userInfo.total_coin}</View>
                  {/* <Image className='integral-img' src='http://video-img.fyshark.com/1680055380074%E7%A7%AF%E5%88%86%E6%98%8E%E7%BB%86.png'></Image> */}
                </View>
              </View>
            </View>
            <View className='get-integral'>
              <View className='inte-button' onClick={e => (this.getEarnPoints())}>获取点券</View>
            </View>
          </View>
        </View>

        <View className='work-list'>
          <View className='work-info' onClick={e => (this.toDetail(0))}>
            <Image className='work-img' src='http://video-img.fyshark.com/1680506115183icon-%E6%88%91%E7%9A%84%E4%BD%9C%E5%93%81.png'></Image>
            <View className='work-title'>绘画作品</View>
          </View>
          <View className='work-info' onClick={e => (this.toDetail(1))}>
            <Image className='work-img' src='http://video-img.fyshark.com/1680506124768icon-%E9%82%80%E8%AF%B7%E5%A5%BD%E5%8F%8B.png'></Image>
            <View className='work-title'>我的喜欢</View>
          </View>
          <View className='work-info' onClick={e => (this.wallet())}>
            <Image className='work-img' src='http://video-img.fyshark.com/1680055380074%E7%A7%AF%E5%88%86%E6%98%8E%E7%BB%86.png'></Image>
            <View className='work-title'>点券详情</View>
          </View>
          {/* {
            process.env.TARO_ENV != 'tt' &&
            <View className='work-info' onClick={e => (this.toDetail(2))}>
              <Image className='work-img' src='http://video-img.fyshark.com/1680506104131icon-%E6%88%91%E7%9A%84%E5%96%9C%E6%AC%A2.png'></Image>
              <View className='work-title'>邀请好友</View>
            </View>
          } */}
          <View className='work-info' onClick={e => (this.toDetail(3))}>
            <Image className='work-img' src='http://video-img.fyshark.com/1680505725946icon-%E5%88%86%E9%94%80%E8%AE%A1%E5%88%92.png'></Image>
            <View className='work-title'>分销计划</View>
          </View>
          {/* {
            process.env.TARO_ENV != 'tt' &&
            <View className='work-info work-info-only' onClick={e => (this.toDetail(4))}>
              <Image className='work-img' src='http://video-img.fyshark.com/1680505998515icon-%E5%8A%A0%E5%85%A5%E4%BA%A4%E5%8F%8B%E7%BE%A4.png'></Image>
              <View className='work-title'>加入交友群</View>
            </View>
          } */}
          <Button className='button work-info work-info-only' type='default' open-type='contact'>
            <Image className='work-img' src='http://video-img.fyshark.com/1680506053680icon-%E8%81%94%E7%B3%BB%E6%88%91%E4%BB%AC.png'></Image>
            <View className='work-title'>联系客服</View>
          </Button>
        </View>
      </View>
    )
  }
}
