import Taro, { Component } from '@tarojs/taro' import { View, Swiper, SwiperItem, Navigator } from '@tarojs/components' import { AtCurtain } from 'taro-ui' import { arrToObj } from '@utils' import Rooms from './components/dtl/rooms' import Around from './components/dtl/around' import './dtl.scss' class Index extends Component { onShareAppMessage() { const userInfo = Taro.getStorageSync('APP_userInfo') || {} const { curId, curObj } = this.state if (userInfo.is_sale == 1) { return { title: `${userInfo.nickname}给您推荐:${curObj.title}`, path: `/pagesRoom/dtl?id=${curId}&referrer=${userInfo.user_id}`, } } else { return { title: `${curObj.title}`, path: `/pagesRoom/dtl?id=${curId}`, } } } onShareTimeline () { const userInfo = Taro.getStorageSync('APP_userInfo') || {} const { curId, curObj } = this.state if (userInfo.is_sale == 1) { return { title: `${userInfo.nickname}给您推荐:${curObj.title}`, path: `/pagesRoom/dtl?id=${curId}&referrer=${userInfo.user_id}`, } } else { return { title: `${curObj.title}`, path: `/pagesRoom/dtl?id=${curId}`, } } } constructor (props) { super(props) const {id: curId} = this.$router.params this.state = { referrer: '', saleUserObj: {}, curId, curObj: {}, curImgIndex: 0, // curShareCardImg: require('./img/dtl/bg_room_dtl.png') curShareCardImg: '', curShareCardImgType: '', } } config = { // navigationBarTitleText: '房源详情', navigationStyle: 'custom', navigationBarTextStyle: 'white', } componentWillMount () { Taro.$AHU(this) this.getDtl() Taro.removeStorageSync('APP_MY_REFERRER') const {referrer} = this.$router.params if (referrer) { this.setState({ referrer }) Taro.removeStorageSync('APP_cur_sale') Taro.setStorageSync("APP_MY_REFERRER", referrer) } } getDtl = () => { const { curId } = this.state Taro.api.room.apieshousedetail({id: curId}).then(res => { // Taro.setNavigationBarTitle({ // title: res.title || '房源详情' // }) this.setState({ curObj: res || {} }, () =>{ if (this.subRooms) this.subRooms.getData(res.es_house_list || []) if (this.subAround) this.subAround.getData(res.estate_id) const {referrer} = this.$router.params if (referrer) { Taro.api.room.apisalelist({ show_status: 1, referrer }).then(res => { const list = res.list || [] if (list.length > 0) { this.setState({ saleUserObj: list[0] }) } else { if (res.sale_user.sale_phone === '18907904022') { Taro.api.room.apisalelist({ show_status: 1, page_size: 99 }).then(res => { const list = res.list || [] const arrIndex = Math.floor(Math.random() * list.length) this.setState({ saleUserObj: list[arrIndex], }) Taro.setStorageSync('APP_cur_sale', {curObj: list[arrIndex]}) }) } else { this.setState({ saleUserObj: res.sale_user }) } } }) } else { if (res.sale_user.sale_phone === '18907904022') { Taro.api.room.apisalelist({ show_status: 1, page_size: 99 }).then(res => { const list = res.list || [] const arrIndex = Math.floor(Math.random() * list.length) this.setState({ saleUserObj: list[arrIndex], }) Taro.setStorageSync('APP_cur_sale', {curObj: list[arrIndex]}) }) } else { this.setState({ saleUserObj: res.sale_user }) } } }) }) } 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] return ( { curObj.video ? : '' } { imgArr.map((item, index) => { return ( ) }) } {curImgIndex + 1}-{imgArr.length + (curObj.video ? 1 : 0)} ) } 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 }) } editHandle () { const { curId } = this.state const appUserInfo = Taro.getStorageSync('APP_userInfo') if (appUserInfo.is_sale == 1) { Taro.navigateTo({ url: `/pagesMore/center/uploadRoom2?id=${curId}` }) } } renderMain () { const signRight = require('@img/icon_sign_right.png') const dictData = Taro.getStorageSync('dictData') const atObj = arrToObj(dictData.area_type) const hryObj = arrToObj(dictData.house_room_year) const roomDecObj = arrToObj(dictData.room_dec) const roomPositionObj = arrToObj(dictData.room_position) const { curObj } = this.state const tagArr = curObj.custom_tag ? curObj.custom_tag.split(',') : [] const moreImg = require('./img/dtl/bg_estate.png') const FH = Number(curObj.floor) || 1 const H = Number(curObj.storeys) || 1 let FHstr = '未知' if (FH > H * 0.6666) { FHstr = '中高层' } else if (FH > H * 0.33333) { FHstr = '中楼层' } else { FHstr = '中低层' } if (FH === 1) FHstr = '低层' if (FH === H) FHstr = '高层' let houseTypeStr = '未知' if (curObj.house_type) { let arr = curObj.house_type.split('-') houseTypeStr = `${arr[0]}室${arr[1]}厅${arr[2]}卫` } const stairsRateArr = curObj.stairs_rate ? curObj.stairs_rate.split('-') : [] const appUserInfo = Taro.getStorageSync('APP_userInfo') const schoolList = curObj.school_list && curObj.school_list.duikou ? curObj.school_list.duikou : [] // {arrToObj(dictData.school_attrib)[item.school_attrib]} // {arrToObj(dictData.school_type)[item.school_type]} const schoolViews = schoolList.map((item) => { return ( {`${item.school_name}[${arrToObj(dictData.school_attrib)[item.school_attrib]}][${arrToObj(dictData.school_type)[item.school_type]}]`} ) }) // console.log(schoolStrList) return ( {/* {this.renderQrcode()} */} { appUserInfo.is_sale == 1 ? {curObj.id}跟进记录 : '' } { tagArr.map((tag, tI) => { return ( {tag} ) }) } {curObj.title} {curObj.price}万 售价 {houseTypeStr} 房型 {curObj.area}㎡ 建筑面积 学区 {schoolViews} {/* */} 单价 {parseInt(curObj.price * 10000 / curObj.area)}元/㎡ 楼层 {FHstr}/{curObj.storeys}层 咨询楼层 满几 {hryObj[curObj.full_year] || '未知'} 装修 {roomDecObj[curObj.is_dec]} 交房 {curObj.delivery_at || '未知'} 电梯 {curObj.is_elevator == 1 ? '有电梯' : '无电梯'} 梯户 {stairsRateArr.length > 0 ? `${stairsRateArr[0]}梯${stairsRateArr[1]}户` : '未知'} 方位 {curObj.position ? roomPositionObj[curObj.position] : '未知'} {/* 预约 房东底价?朝向梯户比?【免费咨询】 */} 区域 {atObj[curObj.area_type]} 查看周边配套 其它 房东底价?套内面积 免费咨询 楼盘 {curObj.estate_name} {/* 查看该楼盘 */} 成交 查看近期成交价 { curObj.introduce && 简介 {curObj.introduce} } ) } 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}` const urls = [`${curObj.house_img}`] Taro.previewImage({ current, urls }) } renderAround () { const { curObj } = this.state return ( 周边配套 ) } refAround = (ref) => { this.subAround = ref } 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}&qId=${curObj.id}` }) } 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, saleUserObj } = this.state let saleObj = saleUserObj || {} const tagStr = saleObj.custom_tag ? saleObj.custom_tag.substring(0, 8) : '' return ( {saleObj.sale_name} {tagStr} 在线问 打电话 ) } renderPopup () { const { isPopupShow, curShareCardImg } = this.state return ( ) } popupClose () { this.setState({ isPopupShow: false }) } popupOpen () { this.setState({ isPopupShow: true }) } dealCanvasImg (qrcodeSrc) { const { curObj } = this.state const that = this const imageArr = (curObj.images || '').split(',') const processMultipleImages = (url) => { return new Promise((resolve, reject) => { Taro.getImageInfo({ src: url, success: (res) => { resolve(res) }, fail: () => { Taro.showToast({ title: '下载失败!' }) } }) }) } Promise.all( imageArr.map(img => processMultipleImages(img+'_adm0')) ).then(img => { let tempImgArr = img.map(i => i.path) that.dealCanvas(tempImgArr) }) } // drawAndSharetestImage () { // const { curObj } = this.state // const imageArr = (curObj.images || '').split(',') // if (imageArr.length < 2) { // Taro.$msgConfirm('房源图片不足~') // return // } // console.log(curObj) // const that = this // const cvs = Taro.createOffscreenCanvas({type: '2d', width: 700, height: 990}) // const ctx = cvs.getContext('2d') // ctx.clearRect(0, 0, cvs.width, cvs.height) // ctx.rect(0 , 0 , cvs.width , cvs.height) // ctx.fillStyle = "#fff" // ctx.fill() // let imgBg = cvs.createImage(); // imgBg.src = require('./img/dtl/bg_room_dtl.jpg') // imgBg.onload = () => { // ctx.drawImage(imgBg, 0, 0, 700, 990) // } // let img1 = cvs.createImage(); // img1.src = curObj.pri_image + '_adm0' // imgBg.onload = () => { // ctx.drawImage(img1, 83, 358, 256, 200) // } // let img2 = cvs.createImage(); // img2.src = curObj.house_img // imgBg.onload = () => { // ctx.drawImage(img2, 362, 358, 256, 200) // } // let img3 = cvs.createImage(); // img3.src = imageArr[0] + '_adm0' // imgBg.onload = () => { // ctx.drawImage(img3, 83, 570, 256, 200) // } // let img4 = cvs.createImage(); // img4.src = imageArr[1] + '_adm0' // imgBg.onload = () => { // ctx.drawImage(img4, 362, 570, 256, 200) // } // that.drawText(ctx, '#333', curObj.title.length > 25 ? curObj.title.substring(0, 25) + '...' : curObj.title, 98, 846, '18px') // if (curObj.estate_name.length > 7) { // that.drawText(ctx, '#333', curObj.estate_name, 80, 220, 'normal bold 36px') // } else { // that.drawText(ctx, '#333', curObj.estate_name, 80, 220, 'normal bold 56px') // } // that.drawText(ctx, '#333', curObj.area + '㎡', 140, 310, 'normal bold 28px') // that.drawText(ctx, '#df6135', curObj.floor_price + '万', 280, 310, 'normal bold 32px') // // let base64 = ctx.canvas.toDataURL("image/png") // // that.setState({ // // curShareCardImg: base64 // // }) // // that.popupOpen() // const imgData = cvs.toDataURL(); // console.log('imgData') // console.log(imgData) // const time = new Date().getTime(); // const fs = wx.getFileSystemManager(); // const filePath = Taro.env.USER_DATA_PATH + "/poster" + time + "share" + ".png"; // fs.writeFile({ // filePath, // data: imgData.replace(/^data:image\/\w+;base64,/, ""), // encoding: 'base64', // success: res => { // console.log('成功:'+res) // wx.showShareImageMenu({ // path: filePath, // success: res => { // console.log(res, 11); // } // }) // }, // fail: err => { // // 此处可能存在内存满了的情况 // // 需要根据具体需求处理 // console.log(err); // } // }); // fs.close() // } async drawAndShare2Image (str) { const { curObj, curShareCardImg, curShareCardImgType } = this.state if (curShareCardImg) { if (curShareCardImgType === str) { wx.showShareImageMenu({ path: curShareCardImg, success: res => { console.log(res, 22); } }) } else { Taro.$msgConfirm('请返回上一层页面,再重新进入当前页面生成图片~') } return } const imageArr = (curObj.images || '').split(',') if (imageArr.length < 2) { Taro.$msgConfirm('房源图片不足~') return } Taro.showLoading({ mask: true, title: '图片智能生成中..' }) const that = this const cvs = Taro.createOffscreenCanvas({type: '2d', width: 700, height: 1516}) const ctx = cvs.getContext('2d') ctx.clearRect(0, 0, cvs.width, cvs.height) ctx.rect(0 , 0 , cvs.width , cvs.height) ctx.fillStyle = "#fff" ctx.fill() let imgBg = cvs.createImage(); // imgBg.src = require('./img/dtl/bg_room_dtl.jpg') imgBg.src = 'https://img.honglounews.com/20260107092402-3240.jpg_adm0?r='+ Math.random() await new Promise(resolve => { imgBg.onload = resolve; }) ctx.drawImage(imgBg, 0, 0, 700, 1516) let img1 = cvs.createImage(); await new Promise(resolve => { img1.onload = resolve; img1.src = curObj.pri_image + '_adm0' }) ctx.drawImage(img1, 0, 530, 345, 286) let img2 = cvs.createImage(); await new Promise(resolve => { img2.onload = resolve; img2.src = curObj.house_img }) ctx.drawImage(img2, 356, 530, 345, 286) let img3 = cvs.createImage(); await new Promise(resolve => { img3.onload = resolve; img3.src = imageArr[0] + '_adm0' }) ctx.drawImage(img3, 0, 828, 345, 286) let img4 = cvs.createImage(); await new Promise(resolve => { img4.onload = resolve; img4.src = imageArr[1] + '_adm0' }) ctx.drawImage(img4, 356, 828, 345, 286) that.drawCenterText(ctx, '#343434', curObj.title.length > 25 ? curObj.title.substring(0, 25) + '...' : curObj.title, 350, 460, '28px') if (str === 'hide') { that.drawCenterText(ctx, '#333', '详情咨询巴老师', 350, 255, 'normal bold 70px') } else { if (curObj.estate_name.length > 10) { that.drawCenterText(ctx, '#343434', curObj.estate_name, 350, 255, 'normal bold 30px') } else if (curObj.estate_name.length > 7) { that.drawCenterText(ctx, '#343434', curObj.estate_name, 350, 255, 'normal bold 56px') } else { that.drawCenterText(ctx, '#343434', curObj.estate_name, 350, 255, 'normal bold 70px') } } // that.drawText(ctx, '#333', curObj.area + '㎡', 140, 310, 'normal bold 28px') // that.drawText(ctx, '#df6135', curObj.price + '万', 280, 310, 'normal bold 32px') that.drawText(ctx, '#ff2400', curObj.area, 170, 390, 'normal bold 80px') that.drawText(ctx, '#ff2400', curObj.price, 380, 390, 'normal bold 80px') // let base64 = ctx.canvas.toDataURL("image/png") // that.setState({ // curShareCardImg: base64 // }) // that.popupOpen() setTimeout(() => { imgBg = null img1 = null img2 = null img3 = null img4 = null Taro.hideLoading() }, 6000) const imgData = cvs.toDataURL(); const time = new Date().getTime(); const fs = wx.getFileSystemManager(); const filePath = Taro.env.USER_DATA_PATH + "/poster" + time + "share" + ".png"; fs.writeFile({ filePath, data: imgData.replace(/^data:image\/\w+;base64,/, ""), encoding: 'base64', success: res => { that.setState({ curShareCardImgType: str, curShareCardImg: filePath }) ctx.clearRect(0, 0, cvs.width, cvs.height) Taro.hideLoading() wx.showShareImageMenu({ path: filePath, success: res => { console.log(res, 11); } }) }, fail: err => { // 此处可能存在内存满了的情况 // 需要根据具体需求处理 console.log(err); Taro.hideLoading() } }); fs.close() } async drawAndShareImage (str) { const { curObj, curShareCardImg, curShareCardImgType } = this.state if (curShareCardImg) { if (curShareCardImgType === str) { wx.showShareImageMenu({ path: curShareCardImg, success: res => { console.log(res, 22); } }) } else { Taro.$msgConfirm('请返回上一层页面,再重新进入当前页面生成图片~') } return } const imageArr = (curObj.images || '').split(',') if (imageArr.length < 2) { Taro.$msgConfirm('房源图片不足~') return } Taro.showLoading({ mask: true, title: '图片智能生成中..' }) const that = this const cvs = Taro.createOffscreenCanvas({type: '2d', width: 700, height: 1516}) const ctx = cvs.getContext('2d') ctx.clearRect(0, 0, cvs.width, cvs.height) ctx.rect(0 , 0 , cvs.width , cvs.height) ctx.fillStyle = "#fff" ctx.fill() let imgBg = cvs.createImage(); // imgBg.src = require('./img/dtl/bg_room_dtl.jpg') imgBg.src = 'https://img.honglounews.com/20260107092402-3240.jpg_adm0?r='+ Math.random() await new Promise(resolve => { imgBg.onload = resolve; }) ctx.drawImage(imgBg, 0, 0, 700, 1516) let img1 = cvs.createImage(); await new Promise(resolve => { img1.onload = resolve; img1.src = curObj.pri_image + '_adm0' }) ctx.drawImage(img1, 0, 530, 345, 286) let img2 = cvs.createImage(); await new Promise(resolve => { img2.onload = resolve; img2.src = curObj.house_img }) ctx.drawImage(img2, 356, 530, 345, 286) let img3 = cvs.createImage(); await new Promise(resolve => { img3.onload = resolve; img3.src = imageArr[0] + '_adm0' }) ctx.drawImage(img3, 0, 828, 345, 286) let img4 = cvs.createImage(); await new Promise(resolve => { img4.onload = resolve; img4.src = imageArr[1] + '_adm0' }) ctx.drawImage(img4, 356, 828, 345, 286) that.drawCenterText(ctx, '#343434', curObj.title.length > 25 ? curObj.title.substring(0, 25) + '...' : curObj.title, 350, 460, '28px') if (str === 'hide') { that.drawCenterText(ctx, '#333', '详情咨询巴老师', 350, 255, 'normal bold 70px') } else { if (curObj.estate_name.length > 10) { that.drawCenterText(ctx, '#343434', curObj.estate_name, 350, 255, 'normal bold 30px') } else if (curObj.estate_name.length > 7) { that.drawCenterText(ctx, '#343434', curObj.estate_name, 350, 255, 'normal bold 56px') } else { that.drawCenterText(ctx, '#343434', curObj.estate_name, 350, 255, 'normal bold 70px') } } that.drawText(ctx, '#ff2400', curObj.area, 170, 390, 'normal bold 80px') that.drawText(ctx, '#ff2400', curObj.price, 380, 390, 'normal bold 80px') // let base64 = ctx.canvas.toDataURL("image/png") // that.setState({ // curShareCardImg: base64 // }) // that.popupOpen() setTimeout(() => { imgBg = null img1 = null img2 = null img3 = null img4 = null Taro.hideLoading() }, 6000) const imgData = cvs.toDataURL(); const time = new Date().getTime(); const fs = wx.getFileSystemManager(); const filePath = Taro.env.USER_DATA_PATH + "/poster" + time + "share" + ".png"; fs.writeFile({ filePath, data: imgData.replace(/^data:image\/\w+;base64,/, ""), encoding: 'base64', success: res => { that.setState({ curShareCardImgType: str, curShareCardImg: filePath }) ctx.clearRect(0, 0, cvs.width, cvs.height) Taro.hideLoading() wx.showShareImageMenu({ path: filePath, success: res => { console.log(res, 11); } }) }, fail: err => { // 此处可能存在内存满了的情况 // 需要根据具体需求处理 console.log(err); Taro.hideLoading() } }); fs.close() } drawText = (ctx, color, text, x, y, font) => { ctx.font=`${font} Microsoft YaHei`; ctx.fillStyle = color; ctx.textAlign = 'left'; ctx.fillText(text, x, y); ctx.stroke(); ctx.closePath(); } drawCenterText = (ctx, color, text, x, y, font) => { ctx.font=`${font} Microsoft YaHei`; ctx.fillStyle = color; ctx.textAlign = 'center'; // 修改为居中对齐 ctx.fillText(text, x, y); ctx.stroke(); ctx.closePath(); } renderShare () { const iconShare = require('@img/images/icon_g_share6s.png') return ( ) } renderShare2 () { const iconShare = require('@img/images/icon_g_share6s2.png') return ( ) } renderFixedTopLift () { const iconSignLeft = require('@img/icon_sign_left.png') return ( ) } goBackPrev () { // 获取当前页面栈 const pages = Taro.getCurrentPages() // 判断是否有上一页 const hasPreviousPage = pages.length > 1 if (hasPreviousPage) { // 如果有上一页,使用 navigateBack 返回至上一页 Taro.navigateBack({ delta: 1, }) } else { // 若无上一页,可以导航至指定的其它页面或首页 Taro.navigateTo({ url: '/pages/index/index', }) } } renderOptionsDkSchool () { const { curObj } = this.state return ( 对口学校 注:目前该楼盘在此学区中 {this.renderDkSchool()} ) } renderDkSchool () { const { curObj } = this.state const dictData = Taro.getStorageSync('dictData') const arr = curObj.school_list && curObj.school_list.duikou || [] const curItems = arr.map((item, index) => { return ( {item.school_name} {item.address} {arrToObj(dictData.school_attrib)[item.school_attrib]} {arrToObj(dictData.school_type)[item.school_type]} ) }) return ( {curItems} ) } render () { const userInfo = Taro.getStorageSync('APP_userInfo') || {} const { curObj } = this.state return ( {this.renderFixedTopLift()} {this.renderHeader()} {this.renderMain()} {this.renderImg()} {this.renderAround()} {this.renderOptionsDkSchool()} {(curObj.es_house_list && curObj.es_house_list.length > 0) && this.renderOther()} {this.renderSale()} {this.renderPopup()} {this.renderShare()} {userInfo.is_sale == 1 ? this.renderShare2() : ''} ) } } export default Index