// pages/LiveCustomer/LiveCustomer.js const app = getApp(); Component({ /** * 组件的属性列表 */ properties: { pullUrl: { type: String }, kid : { type : String }, online_sum : { type : Number } }, /** * 组件的初始数据 */ data: { bool : true, x: 0, y: 0, chatText : "", chatList : [], playData : null, scrollTop : 300, time : 0, num : 1, timer : null }, ready : function() { var _this = this; // _this.getTime(); // console.log(this.data.kid) _this.getChatList(); }, /** * 组件的方法列表 */ methods: { doubleClick : function(e) { var that = this // 控制点击事件在350ms内触发,加这层判断是为了防止长按时会触发点击事件 if (that.data.touchEndTime - that.data.touchStartTime < 350) { // 当前点击的时间 var currentTime = e.timeStamp var lastTapTime = that.lastTapTime // 更新最后一次点击时间 that.lastTapTime = currentTime // 如果两次点击时间在300毫秒内,则认为是双击事件 if (currentTime - lastTapTime < 300) { console.log("double tap") // 成功触发双击事件时,取消单击事件的执行 this.setData({ bool : !this.data.bool },function(){ setInterval(() => { that.getChatList(); },1000) }) } } }, touchStart: function (e) { this.setData({ touchStartTime: e.timeStamp }) }, /// 按钮触摸结束触发的事件 touchEnd: function (e) { this.setData({ touchEndTime: e.timeStamp }) }, send(e) { let _this = this; if (_this.data.chatText !== '') { wx.request({ url: app.globalData.prodUrl + 'web-pm/wx/pm/add_chitchat', data: { content: _this.data.chatText, liveroom_id: _this.data.kid }, header: { 'ydw-token': wx.getStorageSync('key').ydw_token }, method: 'GET', dataType: 'json', responseType: 'text', success: function (data) { console.log(data) _this.setData({ chatText: '' },function() { _this.getChatList() }) } }) } else { } }, chatText(e) { this.setData({ chatText: e.detail.value }) }, getChatList() { var _this = this; wx.request({ url: app.globalData.prodUrl + 'web-pm/wx/pm/get_chatting_records', data: { live_room_id : _this.data.kid, chat_time: _this.data.time }, header: { 'ydw-token': wx.getStorageSync('key').ydw_token }, method: 'GET', dataType: 'json', responseType: 'text', success: function (data) { var chatList = data.data.data; var time = data.data.data[0].created; _this.setData({ chatList: chatList, time },function() { _this.pageScrollToBottom(); }) } }) }, pageScrollToBottom: function () { var _this = this; this.setData({ scrollTop : this.data.scrollTop + 40 },function() { // console.log(_this.data.scrollTop) } ) }, Caeel : function() { return false; }, getTime : function() { var _this = this; wx.request({ url: app.globalData.prodUrl + 'web-pm/wx/pm/select_list', data: { kid: _this.data.kid }, header: { 'ydw-token': wx.getStorageSync('key').ydw_token }, success: function (data) { _this.setData({ time: data.data.nowtime },function(){ // setInterval(function () { // _this.getChatList(); // }, 1000) }) } }) }, updataUserInfo : function(e) { console.log(e) } } })