import Taro, { Component } from '@tarojs/taro';
import getDateFormat from '@utils/chatDate'
import dayjs from 'dayjs'

import './item.scss'
export default class Index extends Component {
  render() {
    const { data = {}, onClick } = this.props
    const timeVal = data.createDate && dayjs(data.createDate).valueOf()
    const time = timeVal && getDateFormat(timeVal, true,'yyyy/M/d')
    return (
      <View className='list__item' key={data.friendId} onClick={onClick.bind(this, data)}>
        <View className='list__item-info'>
          <View className="avatar-box">
            <Image className='avatar' mode="aspectFill" src={data.avatar}></Image>
            {data.unReadNum > 0 && <View className="num">{data.unReadNum}</View>}
          </View>
          <View className="list__item-con">
            <Text className='name'>{data.name}</Text>
            <View className='text'>{data.messageType === 'text' ? data.message : '[图片]'}</View>
          </View>
        </View>
        <View className='list__item-time'>{time}</View>
      </View>
    )
  }
}