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

class Index extends Component {
  onShareAppMessage() {
    const { curId, curObj } = this.state
    return {
      title: `来看看南昌的热门学区有哪些`,
      path: `/pagesSchool/class`,
    }
  }
  onShareTimeline () {
    return {
      title: '让买房，更省心！',
    }
  }

  constructor (props) {
    super(props)
    const {id: curId} = this.$router.params
    this.state = {
      curId,
      curObj: {},
    }
  }

  config = {
    navigationBarTitleText: '热门学区',
  }

  componentWillMount () {}
  

  renderOp () {
    const bg1 = require('./img/class/rmxq01.png')
    const bg2 = require('./img/class/rmxq02.png')
    const bg3 = require('./img/class/rmxq03.png')
    const bg4 = require('./img/class/rmxq04.png')
    const bg5 = require('./img/class/rmxq05.png')
    const bg6 = require('./img/class/rmxq06.png')
    const dictData = Taro.getStorageSync('dictData')
    const cateArr = dictData.school_cate || []
    const curItems = cateArr.map((item, index) => {
      let cObj = {...item}
      if (index === 0) cObj.bg = bg1
      if (index === 1) cObj.bg = bg2
      if (index === 2) cObj.bg = bg3
      if (index === 3) cObj.bg = bg4
      if (index === 4) cObj.bg = bg5
      if (index === 5) cObj.bg = bg6
      return (
        <View className="sb-item" key={index} onClick={this.listLink.bind(this, cObj)}>
          <Image src={cObj.bg} className="bg" />
        </View>
      )
    })
    return (
      <View className="scoped-box">
        {curItems}
      </View>
    )    
  }
  listLink (item) {
    Taro.navigateTo({
      url: `/pagesSchool/theme?type=${item.val}&name=${item.key}`
    })
  }

  componentDidShow () { }

  componentDidHide () { }


  render () {
    const xqbanner = require('@img/xqbanner.jpg')
    return (
      <View className="l-box">
        <Navigator url={'/pagesMore/news/list?type=xqsc'} className="scoped-top">
          <Image src={xqbanner} className="bg" />
        </Navigator>
        {this.renderOp()}
      </View>
    )
  }
}

export default Index
