import Taro, { Component } from '@tarojs/taro';
import './index.scss'

import ready from '@utils/ready'
import dayjs from 'dayjs'
import WxParse from '@components/wxParse/wxParse'
// import { savePoint, updatePoint } from '@services/common'
import {
  queryPolicyDetail,
} from '@services/policy'
import { connect } from '@tarojs/redux'

@connect(state => state.user)
export default class PolicyDetail extends Component {
  config = {
    navigationBarTitleText: '购房百科详情'
  }

  state = {
    policyId: null,
    detail: {},
    recordId: null,
    loaded: false,
  }

  componentWillMount() {
    ready.queue(() => {
      const router = Taro.getStorageSync('router')
      const policyId = this.$router.params.id || router.query.id

      this.setState({ policyId }, () => {
        this.loadDetail()
      })
    })
  }

  toHome() {
    Taro.switchTab({
      url: `/pages/project/index`
    })
  }
  onShareAppMessage = () => {
    const { detail: { title, policyId, policyImg } } = this.state
    const { userInfo: { person: { personId } } } = this.props

    return {
      title: title,
      path: `/pages/policy/detail/index?id=${policyId}&from=share&recommender=${personId}`,//分享地址
      imageUrl: policyImg
    }
  }

  loadDetail() {
    const { policyId } = this.state
    Taro.showLoading()
    queryPolicyDetail(policyId).then(res => {
      Taro.hideLoading()
      this.setState({
        detail: res,
        loaded: true,
      })
      WxParse.wxParse('article', 'html', res.body, this.$scope, 0)

    })
  }

  render() {
    const { detail, loaded } = this.state
    return (
      <Block>
        
        {
          loaded && (
            <View>
              <ScrollView
                scrollY
              // style={{
              //   height: '90vh'
              // }}
              >
                <View className="detail">
                  <View class="detail-title">{detail.title}</View>
                  <View className="detail-stat">
                    <View>{dayjs(detail.createDate).format('YYYY-MM-DD')}</View>
                    <View><Text className="iconfont icon-eye"></Text>{detail.pvNum || 0}</View>
                    {/* <View><Text className="iconfont icon-fenxiang1"></Text>{detail.shareNum || 0}</View> */}
                  </View>
                  <Image mode="widthFix" style={{ width: '100%', marginTop: '20px' }} src={detail.policyImg}></Image>
                  <View className="detail-con">
                    <import src='../../../components/wxParse/wxParse.wxml' />
                    <template is='wxParse' data='{{wxParseData:article.nodes}}' />
                  </View>
                </View>
                <View className='statement'>
                  免责条款：以上价格仅供参考，具体一房一价的信息以售楼处展示为准。本网显示房屋位置、交通、医疗、教育、商业等配套信息，来源于第三方网络数据，不作为要约，仅供参考，双方具体权利义务应以法律规定及买卖合同约定为准。<br></br>本平台对项目周边文化教育的介绍旨在提供相关信息，并不意味着信息发布方对就学安排作出承诺。相关教育资源就学信息存在调整的可能，应以政府教育主管部门及办学颁布的政策规定为准。
                </View>
              </ScrollView>
              <View className="home-entrance" onClick={this.toHome}>
                <Text className="iconfont icon-shouyeshouye"></Text>
                <Text className="text">首页</Text>
              </View>
            </View>
          )
        }
      </Block>
    );
  }
}