detail-scroll.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. import HouseApi from '../../../apis/house'
  2. import { fotmatDate } from '../../../utils/date'
  3. import loginFn from '../../../utils/login'
  4. import MsgManager from '../../../pages/chat/msg-manager'
  5. import { randomString } from './../../../utils/tools'
  6. import { saveViewHistory } from '../../../utils/storage'
  7. import { loginByUserInfo } from '../../../utils/login'
  8. const app = getApp();
  9. Component({
  10. /**
  11. * 组件的属性列表
  12. */
  13. properties: {
  14. house_id: String,
  15. agent_user: Object,
  16. isAgency: Boolean
  17. },
  18. /**
  19. * 组件的初始数据
  20. */
  21. data: {
  22. loginStatus: app.globalData.token ? true : false,
  23. userinfo: app.globalData.userinfo,
  24. isFocused: false,
  25. recommendList: [],
  26. user_code: '',
  27. markers: [],
  28. house: getApp().globalData.lastHouse,
  29. detailItems: [
  30. {
  31. label: '单价',
  32. value: '',
  33. name: 'unit_price'
  34. },
  35. {
  36. label: '挂牌',
  37. value: '',
  38. name: 'apply_time',
  39. format: fotmatDate
  40. },
  41. {
  42. label: '朝向',
  43. value: '',
  44. name: 'orientation'
  45. },
  46. {
  47. label: '楼层',
  48. value: '',
  49. name: 'floor_num'
  50. },
  51. {
  52. label: '楼型',
  53. value: '',
  54. name: 'building_type'
  55. },
  56. {
  57. label: '装修',
  58. value: '',
  59. name: 'decoration'
  60. },
  61. {
  62. label: '年代',
  63. value: '',
  64. name: 'building_age'
  65. },
  66. {
  67. label: '用途',
  68. value: '',
  69. name: 'house_usage'
  70. },
  71. ]
  72. },
  73. pageLifetimes: {
  74. show () {
  75. this.setData({
  76. loginStatus: app.globalData.token ? true : false,
  77. userinfo: app.globalData.userinfo,
  78. app_type: app.globalData.type
  79. })
  80. }
  81. },
  82. ready () {
  83. this.setData({
  84. loginStatus: app.globalData.token ? true : false,
  85. userinfo: app.globalData.userinfo,
  86. })
  87. this.getHouseDetail(this.properties.house_id)
  88. this.fetchRecommendHouseList()
  89. this.msgManager = new MsgManager(this)
  90. if (!this.data.loginStatus) {
  91. wx.login({
  92. success: (res) => {
  93. this.setData({
  94. user_code: res.code
  95. })
  96. }
  97. })
  98. } else {
  99. this.getHouseFocusStatus()
  100. }
  101. },
  102. /**
  103. * 组件的方法列表
  104. */
  105. methods: {
  106. toMap () {
  107. const house = this.data.house
  108. wx.navigateTo({
  109. url: `/pages/map/map?longitude=${house.longitude}&latitude=${house.latitude}&housename=${house.district || ''} ${house.estate_name || ''}${this.properties.isAgency ? '' : `&agency_id=${this.properties.agent_user.agency_user_id}&agency_name=${this.properties.agent_user.name}&phone=${this.properties.agent_user.phone}`}`
  110. })
  111. },
  112. sendSchoolMsg () {
  113. if (!getApp().globalData.token) {
  114. wx.navigateTo({
  115. url: '/pages/login/login',
  116. })
  117. return
  118. }
  119. Promise.all([this.sendTextMsg('您好,请问这个房子周边有哪些学校?')]).then(res => {
  120. wx.navigateTo({
  121. url: `/pages/chat/chat?toId=${this.properties.agent_user.agency_user_id}&toName=${this.properties.agent_user.name}`
  122. })
  123. })
  124. },
  125. getHouseDetail(house_id){
  126. wx.showLoading({
  127. title: '加载数据中'
  128. })
  129. HouseApi.houseDetail(house_id).then(res => {
  130. let { detailItems } = this.data
  131. let house = res.data
  132. detailItems.forEach(item => {
  133. if (house[item.name]) {
  134. // 若有format函数,则执行处理成想要格式化的值
  135. if (item.format && typeof item.format === 'function') {
  136. house[item.name] = item.format(house[item.name])
  137. }
  138. item.value = house[item.name]
  139. } else {
  140. item.value = '暂无数据'
  141. }
  142. })
  143. house.tags = JSON.parse(house.tags || "[]")
  144. house.remarks = JSON.parse(house.remarks || "[]")[0].text
  145. res.data.detail_images = JSON.parse(res.data.detail_images)
  146. res.data.detail_images = res.data.detail_images.map(item => `${item}?x-oss-process=image/resize,w_750,limit_0/quality,q_75`)
  147. let markers = [
  148. {
  149. longitude: house.longitude,
  150. latitude: house.latitude,
  151. housename: house.title,
  152. iconPath: "/image/4Dage/location-cycle.png",
  153. zIndex: -1,
  154. callout: {
  155. content: `${house.district || ''} ${house.estate_name || ''}`,
  156. display: 'ALWAYS',
  157. padding: 15,
  158. anchorY: 10
  159. }
  160. }
  161. ]
  162. this.setData({
  163. house: res.data,
  164. detailItems: detailItems,
  165. markers
  166. })
  167. saveViewHistory(res.data)
  168. app.globalData.last_house = house
  169. wx.hideLoading()
  170. }).catch(err => {
  171. console.log(err, '获取详情出错')
  172. wx.hideLoading()
  173. })
  174. },
  175. getHouseFocusStatus () {
  176. const { loginStatus } = this.data
  177. if (!loginStatus) {
  178. return
  179. }
  180. return HouseApi.isHouseFocused({
  181. house_id: this.properties.house_id,
  182. user_id: this.data.userinfo.user_id
  183. }).then((res) => {
  184. this.setData({
  185. isFocused: res.data === -1 ? false : true
  186. })
  187. return res.data
  188. })
  189. },
  190. bindgetphonenumber (e) {
  191. loginFn(e, this.data.user_code, this.properties.isAgency ? true : false).then(res => {
  192. this.setData({
  193. loginStatus: app.globalData.token ? true : false,
  194. userinfo: app.globalData.userinfo,
  195. })
  196. this.getHouseFocusStatus().then(res => {
  197. if (!res) {
  198. this.changeFocusStatus()
  199. }
  200. })
  201. })
  202. },
  203. changeFocusStatus () {
  204. const is_valid = this.data.isFocused ? 0 : 1
  205. HouseApi.focusHouse({
  206. is_valid,
  207. house_id: this.properties.house_id
  208. }).then(res => {
  209. this.setData({
  210. isFocused: is_valid
  211. })
  212. })
  213. },
  214. cancleFocusStatus () {
  215. return HouseApi.cancleFocusHouse({house_id: this.properties.house_id}).then(() => {
  216. this.setData({
  217. isFocused: 0
  218. })
  219. })
  220. },
  221. fetchRecommendHouseList () {
  222. const fetchData = {
  223. city: app.globalData.city,
  224. saleState: 1,
  225. page_size: 8
  226. }
  227. HouseApi.houseList(fetchData).then(res => {
  228. this.setData({
  229. recommendList: res.data.list
  230. })
  231. })
  232. },
  233. toMoreIntro () {
  234. wx.navigateTo({
  235. url: `/pages/detail-intro/detail-intro?house_id=${this.properties.house_id}`
  236. })
  237. },
  238. addReadHistory () {
  239. HouseApi.addReadHistory({ house_id: this.properties.house_id })
  240. },
  241. // 发送带看
  242. onlineWatch () {
  243. if (!this.data.loginStatus) {
  244. wx.navigateTo({
  245. url: '/pages/login/login'
  246. })
  247. return
  248. }
  249. if (this.properties.isAgency) {
  250. wx.navigateTo({
  251. url: `/pages/message-list/message-list?house_id=${this.properties.house_id}`
  252. })
  253. return
  254. }
  255. const room_id = randomString(18)
  256. this.toVrHouse(room_id, true)
  257. },
  258. // 发送房屋卡片
  259. sendVrMsg (room_id, is_vr_invite) {
  260. const { house } = this.data
  261. let content = {
  262. house_name: house.title,
  263. image_url: house.detail_images[0],
  264. house_type: house.house_type,
  265. house_area: house.area,
  266. orientation: house.orientation,
  267. price: `${(house.price/10000).toFixed(0)}万`,
  268. vr_link: is_vr_invite ? `${house.vrLink}${encodeURIComponent(`&room_id=${room_id}`)}` : '',
  269. house_id: house.house_id
  270. }
  271. return this.sendMsg({content, msgType: 'vr'})
  272. },
  273. // 发送文字
  274. sendTextMsg (content) {
  275. return this.sendMsg({content, msgType: 'text'})
  276. },
  277. sendMsg ({content, msgType}) {
  278. let defaultContent = {
  279. fromId: app.globalData.userinfo.user_id,
  280. fromName: app.globalData.userinfo.phone,
  281. toId: this.properties.agent_user.agency_user_id,
  282. toName: 'xu',
  283. type: 'TYPE_ONE',
  284. msgType,
  285. content: content
  286. }
  287. return getApp().getIMHandler().newFriendSendMsg({content: defaultContent})
  288. },
  289. toVrHouse (room_id, isAuto) {
  290. if (typeof room_id !== 'string') room_id = ''
  291. this.postDataToOpen(room_id).then(res => {
  292. const vr_link = res.data.vrLink
  293. wx.navigateTo({
  294. url: `/pages/web/web?room_id=${res.data.roomId}&vr_link=${encodeURIComponent(vr_link)}&house_id=${this.properties.house_id}${isAuto ? `&is_auto=${isAuto}` : ''}`
  295. })
  296. })
  297. },
  298. postDataToOpen (room_id) {
  299. return HouseApi.postDataToOpen({house_id: this.properties.house_id, room_id, type: 'customer'})
  300. },
  301. toAgentDetail () {
  302. wx.navigateTo({
  303. url: `/pages/agent-detail/agent-detail?agency_id=${this.properties.agent_user.agency_user_id}`,
  304. })
  305. },
  306. bindgetuserinfo (e) {
  307. const { action } = e.currentTarget.dataset
  308. loginByUserInfo().then(res => {
  309. this.setData({
  310. loginStatus: app.globalData.token ? true : false,
  311. userinfo: app.globalData.userinfo,
  312. })
  313. this.getHouseFocusStatus()
  314. this[action] && this[action]()
  315. })
  316. }
  317. }
  318. })