import Taro, { Component } from '@tarojs/taro'
import { View, Swiper, SwiperItem } from '@tarojs/components'
import { arrToObj } from '@utils'
import Rooms from './components/dtl/rooms'
import './dtl.scss'
class Index extends Component {
onShareAppMessage() {
const { curId, curObj } = this.state
return {
title: `${curObj.title}`,
path: `/pagesRoom/dtl?id=${curId}`,
}
}
onShareTimeline () {
const { curId, curObj } = this.state
return {
title: `${curObj.title}`,
path: `/pagesRoom/dtl?id=${curId}`,
}
}
constructor (props) {
super(props)
const {id: curId} = this.$router.params
this.state = {
curId,
curObj: {},
curImgIndex: 0
}
}
config = {
navigationBarTitleText: '房源详情',
}
componentWillMount () {
Taro.$AHU(this)
this.getDtl()
}
getDtl = () => {
const { curId } = this.state
Taro.api.room.apioldhousedetail({id: curId}).then(res => {
Taro.setNavigationBarTitle({
title: res.title || '房源详情'
})
this.setState({
curObj: res || {}
}, () =>{
if (this.subRooms) this.subRooms.getData(res.old_house_list || [])
})
})
}
componentDidShow () { }
componentDidHide () { }
renderHeader () {
const { curImgIndex, curObj } = this.state
let moreImg = []
let images = curObj.images ? curObj.images.split(',') : []
images.forEach(url => {
moreImg.push({img_url: `${url}`})
})
const imgArr = [{img_url: `${curObj.pri_image}`}, ...moreImg, {img_url: curObj.house_img}]
return (
{
imgArr.map((item, index) => {
return (
)
})
}
{curImgIndex + 1}/{imgArr.length}
)
}
headerImgChange (e) {
this.setState({
curImgIndex: e.detail.current || 0
})
}
previewImage2Handle (cur, arr) {
const current = `${cur}_plus`
const urls = arr.map(item => {
return `${item.img_url}_plus`
})
Taro.previewImage({
current,
urls
})
}
renderQrcode () {
const qrcodeImg = 'http://icon.honglounews.com/miniqrcode.jpg'
return (
)
}
previewQrcodeImageHandle (current, urls) {
Taro.previewImage({
current,
urls
})
}
renderMain () {
const dictData = Taro.getStorageSync('dictData')
const htObj = arrToObj(dictData.house_type)
const ptObj = arrToObj(dictData.product_type)
const atObj = arrToObj(dictData.area_type)
const hryObj = arrToObj(dictData.house_room_year)
const yesnoObj = arrToObj(dictData.sys_yesno)
const { curObj } = this.state
const tagArr = curObj.custom_tag ? curObj.custom_tag.split(',') : []
const moreImg = require('./img/dtl/bg_estate.png')
const FH = curObj.floor_height || 1
const H = curObj.height || 1
let FHstr = '未知'
if (FH === 1 || FH === H) FHstr = '天地楼'
if (FH > H * 0.6666) {
FHstr = '中高层'
} else if (FH > H * 0.33333) {
FHstr = '中楼层'
} else {
FHstr = '中低层'
}
return (
{this.renderQrcode()}
{
tagArr.map((tag, tI) => {
return (
{tag}
)
})
}
{curObj.title}
{curObj.price}万
总价
{htObj[curObj.house_type]}
户型
{curObj.area}㎡
建筑面积
单价:
{parseInt(curObj.price * 10000 / curObj.area)}元/㎡
挂牌时间:
{curObj.create_at ? curObj.create_at.substring(0, 10) : ''}
区域:
{atObj[curObj.area_type]}
房源类型:
{ptObj[curObj.product_type]}
满几年:
{hryObj[curObj.how_many_year]}
是否精装:
{yesnoObj[curObj.is_dec]}
楼层:
{FHstr}/{curObj.height}层
{
curObj.introduce
&&
房源简介:
{curObj.introduce}
}
楼盘名称:
{curObj.estate_name}
房源地址:
{curObj.address} 查看周边配套
最近成交:
点击查看最近成交价
)
}
dtlLink () {
const { curObj } = this.state
Taro.navigateTo({
url: `/pagesHouse/indexDtl?id=${curObj.estate_id}`
})
}
renderImg () {
const { curObj } = this.state
return (
户型图
查看大图
)
}
houseImgHandle () {
const { curObj } = this.state
const current = `${curObj.house_img}_plus`
const urls = [`${curObj.house_img}_plus`]
Taro.previewImage({
current,
urls
})
}
renderOther () {
const { curObj } = this.state
return (
同小区房源
查看更多{' >'}
)
}
refRooms = (ref) => {
this.subRooms = ref
}
netLink (saleObj) {
const { curObj } = this.state
Taro.navigateTo({
url: `/pagesQa/msg/chat?to_user_id=${saleObj.user_id}&qTitle=${curObj.title}`
})
}
callHandle (saleObj) {
Taro.makePhoneCall({
phoneNumber: saleObj.sale_phone
})
}
afterCount (type) {
const { curObj } = this.state
if (type === 'chat') {
this.netLink(curObj.sale_user)
}
if (type === 'call') {
this.callHandle(curObj.sale_user)
}
}
countHandle (type) {
const { curObj } = this.state
Taro.api.room.apiusercontactclick({
target_id: curObj.id,
sale_id: curObj.sale_id,
click_type: type === 'call' ? '2' : '1' // 1在线聊 2打电话
}).then(() => {
this.afterCount(type)
}).catch(() => {
this.afterCount(type)
})
}
renderSale () {
const { curObj } = this.state
const saleObj = curObj.sale_user || {}
const tagStr = saleObj.custom_tag ? saleObj.custom_tag.substring(0, 8) : ''
return (
{saleObj.sale_name}
{tagStr}
在线问
打电话
)
}
render () {
const { curObj } = this.state
return (
{this.renderHeader()}
{this.renderMain()}
{this.renderImg()}
{(curObj.old_house_list && curObj.old_house_list.length > 0) && this.renderOther()}
{this.renderSale()}
)
}
}
export default Index