index.jsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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' : curObj.video ? 'video' : '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. const baseNavItems = [{name: '楼栋图', val: 'ld'}, {name: '图片', val: 'tp'}]
  64. let navArr = [...baseNavItems]
  65. if (curObj.video) {
  66. navArr.unshift({name: '视频', val: 'video'})
  67. }
  68. if (curObj.vr_key) {
  69. navArr.unshift({name: '航拍', val: 'hp'})
  70. }
  71. const curItems = navArr.map((item, index) => {
  72. return (
  73. <View className={navVal === item.val ? 'op cur' : 'op'} key={index} onClick={this.navClick.bind(this, item)}>{item.name}</View>
  74. )
  75. })
  76. return (
  77. <View className={curObj.vr_key ? 'sh-nav' : 'sh-nav t2'}>
  78. <View className="main">
  79. <View className="bg"></View>
  80. <View className="content">
  81. {curItems}
  82. </View>
  83. </View>
  84. </View>
  85. )
  86. }
  87. navClick (item) {
  88. if (item.val === 'tp') {
  89. const { curObj } = this.state
  90. Taro.navigateTo({
  91. url: `/pagesHouse/photo?id=${curObj.id}&name=${curObj.estate_naem}`
  92. })
  93. } else {
  94. this.setState({
  95. navVal: item.val
  96. })
  97. }
  98. }
  99. render () {
  100. const { curObj, navVal } = this.state
  101. const iconPk = require('./img/PK.png')
  102. const iconShare = require('./img/share.png')
  103. const ed1 = require('./img/bg_ed1.png')
  104. const ed2 = require('./img/bg_ed2.png')
  105. const hpI1 = require('@img/icon_hp_1.png')
  106. const vrhx = require('@img/icon_vr.png')
  107. const hpI2 = require('@img/icon_hp_2.gif')
  108. const iconView = require('@img/icon_g_eye.png')
  109. return (
  110. <View className="scoped-header">
  111. {
  112. curObj.view_count
  113. ?
  114. <View className="view-num">
  115. <View className="bg"></View>
  116. <View className="content">
  117. <Image src={iconView} className="i" />
  118. <View className="t">{String((curObj.view_count * 11 + 1000) / 10000).substring(0, 4)}w</View>
  119. </View>
  120. </View>
  121. : ''
  122. }
  123. {
  124. curObj.tagDefine1 === '现房'
  125. ? <Image src={ed1} className="bg-t-r" />
  126. : ''
  127. }
  128. {
  129. curObj.tagDefine1 === '准现房'
  130. ? <Image src={ed2} className="bg-t-r" />
  131. : ''
  132. }
  133. {
  134. curObj.custom_tag && curObj.custom_tag.indexOf('户型VR') > -1
  135. ?
  136. <Navigator url={'/pagesHouse/produceType?id=' + curObj.id + '&name=' + curObj.estate_name} className="scoped-hx-vr">
  137. <View className="text">
  138. <View className="bg"></View>
  139. <View className="t">户型VR</View>
  140. </View>
  141. <Image src={vrhx} className="i" />
  142. </Navigator>
  143. : ''
  144. }
  145. {
  146. navVal === 'hp'
  147. ?
  148. <Navigator url={`/pagesHouse/vrList?eid=${curObj.id}&id=${curObj.vr_key}&estateName=${curObj.estate_name}`} className="sh-img">
  149. <View className="icon">
  150. <Image src={hpI1} className="i i1" />
  151. <Image src={hpI2} className="i i2" />
  152. </View>
  153. <Image src={curObj.vr_image} className="img" />
  154. </Navigator>
  155. : ''
  156. }
  157. {
  158. navVal === 'video'
  159. ?
  160. <View className='sh-img'>
  161. <Video
  162. className="img"
  163. src={curObj.video}
  164. controls={true}
  165. autoplay={false}
  166. initialTime='0'
  167. id='video'
  168. loop={false}
  169. muted={false}
  170. />
  171. </View>
  172. : ''
  173. }
  174. {
  175. navVal === 'ld'
  176. ?
  177. <View className="sh-img">
  178. <Image src={curObj.pri_image ? curObj.pri_image + '_white' : ''} className="img" onClick={this.previewImageHandle.bind(this, curObj.pri_image, [curObj.pri_image])} />
  179. </View>
  180. : ''
  181. }
  182. <View className="sh-icon-right pk" onClick={this.pkHandle.bind(this)}>
  183. <Image className="img" src={iconPk} />
  184. </View>
  185. <Button className="sh-icon-right btn-to-div" openType="share">
  186. <Image className="img" src={iconShare} />
  187. </Button>
  188. {this.renderNav()}
  189. </View>
  190. )
  191. }
  192. }