import Taro, { Component } from '@tarojs/taro'
import { View, Image } from '@tarojs/components'
import './index.scss'
export default class TopPie extends Component {
  constructor (props) {
    super(props)
    this.state = {
      newsList: [],
    }
  }


  componentWillMount () {
    // this.getNewNews()
    this.props.onRef(this)
  }

  getData = (list) => {
    this.setState({
      newsList: list
    })
  }

  getNewNews () {
    Taro.api.news.adminformationlist({
      hide_status: 1
    }).then(res => {
      this.setState({
        newsList: res.list || []
      })
    })
  }

  linkMore () {
    Taro.redirectTo({
      url: '/pagesMore/news/index'
    })
  }

  render () {
    const { newsList } = this.state
    const newsArr = [newsList[0], newsList[1], newsList[2]]
    const newsbg = require('./img/news_bg.png')
    const iconN = require('./img/i_news.png')
    const exImg = require('@img/images/ex_banner.jpg')
    const curItems = newsArr.map((item, index) => {
      return (
        <Navigator url={'/pagesMore/news/indexDtl?id=' + item.id} className="snb-li" key={index}>
          <View className="snbl-img">
            <Image className="img" src={item.pri_image || exImg} />
          </View>
          <View className="snbl-right">
            <View className="text">
              <Image className="img" src={iconN} />
              {item.title}</View>
            <View className="time">{item && item.create_at ? item.create_at.substring(0, 10) : '洪楼news'}     {item.author || '洪楼'}</View>
          </View>
        </Navigator>
      )
    })
    return (
      <View className="scoped-news-box">
        <Image src={newsbg} className="snb-bg" onClick={this.linkMore.bind(this)} />
        <View className="snb-wrap">
          <View className="snb-ul">
            {curItems}
          </View>
        </View>
      </View>
    )
  }
}