dtl.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. import Taro, { Component } from '@tarojs/taro'
  2. import { View, Swiper, SwiperItem } from '@tarojs/components'
  3. import { AtCurtain } from 'taro-ui'
  4. import { arrToObj } from '@utils'
  5. import Rooms from './components/dtl/rooms'
  6. import './dtl.scss'
  7. class Index extends Component {
  8. onShareAppMessage() {
  9. const { curId, curObj } = this.state
  10. return {
  11. title: `${curObj.title}`,
  12. path: `/pagesRoom/dtl?id=${curId}`,
  13. }
  14. }
  15. onShareTimeline () {
  16. const { curId, curObj } = this.state
  17. return {
  18. title: `${curObj.title}`,
  19. path: `/pagesRoom/dtl?id=${curId}`,
  20. }
  21. }
  22. constructor (props) {
  23. super(props)
  24. const {id: curId} = this.$router.params
  25. this.state = {
  26. curId,
  27. curObj: {},
  28. curImgIndex: 0,
  29. curShareCardImg: require('./img/dtl/bg_room_dtl.png')
  30. }
  31. }
  32. config = {
  33. navigationBarTitleText: '房源详情',
  34. }
  35. componentWillMount () {
  36. Taro.$AHU(this)
  37. this.getDtl()
  38. // this.popupOpen()
  39. }
  40. getDtl = () => {
  41. const { curId } = this.state
  42. Taro.api.room.apieshousedetail({id: curId}).then(res => {
  43. Taro.setNavigationBarTitle({
  44. title: res.title || '房源详情'
  45. })
  46. this.drawAndShareImage(res.mini_coder)
  47. this.setState({
  48. curObj: res || {}
  49. }, () =>{
  50. if (this.subRooms) this.subRooms.getData(res.old_house_list || [])
  51. })
  52. })
  53. }
  54. componentDidShow () { }
  55. componentDidHide () { }
  56. renderHeader () {
  57. const { curImgIndex, curObj } = this.state
  58. let moreImg = []
  59. let images = curObj.images ? curObj.images.split(',') : []
  60. images.forEach(url => {
  61. moreImg.push({img_url: `${url}`})
  62. })
  63. const imgArr = [{img_url: `${curObj.pri_image}`}, ...moreImg, {img_url: curObj.house_img}]
  64. return (
  65. <View className="dtl-header">
  66. <Swiper
  67. circular
  68. current={curImgIndex}
  69. onChange={this.headerImgChange.bind(this)}
  70. className='dh-swiper'>
  71. {
  72. imgArr.map((item, index) => {
  73. return (
  74. <SwiperItem key={index}>
  75. <View className='dh-item'>
  76. <Image src={item.img_url ? item.img_url + '_white' : ''} className="img" onClick={this.previewImage2Handle.bind(this, item.img_url, imgArr)} />
  77. </View>
  78. </SwiperItem>
  79. )
  80. })
  81. }
  82. </Swiper>
  83. <View className="dh-count">
  84. <View className="bg"></View>
  85. <View className="num">{curImgIndex + 1}/{imgArr.length}</View>
  86. </View>
  87. </View>
  88. )
  89. }
  90. headerImgChange (e) {
  91. this.setState({
  92. curImgIndex: e.detail.current || 0
  93. })
  94. }
  95. previewImage2Handle (cur, arr) {
  96. const current = `${cur}`
  97. const urls = arr.map(item => {
  98. return `${item.img_url}`
  99. })
  100. Taro.previewImage({
  101. current,
  102. urls
  103. })
  104. }
  105. renderQrcode () {
  106. const qrcodeImg = 'http://icon.honglounews.com/miniqrcode.jpg'
  107. return (
  108. <Image src={qrcodeImg} className="scoped-qrcode" onClick={this.previewQrcodeImageHandle.bind(this, qrcodeImg, [qrcodeImg])} />
  109. )
  110. }
  111. previewQrcodeImageHandle (current, urls) {
  112. Taro.previewImage({
  113. current,
  114. urls
  115. })
  116. }
  117. editHandle () {
  118. const { curId } = this.state
  119. const appUserInfo = Taro.getStorageSync('APP_userInfo')
  120. if (appUserInfo.is_sale == 1) {
  121. Taro.navigateTo({
  122. url: `/pagesMore/center/uploadRoom2?id=${curId}`
  123. })
  124. }
  125. }
  126. renderMain () {
  127. const dictData = Taro.getStorageSync('dictData')
  128. const htObj = arrToObj(dictData.house_type)
  129. const ptObj = arrToObj(dictData.product_type)
  130. const atObj = arrToObj(dictData.area_type)
  131. const hryObj = arrToObj(dictData.house_room_year)
  132. const roomDecObj = arrToObj(dictData.room_dec)
  133. const { curObj } = this.state
  134. const tagArr = curObj.custom_tag ? curObj.custom_tag.split(',') : []
  135. const moreImg = require('./img/dtl/bg_estate.png')
  136. const FH = Number(curObj.floor) || 1
  137. const H = Number(curObj.storeys) || 1
  138. let FHstr = '未知'
  139. if (FH > H * 0.6666) {
  140. FHstr = '中高层'
  141. } else if (FH > H * 0.33333) {
  142. FHstr = '中楼层'
  143. } else {
  144. FHstr = '中低层'
  145. }
  146. if (FH === 1) FHstr = '一楼'
  147. if (FH === H) FHstr = '顶楼'
  148. return (
  149. <View className="scoped-main">
  150. {this.renderQrcode()}
  151. <View className="sm-tags">
  152. {
  153. tagArr.map((tag, tI) => {
  154. return (
  155. <View className="s" key={tI}>{tag}</View>
  156. )
  157. })
  158. }
  159. </View>
  160. <View className="sm-title" onClick={this.editHandle.bind(this)}>{curObj.title}</View>
  161. <View className="sm-focus">
  162. <View className="op">
  163. <View className="v">{curObj.price}万</View>
  164. <View className="k">总价</View>
  165. </View>
  166. <View className="op">
  167. <View className="v">{parseInt(curObj.price * 10000 / curObj.area)}元/㎡</View>
  168. <View className="k">单价</View>
  169. </View>
  170. {/* <View className="op">
  171. <View className="v"></View>
  172. <View className="k">户型</View>
  173. </View> */}
  174. <View className="op">
  175. <View className="v">{curObj.area}㎡</View>
  176. <View className="k">建筑面积</View>
  177. </View>
  178. </View>
  179. <View className="sm-op">
  180. <View className="op" onClick={this.houseImgHandle.bind(this)}>
  181. <View className="k">户型:</View>
  182. <View className="v">{htObj[curObj.house_type]}
  183. <View className="s">点击查看户型</View>
  184. </View>
  185. </View>
  186. <View className="op">
  187. <View className="k">楼层:</View>
  188. <View className="v">{FHstr}/{curObj.storeys}层</View>
  189. </View>
  190. <View className="op">
  191. <View className="k">满几年:</View>
  192. <View className="v">{hryObj[curObj.full_year]}</View>
  193. </View>
  194. {/* <View className="op">
  195. <View className="k">房源类型:</View>
  196. <View className="v">{ptObj[curObj.product_type]}</View>
  197. </View> */}
  198. <View className="op">
  199. <View className="k">装修状态:</View>
  200. <View className="v">{roomDecObj[curObj.is_dec]}</View>
  201. </View>
  202. <View className="op full">
  203. <View className="k">楼盘名称:</View>
  204. <View className="v">{curObj.estate_name}</View>
  205. </View>
  206. <Navigator url={`/pagesHouse/indexDtlAround?id=${curObj.estate_id}&name=${curObj.estate_name}`} className="op full">
  207. <View className="k">房源地址:</View>
  208. <View className="v">{curObj.address} <View className="s">查看周边配套</View></View>
  209. </Navigator>
  210. <View className="op">
  211. <View className="k">区域:</View>
  212. <View className="v">{atObj[curObj.area_type]}</View>
  213. </View>
  214. <View className="op">
  215. <View className="k">录入时间:</View>
  216. <View className="v">{curObj.create_at ? curObj.create_at.substring(0, 10) : ''}</View>
  217. </View>
  218. <Navigator url={`/pagesHouse/price?id=${curObj.estate_id}&name=${curObj.estate_name}`} className="op full">
  219. <View className="k">最近成交:</View>
  220. <View className="v t2">点击查看历史成交价</View>
  221. </Navigator>
  222. {
  223. curObj.introduce
  224. &&
  225. <View className="op full">
  226. <View className="k">房源简介:</View>
  227. <View className="v">{curObj.introduce}</View>
  228. </View>
  229. }
  230. </View>
  231. <Image className="sm-more" src={moreImg} onClick={this.dtlLink.bind(this)} />
  232. </View>
  233. )
  234. }
  235. dtlLink () {
  236. const { curObj } = this.state
  237. Taro.navigateTo({
  238. url: `/pagesHouse/indexDtl?id=${curObj.estate_id}`
  239. })
  240. }
  241. renderImg () {
  242. const { curObj } = this.state
  243. return (
  244. <View className="dtl-options">
  245. <View className="do-title">
  246. <View className="t">户型图</View>
  247. </View>
  248. <View className="do-content" onClick={this.houseImgHandle.bind(this)}>
  249. <View className="scoped-img">
  250. <Image src={curObj.house_img + '_xs'} className="img"/>
  251. <View className="tips">
  252. <View className="bg"></View>
  253. <View className="t">查看大图</View>
  254. </View>
  255. </View>
  256. </View>
  257. </View>
  258. )
  259. }
  260. houseImgHandle () {
  261. const { curObj } = this.state
  262. const current = `${curObj.house_img}_plus`
  263. const urls = [`${curObj.house_img}_plus`]
  264. Taro.previewImage({
  265. current,
  266. urls
  267. })
  268. }
  269. renderOther () {
  270. const { curObj } = this.state
  271. return (
  272. <View className="dtl-options">
  273. <View className="do-title">
  274. <View className="t">同小区房源</View>
  275. <Navigator url={'/pagesRoom/list?estate_id=' + curObj.estate_id + '&estate_name=' + curObj.estate_name} className="r">查看更多{' >'}</Navigator>
  276. </View>
  277. <Rooms onRef={this.refRooms} />
  278. </View>
  279. )
  280. }
  281. refRooms = (ref) => {
  282. this.subRooms = ref
  283. }
  284. netLink (saleObj) {
  285. const { curObj } = this.state
  286. Taro.navigateTo({
  287. url: `/pagesQa/msg/chat?to_user_id=${saleObj.user_id}&qTitle=${curObj.title}&qId=${curObj.id}`
  288. })
  289. }
  290. callHandle (saleObj) {
  291. Taro.makePhoneCall({
  292. phoneNumber: saleObj.sale_phone
  293. })
  294. }
  295. afterCount (type) {
  296. const { curObj } = this.state
  297. if (type === 'chat') {
  298. this.netLink(curObj.sale_user)
  299. }
  300. if (type === 'call') {
  301. this.callHandle(curObj.sale_user)
  302. }
  303. }
  304. countHandle (type) {
  305. const { curObj } = this.state
  306. Taro.api.room.apiusercontactclick({
  307. target_id: curObj.id,
  308. sale_id: curObj.sale_id,
  309. click_type: type === 'call' ? '2' : '1' // 1在线聊 2打电话
  310. }).then(() => {
  311. this.afterCount(type)
  312. }).catch(() => {
  313. this.afterCount(type)
  314. })
  315. }
  316. renderSale () {
  317. const { curObj } = this.state
  318. const saleObj = curObj.sale_user || {}
  319. const tagStr = saleObj.custom_tag ? saleObj.custom_tag.substring(0, 8) : ''
  320. return (
  321. <View className="scoped-sale">
  322. <View className="ss-img">
  323. <Image src={saleObj.sale_avatar} className="img"/>
  324. </View>
  325. <View className="ss-info">
  326. <View className="p1">{saleObj.sale_name}</View>
  327. <View className="p2">{tagStr}</View>
  328. </View>
  329. <View className="ss-r">
  330. <View className="b" onClick={this.countHandle.bind(this, 'chat')}>在线问</View>
  331. <View className="b t2" onClick={this.countHandle.bind(this, 'call')}>打电话</View>
  332. </View>
  333. </View>
  334. )
  335. }
  336. renderPopup () {
  337. const { isPopupShow, curShareCardImg } = this.state
  338. return (
  339. <AtCurtain
  340. isOpened={isPopupShow}
  341. onClose={this.popupClose.bind(this)}
  342. >
  343. <Image
  344. className="scoped-share-card-img"
  345. src={curShareCardImg}
  346. />
  347. </AtCurtain>
  348. )
  349. }
  350. popupClose () {
  351. this.setState({
  352. isPopupShow: false
  353. })
  354. }
  355. popupOpen () {
  356. this.setState({
  357. isPopupShow: true
  358. })
  359. }
  360. drawAndShareImage (qrcodeSrc) {
  361. const { curObj } = this.state
  362. const that = this
  363. const canvas = Taro.createOffscreenCanvas({type: '2d', width: 600, height: 1067})
  364. const ctx = canvas.getContext('2d')
  365. ctx.rect(0 , 0 , canvas.width , canvas.height)
  366. ctx.fillStyle = "#fff"
  367. ctx.fill()
  368. const img1 = canvas.createImage()
  369. img1.src = require('./img/dtl/bg_room_dtl.png')
  370. img1.crossOrigin = 'Anonymous'
  371. img1.onload = () => {
  372. ctx.drawImage(img1, 0, 0, 600, 1067)
  373. const img2 = canvas.createImage()
  374. img2.src = qrcodeSrc
  375. img2.crossOrigin = 'Anonymous'
  376. img2.onload = () => {
  377. ctx.drawImage(img2, 320, 950, 100, 100)
  378. that.drawText(ctx, 'red', "哈哈哈哈,测试文字", 100, 500)
  379. let base64 = ctx.canvas.toDataURL("image/png")
  380. that.setState({
  381. curShareCardImg: base64
  382. })
  383. }
  384. }
  385. }
  386. drawText = (ctx, color, text, x, y, font = 50) => {
  387. ctx.font="50px Arial";
  388. ctx.fillStyle = color;
  389. ctx.textAlign = 'left';
  390. ctx.fillText(text, x, y);
  391. // ctx.stroke();
  392. // ctx.closePath();
  393. }
  394. render () {
  395. const { curObj } = this.state
  396. return (
  397. <View className="l-box has-footer">
  398. {this.renderHeader()}
  399. {this.renderMain()}
  400. {this.renderImg()}
  401. {(curObj.old_house_list && curObj.old_house_list.length > 0) && this.renderOther()}
  402. {this.renderSale()}
  403. {this.renderPopup()}
  404. </View>
  405. )
  406. }
  407. }
  408. export default Index