LiveCustomer.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // pages/LiveCustomer/LiveCustomer.js
  2. const app = getApp();
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. pullUrl: {
  9. type: String
  10. },
  11. kid : {
  12. type : String
  13. },
  14. online_sum : {
  15. type : Number
  16. }
  17. },
  18. /**
  19. * 组件的初始数据
  20. */
  21. data: {
  22. bool : true,
  23. x: 0,
  24. y: 0,
  25. chatText : "",
  26. chatList : [],
  27. playData : null,
  28. scrollTop : 300,
  29. time : 0,
  30. num : 1,
  31. timer : null
  32. },
  33. ready : function() {
  34. var _this = this;
  35. // _this.getTime();
  36. // console.log(this.data.kid)
  37. _this.getChatList();
  38. },
  39. /**
  40. * 组件的方法列表
  41. */
  42. methods: {
  43. doubleClick : function(e) {
  44. var that = this
  45. // 控制点击事件在350ms内触发,加这层判断是为了防止长按时会触发点击事件
  46. if (that.data.touchEndTime - that.data.touchStartTime < 350) {
  47. // 当前点击的时间
  48. var currentTime = e.timeStamp
  49. var lastTapTime = that.lastTapTime
  50. // 更新最后一次点击时间
  51. that.lastTapTime = currentTime
  52. // 如果两次点击时间在300毫秒内,则认为是双击事件
  53. if (currentTime - lastTapTime < 300) {
  54. console.log("double tap")
  55. // 成功触发双击事件时,取消单击事件的执行
  56. this.setData({
  57. bool : !this.data.bool
  58. },function(){
  59. setInterval(() => {
  60. that.getChatList();
  61. },1000)
  62. })
  63. }
  64. }
  65. },
  66. touchStart: function (e) {
  67. this.setData({
  68. touchStartTime: e.timeStamp
  69. })
  70. },
  71. /// 按钮触摸结束触发的事件
  72. touchEnd: function (e) {
  73. this.setData({
  74. touchEndTime: e.timeStamp
  75. })
  76. },
  77. send(e) {
  78. let _this = this;
  79. if (_this.data.chatText !== '') {
  80. wx.request({
  81. url: app.globalData.prodUrl + 'web-pm/wx/pm/add_chitchat',
  82. data: {
  83. content: _this.data.chatText,
  84. liveroom_id: _this.data.kid
  85. },
  86. header: { 'ydw-token': wx.getStorageSync('key').ydw_token },
  87. method: 'GET',
  88. dataType: 'json',
  89. responseType: 'text',
  90. success: function (data) {
  91. console.log(data)
  92. _this.setData({
  93. chatText: ''
  94. },function() {
  95. _this.getChatList()
  96. })
  97. }
  98. })
  99. } else {
  100. }
  101. },
  102. chatText(e) {
  103. this.setData({
  104. chatText: e.detail.value
  105. })
  106. },
  107. getChatList() {
  108. var _this = this;
  109. wx.request({
  110. url: app.globalData.prodUrl + 'web-pm/wx/pm/get_chatting_records',
  111. data: {
  112. live_room_id : _this.data.kid,
  113. chat_time: _this.data.time
  114. },
  115. header: {
  116. 'ydw-token': wx.getStorageSync('key').ydw_token
  117. },
  118. method: 'GET',
  119. dataType: 'json',
  120. responseType: 'text',
  121. success: function (data) {
  122. var chatList = data.data.data;
  123. var time = data.data.data[0].created;
  124. _this.setData({
  125. chatList: chatList,
  126. time
  127. },function() {
  128. _this.pageScrollToBottom();
  129. })
  130. }
  131. })
  132. },
  133. pageScrollToBottom: function () {
  134. var _this = this;
  135. this.setData({
  136. scrollTop : this.data.scrollTop + 40
  137. },function() {
  138. // console.log(_this.data.scrollTop)
  139. }
  140. )
  141. },
  142. Caeel : function() {
  143. return false;
  144. },
  145. getTime : function() {
  146. var _this = this;
  147. wx.request({
  148. url: app.globalData.prodUrl + 'web-pm/wx/pm/select_list',
  149. data: {
  150. kid: _this.data.kid
  151. },
  152. header: {
  153. 'ydw-token': wx.getStorageSync('key').ydw_token
  154. },
  155. success: function (data) {
  156. _this.setData({
  157. time: data.data.nowtime
  158. },function(){
  159. // setInterval(function () {
  160. // _this.getChatList();
  161. // }, 1000)
  162. })
  163. }
  164. })
  165. },
  166. updataUserInfo : function(e) {
  167. console.log(e)
  168. }
  169. }
  170. })