customer-list.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import HouseApi from './../../apis/house'
  2. import agentApi from '../../apis/agent'
  3. import { randomString } from './../../utils/tools'
  4. import ImSend from '../../utils/imSend'
  5. const app = getApp()
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. house: {},
  12. house_id: '',
  13. customers: [],
  14. cardShowStatus: false,
  15. selectedCustomer: {}
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. this.getHouseDetail(options.house_id)
  22. this.getMessageList()
  23. },
  24. toCustomerList () {
  25. wx.navigateTo({
  26. url: `/pages/customer-list/customer-list?house_id=${this.data.house_id}`,
  27. })
  28. },
  29. getHouseDetail (house_id) {
  30. HouseApi.houseDetail(house_id).then(res => {
  31. res.data.detail_images = JSON.parse(res.data.detail_images)
  32. this.setData({
  33. house: res.data,
  34. house_id: house_id
  35. })
  36. })
  37. },
  38. confirmInvite (e) {
  39. const { index } = e.currentTarget.dataset
  40. console.log(index, this.data.clients)
  41. this.setData({
  42. cardShowStatus: true,
  43. selectedCustomer: this.data.clients[index]
  44. })
  45. },
  46. submit (e) {
  47. if (e.detail) {
  48. ImSend.sendTextMsg(e.detail, this.data.selectedCustomer.user_id)
  49. }
  50. this.sendVrMsg()
  51. this.setData({
  52. cardShowStatus: false
  53. })
  54. },
  55. cancle () {
  56. this.setData({
  57. cardShowStatus: false
  58. })
  59. },
  60. getMessageList () {
  61. this.setData({
  62. 'fetcherData.agency_user_id': app.globalData.userinfo.agency_user_id
  63. })
  64. app.wxshowloading('拼命加载中...');
  65. agentApi.fetchCustomers(this.data.fetcherData).then(res => {
  66. this.setData({
  67. clients: res.data.list
  68. })
  69. console.log(res.data)
  70. }).finally(() => {
  71. wx.hideLoading()
  72. })
  73. },
  74. dealConversations (conversations) {
  75. return conversations.map(item => {
  76. let content = item.latestMsgContent
  77. try {
  78. let parseContent = JSON.parse(content)
  79. if (parseContent.house_name) {
  80. content = `【云带看】${JSON.parse(content).house_name}`
  81. } else if (parseContent.duration) {
  82. content = '【语音】'
  83. } else if (parseContent.content) {
  84. content = '【图片】'
  85. }
  86. } catch (err) {
  87. }
  88. item.latestMsgContent = content
  89. return item
  90. }).sort((a,b) => new Date(b.latestMsgTime) - new Date(a.latestMsgTime))
  91. },
  92. sendVrMsg () {
  93. const room_id = randomString(18)
  94. const { house } = this.data
  95. this.postDataToOpen(room_id).then(res => {
  96. const vr_link = res.data.vrLink
  97. ImSend.sendVrMsg(house, res.data.roomId, this.data.selectedCustomer.user_id, true)
  98. })
  99. },
  100. postDataToOpen (room_id) {
  101. return HouseApi.postDataToOpen({house_id: this.data.house_id, room_id: '', type: 'customer'})
  102. },
  103. sendMsg ({content, msgType}) {
  104. let defaultContent = {
  105. fromId: app.globalData.userinfo.user_id,
  106. fromName: app.globalData.userinfo.phone,
  107. toId: this.data.selectedCustomer.id, //this.properties.agent_user.agency_user_id,
  108. toName: this.data.selectedCustomer.name,
  109. type: 'TYPE_ONE',
  110. msgType,
  111. content: content
  112. }
  113. return getApp().getIMHandler().newFriendSendMsg({content: defaultContent})
  114. },
  115. bindinput (e) {
  116. const { value } = e.detail
  117. this.setData({
  118. 'fetcherData.user_name': value
  119. })
  120. // this.getMessageList()
  121. },
  122. searchbtnclick () {
  123. }
  124. })