index.jsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import Taro, { Component } from '@tarojs/taro'
  2. import { View, Image } from '@tarojs/components'
  3. import { arrToObj } from '@utils'
  4. import './index.scss'
  5. export default class List extends Component {
  6. constructor (props) {
  7. super(props)
  8. this.state = {
  9. curObj: {},
  10. navVal: 'ld',
  11. }
  12. }
  13. componentWillMount () {
  14. this.props.onRef(this)
  15. }
  16. getData = (curObj) => {
  17. this.setState({
  18. curObj,
  19. navVal: curObj.vr_key ? 'hp' : 'ld'
  20. })
  21. }
  22. pkHandle () {
  23. const { curObj } = this.state
  24. let oldPkList = Taro.getStorageSync('APP_pkList') || []
  25. let addFalg = true
  26. oldPkList.forEach(item => {
  27. if (String(item.id) === String(curObj.id)) {
  28. addFalg = false
  29. }
  30. })
  31. if (addFalg) {
  32. Taro.api.house.admestatesimple({id: curObj.id}).then(res => {
  33. oldPkList.unshift(res)
  34. if (oldPkList.length > 19) oldPkList.splice(19, 1)
  35. Taro.setStorageSync('APP_pkList', oldPkList)
  36. Taro.navigateTo({
  37. url: '/pagesHouse/pkList'
  38. })
  39. })
  40. } else {
  41. Taro.navigateTo({
  42. url: '/pagesHouse/pkList'
  43. })
  44. }
  45. }
  46. headerImgChange (e) {
  47. this.setState({
  48. curImgIndex: e.detail.current || 0
  49. })
  50. }
  51. previewImageHandle (cur, arr) {
  52. const current = `${cur}_plus`
  53. const urls = arr.map(item => {
  54. return `${item}_plus`
  55. })
  56. Taro.previewImage({
  57. current,
  58. urls
  59. })
  60. }
  61. renderNav () {
  62. const { curObj, navVal } = this.state
  63. let navArr = curObj.vr_key ? [{name: '航拍', val: 'hp'}, {name: '楼栋图', val: 'ld'}, {name: '图片', val: 'tp'}] : [{name: '楼栋图', val: 'ld'}, {name: '图片', val: 'tp'}]
  64. const curItems = navArr.map((item, index) => {
  65. return (
  66. <View className={navVal === item.val ? 'op cur' : 'op'} key={index} onClick={this.navClick.bind(this, item)}>{item.name}</View>
  67. )
  68. })
  69. return (
  70. <View className={curObj.vr_key ? 'sh-nav' : 'sh-nav t2'}>
  71. <View className="main">
  72. <View className="bg"></View>
  73. <View className="content">
  74. {curItems}
  75. </View>
  76. </View>
  77. </View>
  78. )
  79. }
  80. navClick (item) {
  81. if (item.val === 'tp') {
  82. const { curObj } = this.state
  83. Taro.navigateTo({
  84. url: `/pagesHouse/photo?id=${curObj.id}&name=${curObj.estate_naem}`
  85. })
  86. } else {
  87. this.setState({
  88. navVal: item.val
  89. })
  90. }
  91. }
  92. render () {
  93. const { curObj, navVal } = this.state
  94. const iconPk = require('./img/PK.png')
  95. const iconShare = require('./img/share.png')
  96. const ed1 = require('./img/bg_ed1.png')
  97. const ed2 = require('./img/bg_ed2.png')
  98. const hpI1 = require('@img/icon_hp_1.png')
  99. const vrhx = require('@img/icon_vr.png')
  100. const hpI2 = require('@img/icon_hp_2.gif')
  101. const iconView = require('@img/icon_g_eye.png')
  102. return (
  103. <View className="scoped-header">
  104. {
  105. curObj.view_count
  106. ?
  107. <View className="view-num">
  108. <View className="bg"></View>
  109. <View className="content">
  110. <Image src={iconView} className="i" />
  111. <View className="t">{String((curObj.view_count * 11 + 1000) / 10000).substring(0, 4)}w</View>
  112. </View>
  113. </View>
  114. : ''
  115. }
  116. {
  117. curObj.tagDefine1 === '现房'
  118. ? <Image src={ed1} className="bg-t-r" />
  119. : ''
  120. }
  121. {
  122. curObj.tagDefine1 === '准现房'
  123. ? <Image src={ed2} className="bg-t-r" />
  124. : ''
  125. }
  126. {
  127. curObj.custom_tag && curObj.custom_tag.indexOf('户型VR') > -1
  128. ?
  129. <Navigator url={'/pagesHouse/produceType?id=' + curObj.id + '&name=' + curObj.estate_name} className="scoped-hx-vr">
  130. <View className="text">
  131. <View className="bg"></View>
  132. <View className="t">户型VR</View>
  133. </View>
  134. <Image src={vrhx} className="i" />
  135. </Navigator>
  136. : ''
  137. }
  138. {
  139. navVal === 'hp'
  140. ?
  141. <Navigator url={`/pagesHouse/vr?id=${curObj.vr_key}&estateName=${curObj.estate_name}`} className="sh-img">
  142. <View className="icon">
  143. <Image src={hpI1} className="i i1" />
  144. <Image src={hpI2} className="i i2" />
  145. </View>
  146. <Image src={curObj.vr_image} className="img" />
  147. </Navigator>
  148. : ''
  149. }
  150. {
  151. navVal === 'ld'
  152. ?
  153. <View className="sh-img">
  154. <Image src={curObj.pri_image ? curObj.pri_image + '_white' : ''} className="img" onClick={this.previewImageHandle.bind(this, curObj.pri_image, [curObj.pri_image])} />
  155. </View>
  156. : ''
  157. }
  158. <View className="sh-icon-right pk" onClick={this.pkHandle.bind(this)}>
  159. <Image className="img" src={iconPk} />
  160. </View>
  161. <Button className="sh-icon-right btn-to-div" openType="share">
  162. <Image className="img" src={iconShare} />
  163. </Button>
  164. {this.renderNav()}
  165. </View>
  166. )
  167. }
  168. }