| | |
| | | <uni-icons type="arrowleft" size="20"></uni-icons> |
| | | </view> |
| | | <view class="title">创建转运任务</view> |
| | | <view class="smart-parse-btn" @click="showSmartParsePopup"> |
| | | <uni-icons type="compose" size="20" color="#007AFF"></uni-icons> |
| | | <text>智能识别</text> |
| | | </view> |
| | | </view> |
| | | |
| | | <view class="form-section"> |
| | |
| | | </view> |
| | | </uni-popup> |
| | | |
| | | <!-- 智能识别弹窗 --> |
| | | <uni-popup ref="smartParsePopup" type="bottom" :safe-area="true"> |
| | | <view class="smart-parse-popup"> |
| | | <view class="popup-header"> |
| | | <view class="popup-title">智能识别</view> |
| | | <view class="popup-close" @click="closeSmartParsePopup"> |
| | | <uni-icons type="closeempty" size="24" color="#333"></uni-icons> |
| | | </view> |
| | | </view> |
| | | |
| | | <view class="parse-content"> |
| | | <view class="parse-tip"> |
| | | <uni-icons type="info" size="18" color="#007AFF"></uni-icons> |
| | | <text>粘贴或输入文本,如:"患者张三,电话13800138000,从广州某某医院转入深圳某某中心,费用¥680"</text> |
| | | </view> |
| | | <textarea |
| | | class="parse-textarea" |
| | | placeholder="请在此粘贴或输入转运信息..." |
| | | v-model="rawText" |
| | | :maxlength="-1" |
| | | /> |
| | | </view> |
| | | |
| | | <view class="popup-footer"> |
| | | <button class="cancel-btn" @click="closeSmartParsePopup">取消</button> |
| | | <button class="confirm-btn" @click="parseFreeText" :disabled="parseLoading"> |
| | | {{ parseLoading ? '识别中...' : '开始识别' }} |
| | | </button> |
| | | </view> |
| | | </view> |
| | | </uni-popup> |
| | | |
| | | <!-- 病情选择弹窗 --> |
| | | <uni-popup ref="diseasePopup" type="bottom" :safe-area="true"> |
| | | <view class="disease-selector-popup"> |
| | |
| | | addressCoordinates: { |
| | | hospitalOutAddress: null, |
| | | hospitalInAddress: null |
| | | } |
| | | }, |
| | | // 智能识别相关 |
| | | rawText: '', |
| | | parseLoading: false |
| | | } |
| | | }, |
| | | computed: { |
| | |
| | | }).catch(() => {}) |
| | | }, |
| | | |
| | | goBack() { |
| | | goBack() { |
| | | uni.navigateBack() |
| | | }, |
| | | |
| | | // ==================== 智能识别相关方法 ==================== |
| | | |
| | | // 显示智能识别弹窗 |
| | | showSmartParsePopup() { |
| | | this.rawText = '' |
| | | this.$refs.smartParsePopup.open() |
| | | }, |
| | | |
| | | // 关闭智能识别弹窗 |
| | | closeSmartParsePopup() { |
| | | this.$refs.smartParsePopup.close() |
| | | this.rawText = '' |
| | | }, |
| | | |
| | | // 解析自由文本并填充表单 |
| | | parseFreeText() { |
| | | const text = (this.rawText || '').trim() |
| | | if (!text) { |
| | | this.$modal.showToast('请先粘贴或输入文本') |
| | | return |
| | | } |
| | | this.parseLoading = true |
| | | |
| | | const result = { |
| | | patientName: this.extractPatientName(text), |
| | | phone: this.extractPhone(text), |
| | | hospitalOutName: this.extractHospital(text, 'out'), |
| | | hospitalInName: this.extractHospital(text, 'in'), |
| | | departmentOut: this.extractDepartment(text, 'out'), |
| | | departmentIn: this.extractDepartment(text, 'in'), |
| | | price: this.extractPrice(text) |
| | | } |
| | | |
| | | // 应用基础字段 |
| | | if (result.patientName) this.taskForm.patient.name = result.patientName |
| | | if (result.phone) this.taskForm.patient.phone = result.phone |
| | | if (result.price) this.taskForm.price = result.price |
| | | |
| | | // 应用科室信息(匹配 departmentOptions 中的数据) |
| | | if (result.departmentOut) { |
| | | const deptOut = this.matchDepartment(result.departmentOut) |
| | | if (deptOut) { |
| | | this.taskForm.hospitalOut.department = deptOut.text |
| | | this.taskForm.hospitalOut.departmentId = deptOut.id |
| | | } |
| | | } |
| | | if (result.departmentIn) { |
| | | const deptIn = this.matchDepartment(result.departmentIn) |
| | | if (deptIn) { |
| | | this.taskForm.hospitalIn.department = deptIn.text |
| | | this.taskForm.hospitalIn.departmentId = deptIn.id |
| | | } |
| | | } |
| | | |
| | | // 处理医院名称 → 精确匹配医院并补全地址与ID(不限制分公司区域) |
| | | Promise.all([ |
| | | this.findHospitalByName(result.hospitalOutName, 'out', false), |
| | | this.findHospitalByName(result.hospitalInName, 'in', false) |
| | | ]) |
| | | .then(([outHosp, inHosp]) => { |
| | | if (outHosp) { |
| | | this.taskForm.hospitalOut.id = outHosp.hospId |
| | | this.taskForm.hospitalOut.name = outHosp.hospName |
| | | if (outHosp.hospName !== '家中') { |
| | | this.taskForm.hospitalOut.address = this.buildFullAddress(outHosp) |
| | | this.taskForm.hospitalOut.city = outHosp.hopsCity || '' |
| | | this.hospitalOutSearchKeyword = outHosp.hospName |
| | | } else { |
| | | this.taskForm.hospitalOut.address = '' |
| | | this.taskForm.hospitalOut.department = '其它' |
| | | this.hospitalOutSearchKeyword = '家中' |
| | | } |
| | | } else if (result.hospitalOutName) { |
| | | this.taskForm.hospitalOut.name = result.hospitalOutName |
| | | this.hospitalOutSearchKeyword = result.hospitalOutName |
| | | } |
| | | |
| | | if (inHosp) { |
| | | this.taskForm.hospitalIn.id = inHosp.hospId |
| | | this.taskForm.hospitalIn.name = inHosp.hospName |
| | | if (inHosp.hospName !== '家中') { |
| | | this.taskForm.hospitalIn.address = this.buildFullAddress(inHosp) |
| | | this.taskForm.hospitalIn.city = inHosp.hopsCity || '' |
| | | this.hospitalInSearchKeyword = inHosp.hospName |
| | | } else { |
| | | this.taskForm.hospitalIn.address = '' |
| | | this.taskForm.hospitalIn.department = '其它' |
| | | this.hospitalInSearchKeyword = '家中' |
| | | } |
| | | } else if (result.hospitalInName) { |
| | | this.taskForm.hospitalIn.name = result.hospitalInName |
| | | this.hospitalInSearchKeyword = result.hospitalInName |
| | | } |
| | | |
| | | // 若两端地址完整,自动计算距离与成交价 |
| | | if (this.taskForm.hospitalOut.address && this.taskForm.hospitalIn.address && |
| | | this.taskForm.hospitalOut.name !== '家中' && this.taskForm.hospitalIn.name !== '家中') { |
| | | this.calculateHospitalDistance() |
| | | } |
| | | }) |
| | | .catch(err => { |
| | | console.error('医院匹配失败:', err) |
| | | }) |
| | | .finally(() => { |
| | | this.parseLoading = false |
| | | this.closeSmartParsePopup() |
| | | this.$modal.showToast('识别完成,请核对自动填充结果') |
| | | }) |
| | | }, |
| | | |
| | | // 提取手机号(优先匹配移动号,次匹配座机) |
| | | extractPhone(text) { |
| | | // 先去除文本中的空格,再进行匹配 |
| | | const cleanText = text.replace(/\s+/g, '') |
| | | |
| | | // 匹配11位手机号(支持原文本中有空格的情况) |
| | | const mobile = cleanText.match(/(?<!\d)(1[3-9]\d{9})(?!\d)/) |
| | | if (mobile) return mobile[1] |
| | | |
| | | // 匹配座机号(支持带区号和连字符) |
| | | const landline = cleanText.match(/0\d{2,3}-?\d{7,8}/) |
| | | if (landline) return landline[0] |
| | | |
| | | // 兜底:在原文本中查找带空格的手机号格式(如:182 8569 1756) |
| | | const mobileWithSpace = text.match(/(?:电话|手机|联系|tel|phone)[::\s]*([1][3-9][\d\s]{9,15})/i) |
| | | if (mobileWithSpace) { |
| | | const cleanMobile = mobileWithSpace[1].replace(/\s+/g, '') |
| | | if (/^1[3-9]\d{9}$/.test(cleanMobile)) { |
| | | return cleanMobile |
| | | } |
| | | } |
| | | |
| | | // 最后尝试:直接查找任意带空格的11位数字组合 |
| | | const anyMobile = text.match(/([1][3-9][\d\s]{9,15})/) |
| | | if (anyMobile) { |
| | | const cleanAny = anyMobile[1].replace(/\s+/g, '') |
| | | if (/^1[3-9]\d{9}$/.test(cleanAny)) { |
| | | return cleanAny |
| | | } |
| | | } |
| | | |
| | | return '' |
| | | }, |
| | | |
| | | // 提取患者姓名(常见关键词前缀) |
| | | extractPatientName(text) { |
| | | const m = text.match(/(?:患者|病人|姓名|联系人)[:: ]?\s*([\u4e00-\u9fa5]{2,4})/) |
| | | return m ? m[1] : '' |
| | | }, |
| | | |
| | | // 提取成交价(支持¥/元/RMB等) |
| | | extractPrice(text) { |
| | | const m1 = text.match(/(?:成交价|价格|费用|收费|总价|共)[:: ]?\s*(?:¥|¥|RMB|人民币)?\s*([0-9]+(?:\.[0-9]{1,2})?)/i) |
| | | if (m1) return parseFloat(m1[1]).toFixed(2) |
| | | const m2 = text.match(/(?:¥|¥)\s*([0-9]+(?:\.[0-9]{1,2})?)/) |
| | | if (m2) return parseFloat(m2[1]).toFixed(2) |
| | | const m3 = text.match(/([0-9]+(?:\.[0-9]{1,2})?)\s*(?:元|人民币|RMB)/i) |
| | | if (m3) return parseFloat(m3[1]).toFixed(2) |
| | | return '' |
| | | }, |
| | | |
| | | // 提取医院名称(基于语义标记,支持简称如"省医") |
| | | extractHospital(text, type) { |
| | | // 先尝试语义标记提取 |
| | | const outReg = /(?:转出|来自|从)[:: ]?\s*([^\s,,。;;转]+?(?:医院|中心|卫生院|急救中心|家中|省医|市医|区医|县医|人民医院|中医院|妇幼|儿童医院))/ |
| | | const inReg = /(?:转入|至|前往|到|去往|转回)[:: ]?\s*([^\s,,。;;转]+?(?:医院|中心|卫生院|急救中心|家中|省医|市医|区医|县医|人民医院|中医院|妇幼|儿童医院))/ |
| | | const reg = type === 'out' ? outReg : inReg |
| | | const m = text.match(reg) |
| | | if (m) { |
| | | // 去除可能包含的楼栋、楼层、科室等信息 |
| | | let hospitalName = m[1] |
| | | // 去除楼栋信息(如:东一号楼、A栋等) |
| | | hospitalName = hospitalName.replace(/[东西南北中]?[一二三四五六七八九十0-9]+号?楼.*/g, '') |
| | | // 去除楼层信息(如:四楼、3F等) |
| | | hospitalName = hospitalName.replace(/[一二三四五六七八九十0-9]+[楼层F].*/g, '') |
| | | return hospitalName.trim() |
| | | } |
| | | |
| | | // 无语义标记时,兜底提取首个"含医院/中心/家中/简称"的片段 |
| | | const any = text.match(/([^\s,,。;;转]+?(?:医院|中心|卫生院|急救中心|家中|省医|市医|区医|县医|人民医院|中医院|妇幼|儿童医院))/g) |
| | | if (any && any.length > 0) { |
| | | if (type === 'out') { |
| | | let name = any[0] |
| | | name = name.replace(/[东西南北中]?[一二三四五六七八九十0-9]+号?楼.*/g, '') |
| | | name = name.replace(/[一二三四五六七八九十0-9]+[楼层F].*/g, '') |
| | | return name.trim() |
| | | } |
| | | if (type === 'in') { |
| | | let name = any[1] || any[0] |
| | | name = name.replace(/[东西南北中]?[一二三四五六七八九十0-9]+号?楼.*/g, '') |
| | | name = name.replace(/[一二三四五六七八九十0-9]+[楼层F].*/g, '') |
| | | return name.trim() |
| | | } |
| | | } |
| | | return '' |
| | | }, |
| | | |
| | | // 匹配科室(优先使用 departmentOptions 中的数据) |
| | | matchDepartment(deptName) { |
| | | if (!deptName || !this.departmentOptions || this.departmentOptions.length === 0) { |
| | | return null |
| | | } |
| | | |
| | | const normalized = deptName.trim().toUpperCase() |
| | | |
| | | // 1. 精确匹配(不区分大小写) |
| | | let matched = this.departmentOptions.find(d => |
| | | d.text.toUpperCase() === normalized |
| | | ) |
| | | if (matched) return matched |
| | | |
| | | // 2. 包含匹配(科室名包含识别到的关键词) |
| | | matched = this.departmentOptions.find(d => |
| | | d.text.toUpperCase().includes(normalized) || |
| | | normalized.includes(d.text.toUpperCase()) |
| | | ) |
| | | if (matched) return matched |
| | | |
| | | // 3. 模糊匹配(去除"科"、"室"等后缀再匹配) |
| | | const cleanedInput = normalized.replace(/[科室部]/g, '') |
| | | matched = this.departmentOptions.find(d => { |
| | | const cleanedDept = d.text.toUpperCase().replace(/[科室部]/g, '') |
| | | return cleanedDept === cleanedInput || |
| | | cleanedDept.includes(cleanedInput) || |
| | | cleanedInput.includes(cleanedDept) |
| | | }) |
| | | if (matched) return matched |
| | | |
| | | return null |
| | | }, |
| | | |
| | | // 提取科室信息 |
| | | extractDepartment(text, type) { |
| | | // 常见科室关键词(作为兜底方案) |
| | | const departments = [ |
| | | 'ICU', 'NICU', 'PICU', 'CCU', 'EICU', |
| | | '重症监护室', '急诊科', '门诊', '住院部', |
| | | '内科', '外科', '妇产科', '儿科', '骨科', '神经科', |
| | | '心内科', '心外科', '呼吸科', '消化科', '肾内科', |
| | | '血液科', '肿瘤科', '感染科', '皮肤科', '眼科', |
| | | '耳鼻喉科', '口腔科', '中医科', '康复科', '精神科', |
| | | '泌尿科', '内分泌科', '风湿科', '普外科', '胸外科', |
| | | '神经外科', '整形科', '烧伤科', '麻醉科', '放射科', |
| | | '检验科', '病理科', '药剂科', '营养科' |
| | | ] |
| | | |
| | | // 优先尝试从 departmentOptions 中匹配 |
| | | if (this.departmentOptions && this.departmentOptions.length > 0) { |
| | | // 构建 departmentOptions 的匹配模式(按长度倒序) |
| | | const optionTexts = this.departmentOptions.map(d => d.text).sort((a, b) => b.length - a.length) |
| | | const optionPattern = optionTexts.map(t => t.replace(/[()()]/g, '\\$&')).join('|') |
| | | |
| | | if (optionPattern) { |
| | | const regex = new RegExp(`(${optionPattern})`, 'gi') |
| | | const matches = text.match(regex) |
| | | |
| | | if (matches && matches.length > 0) { |
| | | // 如果是转出,取第一个科室;如果是转入,取最后一个科室 |
| | | return type === 'out' ? matches[0] : matches[matches.length - 1] |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 兜底:使用默认科室列表匹配 |
| | | const sortedDepts = departments.sort((a, b) => b.length - a.length) |
| | | const deptPattern = sortedDepts.join('|') |
| | | |
| | | const regex = new RegExp(`(${deptPattern})`, 'g') |
| | | const matches = text.match(regex) |
| | | |
| | | if (matches && matches.length > 0) { |
| | | // 如果是转出,取第一个科室;如果是转入,取最后一个科室 |
| | | return type === 'out' ? matches[0] : matches[matches.length - 1] |
| | | } |
| | | |
| | | return '' |
| | | }, |
| | | |
| | | // 通过名称匹配医院(restrictRegion=false 时全局查询) |
| | | findHospitalByName(name, type, restrictRegion = true) { |
| | | if (!name) return Promise.resolve(null) |
| | | const normalized = name.trim() |
| | | |
| | | // 特殊处理"家中" |
| | | if (normalized === '家中') { |
| | | // 查询医院库中的"家中"记录 |
| | | const deptId = this.selectedOrganizationId || null |
| | | const queryPromise = restrictRegion && deptId |
| | | ? searchHospitalsByDeptRegion('家中', deptId, 50) |
| | | : searchHospitals('家中', null, 50) |
| | | |
| | | return queryPromise.then(res => { |
| | | const list = res.data || [] |
| | | // 查找名称为"家中"的医院记录 |
| | | const homeHospital = list.find(h => h.hospName === '家中') |
| | | if (homeHospital) { |
| | | return homeHospital |
| | | } |
| | | // 如果没有找到,返回默认结构 |
| | | return { |
| | | hospId: null, |
| | | hospName: '家中', |
| | | hopsCity: '', |
| | | hospAddress: '' |
| | | } |
| | | }).catch(() => { |
| | | // 查询失败,返回默认结构 |
| | | return { |
| | | hospId: null, |
| | | hospName: '家中', |
| | | hopsCity: '', |
| | | hospAddress: '' |
| | | } |
| | | }) |
| | | } |
| | | |
| | | // restrictRegion=false 时走全量查询;true 且有 deptId 时走区域接口 |
| | | const deptId = this.selectedOrganizationId || null |
| | | const queryPromise = (restrictRegion && deptId) |
| | | ? searchHospitalsByDeptRegion(normalized, deptId, 50) |
| | | : searchHospitals(normalized, null, 50) |
| | | |
| | | return queryPromise.then(res => { |
| | | const list = res.data || [] |
| | | if (!list.length) return null |
| | | |
| | | // 自动选择第一个非"家中"的区院,如果全是"家中"则选第一个 |
| | | const best = this.pickBestHospitalMatch(list, normalized) |
| | | return best || null |
| | | }) |
| | | }, |
| | | |
| | | // 在候选中选择最优匹配(支持简称匹配、包含与长度接近) |
| | | pickBestHospitalMatch(list, name) { |
| | | const n = name.trim() |
| | | |
| | | // 过滤掉"家中",优先选择真实医院 |
| | | const realHospitals = list.filter(h => h.hospName !== '家中') |
| | | const searchList = realHospitals.length > 0 ? realHospitals : list |
| | | |
| | | // 1. 完全相等(正式名) |
| | | let best = searchList.find(h => (h.hospName || '').trim() === n) |
| | | if (best) return best |
| | | // 2. 完全相等(简称) |
| | | best = searchList.find(h => (h.hospShort || '').trim() === n) |
| | | if (best) return best |
| | | // 3. 包含(正式名) |
| | | best = searchList.find(h => (h.hospName || '').includes(n) || n.includes((h.hospName || ''))) |
| | | if (best) return best |
| | | // 4. 包含(简称) |
| | | best = searchList.find(h => (h.hospShort || '').includes(n) || n.includes((h.hospShort || ''))) |
| | | if (best) return best |
| | | // 5. 长度最接近 |
| | | best = [...searchList].sort((a, b) => { |
| | | const da = Math.abs((a.hospName || '').length - n.length) |
| | | const db = Math.abs((b.hospName || '').length - n.length) |
| | | return da - db |
| | | })[0] |
| | | |
| | | // 如果没有找到任何匹配,返回第一个 |
| | | return best || searchList[0] || null |
| | | }, |
| | | |
| | | // 合并医院地址(省 + 市 + 区 + 详细地址) |
| | |
| | | } |
| | | |
| | | .title { |
| | | flex: 1; |
| | | font-size: 36rpx; |
| | | font-weight: bold; |
| | | color: #333; |
| | | } |
| | | |
| | | .smart-parse-btn { |
| | | display: flex; |
| | | flex-direction: column; |
| | | align-items: center; |
| | | justify-content: center; |
| | | padding: 10rpx 20rpx; |
| | | |
| | | text { |
| | | font-size: 22rpx; |
| | | color: #007AFF; |
| | | margin-top: 4rpx; |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | // 智能识别弹窗样式 |
| | | .smart-parse-popup { |
| | | background-color: white; |
| | | border-radius: 20rpx 20rpx 0 0; |
| | | max-height: 80vh; |
| | | display: flex; |
| | | flex-direction: column; |
| | | |
| | | .popup-header { |
| | | display: flex; |
| | | justify-content: space-between; |
| | | align-items: center; |
| | | padding: 30rpx; |
| | | border-bottom: 1rpx solid #f0f0f0; |
| | | flex-shrink: 0; |
| | | |
| | | .popup-title { |
| | | font-size: 32rpx; |
| | | font-weight: bold; |
| | | color: #333; |
| | | } |
| | | |
| | | .popup-close { |
| | | padding: 10rpx; |
| | | } |
| | | } |
| | | |
| | | .parse-content { |
| | | flex: 1; |
| | | padding: 30rpx; |
| | | overflow-y: auto; |
| | | |
| | | .parse-tip { |
| | | display: flex; |
| | | align-items: flex-start; |
| | | padding: 20rpx; |
| | | background-color: #f0f7ff; |
| | | border-radius: 10rpx; |
| | | margin-bottom: 20rpx; |
| | | |
| | | text { |
| | | flex: 1; |
| | | margin-left: 10rpx; |
| | | font-size: 24rpx; |
| | | color: #666; |
| | | line-height: 1.6; |
| | | } |
| | | } |
| | | |
| | | .parse-textarea { |
| | | width: 100%; |
| | | min-height: 300rpx; |
| | | padding: 20rpx; |
| | | border: 1rpx solid #eee; |
| | | border-radius: 10rpx; |
| | | font-size: 28rpx; |
| | | line-height: 1.6; |
| | | } |
| | | } |
| | | |
| | | .popup-footer { |
| | | display: flex; |
| | | padding: 20rpx 30rpx; |
| | | border-top: 1rpx solid #f0f0f0; |
| | | gap: 20rpx; |
| | | flex-shrink: 0; |
| | | |
| | | button { |
| | | flex: 1; |
| | | height: 80rpx; |
| | | border-radius: 10rpx; |
| | | font-size: 30rpx; |
| | | } |
| | | |
| | | .cancel-btn { |
| | | background-color: #f5f5f5; |
| | | color: #666; |
| | | } |
| | | |
| | | .confirm-btn { |
| | | background-color: #007AFF; |
| | | color: white; |
| | | |
| | | &[disabled] { |
| | | background-color: #ccc; |
| | | color: #999; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 病情选择弹窗样式 |
| | | .disease-selector-popup { |
| | | background-color: white; |