import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import { arrToObj } from '@utils'
import './indexDtl.scss'

class Index extends Component {
  onShareAppMessage() {
    const { curObj } = this.state
    return {
      title: '洪楼Plus-南昌楼市测评-动态资讯-学区地铁',
      path: `/pagesMore/news/indexDtl?id=${curObj.id}`,  // 自定义的分享路径，点击分享的卡片之后会跳转这里定义的路由
      // imageUrl: '' // 图片路径
    }
  }
  onShareTimeline () {
    return {
      title: '让买房，更省心！',
    }
  }

  constructor (props) {
    super(props)
    
    this.state = {
      curObj: {},
    }
  }

  componentWillMount () {
    const {id} = this.$router.params
    Taro.api.news.adminformationdetail({
      id
    }).then(res => {
      let curObj = res || {}
      if (res.news_type === 'adminadd') {
        curObj.link = 'https://h5.honglounews.com/wxnews.html?id=' + curObj.id
      }
      this.setState({
        curObj
      })
    })
  }

  config = {
    navigationBarTitleText: '洪楼Plus',
  }

  handleMessage () {
    console.log('abc')
  }

  render () {
    const { curObj } = this.state
    return (
      <WebView src={curObj.link} onMessage={this.handleMessage} />
    )
  }
}

export default Index
