import Taro, { Component } from '@tarojs/taro';
import './index.scss'
import { DECREASE_UNREADNUM } from '@constants/user'
import { getStore, connect } from '@tarojs/redux'

@connect(state => state.user)
export default class Index extends Component {
  static options = {
    addGlobalClass: true
  }

  handleClick() {
    const { dispatch } = getStore()
    dispatch({ type: DECREASE_UNREADNUM })
    Taro.navigateTo({
      url: '/pages/im/list/index'
    })
  }

  render() {
    const { unReadNum, userInfo: { person: { avatarurl } } } = this.props
    return (
      <Block>
        {unReadNum > 0 && (
          <View className="notice" onClick={this.handleClick}>
            <View>
              {avatarurl && <Image className='notice__img' src={avatarurl} mode="aspectFill"></Image>}
              <Text className="notice__text">您有<Text className="num">{unReadNum}</Text>条未读消息哦~</Text>
            </View>
            <Text className="iconfont icon-jiantou-copy"></Text>
          </View>
        )}
      </Block>
    );
  }
}