detail-scroll.js 10 KB

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