dtl.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. import Taro, { Component } from '@tarojs/taro'
  2. import { View, Swiper, SwiperItem } from '@tarojs/components'
  3. import { arrToObj } from '@utils'
  4. import Rooms from './components/dtl/rooms'
  5. import './dtl.scss'
  6. class Index extends Component {
  7. onShareAppMessage() {
  8. const { curId, curObj } = this.state
  9. return {
  10. title: `${curObj.title}`,
  11. path: `/pagesRoom/dtl?id=${curId}`,
  12. }
  13. }
  14. onShareTimeline () {
  15. const { curId, curObj } = this.state
  16. return {
  17. title: `${curObj.title}`,
  18. path: `/pagesRoom/dtl?id=${curId}`,
  19. }
  20. }
  21. constructor (props) {
  22. super(props)
  23. const {id: curId} = this.$router.params
  24. this.state = {
  25. curId,
  26. curObj: {},
  27. curImgIndex: 0
  28. }
  29. }
  30. config = {
  31. navigationBarTitleText: '房源详情',
  32. }
  33. componentWillMount () {
  34. Taro.$AHU(this)
  35. this.getDtl()
  36. }
  37. getDtl = () => {
  38. const { curId } = this.state
  39. Taro.api.room.apioldhousedetail({id: curId}).then(res => {
  40. Taro.setNavigationBarTitle({
  41. title: res.title || '房源详情'
  42. })
  43. this.setState({
  44. curObj: res || {}
  45. }, () =>{
  46. if (this.subRooms) this.subRooms.getData(res.old_house_list || [])
  47. })
  48. })
  49. }
  50. componentDidShow () { }
  51. componentDidHide () { }
  52. renderHeader () {
  53. const { curImgIndex, curObj } = this.state
  54. let moreImg = []
  55. let images = curObj.images ? curObj.images.split(',') : []
  56. images.forEach(url => {
  57. moreImg.push({img_url: `${url}`})
  58. })
  59. const imgArr = [{img_url: `${curObj.pri_image}`}, ...moreImg, {img_url: curObj.house_img}]
  60. return (
  61. <View className="dtl-header">
  62. <Swiper
  63. circular
  64. current={curImgIndex}
  65. onChange={this.headerImgChange.bind(this)}
  66. className='dh-swiper'>
  67. {
  68. imgArr.map((item, index) => {
  69. return (
  70. <SwiperItem key={index}>
  71. <View className='dh-item'>
  72. <Image src={item.img_url ? item.img_url + '_white' : ''} className="img" onClick={this.previewImage2Handle.bind(this, item.img_url, imgArr)} />
  73. </View>
  74. </SwiperItem>
  75. )
  76. })
  77. }
  78. </Swiper>
  79. <View className="dh-count">
  80. <View className="bg"></View>
  81. <View className="num">{curImgIndex + 1}/{imgArr.length}</View>
  82. </View>
  83. </View>
  84. )
  85. }
  86. headerImgChange (e) {
  87. this.setState({
  88. curImgIndex: e.detail.current || 0
  89. })
  90. }
  91. previewImage2Handle (cur, arr) {
  92. const current = `${cur}_plus`
  93. const urls = arr.map(item => {
  94. return `${item.img_url}_plus`
  95. })
  96. Taro.previewImage({
  97. current,
  98. urls
  99. })
  100. }
  101. renderQrcode () {
  102. const qrcodeImg = 'http://icon.honglounews.com/miniqrcode.jpg'
  103. return (
  104. <Image src={qrcodeImg} className="scoped-qrcode" onClick={this.previewQrcodeImageHandle.bind(this, qrcodeImg, [qrcodeImg])} />
  105. )
  106. }
  107. previewQrcodeImageHandle (current, urls) {
  108. Taro.previewImage({
  109. current,
  110. urls
  111. })
  112. }
  113. renderMain () {
  114. const dictData = Taro.getStorageSync('dictData')
  115. const htObj = arrToObj(dictData.house_type)
  116. const ptObj = arrToObj(dictData.product_type)
  117. const atObj = arrToObj(dictData.area_type)
  118. const hryObj = arrToObj(dictData.house_room_year)
  119. const yesnoObj = arrToObj(dictData.sys_yesno)
  120. const { curObj } = this.state
  121. const tagArr = curObj.custom_tag ? curObj.custom_tag.split(',') : []
  122. const moreImg = require('./img/dtl/bg_estate.png')
  123. const FH = curObj.floor_height || 1
  124. const H = curObj.height || 1
  125. let FHstr = '未知'
  126. if (FH === 1 || FH === H) FHstr = '天地楼'
  127. if (FH > H * 0.6666) {
  128. FHstr = '中高层'
  129. } else if (FH > H * 0.33333) {
  130. FHstr = '中楼层'
  131. } else {
  132. FHstr = '中低层'
  133. }
  134. return (
  135. <View className="scoped-main">
  136. {this.renderQrcode()}
  137. <View className="sm-tags">
  138. {
  139. tagArr.map((tag, tI) => {
  140. return (
  141. <View className="s" key={tI}>{tag}</View>
  142. )
  143. })
  144. }
  145. </View>
  146. <View className="sm-title">{curObj.title}</View>
  147. <View className="sm-focus">
  148. <View className="op">
  149. <View className="v">{curObj.price}万</View>
  150. <View className="k">总价</View>
  151. </View>
  152. <View className="op" onClick={this.houseImgHandle.bind(this)}>
  153. <View className="v">{htObj[curObj.house_type]}</View>
  154. <View className="k">户型</View>
  155. </View>
  156. <View className="op">
  157. <View className="v">{curObj.area}㎡</View>
  158. <View className="k">建筑面积</View>
  159. </View>
  160. </View>
  161. <View className="sm-op">
  162. <View className="op">
  163. <View className="k">单价:</View>
  164. <View className="v c2">{parseInt(curObj.price * 10000 / curObj.area)}元/㎡</View>
  165. </View>
  166. <View className="op">
  167. <View className="k">挂牌时间:</View>
  168. <View className="v">{curObj.create_at ? curObj.create_at.substring(0, 10) : ''}</View>
  169. </View>
  170. <View className="op">
  171. <View className="k">区域:</View>
  172. <View className="v">{atObj[curObj.area_type]}</View>
  173. </View>
  174. <View className="op">
  175. <View className="k">房源类型:</View>
  176. <View className="v">{ptObj[curObj.product_type]}</View>
  177. </View>
  178. <View className="op">
  179. <View className="k">满几年:</View>
  180. <View className="v">{hryObj[curObj.how_many_year]}</View>
  181. </View>
  182. <View className="op">
  183. <View className="k">是否精装:</View>
  184. <View className="v">{yesnoObj[curObj.is_dec]}</View>
  185. </View>
  186. <View className="op">
  187. <View className="k">楼层:</View>
  188. <View className="v">{FHstr}/{curObj.height}层</View>
  189. </View>
  190. {
  191. curObj.introduce
  192. &&
  193. <View className="op full">
  194. <View className="k">房源简介:</View>
  195. <View className="v">{curObj.introduce}</View>
  196. </View>
  197. }
  198. <View className="op full">
  199. <View className="k">楼盘名称:</View>
  200. <View className="v">{curObj.estate_name}</View>
  201. </View>
  202. <Navigator url={`/pagesHouse/indexDtlAround?id=${curObj.estate_id}&name=${curObj.estate_name}`} className="op full">
  203. <View className="k">房源地址:</View>
  204. <View className="v">{curObj.address} <View className="s">查看周边配套</View></View>
  205. </Navigator>
  206. <Navigator url={`/pagesHouse/price?id=${curObj.estate_id}&name=${curObj.estate_name}`} className="op full">
  207. <View className="k">最近成交:</View>
  208. <View className="v t2">点击查看最近成交价</View>
  209. </Navigator>
  210. </View>
  211. <Image className="sm-more" src={moreImg} onClick={this.dtlLink.bind(this)} />
  212. </View>
  213. )
  214. }
  215. dtlLink () {
  216. const { curObj } = this.state
  217. Taro.navigateTo({
  218. url: `/pagesHouse/indexDtl?id=${curObj.estate_id}`
  219. })
  220. }
  221. renderImg () {
  222. const { curObj } = this.state
  223. return (
  224. <View className="dtl-options">
  225. <View className="do-title">
  226. <View className="t">户型图</View>
  227. </View>
  228. <View className="do-content" onClick={this.houseImgHandle.bind(this)}>
  229. <View className="scoped-img">
  230. <Image src={curObj.house_img + '_xs'} className="img"/>
  231. <View className="tips">
  232. <View className="bg"></View>
  233. <View className="t">查看大图</View>
  234. </View>
  235. </View>
  236. </View>
  237. </View>
  238. )
  239. }
  240. houseImgHandle () {
  241. const { curObj } = this.state
  242. const current = `${curObj.house_img}_plus`
  243. const urls = [`${curObj.house_img}_plus`]
  244. Taro.previewImage({
  245. current,
  246. urls
  247. })
  248. }
  249. renderOther () {
  250. const { curObj } = this.state
  251. return (
  252. <View className="dtl-options">
  253. <View className="do-title">
  254. <View className="t">同小区房源</View>
  255. <Navigator url={'/pagesRoom/list?estate_id=' + curObj.estate_id + '&estate_name=' + curObj.estate_name} className="r">查看更多{' >'}</Navigator>
  256. </View>
  257. <Rooms onRef={this.refRooms} />
  258. </View>
  259. )
  260. }
  261. refRooms = (ref) => {
  262. this.subRooms = ref
  263. }
  264. netLink (saleObj) {
  265. const { curObj } = this.state
  266. Taro.navigateTo({
  267. url: `/pagesQa/msg/chat?to_user_id=${saleObj.user_id}&qTitle=${curObj.title}`
  268. })
  269. }
  270. callHandle (saleObj) {
  271. Taro.makePhoneCall({
  272. phoneNumber: saleObj.sale_phone
  273. })
  274. }
  275. afterCount (type) {
  276. const { curObj } = this.state
  277. if (type === 'chat') {
  278. this.netLink(curObj.sale_user)
  279. }
  280. if (type === 'call') {
  281. this.callHandle(curObj.sale_user)
  282. }
  283. }
  284. countHandle (type) {
  285. const { curObj } = this.state
  286. Taro.api.room.apiusercontactclick({
  287. target_id: curObj.id,
  288. sale_id: curObj.sale_id,
  289. click_type: type === 'call' ? '2' : '1' // 1在线聊 2打电话
  290. }).then(() => {
  291. this.afterCount(type)
  292. }).catch(() => {
  293. this.afterCount(type)
  294. })
  295. }
  296. renderSale () {
  297. const { curObj } = this.state
  298. const saleObj = curObj.sale_user || {}
  299. const tagStr = saleObj.custom_tag ? saleObj.custom_tag.substring(0, 8) : ''
  300. return (
  301. <View className="scoped-sale">
  302. <View className="ss-img">
  303. <Image src={saleObj.sale_avatar} className="img"/>
  304. </View>
  305. <View className="ss-info">
  306. <View className="p1">{saleObj.sale_name}</View>
  307. <View className="p2">{tagStr}</View>
  308. </View>
  309. <View className="ss-r">
  310. <View className="b" onClick={this.countHandle.bind(this, 'chat')}>在线问</View>
  311. <View className="b t2" onClick={this.countHandle.bind(this, 'call')}>打电话</View>
  312. </View>
  313. </View>
  314. )
  315. }
  316. render () {
  317. const { curObj } = this.state
  318. return (
  319. <View className="l-box has-footer">
  320. {this.renderHeader()}
  321. {this.renderMain()}
  322. {this.renderImg()}
  323. {(curObj.old_house_list && curObj.old_house_list.length > 0) && this.renderOther()}
  324. {this.renderSale()}
  325. </View>
  326. )
  327. }
  328. }
  329. export default Index