569 lines
20 KiB
JavaScript
569 lines
20 KiB
JavaScript
import { API } from './../../../utils/network/api'
|
||
import { getTimeAgo } from './../../../utils/util'
|
||
// import TIM from '../../../TUIKit/lib/tim-wx-sdk';
|
||
const api = new API()
|
||
const app = getApp()
|
||
Page({
|
||
data: {
|
||
navbarData: {
|
||
showCapsule: 0, //是否显示左上角图标 1表示显示 0表示不显示
|
||
title: '问诊消息', //导航栏 中间的标题
|
||
},
|
||
height: app.globalData.height,
|
||
static_host: api.getStaticHost(),
|
||
has_data: false,
|
||
data_list_1: [],//在线问诊
|
||
data_list_2: [],//快速问诊
|
||
data_list_3: [],//公益问诊
|
||
data_list_4: [], //问诊购药
|
||
data_list_5: [],//糖组检测
|
||
data_list_6: [],//问诊结束
|
||
data_list_6_loading: false,
|
||
conversationList: [],
|
||
message_inquiry_type: 99999,
|
||
now_message_inquiry_type: 6,
|
||
system_notice_unreadnnum: "",
|
||
service_notice_unreadnnum: "",
|
||
hasOnShow: false,
|
||
show: false,
|
||
show_dialog_from_account: "",
|
||
show_dialog_order_inquiry_id: "",
|
||
show_dialog_inquiry_type: "",
|
||
unreadnnum_inter: 0,
|
||
current_page: 0,
|
||
total: 0,
|
||
per_page: 0,
|
||
last_page: 0,
|
||
dot_1: false,
|
||
dot_2: false,
|
||
dot_3: false,
|
||
dot_4: false,
|
||
dot_5: false,
|
||
},
|
||
onLoad() {
|
||
},
|
||
initInterval(){
|
||
let _this = this;
|
||
let usertype = wx.getStorageSync('usertype');
|
||
let userID = wx.getStorageSync('user_id_'+usertype);
|
||
let unreadnnum_inter = setInterval(() => {
|
||
let system_notice_unreadnnum = wx.getStorageSync(userID+"_system_notice_unreadnnum");
|
||
let service_notice_unreadnnum = wx.getStorageSync(userID+"_service_notice_unreadnnum");
|
||
this.setData({
|
||
system_notice_unreadnnum: system_notice_unreadnnum,
|
||
service_notice_unreadnnum: service_notice_unreadnnum,
|
||
})
|
||
|
||
if(_this.data.data_list_1.length > 0 || _this.data.data_list_2.length > 0 || _this.data.data_list_3.length > 0 || _this.data.data_list_4.length > 0 || _this.data.data_list_5.length > 0 || _this.data.data_list_6.length > 0){
|
||
_this.setData({
|
||
has_data: true
|
||
})
|
||
try {
|
||
_this.selectComponent('#tabs').resize();
|
||
} catch (y) {
|
||
|
||
}
|
||
let getCurrentName = _this.selectComponent('#tabs').getCurrentName();
|
||
let now_message_inquiry_type = _this.data.now_message_inquiry_type;
|
||
if(getCurrentName != now_message_inquiry_type){
|
||
_this.setData({
|
||
now_message_inquiry_type: getCurrentName
|
||
})
|
||
}
|
||
}
|
||
}, 100);
|
||
this.setData({
|
||
unreadnnum_inter: unreadnnum_inter
|
||
})
|
||
},
|
||
onShow: function () {
|
||
//console.log("onShow from wenzhen V2")
|
||
if(this.data.hasOnShow){
|
||
wx.stopPullDownRefresh()
|
||
return;
|
||
}
|
||
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
||
this.getTabBar().setData({
|
||
active: 1 //数字是当前页面在tabbar的索引,如我的查询页索引是2,因此这边为2,同理首页就为0,审批页面为1
|
||
})
|
||
|
||
this.getTabBar().startInterval()
|
||
}
|
||
this.getDoctorInquiryFinishMessage();
|
||
this.getDoctorMessageNotice();
|
||
this.getConversationList();
|
||
if(this.data.unreadnnum_inter == 0){
|
||
this.initInterval();
|
||
}
|
||
//避免onshow加载多次
|
||
this.setData({
|
||
hasOnShow: true
|
||
})
|
||
|
||
|
||
if(wx.$TUIKit){
|
||
wx.$TUIKit.off(wx.$TUIKitTIM.EVENT.SDK_READY, this.onSDKReady);
|
||
wx.$TUIKit.on(wx.$TUIKitTIM.EVENT.SDK_READY, this.onSDKReady, this);
|
||
wx.$TUIKit.on(wx.$TUIKitTIM.EVENT.MESSAGE_RECEIVED, this.$onMessageReceived, this);
|
||
}else{
|
||
app.imInit().then(res => {
|
||
wx.$TUIKit.on(wx.$TUIKitTIM.EVENT.SDK_READY, this.onSDKReady, this);
|
||
wx.$TUIKit.on(wx.$TUIKitTIM.EVENT.MESSAGE_RECEIVED, this.$onMessageReceived, this);
|
||
});
|
||
}
|
||
},
|
||
onHide(){
|
||
// console.log("onHideonHide from wenzhen")
|
||
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
||
this.getTabBar().stopInterval()
|
||
}
|
||
if(this.data.unreadnnum_inter){
|
||
clearInterval(this.data.unreadnnum_inter);
|
||
}
|
||
|
||
this.setData({
|
||
hasOnShow: false,
|
||
data_list_1: [],
|
||
data_list_2: [],
|
||
data_list_3: [],
|
||
data_list_4: [],
|
||
data_list_5: [],
|
||
data_list_6: [],
|
||
message_inquiry_type: 9999,
|
||
now_message_inquiry_type: 5,
|
||
unreadnnum_inter: 0,
|
||
has_data: false,
|
||
current_page: 0,
|
||
total: 0,
|
||
per_page: 0,
|
||
last_page: 0,
|
||
dot_1: false,
|
||
dot_2: false,
|
||
dot_3: false,
|
||
dot_4: false,
|
||
dot_5: false,
|
||
})
|
||
wx.$TUIKit.off(wx.$TUIKitTIM.EVENT.MESSAGE_RECEIVED, this.$onMessageReceived);
|
||
wx.$TUIKit.off(wx.$TUIKitTIM.EVENT.SDK_READY, this.onSDKReady);
|
||
},
|
||
onUnload(){
|
||
// console.log("onUnload from wenzhen")
|
||
this.setData({
|
||
hasOnShow: false,
|
||
message_inquiry_type: 9999,
|
||
now_message_inquiry_type: 6,
|
||
})
|
||
},
|
||
onSDKReady(){
|
||
console.log("onSDKReady from wenzhen");
|
||
this.getConversationList();
|
||
},
|
||
getConversationList(){
|
||
app.imInit().then(res => {
|
||
|
||
wx.$TUIKit.getConversationList().then((imResponse) => {
|
||
//console.log("监听会话接口列表")
|
||
console.log(imResponse.data.conversationList)
|
||
this.setData({
|
||
conversationList: imResponse.data.conversationList,
|
||
});
|
||
}).then(() => {
|
||
this.formatStatus();
|
||
}).catch(error => {
|
||
console.error(error)
|
||
});
|
||
});
|
||
},
|
||
go(e){
|
||
this.setData({
|
||
show: false
|
||
})
|
||
let url = e.currentTarget.dataset.url;
|
||
let name = e.currentTarget.dataset.name;
|
||
if(name){
|
||
wx.setStorageSync(name, 0);
|
||
}
|
||
app.go(url);
|
||
},
|
||
$onMessageReceived(value) {
|
||
const message = value.data[0];
|
||
// console.log("message from wenzhen: ",message)
|
||
this.getConversationList();
|
||
},
|
||
formatStatus(){
|
||
let order_inquiry_id_list = [];
|
||
order_inquiry_id_list.push("");//初始化一个,防止失败
|
||
console.log(this.data.conversationList)
|
||
let arr=this.data.conversationList.filter(item => item.conversationID != 'C2Cadministrator');
|
||
|
||
arr.forEach(item => {
|
||
let conversationID = item.conversationID;
|
||
console.warn("conversationID: ", conversationID)
|
||
// if(conversationID == "C2Cadministrator") return;//如果是管理员消息直接跳过
|
||
let lastMessage = item.lastMessage;
|
||
if(!lastMessage) return;
|
||
let cloudCustomData = lastMessage.cloudCustomData;
|
||
|
||
if(!cloudCustomData) return;
|
||
let cloudCustomDataJson;
|
||
try {
|
||
if(!cloudCustomData){
|
||
return
|
||
}
|
||
cloudCustomDataJson = JSON.parse(cloudCustomData);
|
||
} catch (error) {
|
||
// console.log(error);
|
||
return;
|
||
}
|
||
let order_inquiry_id = cloudCustomDataJson.order_inquiry_id;
|
||
|
||
order_inquiry_id_list.push(order_inquiry_id);//准备去请求后端那订单状态
|
||
})
|
||
let conversationList = arr; //this.data.conversationList;
|
||
//获取医生问诊消息用户属性
|
||
let order_inquiry_ids='';
|
||
order_inquiry_id_list.forEach(item=>{
|
||
if(order_inquiry_ids){
|
||
order_inquiry_ids+=','+item;
|
||
}else{
|
||
order_inquiry_ids+=item
|
||
}
|
||
});
|
||
//console.log(order_inquiry_ids)
|
||
api.getDoctorInquiryMessageAttr({order_inquiry_ids: order_inquiry_ids}).then(response => {
|
||
let new_conversationList = [];
|
||
if(response.data.length > 0){
|
||
conversationList.forEach(item => {
|
||
let conversationID = item.conversationID;
|
||
//if(conversationID == "C2Cadministrator") return;//如果是管理员消息直接跳过
|
||
let lastMessage = item.lastMessage;
|
||
if(!lastMessage) return;
|
||
let cloudCustomData = lastMessage.cloudCustomData;
|
||
if(!cloudCustomData) return;
|
||
let cloudCustomDataJson;
|
||
try {
|
||
if(!item.lastMessage.cloudCustomData){
|
||
return
|
||
}
|
||
cloudCustomDataJson = JSON.parse(item.lastMessage.cloudCustomData);
|
||
} catch (error) {
|
||
return;
|
||
}
|
||
let order_inquiry_id = cloudCustomDataJson.order_inquiry_id;
|
||
let order = response.data.find(attr_item => {
|
||
return attr_item.order_inquiry_id == order_inquiry_id;
|
||
})
|
||
if(!order) return;
|
||
|
||
let inquiry_status = order.inquiry_status;
|
||
//inquiry_status 状态
|
||
if(inquiry_status !=3 && inquiry_status != 4){
|
||
return;
|
||
}
|
||
item.inquiry_status = inquiry_status;
|
||
item.patient_age = order.patient_age;
|
||
item.patient_name = order.patient_name;
|
||
item.patient_sex = order.patient_sex;
|
||
new_conversationList.push(item);
|
||
})
|
||
};
|
||
//console.log(new_conversationList);
|
||
this.setData({
|
||
conversationList: new_conversationList
|
||
})
|
||
}).then(() => {
|
||
//console.log("开始格式化formatConversationList")
|
||
this.formatConversationList();
|
||
}).catch(errors => {console.error(errors);})
|
||
},
|
||
formatConversationList(){
|
||
let session_list = [];
|
||
|
||
let session_data_list_1 = [];
|
||
let session_data_list_2 = [];
|
||
let session_data_list_3 = [];
|
||
let session_data_list_4 = [];
|
||
let session_data_list_5 = [];
|
||
let session_data_list_6 = [];
|
||
session_list.push(session_data_list_1);
|
||
session_list.push(session_data_list_2);
|
||
session_list.push(session_data_list_3);
|
||
session_list.push(session_data_list_4);
|
||
session_list.push(session_data_list_5);
|
||
session_list.push(session_data_list_6);
|
||
|
||
let usertype = wx.getStorageSync('usertype');
|
||
let userID = wx.getStorageSync('user_id_'+usertype);
|
||
let totalUnreadCount = 0;
|
||
let message_inquiry_type = this.data.message_inquiry_type;
|
||
//console.log(this.data.conversationList);
|
||
this.data.conversationList.forEach(item => {
|
||
let conversationID = item.conversationID;
|
||
if(conversationID == "C2Cadministrator") return;//如果是管理员消息直接跳过
|
||
let lastMessage = item.lastMessage;
|
||
let type = lastMessage.type;
|
||
let userProfile = item.userProfile;
|
||
if(!lastMessage) return;
|
||
let cloudCustomData = lastMessage.cloudCustomData;
|
||
if(!cloudCustomData) return;
|
||
let cloudCustomDataJson = JSON.parse(cloudCustomData);
|
||
// remaining_month_inquiry_count:serviceInfo.remaining_month_inquiry_count,
|
||
// service_package_start_time:serviceInfo.start_time,
|
||
// service_package_finish_time:serviceInfo.finish_timestart_time,
|
||
// service_period:serviceInfo.service_period,
|
||
// remaining_quantity:serviceInfo.remaining_quantity,
|
||
let remaining_month_inquiry_count=cloudCustomDataJson.remaining_month_inquiry_count;
|
||
let service_package_start_time=cloudCustomDataJson.service_package_start_time;
|
||
let service_package_finish_time=cloudCustomDataJson.service_package_finish_time;
|
||
let remaining_quantity=cloudCustomDataJson.remaining_quantity;
|
||
let service_period=cloudCustomDataJson.service_period;
|
||
let monthly_frequency=cloudCustomDataJson.monthly_frequency;
|
||
let order_inquiry_id = cloudCustomDataJson.order_inquiry_id;
|
||
if(!order_inquiry_id) return;
|
||
let inquiry_type = cloudCustomDataJson.inquiry_type;
|
||
let inquiry_mode=cloudCustomDataJson.inquiry_mode;
|
||
if(!inquiry_type) return;
|
||
if(inquiry_type > 5) return;
|
||
if(inquiry_type < message_inquiry_type){
|
||
message_inquiry_type = inquiry_type;
|
||
}
|
||
//去重order_inquiry_id
|
||
let index = this.checkOrderInquiryId(session_list[inquiry_type - 1], order_inquiry_id);
|
||
if(index > -1) return;
|
||
let patient_family_data = cloudCustomDataJson.patient_family_data;
|
||
if(patient_family_data == undefined) return;
|
||
// console.log("patient_family_data: ", patient_family_data);
|
||
let session_item = {};
|
||
session_item.inquiry_status = item.inquiry_status;//订单状态暂无
|
||
let txt = {};
|
||
if(lastMessage.messageForShow == "[自定义消息]"){
|
||
let text = "系统消息";
|
||
let payload = lastMessage.payload;
|
||
if(payload && payload.data) {
|
||
// console.log("payload: ",payload.data);
|
||
let payloadJson = JSON.parse(payload.data);
|
||
text = payloadJson.title.replaceAll(/—/g, "");
|
||
}
|
||
lastMessage.messageForShow = text;
|
||
}
|
||
if(lastMessage.type=="TIMCustomElem"){
|
||
let payload = lastMessage.payload;
|
||
if(payload && payload.data) {
|
||
// console.log("payload: ",payload.data);
|
||
let payloadJson = JSON.parse(payload.data);
|
||
session_item.custommessagetype =payloadJson.message_type?payloadJson.message_type:'';
|
||
}
|
||
|
||
}
|
||
if(lastMessage.isRevoked){
|
||
if(lastMessage.fromAccount == app.globalData.config.userID){
|
||
lastMessage.messageForShow = "你撤回了一条消息";
|
||
}else{
|
||
lastMessage.messageForShow = "对方撤回了一条消息";
|
||
}
|
||
}
|
||
txt.Text= lastMessage.messageForShow;
|
||
session_item.last_message_content = txt;
|
||
session_item.message_send_time = getTimeAgo(lastMessage.lastTime);
|
||
|
||
session_item.remaining_month_inquiry_count=remaining_month_inquiry_count;
|
||
session_item.service_package_start_time=service_package_start_time;
|
||
session_item.service_package_finish_time=service_package_finish_time;
|
||
session_item.service_period=service_period;
|
||
session_item.remaining_quantity=remaining_quantity;
|
||
session_item.monthly_frequency= monthly_frequency;
|
||
session_item.message_type = type;
|
||
session_item.order_inquiry_id = order_inquiry_id;
|
||
session_item.inquiry_type = inquiry_type;
|
||
session_item.inquiry_mode = inquiry_mode;
|
||
session_item.patient_age = patient_family_data.patient_age;
|
||
session_item.patient_name = patient_family_data.patient_name;
|
||
session_item.patient_sex = patient_family_data.patient_sex;
|
||
session_item.from_account = userProfile.userID;
|
||
let unreadCount = item.unreadCount;
|
||
if(unreadCount > 0){
|
||
totalUnreadCount = totalUnreadCount + unreadCount;
|
||
session_item.message_dot = true;
|
||
let dot_name = "dot_"+inquiry_type
|
||
this.setData({
|
||
[dot_name]: true
|
||
})
|
||
}else{
|
||
if(item.inquiry_status == 3){
|
||
totalUnreadCount = totalUnreadCount + 1;
|
||
session_item.message_dot = true;
|
||
let dot_name = "dot_"+inquiry_type
|
||
this.setData({
|
||
[dot_name]: true
|
||
})
|
||
}else{
|
||
session_item.message_dot = false;
|
||
}
|
||
}
|
||
|
||
session_list[inquiry_type - 1].push(session_item);
|
||
console.log("--------------------")
|
||
console.log(session_list)
|
||
})
|
||
|
||
|
||
wx.setStorageSync(userID+'_wenzhen_info', totalUnreadCount);
|
||
|
||
console.log(session_data_list_1)
|
||
this.setData({
|
||
data_list_1: session_data_list_1,
|
||
data_list_2: session_data_list_2,
|
||
data_list_3: session_data_list_3,
|
||
data_list_4: session_data_list_4,
|
||
data_list_5: session_data_list_5,
|
||
message_inquiry_type: message_inquiry_type
|
||
})
|
||
wx.stopPullDownRefresh()
|
||
// this.selectComponent('#tabs').resize();
|
||
|
||
},
|
||
checkOrderInquiryId(list, order_inquiry_id){
|
||
let index = list.findIndex(item => {
|
||
return item.order_inquiry_id == order_inquiry_id;
|
||
})
|
||
return index;
|
||
},
|
||
onTabsChange(e){
|
||
// console.log(e);
|
||
},
|
||
goChat(e){
|
||
this.setData({
|
||
show: false
|
||
})
|
||
// console.log("开始订阅消息");
|
||
// wx.requestSubscribeMessage({
|
||
// tmplIds: ['jhYUf91ULCTX_f69hazqAYwImdFf8ELasRAwB6X-MTM'],
|
||
// success (res) {
|
||
// console.log(res);
|
||
// }
|
||
// })
|
||
|
||
let from_account = e.currentTarget.dataset.from_account;
|
||
let order_inquiry_id = e.currentTarget.dataset.order_inquiry_id;
|
||
let from= e.currentTarget.dataset.from;
|
||
let inquiry_type = e.currentTarget.dataset.inquiry_type;
|
||
let url='';
|
||
|
||
//from=end代表从问诊接触过来,from=prescription 代表从处方管理进来
|
||
//主要处理有新的问诊还停留在老的聊天问诊里的bug。
|
||
if(from){
|
||
|
||
url = e.currentTarget.dataset.url+"?from_account="+from_account+"&order_inquiry_id="+order_inquiry_id+"&inquiry_type="+inquiry_type+"&from="+from;
|
||
}else{
|
||
|
||
url = e.currentTarget.dataset.url+"?from_account="+from_account+"&order_inquiry_id="+order_inquiry_id+"&inquiry_type="+inquiry_type;
|
||
}
|
||
|
||
app.go(url);
|
||
},
|
||
postDoctorInquiry(e){
|
||
this.setData({
|
||
show: false
|
||
})
|
||
// console.log("order_inquiry_id: ", e.currentTarget.dataset.order_inquiry_id);
|
||
let params = {};
|
||
params.order_inquiry_id = e.currentTarget.dataset.order_inquiry_id;
|
||
// console.log("params: ",params)
|
||
api.postDoctorInquiry(params).then(response => {
|
||
// console.log("开始接诊");
|
||
// console.log(response);
|
||
}).then(() => {
|
||
console.log(e)
|
||
console.log("gochat")
|
||
this.goChat(e);
|
||
}).catch(errors => {
|
||
console.error(errors);
|
||
})
|
||
},
|
||
//获取上方角标
|
||
getDoctorMessageNotice(e){
|
||
let usertype = wx.getStorageSync('usertype');
|
||
let userID = wx.getStorageSync('user_id_'+usertype);
|
||
api.getDoctorMessageNotice().then(response => {
|
||
let service_message_notice = response.data.service_message_notice;
|
||
let system_message_notice = response.data.system_message_notice;
|
||
wx.setStorageSync(userID+"_service_notice_unreadnnum", service_message_notice==true?1:"");//3、医生端系统通知
|
||
wx.setStorageSync(userID+"_system_notice_unreadnnum", system_message_notice);//4、医生端服务通知
|
||
}).catch(errors => {
|
||
console.error(errors);
|
||
})
|
||
},
|
||
tabShow(e){
|
||
let show_dialog_from_account = e.currentTarget.dataset.show_dialog_from_account;
|
||
let show_dialog_order_inquiry_id = e.currentTarget.dataset.show_dialog_order_inquiry_id;
|
||
let show_dialog_inquiry_type = e.currentTarget.dataset.show_dialog_inquiry_type;
|
||
// console.log("tabShowtabShowtabShowtabShow");
|
||
this.setData({
|
||
show_dialog_from_account: show_dialog_from_account,
|
||
show_dialog_order_inquiry_id: show_dialog_order_inquiry_id,
|
||
show_dialog_inquiry_type: show_dialog_inquiry_type,
|
||
show: true
|
||
})
|
||
},
|
||
onClose(){
|
||
// console.log("onCloseonCloseonCloseonClose")
|
||
this.setData({
|
||
show: false
|
||
})
|
||
},
|
||
onTabClick(e){
|
||
if(e.detail.name==6){
|
||
this.setData({
|
||
current_page:0,
|
||
data_list_6:[]
|
||
})
|
||
//点击请求数据为0,则重新渲染页面
|
||
this.getDoctorInquiryFinishMessage('end');
|
||
}
|
||
},
|
||
vanTabsChange(e){
|
||
//console.log(e)
|
||
this.setData({
|
||
now_message_inquiry_type: e.detail.name
|
||
});
|
||
|
||
},
|
||
onPullDownRefresh(){
|
||
// console.log("用户下拉动作")
|
||
this.onHide();
|
||
this.onShow();
|
||
},
|
||
onReachBottom() {
|
||
// console.log('===触底了!!===');
|
||
let now_message_inquiry_type = this.data.now_message_inquiry_type;
|
||
if(now_message_inquiry_type == 6){
|
||
if(this.data.current_page < this.data.last_page){//最后一页时停止分页
|
||
this.getDoctorInquiryFinishMessage()
|
||
}
|
||
}
|
||
},
|
||
getDoctorInquiryFinishMessage(from=''){
|
||
let data_list_6= this.data.data_list_6;
|
||
let params = {};
|
||
params.page = this.data.current_page + 1;
|
||
this.setData({data_list_6_loading: true})
|
||
api.getDoctorInquiryFinishMessage(params).then(response => {
|
||
this.setData({
|
||
"data_list_6": data_list_6.concat(response.data.data),
|
||
current_page: response.data.current_page,
|
||
total: response.data.total,
|
||
per_page: response.data.per_page,
|
||
last_page: response.data.last_page
|
||
})
|
||
if(from && response.data.data.length==0){
|
||
this.formatStatus();
|
||
}
|
||
// this.selectComponent('#tabs').resize();
|
||
}).then(res =>{
|
||
this.setData({ data_list_6_loading: false})
|
||
}).catch(errors => {
|
||
this.setData({ data_list_6_loading: false})
|
||
console.error(errors);
|
||
})
|
||
}
|
||
}) |