diff --git a/subPackages/doctor/doctor-userinfo.vue b/subPackages/doctor/doctor-userinfo.vue index f179860..358c5e9 100644 --- a/subPackages/doctor/doctor-userinfo.vue +++ b/subPackages/doctor/doctor-userinfo.vue @@ -409,9 +409,9 @@ export default { }); }).catch((error) => { console.error('保存患者就诊信息失败:', error); - // 即使保存失败,也跳转到挂号页面 + const rInfoStr = typeof this.rInfo === 'string' ? this.rInfo : JSON.stringify(this.rInfo); uni.navigateTo({ - url: `/subPackages/register/register?id=${this.register_id}&doctor_id=${this.Did}&r_info=${this.rInfo}` + url: `/subPackages/register/register?id=${this.register_id}&doctor_id=${this.Did}&r_info=${encodeURIComponent(rInfoStr)}` }); }); } @@ -419,9 +419,10 @@ export default { } uni.setStorageSync('register_id', this.register_id) + const rInfoEncoded = encodeURIComponent(typeof this.rInfo === 'string' ? this.rInfo : JSON.stringify(this.rInfo || {})); if (res.data.data.isHas == 0) { uni.navigateTo({ - url: `/subPackages/register/register?id=${this.register_id}&doctor_id=${this.Did}&r_info=${this.rInfo}`, + url: `/subPackages/register/register?id=${this.register_id}&doctor_id=${this.Did}&r_info=${rInfoEncoded}`, }) } else { this.$refs.uToast.show({ @@ -431,7 +432,7 @@ export default { }) setTimeout(() => { uni.navigateTo({ - url: `/subPackages/register/register?id=${this.register_id}&doctor_id=${this.Did}&r_info=${this.rInfo}`, + url: `/subPackages/register/register?id=${this.register_id}&doctor_id=${this.Did}&r_info=${rInfoEncoded}`, }) }, 900) } diff --git a/subPackages/product/symptoms.vue b/subPackages/product/symptoms.vue index 8d36659..4622d1e 100644 --- a/subPackages/product/symptoms.vue +++ b/subPackages/product/symptoms.vue @@ -606,6 +606,7 @@ export default { // 3. 准备患者就诊信息(包含info_id,用于后续更新register_id) const rInfo = { info_id: infoId, // 新增:用于挂号后更新关联 + doctor_id: doctorId, has_visited: formData.hasVisited, has_used_drug: formData.hasUsedDrug, illness_info: formData.illnessInfo, diff --git a/subPackages/register/register.vue b/subPackages/register/register.vue index 926bf51..90ddce5 100644 --- a/subPackages/register/register.vue +++ b/subPackages/register/register.vue @@ -163,70 +163,151 @@ 3: '复诊', }, rInfo: {}, + _urlDoctorId: '', + _getInfoPromise: null, } }, onLoad(e) { - // console.log(e, 'role'); - this.currentUserId = 'user-' + uni.getStorageSync('user_id') || 'user-2512'; - - // 原有逻辑:已有 register_id + const uid = uni.getStorageSync('user_id'); + this.currentUserId = 'user-' + (uid !== '' && uid !== undefined && uid !== null ? uid : '2512'); + this.register_id = e.id; - this.rInfo = e.r_info ? (typeof e.r_info === 'string' ? JSON.parse(decodeURIComponent(e.r_info)) : e.r_info) : {}; - // 修复:如果 doctor_id 为空字符串,也使用默认值;如果 doctor_id 存在且不为空,则使用它 - const doctorId = e.doctor_id && e.doctor_id.trim() !== '' ? e.doctor_id : null; - this.currentDoctorId = doctorId ? ('doctor-' + doctorId.replace('doctor-', '')) : 'doctor-39'; + try { + this.rInfo = e.r_info ? (typeof e.r_info === 'string' ? JSON.parse(decodeURIComponent(e.r_info)) : e.r_info) : {}; + } catch (err) { + console.error('register onLoad r_info parse', err); + this.rInfo = {}; + } + + const urlRaw = e.doctor_id && String(e.doctor_id).trim() !== '' ? String(e.doctor_id) : ''; + this._urlDoctorId = urlRaw ? this.stripDoctorPrefix(urlRaw) : ''; + + let initialDoc = ''; + if (this._urlDoctorId) initialDoc = this._urlDoctorId; + else if (this.rInfo && (this.rInfo.doctor_id != null && this.rInfo.doctor_id !== '')) { + initialDoc = this.stripDoctorPrefix(this.rInfo.doctor_id); + } else if (this.rInfo && (this.rInfo.doctorId != null && this.rInfo.doctorId !== '')) { + initialDoc = this.stripDoctorPrefix(this.rInfo.doctorId); + } + this.currentDoctorId = initialDoc ? ('doctor-' + initialDoc) : ''; + uni.setStorageSync('register_id', this.register_id); - - // 获取挂号信息 + if (this.register_id) { - this.getInfo(); + this._getInfoPromise = this.getInfo(); + this._getInfoPromise.then(() => this.ensureDoctorAfterLoad()); + } else { + this.ensureDoctorAfterLoad(); } }, methods: { + stripDoctorPrefix(raw) { + if (raw === null || raw === undefined || raw === '') return ''; + return String(raw).replace(/^doctor-/, '').trim(); + }, + applyDoctorNumericId(id) { + const n = this.stripDoctorPrefix(id); + if (!n) return; + this.currentDoctorId = 'doctor-' + n; + }, + /** 同步可用的医生数字 id:详情 > rInfo > URL > 当前 currentDoctorId */ + getDoctorNumericIdFromLocalSync() { + const rl = this.registList; + if (rl && typeof rl === 'object' && !Array.isArray(rl) && rl.service_user_id) { + const s = this.stripDoctorPrefix(rl.service_user_id); + if (s) return s; + } + if (this.rInfo) { + const d = this.rInfo.doctor_id != null && this.rInfo.doctor_id !== '' ? this.rInfo.doctor_id : this.rInfo.doctorId; + if (d != null && d !== '') { + const s = this.stripDoctorPrefix(d); + if (s) return s; + } + } + if (this._urlDoctorId) { + const s = this.stripDoctorPrefix(this._urlDoctorId); + if (s) return s; + } + const cur = this.stripDoctorPrefix(this.currentDoctorId); + if (cur) return cur; + return ''; + }, + async fetchDefaultDoctorIdApi() { + const storeId = uni.getStorageSync('store_id') || '11001'; + try { + const res = await request('/xkApi/online-consultation/get-default-doctor-id', { + method: 'GET', + data: { store_id: storeId } + }, 0); + const id = res.data?.result?.doctor_id ?? res.data?.doctor_id; + return id ? this.stripDoctorPrefix(id) : ''; + } catch (err) { + console.error('get-default-doctor-id failed', err); + return ''; + } + }, + async resolveDoctorNumericIdForIm() { + let id = this.getDoctorNumericIdFromLocalSync(); + if (!id) id = await this.fetchDefaultDoctorIdApi(); + if (id) this.applyDoctorNumericId(id); + return id || ''; + }, + async ensureDoctorAfterLoad() { + const existing = this.getDoctorNumericIdFromLocalSync(); + if (existing) { + this.applyDoctorNumericId(existing); + return; + } + const id = await this.fetchDefaultDoctorIdApi(); + if (id) this.applyDoctorNumericId(id); + }, + async waitForRegisterDetail() { + if (!this.register_id) return; + try { + if (this._getInfoPromise) await this._getInfoPromise; + else await this.getInfo(); + } catch (err) { + console.error('waitForRegisterDetail', err); + } + }, // 挂号信息 getInfo() { - let that = this; - registeInfo({ + const that = this; + if (!this.register_id) return Promise.resolve(); + const p = registeInfo({ method: "post", data: { store_id: uni.getStorageSync('store_id') || '11001', register_id: that.register_id } }).then((res) => { - // console.log(res, 'gh'); - if (res.data.errcode == 0) { - that.registList = res.data.data.list[0] - that.registerType = that.registerMap[that.registList.register_type]; - // 如果挂号信息中有医生ID,更新 currentDoctorId + if (res.data.errcode == 0 && res.data.data.list && res.data.data.list[0]) { + that.registList = res.data.data.list[0]; + that.registerType = that.registerMap[that.registList.register_type]; if (that.registList.service_user_id) { - that.currentDoctorId = 'doctor-' + that.registList.service_user_id; + that.applyDoctorNumericId(that.registList.service_user_id); } } - }) + }); + this._getInfoPromise = p; + return p; }, // 处理在线复诊支付后的流程 async handleOnlineConsultationAfterPayment() { - let that = this; + const that = this; try { - // 1. 获取医生ID(优先从挂号信息中获取,否则从 currentDoctorId 中提取) - let doctorId = ''; - if (that.registList && that.registList.service_user_id) { - doctorId = String(that.registList.service_user_id); - } else { - doctorId = that.currentDoctorId.replace('doctor-', ''); - } - - // 如果医生ID仍然为空,报错 - if (!doctorId || doctorId === '') { + const doctorId = await that.resolveDoctorNumericIdForIm(); + if (!doctorId) { uni.hideLoading(); uni.showToast({ - title: '医生ID不能为空:' + doctorId, + title: '无法获取医生信息,请稍后重试', icon: 'none' }); return; } - - // 2. 获取患者ID + const doctorPrefixed = 'doctor-' + doctorId; + that.currentDoctorId = doctorPrefixed; + const patientId = that.currentUserId.replace('user-', ''); // 3. 创建或获取聊天房间 @@ -295,16 +376,14 @@ register_info: typeof that.rInfo === 'string' ? that.rInfo : JSON.stringify(that.rInfo), }).then((resOrder) => { uni.hideLoading(); - // 跳转到聊天页面 uni.navigateTo({ - url: `/subPackages/chat/chat?user_id=${that.currentDoctorId}&room_id=${roomId}®ister_id=${that.register_id}` + url: `/subPackages/chat/chat?user_id=${encodeURIComponent(doctorPrefixed)}&room_id=${roomId}®ister_id=${that.register_id}` }); }).catch((error) => { console.error('生成订单失败:', error); uni.hideLoading(); - // 即使生成订单失败,也跳转到聊天页面 uni.navigateTo({ - url: `/subPackages/chat/chat?user_id=${that.currentDoctorId}&room_id=${roomId}®ister_id=${that.register_id}` + url: `/subPackages/chat/chat?user_id=${encodeURIComponent(doctorPrefixed)}&room_id=${roomId}®ister_id=${that.register_id}` }); }); } catch (error) { @@ -329,46 +408,41 @@ register_id: this.register_id, store_id: uni.getStorageSync('store_id') || '11001', } - }).then((res) => { - // console.log(res, 'pay'); + }).then(async (res) => { uni.showLoading({ title: "加载中" }); - console.log(checkDev('open-im') && that.registList.register_type === 1, 'sssssssssssss') - if (checkDev('open-im') && that.registList.register_type === 1) { - // 在线咨询:创建type=1的房间 - createRoomByDoctorIdApi({ - doctor_id: that.currentDoctorId, - type: 1 // 在线咨询 - }).then(result => { - sendToUserApi({ - room_id: result.data.result.room_id, - sender_user_id: `user-${that.currentUserId}`, - receiver_user_id: `doctor-${that.currentDoctorId}`, - message_type: 10, - message_content: JSON.stringify({ - id: that.register_id, - }), - duration: 0 - }) - }) - } + if (checkDev('open-im') && that.registList && that.registList.register_type === 1) { + createRoomByDoctorIdApi({ + doctor_id: that.currentDoctorId, + type: 1 + }).then(result => { + sendToUserApi({ + room_id: result.data.result.room_id, + sender_user_id: `user-${that.currentUserId}`, + receiver_user_id: `doctor-${that.currentDoctorId}`, + message_type: 10, + message_content: JSON.stringify({ + id: that.register_id, + }), + duration: 0 + }) + }) + } if (res.data.data.is_paid == 1) { - - if (that.registList.register_type === 2 || that.registList.register_type === 3) { - // 在线复诊/购药流程:创建type=3的聊天房间并发送患者就诊经历消息 - that.handleOnlineConsultationAfterPayment(); - return; - } + await that.waitForRegisterDetail(); + if (that.registList && (that.registList.register_type === 2 || that.registList.register_type === 3)) { + await that.handleOnlineConsultationAfterPayment(); + return; + } setTimeout(() => { uni.navigateTo({ url: `/subPackages/register/register-success?id=${that.register_id}®ister_type=${that.registList.register_type}`, }) uni.hideLoading(); }, 800) - return } @@ -379,31 +453,37 @@ package: res.data.data.package, signType: res.data.data.signType, paySign: res.data.data.paySign, - success: (res) => { - // console.log('success:' + JSON.stringify(res)); + success: async () => { + await that.waitForRegisterDetail(); + that.flag = false; + if (that.registList && (that.registList.register_type === 2 || that.registList.register_type === 3)) { + uni.showLoading({ title: '加载中' }); + await that.handleOnlineConsultationAfterPayment(); + return; + } setTimeout(() => { - that.flag = false - uni.navigateTo({ - url: '/subPackages/register/register-success?id=' + - this.register_id + url: '/subPackages/register/register-success?id=' + that.register_id }) uni.hideLoading(); }, 300) }, fail: function(err) { - // console.log('fail:' + JSON.stringify(err)); that.flag = false uni.hideLoading(); setTimeout(() => { that.$refs.uToast.show({ - title: res.data.msg || '支付失败', + title: (err && err.errMsg) || '支付失败', type: 'default', icon: false }) }, 300) } }) + }).catch((err) => { + console.error('registePay', err); + that.flag = true; + uni.hideLoading(); }) } }, @@ -429,7 +509,6 @@ } }, mounted() { - this.getInfo(); this.toAbout() } }