// TUIKit-WChat/Chat/index.js import logger from '../../utils/logger'; import constant from '../../utils/constant'; import { API } from './../../../utils/network/api' const api = new API() // eslint-disable-next-line no-undef const app = getApp(); const inputStyle = ` --padding: 0px; `; let newInputStyle = ` --padding: 0px; position: absolute; `; const setNewInputStyle = (number) => { const height = number; newInputStyle = `--padding: ${height}px`; }; Component({ /** * 组件的属性列表 */ properties: { currentConversationID: { type: String, value: '', observer(currentConversationID) { this.setData({ conversationID: currentConversationID, }); }, }, order_inquiry_id: { type: String, value: '' }, inquiry_type: { type: String, value: '' }, unreadCount: { type: Number, value: '', observer(unreadCount) { this.setData({ unreadCount, }); }, }, hasCallKit: { type: Boolean, value: false, observer(hasCallKit) { this.setData({ hasCallKit, }); }, }, baseInfo: { type: Object, value: {}, observer(baseInfo) { this.setData({ "navbarData.title": baseInfo.patient_family_name }); }, } }, lifetimes: { attached() { if (app?.globalData?.reportType === constant.OPERATING_ENVIRONMENT) { this.setData({ showTips: true, }); } let rect = null; if (wx.getMenuButtonBoundingClientRect) { rect = wx.getMenuButtonBoundingClientRect(); } console.log("rect: ", rect) wx.getSystemInfo({ success: (res) => { const { statusBarHeight } = wx.getSystemInfoSync(); console.log("statusBarHeight: ", statusBarHeight); console.log("${rect.height}px: ", `${rect.height}`); let height = Number.parseInt(statusBarHeight) + Number.parseInt(`${rect.height}`) + 50; this.setData({ navbar_height: height }) }, fail: (err) => { console.error('navbar 获取系统信息失败', err); }, }); }, ready() { //修改为组件传值 // this.getInquiryMessageBasic() console.log("app.globalData.scene from TUIchat ready: ", app.globalData.scene); let pages = getCurrentPages(); console.log("pages:", pages) console.log("pages.length:", pages.length) console.log("pages:", pages[0]) if(pages.length == 1){ console.log("navbarData.showCapsule"); this.setData({ "navbarData.showCapsule": 3 }) } } }, /** * 组件的初始数据 */ data: { conversationName: '', conversation: {}, messageList: [], isShow: false, showImage: false, showChat: true, conversationID: '', config: { sdkAppID: '', userID: '', userSig: '', type: 1, tim: null, }, unreadCount: 0, hasCallKit: false, viewData: { style: inputStyle, }, input_area_style:"", KeyboardHeight: 0, showTips: false, showGroupTips: false, showAll: false, navbarData: { showCapsule: 2, //是否显示左上角图标 1表示显示 0表示不显示 title: '', //导航栏 中间的标题 }, navbar_height: 0, dialog_visible: false, }, /** * 组件的方法列表 */ methods: { //结束问诊 putDoctorInquiryFinish() { this.setData({ dialog_visible: true }) }, cancelDialog(){ this.setData({ dialog_visible: false }) }, confirmDialog(){ api.putDoctorInquiryFinish({order_inquiry_id: this.data.order_inquiry_id}).then(response => { console.log(response); this.getInquiryMessageBasic() }).catch(errors => {console.error(errors);}) this.setData({ dialog_visible: false }) }, //获取问诊订单消息内页基础数据 getInquiryMessageBasic() { console.log("order_inquiry_id: ", this.data.order_inquiry_id); api.getInquiryMessageBasic({order_inquiry_id: this.data.order_inquiry_id}).then(response => { console.log(response); this.setData({ baseInfo: response.data, }) }).catch(errors => {console.error(errors);}) }, init() { console.warn("TUIChat js: init", this.data.conversationID) wx.$TUIKit.setMessageRead({ conversationID: this.data.conversationID }).then(() => { logger.log('| TUI-chat | setMessageRead | ok'); }); wx.$TUIKit.getConversationProfile(this.data.conversationID).then((res) => { const { conversation } = res.data; this.setData({ conversationName: this.getConversationName(conversation), conversation, isShow: conversation.type === wx.$TUIKitTIM.TYPES.CONV_GROUP, }); if (conversation.type !== wx.$TUIKitTIM.TYPES.CONV_GROUP) return; if (!this.data.showTips) { this.setData({ showGroupTips: true, }); } else { this.setData({ showAll: true, }); } }); }, getConversationName(conversation) { if (conversation.type === '@TIM#SYSTEM') { this.setData({ showChat: false, }); return '系统通知'; } if (conversation.type === wx.$TUIKitTIM.TYPES.CONV_C2C) { return conversation.remark || conversation.userProfile.nick || conversation.userProfile.userID; } if (conversation.type === wx.$TUIKitTIM.TYPES.CONV_GROUP) { return conversation.groupProfile.name || conversation.groupProfile.groupID; } }, sendMessage(event) { // 将自己发送的消息写进消息列表里面 this.selectComponent('#MessageList').updateMessageList(event.detail.message); }, showMessageErrorImage(event) { this.selectComponent('#MessageList').sendMessageError(event); }, triggerClose() { this.selectComponent('#MessageInput').handleClose(); }, handleCall(event) { if (event.detail.conversationType === wx.$TUIKitTIM.TYPES.CONV_GROUP) { this.selectComponent('#TUIGroup').callShowMoreMember(event); } else { this.triggerEvent('handleCall', event.detail); } }, groupCall(event) { const { selectedUserIDList, type, groupID } = event.detail; const userIDList = selectedUserIDList; this.triggerEvent('handleCall', { userIDList, type, groupID }); }, goBack() { this.triggerEvent('showConversationList'); wx.$TUIKit.setMessageRead({ conversationID: this.data.conversationID, }).then(() => { wx.navigateBack(); }); }, showConversationList() { this.triggerEvent('showConversationList'); }, changeMemberCount(event) { this.selectComponent('#TUIGroup').updateMemberCount(event.detail.groupOptionsNumber); }, resendMessage(event) { this.selectComponent('#MessageInput').onInputValueChange(event); }, myhandleExtensions(e){ console.log("myhandleExtensionsmyhandleExtensions: ", e); let displayFlag = e.detail.displayFlag; if(displayFlag){ this.setData({ input_area_style: "position: absolute; bottom: 30px;" }) }else{ this.setData({ input_area_style: "" }) } }, // 监听键盘,获取焦点时将输入框推到键盘上方 pullKeysBoards(event) { setNewInputStyle(event.detail.event.detail.height); this.setData({ 'viewData.style': newInputStyle, input_area_style: "position: absolute; bottom: 45rpx;" }); }, // 监听键盘,失去焦点时收起键盘 downKeysBoards(event) { console.log(event) let value = event.detail.event.detail.value; if(value){ this.setData({ 'viewData.style': inputStyle, }); }else{ this.setData({ 'viewData.style': inputStyle, input_area_style: "" }); } }, typing(event) { const { STRING_TEXT, FEAT_NATIVE_CODE } = constant; if (this.data.conversation.type === wx.$TUIKitTIM.TYPES.CONV_C2C) { if (event.detail.typingMessage.typingStatus === FEAT_NATIVE_CODE.ISTYPING_STATUS && event.detail.typingMessage.actionParam === constant.TYPE_INPUT_STATUS_ING) { this.setData({ conversationName: STRING_TEXT.TYPETYPING, }); setTimeout(() => { this.setData({ conversationName: this.getConversationName(this.data.conversation), }); }, (1000 * 30)); } else if (event.detail.typingMessage.typingStatus === FEAT_NATIVE_CODE.NOTTYPING_STATUS && event.detail.typingMessage.actionParam === constant.TYPE_INPUT_STATUS_END) { this.setData({ conversationName: this.getConversationName(this.data.conversation), }); } } }, handleReport() { const url = '/pages/TUI-User-Center/webview/webview?url=https://cloud.tencent.com/apply/p/xc3oaubi98g'; wx.navigateTo({ url, }); }, }, });