indexDtlAround.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. import Taro, { Component } from '@tarojs/taro'
  2. import { View, Map } from '@tarojs/components'
  3. import { arrToObj } from '@utils'
  4. var QQMapWX = require('@js/qqmap-wx-jssdk.js')
  5. import ListMore from '@/c/pageDataList/listMore'
  6. var qqmapsdk
  7. import './indexDtlAround.scss'
  8. class Index extends Component {
  9. onShareAppMessage() {
  10. const { id, name } = this.$router.params
  11. return {
  12. title: `${name}-楼盘详情-洪楼Plus`,
  13. path: `/pagesHouse/indexDtl?id=${id}`,
  14. }
  15. }
  16. onShareTimeline () {
  17. return {
  18. title: '让买房,更省心!',
  19. }
  20. }
  21. constructor (props) {
  22. super(props)
  23. const {id: curId} = this.$router.params
  24. this.state = {
  25. curId,
  26. curObj: {},
  27. aroundArr: [],
  28. posIndex: 0,
  29. isPosMoreShow: true,
  30. markers: [],
  31. markerLabelIndex: -1,
  32. markersNameArr: ['地铁', '公交', '公园', '医院', '购物']
  33. }
  34. }
  35. config = {
  36. navigationBarTitleText: '周边配套',
  37. }
  38. componentWillMount () {
  39. const { name } = this.$router.params
  40. Taro.setNavigationBarTitle({
  41. title: name + '-周边配套' || '周边配套'
  42. })
  43. this.getDtl()
  44. qqmapsdk = new QQMapWX({
  45. key: '5WFBZ-LCZ3J-D5AFM-KNUUL-BTT46-45BWB'
  46. })
  47. }
  48. getDtl = () => {
  49. const { curId, markersNameArr } = this.state
  50. Taro.api.house.admestatedetail({id: curId}).then(obj => {
  51. const curObj = obj || {}
  52. this.setState({
  53. curObj,
  54. aroundArr: []
  55. }, () => {
  56. Taro.api.house.apiestateperipherydata({estate_id: curId}).then(eObj => {
  57. if (eObj.periphery) {
  58. this.setState({
  59. aroundArr: JSON.parse(eObj.periphery)
  60. })
  61. } else {
  62. let aroundTags = markersNameArr
  63. this.getAroundInfo(aroundTags)
  64. }
  65. })
  66. // let aroundTags = ['餐饮', '购物', '公园', '银行']
  67. })
  68. })
  69. }
  70. getMarker () {
  71. let markers = []
  72. const { posIndex, aroundArr, curObj, markerLabelIndex } = this.state
  73. let newAround = aroundArr.length > 0 ? aroundArr[posIndex].list : []
  74. markers.push({
  75. longitude: curObj.longitude,
  76. latitude: curObj.latitude,
  77. iconPath: 'http://icon.honglounews.com/g_map_pos.png',
  78. width: '30px',
  79. height: '30px',
  80. zIndex: 9999,
  81. label: {
  82. content: curObj.estate_name,
  83. color: '#333',
  84. fontSize: 12,
  85. // // anchorX: -(0.5 * (5 * 24))/2,
  86. anchorY: -56,
  87. textAlign: 'center',
  88. bgColor: '#fff',
  89. padding: 5,
  90. borderRadius: 5,
  91. borderColor: '#f2f2f2',
  92. borderWidth: 1,
  93. }
  94. })
  95. newAround.forEach((item, curIndex) => {
  96. let iconPath = 'http://icon.honglounews.com/icon_ex2.png'
  97. if (posIndex === 0) iconPath = 'http://icon.honglounews.com/g_map_0.png'
  98. if (posIndex === 1) iconPath = 'http://icon.honglounews.com/g_map_1.png'
  99. if (posIndex === 2) iconPath = 'http://icon.honglounews.com/g_map_2.png'
  100. if (posIndex === 3) iconPath = 'http://icon.honglounews.com/g_map_3.png'
  101. if (posIndex === 4) iconPath = 'http://icon.honglounews.com/g_map_4.png'
  102. if (posIndex === 5) iconPath = 'http://icon.honglounews.com/g_map_5.png'
  103. let obj = {
  104. longitude: String(item.location.lng),
  105. latitude: String(item.location.lat),
  106. iconPath,
  107. width: '28px',
  108. height: '28px',
  109. zIndex: 999,
  110. }
  111. if (curIndex === markerLabelIndex)
  112. obj.label = {
  113. content: item.title,
  114. color: '#333',
  115. fontSize: 12,
  116. anchorX: -(0.5 * (5 * 28))/2,
  117. anchorY: -56,
  118. textAlign: 'center',
  119. bgColor: '#fff',
  120. padding: 5,
  121. borderRadius: 5,
  122. borderColor: '#f2f2f2',
  123. borderWidth: 1,
  124. }
  125. markers.push(obj)
  126. })
  127. this.setState({
  128. markers
  129. })
  130. }
  131. getAroundInfo (aroundTags) {
  132. const { curObj, curId, markersNameArr } = this.state
  133. let aroundInfoTemp = []
  134. aroundTags.forEach((keyword, keywordIndex) => {
  135. aroundInfoTemp.push(
  136. new Promise((resolve, reject) => {
  137. let keywordParams = {
  138. keyword,
  139. address_format: 'short',
  140. page_size: '30',
  141. location: {
  142. latitude: curObj.latitude,
  143. longitude: curObj.longitude
  144. },
  145. success: function (res) {
  146. let cData = res.data || []
  147. qqmapsdk.calculateDistance({
  148. mode: 'driving',
  149. from: {
  150. latitude: curObj.latitude,
  151. longitude: curObj.longitude
  152. },
  153. to: cData,
  154. success: (distance) => {
  155. if (distance.status === 0) {
  156. const elements = distance.result.elements || []
  157. let list = []
  158. elements.map((eItem, eI) => {
  159. let num = 3000
  160. // if (keywordIndex === 0) num = 1000
  161. // if (keywordIndex === 1) num = 1000
  162. if (eItem.distance < num) {
  163. list.push({
  164. ...cData[eI],
  165. distance: eItem.distance,
  166. duration: eItem.duration,
  167. })
  168. }
  169. })
  170. return resolve({keyword, list})
  171. }
  172. },
  173. fail: function (res) {
  174. return reject(res)
  175. }
  176. })
  177. },
  178. fail: function (res) {
  179. return reject(res)
  180. }
  181. }
  182. // if (keywordIndex === 2) keywordParams.filter = 'category=小学,中学'
  183. qqmapsdk.search(keywordParams)
  184. })
  185. )
  186. })
  187. Promise.all(aroundInfoTemp).then(res => {
  188. const curRes = res || []
  189. let aroundArr = []
  190. curRes.map((item, index) =>{
  191. if (item.list.length > 0) {
  192. aroundArr.push({...item})
  193. } else {
  194. aroundArr.push({
  195. keyword: markersNameArr[index],
  196. list: []
  197. })
  198. }
  199. })
  200. let csl = curObj.school_list || {}
  201. const schoolList = [...csl.duikou, ...csl.guihua]
  202. const schoolArr = schoolList.map(slItem => {
  203. return {
  204. title: slItem.school_name,
  205. address: slItem.address,
  206. location: {
  207. lat: Number(slItem.latitude),
  208. lng: Number(slItem.longitude),
  209. }
  210. }
  211. })
  212. aroundArr.unshift({
  213. keyword: '学校',
  214. list: schoolArr
  215. })
  216. this.setState({
  217. aroundArr
  218. }, () => {
  219. this.getMarker()
  220. })
  221. Taro.api.house.apiestateperipheryadd({
  222. estate_id: curId,
  223. periphery: JSON.stringify(aroundArr)
  224. }).then(eObj => {
  225. // console.log(eObj)
  226. })
  227. })
  228. }
  229. componentDidShow () { }
  230. componentDidHide () { }
  231. posMoreHandle (str) {
  232. this.setState({
  233. isPosMoreShow: str === 'down' ? false : true
  234. })
  235. }
  236. renderOptionsInfo () {
  237. const { aroundArr, posIndex, isPosMoreShow } = this.state
  238. const icon0 = require('./img/map/school0.png')
  239. const icon0c = require('./img/map/school1.png')
  240. const icon1 = require('./img/map/subway0.png')
  241. const icon1c = require('./img/map/subway1.png')
  242. const icon2 = require('./img/map/bus0.png')
  243. const icon2c = require('./img/map/bus1.png')
  244. const icon3 = require('./img/map/park0.png')
  245. const icon3c = require('./img/map/park1.png')
  246. const icon4 = require('./img/map/hospital0.png')
  247. const icon4c = require('./img/map/hospital1.png')
  248. const icon5 = require('./img/map/shop0.png')
  249. const icon5c = require('./img/map/shop1.png')
  250. const iconDown = require('./img/map/down.png')
  251. const iconUp = require('./img/map/up.png')
  252. const lebelPos = require('./img/map/label_pos.png')
  253. const curMoreList = aroundArr[posIndex] && aroundArr[posIndex].list.length > 0 ? aroundArr[posIndex].list : []
  254. return (
  255. <View className="scoped-options">
  256. {
  257. isPosMoreShow
  258. ? <Image src={iconDown} className="so-icon-updown" onClick={this.posMoreHandle.bind(this, 'down')}/>
  259. : <Image src={iconUp} className="so-icon-updown" onClick={this.posMoreHandle.bind(this, 'up')}/>
  260. }
  261. <View className="so-wrap">
  262. {
  263. aroundArr.map((one, oneIndex) => {
  264. let str = icon0
  265. if (oneIndex === 0) str = oneIndex === posIndex ? icon0c : icon0
  266. if (oneIndex === 1) str = oneIndex === posIndex ? icon1c : icon1
  267. if (oneIndex === 2) str = oneIndex === posIndex ? icon2c : icon2
  268. if (oneIndex === 3) str = oneIndex === posIndex ? icon3c : icon3
  269. if (oneIndex === 4) str = oneIndex === posIndex ? icon4c : icon4
  270. if (oneIndex === 5) str = oneIndex === posIndex ? icon5c : icon5
  271. return (
  272. <View className="so-item" key={oneIndex}>
  273. <View className={oneIndex === posIndex ? 'so-title cur' : 'so-title'} onClick={this.navChange.bind(this, oneIndex)}>
  274. <Image src={str} className="img"/>
  275. <View className="t">{one.keyword}</View>
  276. </View>
  277. </View>
  278. )
  279. })
  280. }
  281. </View>
  282. {
  283. isPosMoreShow
  284. &&
  285. <View className="so-content">
  286. {
  287. curMoreList.map((two, twoIndex) => {
  288. return (
  289. <View className="so-p" key={twoIndex} onClick={this.posLabelHandle.bind(this, twoIndex)}>
  290. <View className="p1">{two.title}</View>
  291. <View className="p2">{two.address} </View>
  292. {
  293. posIndex > 0
  294. &&
  295. <View className="r1"><Image src={lebelPos} className="i"/>{two._distance}米</View>
  296. }
  297. {
  298. posIndex > 2
  299. &&
  300. <View className="r2">开车约:{(two.duration / 60).toFixed(0)}分钟</View>
  301. }
  302. </View>
  303. )
  304. })
  305. }
  306. {
  307. curMoreList.length === 0
  308. &&
  309. <ListMore isOther={true} />
  310. }
  311. </View>
  312. }
  313. </View>
  314. )
  315. }
  316. posLabelHandle (index) {
  317. this.setState({
  318. markerLabelIndex: index
  319. }, () => {
  320. this.getMarker()
  321. })
  322. }
  323. previewImageHandle (cur, arr) {
  324. const current = `${cur}_plus`
  325. const urls = arr.map(item => {
  326. return `${item.img_url}_plus`
  327. })
  328. Taro.previewImage({
  329. current,
  330. urls
  331. })
  332. }
  333. navChange (posIndex) {
  334. this.setState({
  335. posIndex,
  336. markerLabelIndex: -1,
  337. }, () => {
  338. this.getMarker()
  339. })
  340. }
  341. renderPos () {
  342. const { curObj, isPosMoreShow, markers } = this.state
  343. return (
  344. <View className="scoped-list-map">
  345. <Map
  346. className={isPosMoreShow ? 'm t2' : 'm'}
  347. longitude={curObj.longitude}
  348. latitude={curObj.latitude}
  349. scale="14"
  350. markers={markers}
  351. show-compass={true}
  352. />
  353. </View>
  354. )
  355. }
  356. render () {
  357. const { aroundArr } = this.state
  358. return (
  359. <View className="l-box">
  360. {
  361. aroundArr.length > 0
  362. &&
  363. this.renderPos()
  364. }
  365. {this.renderOptionsInfo()}
  366. </View>
  367. )
  368. }
  369. }
  370. export default Index