import Taro, { Component } from '@tarojs/taro'
import { View, Image } from '@tarojs/components'
import './roomPriceImg.scss'

class Index extends Component {
  onShareAppMessage() {
    const {eId, id, name} = this.$router.params
    return {
      title: `来看看${name}的一房一价表`,
      path: `/pagesHouse/roomPrice?eId=${eId}&id=${id}&name=${name}`,
    }
  }
  onShareTimeline () {
    const {eId, id, name} = this.$router.params
    return {
      title: `来看看${name}的一房一价表`,
      path: `/pagesHouse/roomPrice?eId=${eId}&id=${id}&name=${name}`,
    }
  }
  
  constructor (props) {
    super(props)
    this.state = {
      curObj: {},
    }
  }

  config = {
    navigationBarTitleText: '项目公示图',
  }

  componentDidMount () {
    const { id } = this.$router.params
    Taro.api.house.apiestatelottery2batchinfo({
      lottery_id: id,
    }).then(res => {
      this.setState({
        curObj: res || {}
      })
    })
  }

  renderTop () {
    const { name } = this.$router.params
    const bg = require('@img/images/bg_house.jpg')
    return (
      <View className="scoped-bg-top">
        <View className="sbt-wrap" onClick={this.urlDtlLink.bind(this)}>
          <View className="t">{name}</View>
          <Image src={bg} className="bg"></Image>
        </View>
      </View>
    )
  }
  urlDtlLink () {
    const { eId } = this.$router.params
    Taro.navigateTo({url: '/pagesHouse/indexDtl?id=' + eId})
  }

  renderYH () {
    const { curObj } = this.state
    const lotteryObj = curObj || {}
    let houseImg = []
    if (lotteryObj.house_img) houseImg = lotteryObj.house_img.split(',')
    let lotteryImg = []
    if (lotteryObj.lottery_img) lotteryImg = lotteryObj.lottery_img.split(',')
    let infoImg = []
    if (lotteryObj.info_img) infoImg = lotteryObj.info_img.split(',')
    return (
      <View className="scoped-yh">
        <View className="sy-wrap">
          {
            lotteryObj.lottery_res && lotteryImg.length > 0
            &&
            <View>
              <View className="sy-p">{lotteryObj.lottery_res}</View>
              <View className="sy-op">
                <View className="l">摇号结果表</View>
                <View className="r">
                  {
                    lotteryImg.map((hImg, hi) => {
                      return (
                        <View className="o" key={hi} onClick={this.YHImageHandle.bind(this, hImg, lotteryImg)}>
                          <Image src={hImg + '_xs'} className="img" />
                          <View className="tips">
                            <View className="bg"></View>
                            <View className="t">查看大图</View>
                          </View>
                        </View>
                      )
                    })
                  }
                </View>
              </View>
            </View>
          }
          {
            lotteryObj.under_way && houseImg.length > 0
            &&
            <View>
              <View className="sy-p">{lotteryObj.under_way}</View>
              <View className="sy-op">
                <View className="l">一房一价表</View>
                <View className="r">
                  {
                    houseImg.map((hImg, hi) => {
                      return (
                        <View className="o" key={hi} onClick={this.YHImageHandle.bind(this, hImg, houseImg)}>
                          <Image src={hImg + '_xs'} className="img" />
                          <View className="tips">
                            <View className="bg"></View>
                            <View className="t">查看大图</View>
                          </View>
                        </View>
                      )
                    })
                  }
                </View>
              </View>
            </View>
          }
          {
            infoImg.length > 0
            &&
            <View>
              <View className="sy-op">
                <View className="l">项目公示表</View>
                <View className="r">
                  {
                    infoImg.map((hImg, hi) => {
                      return (
                        <View className="o" key={hi} onClick={this.YHImageHandle.bind(this, hImg, houseImg)}>
                          <Image src={hImg + '_xs'} className="img" />
                          <View className="tips">
                            <View className="bg"></View>
                            <View className="t">查看大图</View>
                          </View>
                        </View>
                      )
                    })
                  }
                </View>
              </View>
            </View>
          }
        </View>
      </View>
    )
  }
  YHImageHandle (current, urls) {
    Taro.previewImage({
      current,
      urls
    })
  }

  render () {
    return (
      <View className="l-box">
        {this.renderTop()}
        {this.renderYH()}
      </View>
    )
  }
}

export default Index
