dtl.jsx 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  1. import Taro, { Component } from '@tarojs/taro'
  2. import { View, Swiper, SwiperItem, Navigator } from '@tarojs/components'
  3. import { AtCurtain } from 'taro-ui'
  4. import { arrToObj } from '@utils'
  5. import Rooms from './components/dtl/rooms'
  6. import Around from './components/dtl/around'
  7. import './dtl.scss'
  8. class Index extends Component {
  9. onShareAppMessage() {
  10. const userInfo = Taro.getStorageSync('APP_userInfo') || {}
  11. const { curId, curObj } = this.state
  12. if (userInfo.is_sale == 1) {
  13. return {
  14. title: `${userInfo.nickname}给您推荐:${curObj.title}`,
  15. path: `/pagesRoom/dtl?id=${curId}&referrer=${userInfo.user_id}`,
  16. }
  17. } else {
  18. return {
  19. title: `${curObj.title}`,
  20. path: `/pagesRoom/dtl?id=${curId}`,
  21. }
  22. }
  23. }
  24. onShareTimeline () {
  25. const userInfo = Taro.getStorageSync('APP_userInfo') || {}
  26. const { curId, curObj } = this.state
  27. if (userInfo.is_sale == 1) {
  28. return {
  29. title: `${userInfo.nickname}给您推荐:${curObj.title}`,
  30. path: `/pagesRoom/dtl?id=${curId}&referrer=${userInfo.user_id}`,
  31. }
  32. } else {
  33. return {
  34. title: `${curObj.title}`,
  35. path: `/pagesRoom/dtl?id=${curId}`,
  36. }
  37. }
  38. }
  39. constructor (props) {
  40. super(props)
  41. const {id: curId} = this.$router.params
  42. this.state = {
  43. referrer: '',
  44. saleUserObj: {},
  45. curId,
  46. curObj: {},
  47. curImgIndex: 0,
  48. // curShareCardImg: require('./img/dtl/bg_room_dtl.png')
  49. curShareCardImg: '',
  50. curShareCardImgType: '',
  51. }
  52. }
  53. config = {
  54. // navigationBarTitleText: '房源详情',
  55. navigationStyle: 'custom',
  56. navigationBarTextStyle: 'white',
  57. }
  58. componentWillMount () {
  59. Taro.$AHU(this)
  60. this.getDtl()
  61. Taro.removeStorageSync('APP_MY_REFERRER')
  62. const {referrer} = this.$router.params
  63. if (referrer) {
  64. this.setState({
  65. referrer
  66. })
  67. Taro.removeStorageSync('APP_cur_sale')
  68. Taro.setStorageSync("APP_MY_REFERRER", referrer)
  69. }
  70. }
  71. getDtl = () => {
  72. const { curId } = this.state
  73. Taro.api.room.apieshousedetail({id: curId}).then(res => {
  74. // Taro.setNavigationBarTitle({
  75. // title: res.title || '房源详情'
  76. // })
  77. this.setState({
  78. curObj: res || {}
  79. }, () =>{
  80. if (this.subRooms) this.subRooms.getData(res.es_house_list || [])
  81. if (this.subAround) this.subAround.getData(res.estate_id)
  82. const {referrer} = this.$router.params
  83. if (referrer) {
  84. Taro.api.room.apisalelist({
  85. show_status: 1,
  86. referrer
  87. }).then(res => {
  88. const list = res.list || []
  89. if (list.length > 0) {
  90. this.setState({
  91. saleUserObj: list[0]
  92. })
  93. } else {
  94. if (res.sale_user.sale_phone === '18907904022') {
  95. Taro.api.room.apisalelist({
  96. show_status: 1,
  97. page_size: 99
  98. }).then(res => {
  99. const list = res.list || []
  100. const arrIndex = Math.floor(Math.random() * list.length)
  101. this.setState({
  102. saleUserObj: list[arrIndex],
  103. })
  104. Taro.setStorageSync('APP_cur_sale', {curObj: list[arrIndex]})
  105. })
  106. } else {
  107. this.setState({
  108. saleUserObj: res.sale_user
  109. })
  110. }
  111. }
  112. })
  113. } else {
  114. if (res.sale_user.sale_phone === '18907904022') {
  115. Taro.api.room.apisalelist({
  116. show_status: 1,
  117. page_size: 99
  118. }).then(res => {
  119. const list = res.list || []
  120. const arrIndex = Math.floor(Math.random() * list.length)
  121. this.setState({
  122. saleUserObj: list[arrIndex],
  123. })
  124. Taro.setStorageSync('APP_cur_sale', {curObj: list[arrIndex]})
  125. })
  126. } else {
  127. this.setState({
  128. saleUserObj: res.sale_user
  129. })
  130. }
  131. }
  132. })
  133. })
  134. }
  135. componentDidShow () { }
  136. componentDidHide () { }
  137. renderHeader () {
  138. const { curImgIndex, curObj } = this.state
  139. let moreImg = []
  140. let images = curObj.images ? curObj.images.split(',') : []
  141. images.forEach(url => {
  142. moreImg.push({img_url: `${url}`})
  143. })
  144. const imgArr = [{img_url: `${curObj.pri_image}`}, ...moreImg]
  145. return (
  146. <View className="dtl-header">
  147. <Swiper
  148. circular
  149. current={curImgIndex}
  150. onChange={this.headerImgChange.bind(this)}
  151. className='dh-swiper'>
  152. {
  153. curObj.video
  154. ?
  155. <SwiperItem>
  156. <View className='dh-item'>
  157. <Video
  158. className="img"
  159. src={curObj.video}
  160. controls={true}
  161. autoplay={false}
  162. initialTime='0'
  163. id='video'
  164. loop={false}
  165. muted={false}
  166. />
  167. </View>
  168. </SwiperItem>
  169. : ''
  170. }
  171. {
  172. imgArr.map((item, index) => {
  173. return (
  174. <SwiperItem key={index}>
  175. <View className='dh-item'>
  176. <Image src={item.img_url ? item.img_url + '_white' : ''} className="img" onClick={this.previewImage2Handle.bind(this, item.img_url, imgArr)} />
  177. </View>
  178. </SwiperItem>
  179. )
  180. })
  181. }
  182. </Swiper>
  183. <View className="dh-count">
  184. <View className="bg"></View>
  185. <View className="num">{curImgIndex + 1}-{imgArr.length + (curObj.video ? 1 : 0)}</View>
  186. </View>
  187. </View>
  188. )
  189. }
  190. headerImgChange (e) {
  191. this.setState({
  192. curImgIndex: e.detail.current || 0
  193. })
  194. }
  195. previewImage2Handle (cur, arr) {
  196. const current = `${cur}_plus`
  197. const urls = arr.map(item => {
  198. return `${item.img_url}_plus`
  199. })
  200. Taro.previewImage({
  201. current,
  202. urls
  203. })
  204. }
  205. renderQrcode () {
  206. const qrcodeImg = 'http://icon.honglounews.com/miniqrcode.jpg'
  207. return (
  208. <Image src={qrcodeImg} className="scoped-qrcode" onClick={this.previewQrcodeImageHandle.bind(this, qrcodeImg, [qrcodeImg])} />
  209. )
  210. }
  211. previewQrcodeImageHandle (current, urls) {
  212. Taro.previewImage({
  213. current,
  214. urls
  215. })
  216. }
  217. editHandle () {
  218. const { curId } = this.state
  219. const appUserInfo = Taro.getStorageSync('APP_userInfo')
  220. if (appUserInfo.is_sale == 1) {
  221. Taro.navigateTo({
  222. url: `/pagesMore/center/uploadRoom2?id=${curId}`
  223. })
  224. }
  225. }
  226. renderMain () {
  227. const signRight = require('@img/icon_sign_right.png')
  228. const dictData = Taro.getStorageSync('dictData')
  229. const atObj = arrToObj(dictData.area_type)
  230. const hryObj = arrToObj(dictData.house_room_year)
  231. const roomDecObj = arrToObj(dictData.room_dec)
  232. const roomPositionObj = arrToObj(dictData.room_position)
  233. const { curObj } = this.state
  234. const tagArr = curObj.custom_tag ? curObj.custom_tag.split(',') : []
  235. const moreImg = require('./img/dtl/bg_estate.png')
  236. const FH = Number(curObj.floor) || 1
  237. const H = Number(curObj.storeys) || 1
  238. let FHstr = '未知'
  239. if (FH > H * 0.6666) {
  240. FHstr = '中高层'
  241. } else if (FH > H * 0.33333) {
  242. FHstr = '中楼层'
  243. } else {
  244. FHstr = '中低层'
  245. }
  246. if (FH === 1) FHstr = '低层'
  247. if (FH === H) FHstr = '高层'
  248. let houseTypeStr = '未知'
  249. if (curObj.house_type) {
  250. let arr = curObj.house_type.split('-')
  251. houseTypeStr = `${arr[0]}室${arr[1]}厅${arr[2]}卫`
  252. }
  253. const stairsRateArr = curObj.stairs_rate ? curObj.stairs_rate.split('-') : []
  254. const appUserInfo = Taro.getStorageSync('APP_userInfo')
  255. const schoolList = curObj.school_list && curObj.school_list.duikou ? curObj.school_list.duikou : []
  256. // <View className="t t1">{arrToObj(dictData.school_attrib)[item.school_attrib]}</View>
  257. // <View className="t t4">{arrToObj(dictData.school_type)[item.school_type]}</View>
  258. const schoolViews = schoolList.map((item) => {
  259. return (
  260. <View className="v-sub-op" key={item.id}>{`${item.school_name}[${arrToObj(dictData.school_attrib)[item.school_attrib]}][${arrToObj(dictData.school_type)[item.school_type]}]`}</View>
  261. )
  262. })
  263. // console.log(schoolStrList)
  264. return (
  265. <View className="scoped-main">
  266. {/* {this.renderQrcode()} */}
  267. <View className="sm-tags">
  268. {
  269. appUserInfo.is_sale == 1
  270. ? <Navigator url={`/pagesRoom/follow/room?id=${curObj.id}`} className="s s2">{curObj.id}跟进记录</Navigator>
  271. : ''
  272. }
  273. {
  274. tagArr.map((tag, tI) => {
  275. return (
  276. <View className="s" key={tI}>{tag}</View>
  277. )
  278. })
  279. }
  280. </View>
  281. <View className="sm-title" onClick={this.editHandle.bind(this)}>{curObj.title}</View>
  282. <View className="sm-focus">
  283. <View className="op">
  284. <View className="v">{curObj.price}万</View>
  285. <View className="k">售价</View>
  286. </View>
  287. <View className="op" onClick={this.houseImgHandle.bind(this)}>
  288. <View className="v">{houseTypeStr}</View>
  289. <View className="k">房型</View>
  290. </View>
  291. <View className="op">
  292. <View className="v">{curObj.area}㎡</View>
  293. <View className="k">建筑面积</View>
  294. </View>
  295. </View>
  296. <View className="sm-op">
  297. <View className="op full">
  298. <View className="k">学区</View>
  299. <View className="v">
  300. <View className="v-sub">
  301. {schoolViews}
  302. {/* <View className="v-sub-op"></View> */}
  303. </View>
  304. </View>
  305. </View>
  306. <View className="op full">
  307. <View className="k">单价</View>
  308. <View className="v">{parseInt(curObj.price * 10000 / curObj.area)}元/㎡</View>
  309. </View>
  310. <View className="op">
  311. <View className="k">楼层</View>
  312. <View className="v">{FHstr}/{curObj.storeys}层</View>
  313. </View>
  314. <View className="op" onClick={this.countHandle.bind(this, 'chat')}>
  315. <View className="m">咨询楼层</View>
  316. <Image src={signRight} className="r" />
  317. </View>
  318. <View className="op">
  319. <View className="k">满几</View>
  320. <View className="v">{hryObj[curObj.full_year] || '未知'}</View>
  321. </View>
  322. <View className="op">
  323. <View className="k">装修</View>
  324. <View className="v">{roomDecObj[curObj.is_dec]}</View>
  325. </View>
  326. <View className="op">
  327. <View className="k">交房</View>
  328. <View className="v">{curObj.delivery_at || '未知'}</View>
  329. </View>
  330. <View className="op">
  331. <View className="k">电梯</View>
  332. <View className="v">{curObj.is_elevator == 1 ? '有电梯' : '无电梯'}</View>
  333. </View>
  334. <View className="op">
  335. <View className="k">梯户</View>
  336. <View className="v">{stairsRateArr.length > 0 ? `${stairsRateArr[0]}梯${stairsRateArr[1]}户` : '未知'}</View>
  337. </View>
  338. <View className="op">
  339. <View className="k">方位</View>
  340. <View className="v">{curObj.position ? roomPositionObj[curObj.position] : '未知'}</View>
  341. </View>
  342. {/* <View className="op">
  343. <View className="k">预约</View>
  344. <View className="v">房东底价?朝向梯户比?<View onClick={this.countHandle.bind(this, 'chat')} className="s">【免费咨询】</View></View>
  345. </View> */}
  346. <View className="op">
  347. <View className="k">区域</View>
  348. <View className="v">{atObj[curObj.area_type]}</View>
  349. </View>
  350. <Navigator url={`/pagesHouse/indexDtlAround?id=${curObj.estate_id}&name=${curObj.estate_name}`} className="op">
  351. <View className="m">查看周边配套</View>
  352. <Image src={signRight} className="r" />
  353. </Navigator>
  354. <View className="op">
  355. <View className="k">其它</View>
  356. <View className="v">房东底价?套内面积</View>
  357. </View>
  358. <View className="op" onClick={this.countHandle.bind(this, 'chat')}>
  359. <View className="m">免费咨询</View>
  360. <Image src={signRight} className="r" />
  361. </View>
  362. <View className="op full" onClick={this.dtlLink.bind(this)}>
  363. <View className="k">楼盘</View>
  364. <View className="v t2">{curObj.estate_name}
  365. {/* <View onClick={this.dtlLink.bind(this)} className="s">查看该楼盘</View> */}
  366. </View>
  367. </View>
  368. <Navigator url={`/pagesHouse/price?id=${curObj.estate_id}&name=${curObj.estate_name}`} className="op full">
  369. <View className="k">成交</View>
  370. <View className="v t2">查看近期成交价</View>
  371. </Navigator>
  372. {
  373. curObj.introduce
  374. &&
  375. <View className="op full">
  376. <View className="k">简介</View>
  377. <View className="v">{curObj.introduce}</View>
  378. </View>
  379. }
  380. </View>
  381. <Image className="sm-more" src={moreImg} onClick={this.dtlLink.bind(this)} />
  382. </View>
  383. )
  384. }
  385. dtlLink () {
  386. const { curObj } = this.state
  387. Taro.navigateTo({
  388. url: `/pagesHouse/indexDtl?id=${curObj.estate_id}`
  389. })
  390. }
  391. renderImg () {
  392. const { curObj } = this.state
  393. return (
  394. <View className="dtl-options">
  395. <View className="do-title">
  396. <View className="t">户型图</View>
  397. </View>
  398. <View className="do-content" onClick={this.houseImgHandle.bind(this)}>
  399. <View className="scoped-img">
  400. <Image src={curObj.house_img} className="img"/>
  401. <View className="tips">
  402. <View className="bg"></View>
  403. <View className="t">查看大图</View>
  404. </View>
  405. </View>
  406. </View>
  407. </View>
  408. )
  409. }
  410. houseImgHandle () {
  411. const { curObj } = this.state
  412. const current = `${curObj.house_img}`
  413. const urls = [`${curObj.house_img}`]
  414. Taro.previewImage({
  415. current,
  416. urls
  417. })
  418. }
  419. renderAround () {
  420. const { curObj } = this.state
  421. return (
  422. <View className="dtl-options">
  423. <View className="do-title">
  424. <View className="t">周边配套</View>
  425. </View>
  426. <View className="do-content">
  427. <Around onRef={this.refAround} />
  428. </View>
  429. </View>
  430. )
  431. }
  432. refAround = (ref) => {
  433. this.subAround = ref
  434. }
  435. renderOther () {
  436. const { curObj } = this.state
  437. return (
  438. <View className="dtl-options">
  439. <View className="do-title">
  440. <View className="t">猜你喜欢</View>
  441. {/* <Navigator url={'/pagesRoom/list?estate_id=' + curObj.estate_id + '&estate_name=' + curObj.estate_name} className="r">查看更多{' >'}</Navigator> */}
  442. </View>
  443. <Rooms onRef={this.refRooms} />
  444. </View>
  445. )
  446. }
  447. refRooms = (ref) => {
  448. this.subRooms = ref
  449. }
  450. netLink (saleObj) {
  451. const { curObj } = this.state
  452. Taro.navigateTo({
  453. url: `/pagesQa/msg/chat?to_user_id=${saleObj.user_id}&qTitle=${curObj.title}&qId=${curObj.id}`
  454. })
  455. }
  456. callHandle (saleObj) {
  457. Taro.makePhoneCall({
  458. phoneNumber: saleObj.sale_phone
  459. })
  460. }
  461. afterCount (type) {
  462. const { curObj } = this.state
  463. if (type === 'chat') {
  464. this.netLink(curObj.sale_user)
  465. }
  466. if (type === 'call') {
  467. this.callHandle(curObj.sale_user)
  468. }
  469. }
  470. countHandle (type) {
  471. const { curObj } = this.state
  472. Taro.api.room.apiusercontactclick({
  473. target_id: curObj.id,
  474. sale_id: curObj.sale_id,
  475. click_type: type === 'call' ? '2' : '1' // 1在线聊 2打电话
  476. }).then(() => {
  477. this.afterCount(type)
  478. }).catch(() => {
  479. this.afterCount(type)
  480. })
  481. }
  482. renderSale () {
  483. const { curObj, saleUserObj } = this.state
  484. let saleObj = saleUserObj || {}
  485. const tagStr = saleObj.custom_tag ? saleObj.custom_tag.substring(0, 8) : ''
  486. return (
  487. <View className="scoped-sale">
  488. <View className="ss-img">
  489. <Image src={saleObj.sale_avatar} className="img"/>
  490. </View>
  491. <View className="ss-info">
  492. <View className="p1">{saleObj.sale_name}</View>
  493. <View className="p2">{tagStr}</View>
  494. </View>
  495. <View className="ss-r">
  496. <View className="b" onClick={this.countHandle.bind(this, 'chat')}>在线问</View>
  497. <View className="b t2" onClick={this.countHandle.bind(this, 'call')}>打电话</View>
  498. </View>
  499. </View>
  500. )
  501. }
  502. renderPopup () {
  503. const { isPopupShow, curShareCardImg } = this.state
  504. return (
  505. <AtCurtain
  506. isOpened={isPopupShow}
  507. onClose={this.popupClose.bind(this)}
  508. >
  509. <View className="scoped-share-card-img">
  510. <Image
  511. className="img"
  512. src={curShareCardImg}
  513. />
  514. </View>
  515. </AtCurtain>
  516. )
  517. }
  518. popupClose () {
  519. this.setState({
  520. isPopupShow: false
  521. })
  522. }
  523. popupOpen () {
  524. this.setState({
  525. isPopupShow: true
  526. })
  527. }
  528. dealCanvasImg (qrcodeSrc) {
  529. const { curObj } = this.state
  530. const that = this
  531. const imageArr = (curObj.images || '').split(',')
  532. const processMultipleImages = (url) => {
  533. return new Promise((resolve, reject) => {
  534. Taro.getImageInfo({
  535. src: url,
  536. success: (res) => {
  537. resolve(res)
  538. },
  539. fail: () => {
  540. Taro.showToast({
  541. title: '下载失败!'
  542. })
  543. }
  544. })
  545. })
  546. }
  547. Promise.all(
  548. imageArr.map(img => processMultipleImages(img+'_adm0'))
  549. ).then(img => {
  550. let tempImgArr = img.map(i => i.path)
  551. that.dealCanvas(tempImgArr)
  552. })
  553. }
  554. // drawAndSharetestImage () {
  555. // const { curObj } = this.state
  556. // const imageArr = (curObj.images || '').split(',')
  557. // if (imageArr.length < 2) {
  558. // Taro.$msgConfirm('房源图片不足~')
  559. // return
  560. // }
  561. // console.log(curObj)
  562. // const that = this
  563. // const cvs = Taro.createOffscreenCanvas({type: '2d', width: 700, height: 990})
  564. // const ctx = cvs.getContext('2d')
  565. // ctx.clearRect(0, 0, cvs.width, cvs.height)
  566. // ctx.rect(0 , 0 , cvs.width , cvs.height)
  567. // ctx.fillStyle = "#fff"
  568. // ctx.fill()
  569. // let imgBg = cvs.createImage();
  570. // imgBg.src = require('./img/dtl/bg_room_dtl.jpg')
  571. // imgBg.onload = () => {
  572. // ctx.drawImage(imgBg, 0, 0, 700, 990)
  573. // }
  574. // let img1 = cvs.createImage();
  575. // img1.src = curObj.pri_image + '_adm0'
  576. // imgBg.onload = () => {
  577. // ctx.drawImage(img1, 83, 358, 256, 200)
  578. // }
  579. // let img2 = cvs.createImage();
  580. // img2.src = curObj.house_img
  581. // imgBg.onload = () => {
  582. // ctx.drawImage(img2, 362, 358, 256, 200)
  583. // }
  584. // let img3 = cvs.createImage();
  585. // img3.src = imageArr[0] + '_adm0'
  586. // imgBg.onload = () => {
  587. // ctx.drawImage(img3, 83, 570, 256, 200)
  588. // }
  589. // let img4 = cvs.createImage();
  590. // img4.src = imageArr[1] + '_adm0'
  591. // imgBg.onload = () => {
  592. // ctx.drawImage(img4, 362, 570, 256, 200)
  593. // }
  594. // that.drawText(ctx, '#333', curObj.title.length > 25 ? curObj.title.substring(0, 25) + '...' : curObj.title, 98, 846, '18px')
  595. // if (curObj.estate_name.length > 7) {
  596. // that.drawText(ctx, '#333', curObj.estate_name, 80, 220, 'normal bold 36px')
  597. // } else {
  598. // that.drawText(ctx, '#333', curObj.estate_name, 80, 220, 'normal bold 56px')
  599. // }
  600. // that.drawText(ctx, '#333', curObj.area + '㎡', 140, 310, 'normal bold 28px')
  601. // that.drawText(ctx, '#df6135', curObj.floor_price + '万', 280, 310, 'normal bold 32px')
  602. // // let base64 = ctx.canvas.toDataURL("image/png")
  603. // // that.setState({
  604. // // curShareCardImg: base64
  605. // // })
  606. // // that.popupOpen()
  607. // const imgData = cvs.toDataURL();
  608. // console.log('imgData')
  609. // console.log(imgData)
  610. // const time = new Date().getTime();
  611. // const fs = wx.getFileSystemManager();
  612. // const filePath = Taro.env.USER_DATA_PATH + "/poster" + time + "share" + ".png";
  613. // fs.writeFile({
  614. // filePath,
  615. // data: imgData.replace(/^data:image\/\w+;base64,/, ""),
  616. // encoding: 'base64',
  617. // success: res => {
  618. // console.log('成功:'+res)
  619. // wx.showShareImageMenu({
  620. // path: filePath,
  621. // success: res => {
  622. // console.log(res, 11);
  623. // }
  624. // })
  625. // },
  626. // fail: err => {
  627. // // 此处可能存在内存满了的情况
  628. // // 需要根据具体需求处理
  629. // console.log(err);
  630. // }
  631. // });
  632. // fs.close()
  633. // }
  634. async drawAndShare2Image (str) {
  635. const { curObj, curShareCardImg, curShareCardImgType } = this.state
  636. if (curShareCardImg) {
  637. if (curShareCardImgType === str) {
  638. wx.showShareImageMenu({
  639. path: curShareCardImg,
  640. success: res => {
  641. console.log(res, 22);
  642. }
  643. })
  644. } else {
  645. Taro.$msgConfirm('请返回上一层页面,再重新进入当前页面生成图片~')
  646. }
  647. return
  648. }
  649. const imageArr = (curObj.images || '').split(',')
  650. if (imageArr.length < 2) {
  651. Taro.$msgConfirm('房源图片不足~')
  652. return
  653. }
  654. Taro.showLoading({
  655. mask: true,
  656. title: '图片智能生成中..'
  657. })
  658. const that = this
  659. const cvs = Taro.createOffscreenCanvas({type: '2d', width: 700, height: 1516})
  660. const ctx = cvs.getContext('2d')
  661. ctx.clearRect(0, 0, cvs.width, cvs.height)
  662. ctx.rect(0 , 0 , cvs.width , cvs.height)
  663. ctx.fillStyle = "#fff"
  664. ctx.fill()
  665. let imgBg = cvs.createImage();
  666. // imgBg.src = require('./img/dtl/bg_room_dtl.jpg')
  667. imgBg.src = 'https://img.honglounews.com/20260107092402-3240.jpg_adm0?r='+ Math.random()
  668. await new Promise(resolve => {
  669. imgBg.onload = resolve;
  670. })
  671. ctx.drawImage(imgBg, 0, 0, 700, 1516)
  672. let img1 = cvs.createImage();
  673. await new Promise(resolve => {
  674. img1.onload = resolve;
  675. img1.src = curObj.pri_image + '_adm0'
  676. })
  677. ctx.drawImage(img1, 0, 530, 345, 286)
  678. let img2 = cvs.createImage();
  679. await new Promise(resolve => {
  680. img2.onload = resolve;
  681. img2.src = curObj.house_img
  682. })
  683. ctx.drawImage(img2, 356, 530, 345, 286)
  684. let img3 = cvs.createImage();
  685. await new Promise(resolve => {
  686. img3.onload = resolve;
  687. img3.src = imageArr[0] + '_adm0'
  688. })
  689. ctx.drawImage(img3, 0, 828, 345, 286)
  690. let img4 = cvs.createImage();
  691. await new Promise(resolve => {
  692. img4.onload = resolve;
  693. img4.src = imageArr[1] + '_adm0'
  694. })
  695. ctx.drawImage(img4, 356, 828, 345, 286)
  696. that.drawCenterText(ctx, '#343434', curObj.title.length > 25 ? curObj.title.substring(0, 25) + '...' : curObj.title, 350, 460, '28px')
  697. if (str === 'hide') {
  698. that.drawCenterText(ctx, '#333', '详情咨询巴老师', 350, 255, 'normal bold 70px')
  699. } else {
  700. if (curObj.estate_name.length > 10) {
  701. that.drawCenterText(ctx, '#343434', curObj.estate_name, 350, 255, 'normal bold 30px')
  702. } else if (curObj.estate_name.length > 7) {
  703. that.drawCenterText(ctx, '#343434', curObj.estate_name, 350, 255, 'normal bold 56px')
  704. } else {
  705. that.drawCenterText(ctx, '#343434', curObj.estate_name, 350, 255, 'normal bold 70px')
  706. }
  707. }
  708. // that.drawText(ctx, '#333', curObj.area + '㎡', 140, 310, 'normal bold 28px')
  709. // that.drawText(ctx, '#df6135', curObj.price + '万', 280, 310, 'normal bold 32px')
  710. that.drawText(ctx, '#ff2400', curObj.area, 170, 390, 'normal bold 80px')
  711. that.drawText(ctx, '#ff2400', curObj.price, 380, 390, 'normal bold 80px')
  712. // let base64 = ctx.canvas.toDataURL("image/png")
  713. // that.setState({
  714. // curShareCardImg: base64
  715. // })
  716. // that.popupOpen()
  717. setTimeout(() => {
  718. imgBg = null
  719. img1 = null
  720. img2 = null
  721. img3 = null
  722. img4 = null
  723. Taro.hideLoading()
  724. }, 6000)
  725. const imgData = cvs.toDataURL();
  726. const time = new Date().getTime();
  727. const fs = wx.getFileSystemManager();
  728. const filePath = Taro.env.USER_DATA_PATH + "/poster" + time + "share" + ".png";
  729. fs.writeFile({
  730. filePath,
  731. data: imgData.replace(/^data:image\/\w+;base64,/, ""),
  732. encoding: 'base64',
  733. success: res => {
  734. that.setState({
  735. curShareCardImgType: str,
  736. curShareCardImg: filePath
  737. })
  738. ctx.clearRect(0, 0, cvs.width, cvs.height)
  739. Taro.hideLoading()
  740. wx.showShareImageMenu({
  741. path: filePath,
  742. success: res => {
  743. console.log(res, 11);
  744. }
  745. })
  746. },
  747. fail: err => {
  748. // 此处可能存在内存满了的情况
  749. // 需要根据具体需求处理
  750. console.log(err);
  751. Taro.hideLoading()
  752. }
  753. });
  754. fs.close()
  755. }
  756. async drawAndShareImage (str) {
  757. const { curObj, curShareCardImg, curShareCardImgType } = this.state
  758. if (curShareCardImg) {
  759. if (curShareCardImgType === str) {
  760. wx.showShareImageMenu({
  761. path: curShareCardImg,
  762. success: res => {
  763. console.log(res, 22);
  764. }
  765. })
  766. } else {
  767. Taro.$msgConfirm('请返回上一层页面,再重新进入当前页面生成图片~')
  768. }
  769. return
  770. }
  771. const imageArr = (curObj.images || '').split(',')
  772. if (imageArr.length < 2) {
  773. Taro.$msgConfirm('房源图片不足~')
  774. return
  775. }
  776. Taro.showLoading({
  777. mask: true,
  778. title: '图片智能生成中..'
  779. })
  780. const that = this
  781. const cvs = Taro.createOffscreenCanvas({type: '2d', width: 700, height: 1516})
  782. const ctx = cvs.getContext('2d')
  783. ctx.clearRect(0, 0, cvs.width, cvs.height)
  784. ctx.rect(0 , 0 , cvs.width , cvs.height)
  785. ctx.fillStyle = "#fff"
  786. ctx.fill()
  787. let imgBg = cvs.createImage();
  788. // imgBg.src = require('./img/dtl/bg_room_dtl.jpg')
  789. imgBg.src = 'https://img.honglounews.com/20260107092402-3240.jpg_adm0?r='+ Math.random()
  790. await new Promise(resolve => {
  791. imgBg.onload = resolve;
  792. })
  793. ctx.drawImage(imgBg, 0, 0, 700, 1516)
  794. let img1 = cvs.createImage();
  795. await new Promise(resolve => {
  796. img1.onload = resolve;
  797. img1.src = curObj.pri_image + '_adm0'
  798. })
  799. ctx.drawImage(img1, 0, 530, 345, 286)
  800. let img2 = cvs.createImage();
  801. await new Promise(resolve => {
  802. img2.onload = resolve;
  803. img2.src = curObj.house_img
  804. })
  805. ctx.drawImage(img2, 356, 530, 345, 286)
  806. let img3 = cvs.createImage();
  807. await new Promise(resolve => {
  808. img3.onload = resolve;
  809. img3.src = imageArr[0] + '_adm0'
  810. })
  811. ctx.drawImage(img3, 0, 828, 345, 286)
  812. let img4 = cvs.createImage();
  813. await new Promise(resolve => {
  814. img4.onload = resolve;
  815. img4.src = imageArr[1] + '_adm0'
  816. })
  817. ctx.drawImage(img4, 356, 828, 345, 286)
  818. that.drawCenterText(ctx, '#343434', curObj.title.length > 25 ? curObj.title.substring(0, 25) + '...' : curObj.title, 350, 460, '28px')
  819. if (str === 'hide') {
  820. that.drawCenterText(ctx, '#333', '详情咨询巴老师', 350, 255, 'normal bold 70px')
  821. } else {
  822. if (curObj.estate_name.length > 10) {
  823. that.drawCenterText(ctx, '#343434', curObj.estate_name, 350, 255, 'normal bold 30px')
  824. } else if (curObj.estate_name.length > 7) {
  825. that.drawCenterText(ctx, '#343434', curObj.estate_name, 350, 255, 'normal bold 56px')
  826. } else {
  827. that.drawCenterText(ctx, '#343434', curObj.estate_name, 350, 255, 'normal bold 70px')
  828. }
  829. }
  830. that.drawText(ctx, '#ff2400', curObj.area, 170, 390, 'normal bold 80px')
  831. that.drawText(ctx, '#ff2400', curObj.price, 380, 390, 'normal bold 80px')
  832. // let base64 = ctx.canvas.toDataURL("image/png")
  833. // that.setState({
  834. // curShareCardImg: base64
  835. // })
  836. // that.popupOpen()
  837. setTimeout(() => {
  838. imgBg = null
  839. img1 = null
  840. img2 = null
  841. img3 = null
  842. img4 = null
  843. Taro.hideLoading()
  844. }, 6000)
  845. const imgData = cvs.toDataURL();
  846. const time = new Date().getTime();
  847. const fs = wx.getFileSystemManager();
  848. const filePath = Taro.env.USER_DATA_PATH + "/poster" + time + "share" + ".png";
  849. fs.writeFile({
  850. filePath,
  851. data: imgData.replace(/^data:image\/\w+;base64,/, ""),
  852. encoding: 'base64',
  853. success: res => {
  854. that.setState({
  855. curShareCardImgType: str,
  856. curShareCardImg: filePath
  857. })
  858. ctx.clearRect(0, 0, cvs.width, cvs.height)
  859. Taro.hideLoading()
  860. wx.showShareImageMenu({
  861. path: filePath,
  862. success: res => {
  863. console.log(res, 11);
  864. }
  865. })
  866. },
  867. fail: err => {
  868. // 此处可能存在内存满了的情况
  869. // 需要根据具体需求处理
  870. console.log(err);
  871. Taro.hideLoading()
  872. }
  873. });
  874. fs.close()
  875. }
  876. drawText = (ctx, color, text, x, y, font) => {
  877. ctx.font=`${font} Microsoft YaHei`;
  878. ctx.fillStyle = color;
  879. ctx.textAlign = 'left';
  880. ctx.fillText(text, x, y);
  881. ctx.stroke();
  882. ctx.closePath();
  883. }
  884. drawCenterText = (ctx, color, text, x, y, font) => {
  885. ctx.font=`${font} Microsoft YaHei`;
  886. ctx.fillStyle = color;
  887. ctx.textAlign = 'center'; // 修改为居中对齐
  888. ctx.fillText(text, x, y);
  889. ctx.stroke();
  890. ctx.closePath();
  891. }
  892. renderShare () {
  893. const iconShare = require('@img/images/icon_g_share6s.png')
  894. return (
  895. <Button className="g-icon-share btn-to-div" onClick={this.drawAndShareImage.bind(this, 'normal')}>
  896. <Image className="img" src={iconShare} />
  897. </Button>
  898. )
  899. }
  900. renderShare2 () {
  901. const iconShare = require('@img/images/icon_g_share6s2.png')
  902. return (
  903. <Button className="g-icon-share b2 btn-to-div" onClick={this.drawAndShare2Image.bind(this, 'hide')}>
  904. <Image className="img" src={iconShare} />
  905. </Button>
  906. )
  907. }
  908. renderFixedTopLift () {
  909. const iconSignLeft = require('@img/icon_sign_left.png')
  910. return (
  911. <View className="g-fixed-top-left" onClick={this.goBackPrev.bind(this)}>
  912. <Image className="img" src={iconSignLeft} />
  913. </View>
  914. )
  915. }
  916. goBackPrev () {
  917. // 获取当前页面栈
  918. const pages = Taro.getCurrentPages()
  919. // 判断是否有上一页
  920. const hasPreviousPage = pages.length > 1
  921. if (hasPreviousPage) {
  922. // 如果有上一页,使用 navigateBack 返回至上一页
  923. Taro.navigateBack({
  924. delta: 1,
  925. })
  926. } else {
  927. // 若无上一页,可以导航至指定的其它页面或首页
  928. Taro.navigateTo({
  929. url: '/pages/index/index',
  930. })
  931. }
  932. }
  933. renderOptionsDkSchool () {
  934. const { curObj } = this.state
  935. return (
  936. <View className="dtl-options scoped-school">
  937. <View className="do-title">
  938. <View className="t">对口学校</View>
  939. <View className="r2">注:目前该楼盘在此学区中</View>
  940. </View>
  941. {this.renderDkSchool()}
  942. </View>
  943. )
  944. }
  945. renderDkSchool () {
  946. const { curObj } = this.state
  947. const dictData = Taro.getStorageSync('dictData')
  948. const arr = curObj.school_list && curObj.school_list.duikou || []
  949. const curItems = arr.map((item, index) => {
  950. return (
  951. <Navigator url={'/pagesSchool/indexDtl?id=' + item.id} className="lb-item" key={index}>
  952. <View className="lb-img">
  953. <Image className="img" src={item.pri_image + '_xs'} />
  954. </View>
  955. <View className="lb-info">
  956. <View className="lb-p1">{item.school_name}</View>
  957. <View className="lb-p2">{item.address}</View>
  958. <View className="lb-tag">
  959. <View className="t t1">{arrToObj(dictData.school_attrib)[item.school_attrib]}</View>
  960. <View className="t t4">{arrToObj(dictData.school_type)[item.school_type]}</View>
  961. </View>
  962. </View>
  963. </Navigator>
  964. )
  965. })
  966. return (
  967. <View className="l-list-box t2">
  968. {curItems}
  969. </View>
  970. )
  971. }
  972. render () {
  973. const userInfo = Taro.getStorageSync('APP_userInfo') || {}
  974. const { curObj } = this.state
  975. return (
  976. <View className="l-box has-footer">
  977. {this.renderFixedTopLift()}
  978. {this.renderHeader()}
  979. {this.renderMain()}
  980. {this.renderImg()}
  981. {this.renderAround()}
  982. {this.renderOptionsDkSchool()}
  983. {(curObj.es_house_list && curObj.es_house_list.length > 0) && this.renderOther()}
  984. {this.renderSale()}
  985. {this.renderPopup()}
  986. {this.renderShare()}
  987. {userInfo.is_sale == 1 ? this.renderShare2() : ''}
  988. </View>
  989. )
  990. }
  991. }
  992. export default Index