
import { useEffect, useState } from 'react'
import Taro from '@tarojs/taro'
import withLayout from '@/layout'
import { ScrollView, Image } from '@tarojs/components'
import { getBuildingRule } from '@/services/item'
import '@/assets/css/iconfont.css'
import './index.scss'

const defaultRuleImage = 'https://yz-websit.oss-cn-hangzhou.aliyuncs.com/xlk/index-icon18.jpg'

export default withLayout((props) => {
  const { router } = props
  const { buildingId } = router.params

  const [rule, setRule] = useState({})
  
  useEffect(() => {
    if (buildingId) {
      Taro.showLoading({
        title: '请稍候...',
      })
      getBuildingRule(buildingId).then((res) => {
        setRule(res)
        Taro.hideLoading()
      }).catch((err) => {
        console.error(err)
        Taro.hideLoading()
        Taro.showToast({
          title: '获取规则失败',
          icon: 'none',
        })
      })
    }
  }, [buildingId])

  return (
    <view className='Page buildingRules'>
      <ScrollView scroll-y>
        <view className='Content'>
          <Image mode='widthFix' src={defaultRuleImage}></Image>

          <view className='Title'>
            <view>
              <text className='iconfont icon-shoucang'></text>
              <text>报备规则</text>
              <text className='iconfont icon-shoucang'></text>
            </view>
          </view>

          <view className='Text'>
            {rule?.remark}
          </view>
        </view>
      </ScrollView>
    </view>
  )
})
