wlzboy
2025-11-22 fd047fa7234dc11643dab8ecbf38e8d7a8ba0854
app/pages/task/create-emergency.vue
@@ -5,6 +5,10 @@
        <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">
@@ -18,13 +22,12 @@
        </picker>
      </view>
        <view class="form-item">
        <view class="form-label required">归属机构</view>
        <picker mode="selector" :range="organizations" @change="onOrganizationChange">
          <view class="form-input picker-input">
            {{ selectedOrganization || '请选择归属机构' }}
            <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
          </view>
        </picker>
        <OrganizationSelector
          v-model="selectedOrganizationId"
          :required="true"
          :auto-select-user-dept="true"
          @change="onOrganizationChange"
        />
      </view>
      
      <view class="form-item">
@@ -140,200 +143,38 @@
        />
      </view>
      
      <view class="form-item">
        <view class="form-label">病情</view>
        <view class="disease-container">
          <view class="disease-tags" v-if="selectedDiseases.length > 0">
            <view
              class="disease-tag"
              v-for="(disease, index) in selectedDiseases"
              :key="index"
            >
              <text class="disease-name">{{ disease.icdName }}</text>
              <uni-icons
                type="closeempty"
                size="16"
                color="#fff"
                @click="removeDisease(index)"
              ></uni-icons>
            </view>
          </view>
          <view class="add-disease-btn" @click="showDiseaseSelector">
            <uni-icons type="plusempty" size="20" color="#007AFF"></uni-icons>
            <text>添加病情</text>
          </view>
          <textarea
            class="form-textarea"
            placeholder="其他病情描述(选填)"
            v-model="taskForm.patient.condition"
            style="margin-top: 20rpx;"
          />
        </view>
      </view>
      <DiseaseSelector
        v-model="selectedDiseases"
        :other-description.sync="taskForm.patient.condition"
      />
      
      <view class="form-section-title">转出医院信息</view>
      <view class="form-item">
        <view class="form-label required">医院名称</view>
        <view class="hospital-search-container">
          <input
            class="form-input"
            placeholder="请输入医院名称或地址搜索"
            v-model="hospitalOutSearchKeyword"
            @input="onHospitalOutSearch"
            @focus="onHospitalOutFocus"
          />
          <view class="search-results" v-if="showHospitalOutResults && hospitalOutResults.length > 0">
            <view
              class="search-result-item"
              v-for="hospital in hospitalOutResults"
              :key="hospital.hospId"
              @click="selectHospitalOut(hospital)"
            >
              <view class="hospital-name">
                {{ hospital.hospName }}
                <text class="hospital-short" v-if="hospital.hospShort">{{ hospital.hospShort }}</text>
              </view>
              <view class="hospital-address">{{ buildFullAddress(hospital) }}</view>
            </view>
          </view>
        </view>
      </view>
      <view class="form-item">
        <view class="form-label required">科室</view>
        <picker
          v-if="taskForm.hospitalOut.name !== '家中'"
          mode="selector"
          :range="departmentOptions"
          range-key="text"
          @change="onHospitalOutDepartmentChange"
        >
          <view class="form-input picker-input">
            {{ taskForm.hospitalOut.department || '请选择科室' }}
            <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
          </view>
        </picker>
        <view v-else class="form-input picker-input disabled">
          其它
        </view>
      </view>
      <view class="form-item">
        <view class="form-label">床号</view>
        <input
          class="form-input"
          placeholder="请输入床号"
          v-model="taskForm.hospitalOut.bedNumber"
        />
      </view>
      <view class="form-item">
        <view class="form-label">转出地址</view>
        <view class="address-input-container" v-if="taskForm.hospitalOut.name === '家中'">
          <input
            class="form-input"
            placeholder="请输入详细地址"
            v-model="taskForm.hospitalOut.address"
            @input="onAddressOutInput"
            @focus="onAddressOutFocus"
          />
          <view class="address-suggestions" v-if="showAddressOutSuggestions && addressOutSuggestions.length > 0">
            <view
              class="address-suggestion-item"
              v-for="(item, index) in addressOutSuggestions"
              :key="index"
              @click="selectAddressOut(item)">
              <view class="suggestion-name">{{ item.name }}</view>
              <view class="suggestion-address">{{ item.district }}{{ item.address }}</view>
            </view>
          </view>
        </view>
        <view v-else class="form-input picker-input disabled">
          {{ taskForm.hospitalOut.address || '选择医院后自动填充' }}
        </view>
      </view>
      <HospitalSelector
        label="医院名称"
        address-label="转出地址"
        :required="true"
        :department-required="true"
        v-model="taskForm.hospitalOut"
        :dept-id="selectedOrganizationId"
        :region="selectedRegion"
        :department-options="departmentOptions"
        @change="onHospitalOutChange"
        @address-selected="onHospitalOutAddressSelected"
      />
      
      <view class="form-section-title">转入医院信息</view>
      <view class="form-item">
        <view class="form-label required">医院名称</view>
        <view class="hospital-search-container">
          <input
            class="form-input"
            placeholder="请输入医院名称或地址搜索"
            v-model="hospitalInSearchKeyword"
            @input="onHospitalInSearch"
            @focus="onHospitalInFocus"
          />
          <view class="search-results" v-if="showHospitalInResults && hospitalInResults.length > 0">
            <view
              class="search-result-item"
              v-for="hospital in hospitalInResults"
              :key="hospital.hospId"
              @click="selectHospitalIn(hospital)"
            >
              <view class="hospital-name">
                {{ hospital.hospName }}
                <text class="hospital-short" v-if="hospital.hospShort">{{ hospital.hospShort }}</text>
              </view>
              <view class="hospital-address">{{ buildFullAddress(hospital) }}</view>
            </view>
          </view>
        </view>
      </view>
      <view class="form-item">
        <view class="form-label required">科室</view>
        <picker
          v-if="taskForm.hospitalIn.name !== '家中'"
          mode="selector"
          :range="departmentOptions"
          range-key="text"
          @change="onHospitalInDepartmentChange"
        >
          <view class="form-input picker-input">
            {{ taskForm.hospitalIn.department || '请选择科室' }}
            <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
          </view>
        </picker>
        <view v-else class="form-input picker-input disabled">
          其它
        </view>
      </view>
      <view class="form-item">
        <view class="form-label">床号</view>
        <input
          class="form-input"
          placeholder="请输入床号"
          v-model="taskForm.hospitalIn.bedNumber"
        />
      </view>
      <view class="form-item">
        <view class="form-label">转入地址</view>
        <view class="address-input-container" v-if="taskForm.hospitalIn.name === '家中'">
          <input
            class="form-input"
            placeholder="请输入详细地址"
            v-model="taskForm.hospitalIn.address"
            @input="onAddressInInput"
            @focus="onAddressInFocus"
          />
          <view class="address-suggestions" v-if="showAddressInSuggestions && addressInSuggestions.length > 0">
            <view
              class="address-suggestion-item"
              v-for="(item, index) in addressInSuggestions"
              :key="index"
              @click="selectAddressIn(item)">
              <view class="suggestion-name">{{ item.name }}</view>
              <view class="suggestion-address">{{ item.district }}{{ item.address }}</view>
            </view>
          </view>
        </view>
        <view v-else class="form-input picker-input disabled">
          {{ taskForm.hospitalIn.address || '选择医院后自动填充' }}
        </view>
      </view>
      <HospitalSelector
        label="医院名称"
        address-label="转入地址"
        :required="true"
        :department-required="true"
        v-model="taskForm.hospitalIn"
        :dept-id="selectedOrganizationId"
        :region="selectedRegion"
        :department-options="departmentOptions"
        @change="onHospitalInChange"
        @address-selected="onHospitalInAddressSelected"
      />
      
      <view class="form-item">
        <view class="form-label required">转运公里数</view>
@@ -342,6 +183,7 @@
          type="digit" 
          placeholder="请输入转运公里数" 
          v-model="taskForm.transferDistance"
          @blur="onDistanceChange"
        />
      </view>
      
@@ -439,60 +281,34 @@
      </view>
    </uni-popup>
    
    <!-- 病情选择弹窗 -->
    <uni-popup ref="diseasePopup" type="bottom" :safe-area="true">
      <view class="disease-selector-popup">
   <!-- 智能识别弹窗 -->
    <uni-popup ref="smartParsePopup" type="bottom" :safe-area="true">
      <view class="smart-parse-popup">
        <view class="popup-header">
          <view class="popup-title">选择病情(ICD-10)</view>
          <view class="popup-close" @click="closeDiseaseSelector">
          <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="search-box">
          <uni-icons type="search" size="18" color="#999"></uni-icons>
          <input
            class="search-input"
            placeholder="搜索疾病名称、编码或助记码"
            v-model="diseaseSearchKeyword"
            @input="onDiseaseSearch"
        <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>
        
        <scroll-view class="disease-list-popup" scroll-y="true">
          <view
            class="disease-item-popup"
            v-for="disease in diseaseSearchResults"
            :key="disease.id"
            @click="toggleDiseaseSelection(disease)"
          >
            <view class="disease-info">
              <view class="disease-name-row">
                <text class="disease-name">{{ disease.icdName }}</text>
                <text class="disease-code">[{{ disease.icdCode }}]</text>
              </view>
              <view class="disease-detail-row" v-if="disease.sm">
                <text class="disease-desc">{{ disease.sm }}</text>
              </view>
            </view>
            <uni-icons
              v-if="isDiseaseSelected(disease.id)"
              type="checkmarkempty"
              size="24"
              color="#007AFF"
            ></uni-icons>
            <view v-else class="checkbox-empty"></view>
          </view>
          <view class="no-data" v-if="diseaseSearchResults.length === 0">
            <uni-icons type="info" size="40" color="#ccc"></uni-icons>
            <text>{{ diseaseSearchKeyword ? '未找到相关疾病' : '暂无病情数据' }}</text>
          </view>
        </scroll-view>
        <view class="popup-footer">
          <button class="cancel-btn" @click="closeDiseaseSelector">取消</button>
          <button class="confirm-btn" @click="confirmDiseaseSelection">确定(已选{{ tempSelectedDiseases.length }})</button>
          <button class="cancel-btn" @click="closeSmartParsePopup">取消</button>
          <button class="confirm-btn" @click="parseFreeText" :disabled="parseLoading">
            {{ parseLoading ? '识别中...' : '开始识别' }}
          </button>
        </view>
      </view>
    </uni-popup>
@@ -506,26 +322,33 @@
import { addTask } from "@/api/task"
import { listAvailableVehicles, getUserBoundVehicle } from "@/api/vehicle"
import { calculateDistance, baiduDistanceByAddress, baiduPlaceSuggestion } from "@/api/map"
import { searchHospitals, getFrequentOutHospitals, getFrequentInHospitals } from "@/api/hospital"
import { listUser } from "@/api/system/user"
import { searchHospitals, getFrequentOutHospitals, getFrequentInHospitals, searchHospitalsByDeptRegion } from "@/api/hospital"
import { listBranchUsers } from "@/api/system/user"
import { searchIcd10 } from "@/api/icd10"
import { calculateTransferPrice } from "@/api/price"
import { checkVehicleActiveTasks } from "@/api/task"
import { getDicts } from "@/api/dict"
import { getServiceOrdAreaTypes, getServiceOrderTypes, getHospitalDepartments } from "@/api/dictionary"
import { listBranchCompany, getDept } from "@/api/system/dept"
import MapSelector from '@/components/map-selector.vue'
import OrganizationSelector from '@/components/OrganizationSelector.vue'
import HospitalSelector from '@/components/HospitalSelector.vue'
import DiseaseSelector from '@/components/DiseaseSelector.vue'
export default {
  components: {
    uniDatetimePicker,
    uniPopup,
    MapSelector
    MapSelector,
    OrganizationSelector,
    HospitalSelector,
    DiseaseSelector
  },
  data() {
    return {
      selectedVehicle: '',
      selectedVehicleId: null,
      selectedOrganization: '',
      selectedOrganizationId: null, // 归属机构ID(部门ID)
      selectedOrganizationServiceOrderClass: '', // 归属机构的服务单编码
      selectedRegion: '', // 从归属机构中提取的地域信息(如:广州、深圳等)
@@ -534,21 +357,6 @@
      selectedDocumentType: '', // 选中的单据类型文本
      selectedDocumentTypeId: null, // 选中的单据类型ID
      mapSelectorType: '',
      // 医院搜索相关
      hospitalOutSearchKeyword: '',
      hospitalOutResults: [],
      showHospitalOutResults: false,
      hospitalInSearchKeyword: '',
      hospitalInResults: [],
      showHospitalInResults: false,
      searchTimer: null,
      defaultHospitals: [], // 默认的100条医院数据
      // 地址搜索提示相关
      addressOutSuggestions: [], // 转出地址提示列表
      showAddressOutSuggestions: false,
      addressInSuggestions: [], // 转入地址提示列表
      showAddressInSuggestions: false,
      addressSearchTimer: null, // 地址搜索防抖定时器
      // 人员选择相关
      selectedStaff: [], // 已选择的人员列表
      allStaffList: [], // 所有人员列表
@@ -557,10 +365,6 @@
      staffFilterType: 'driver', // 人员筛选类型:driver/doctor/nurse,默认选中司机
      // 病情选择相关
      selectedDiseases: [], // 已选择的病情列表
      tempSelectedDiseases: [], // 临时选择的病情列表(用于弹窗)
      diseaseSearchKeyword: '', // 病情搜索关键词
      diseaseSearchResults: [], // 病情搜索结果
      diseaseSearchTimer: null, // 病情搜索防抖定时器
      taskForm: {
        transferTime: '',
        patient: {
@@ -592,8 +396,7 @@
      },
      vehicles: [],
      vehicleOptions: [],
      organizations: [], // 归属机构列表(从后台加载分公司数据)
      organizationOptions: [], // 归属机构选项(用于picker显示)
      emergencyTaskTypes: [], // 任务类型列表(从 SQL Server 动态加载)
      emergencyTaskTypeOptions: [], // 任务类型选项(用于picker显示)
      documentTypes: [], // 单据类型列表
@@ -603,7 +406,10 @@
      addressCoordinates: {
        hospitalOutAddress: null,
        hospitalInAddress: null
      }
      },
      // 智能识别相关
      rawText: '',
      parseLoading: false
    }
  },
  computed: {
@@ -638,8 +444,6 @@
    })
    this.initSelectedStaff()
    this.loadDeptStaff()
    // 加载分公司数据(会自动设置默认分公司并加载医院列表)
    this.loadBranchCompanies()
    // 加载科室字典数据
    this.loadDepartments()
    // 加载任务类型数据
@@ -712,50 +516,17 @@
      this.selectedVehicleId = this.vehicleOptions[index]?.id
    },
    
    onOrganizationChange(e) {
      const index = e.detail.value
      const selected = this.organizationOptions[index]
      this.selectedOrganization = selected.deptName
      this.selectedOrganizationId = selected.deptId // 保存部门ID
      this.selectedOrganizationServiceOrderClass = selected.serviceOrderClass || '' // 保存服务单编码
      // 从归属机构中提取地域关键词(去除“分公司”后缀)
      // 例如:“广州分公司” -> “广州”
      this.selectedRegion = selected.deptName.replace(/分公司$/g, '').trim()
      // 重新加载医院列表(带地域过滤)
      this.loadDefaultHospitals()
    onOrganizationChange(orgData) {
      // orgData 包含:deptId, deptName, serviceOrderClass, region
      this.selectedOrganizationId = orgData.deptId
      this.selectedOrganizationServiceOrderClass = orgData.serviceOrderClass
      this.selectedRegion = orgData.region
      console.log('选中归属机构:', orgData.deptName, '部门ID:', orgData.deptId, '服务单编码:', orgData.serviceOrderClass, '地域:', orgData.region)
    },
    // 加载分公司数据(parent_id=100的部门)
    loadBranchCompanies() {
      listBranchCompany().then(response => {
        const list = response.data || []
        // 过滤出 parent_id = 100 的部门(分公司)
        this.organizationOptions = list.filter(dept => dept.parentId === 100)
        // 生成picker的数据源(只显示名称)
        this.organizations = this.organizationOptions.map(dept => dept.deptName)
        // 默认设置为当前用户的分公司
        if (this.currentUser.branchCompanyName) {
          const index = this.organizationOptions.findIndex(
            dept => dept.deptName === this.currentUser.branchCompanyName
          )
          if (index !== -1) {
            this.selectedOrganization = this.currentUser.branchCompanyName
            this.selectedOrganizationId = this.organizationOptions[index].deptId // 保存部门ID
            this.selectedOrganizationServiceOrderClass = this.organizationOptions[index].serviceOrderClass || '' // 保存服务单编码
            // 提取地域关键词
            this.selectedRegion = this.selectedOrganization.replace(/分公司$/g, '').trim()
            console.log('默认选中归属机构:', this.selectedOrganization, '部门ID:', this.selectedOrganizationId, '服务单编码:', this.selectedOrganizationServiceOrderClass, '地域:', this.selectedRegion)
            // 加载医院列表(带地域过滤)
            this.loadDefaultHospitals()
          }
        }
      }).catch(error => {
        console.error('加载分公司数据失败:', error)
        this.organizationOptions = []
        this.organizations = []
      })
    },
    replaceRegion(region){
      return region.replace(/(分公司|总公司|总部)$/g, '').trim();
   },
    
    // 加载科室数据(从 SQL Server 动态加载)
    loadDepartments() {
@@ -807,7 +578,7 @@
      switch(staffType){
        case "nurse":
          return "护士";
        case "doctor":
        case "doctor":
          return "医生";
        case "driver":
          return "司机";
@@ -847,256 +618,15 @@
      this.selectedDocumentTypeId = selected.id
    },
    
    // 转出医院科室选择
    onHospitalOutDepartmentChange(e) {
      const index = e.detail.value
      const selected = this.departmentOptions[index]
      this.taskForm.hospitalOut.department = selected.text  // 保存科室名称
      this.taskForm.hospitalOut.departmentId = selected.id  // 保存科室ID
    },
    // 转入医院科室选择
    onHospitalInDepartmentChange(e) {
      const index = e.detail.value
      const selected = this.departmentOptions[index]
      this.taskForm.hospitalIn.department = selected.text  // 保存科室名称
      this.taskForm.hospitalIn.departmentId = selected.id  // 保存科室ID
    },
    // 加载默认医院列表(常用医院)
    loadDefaultHospitals() {
      // 检查是否有服务单编码
      if (!this.selectedOrganizationServiceOrderClass) {
        console.warn('未找到服务单编码,无法加载常用医院')
        // 如果没有服务单编码,降级为普通搜索(按地域过滤)
        this.loadDefaultHospitalsByRegion()
        return
      }
      // 转出医院:加载当前分公司的常用转出医院
      getFrequentOutHospitals(this.selectedOrganizationServiceOrderClass, this.selectedRegion).then(response => {
        this.hospitalOutResults = response.data || []
        console.log('加载常用转出医院:', this.selectedOrganizationServiceOrderClass, '地域:', this.selectedRegion, '数量:', this.hospitalOutResults.length)
        // 如果没有常用医院,降级为普通搜索
        if (this.hospitalOutResults.length === 0) {
          console.log('未找到常用转出医院,降级为地域搜索')
          searchHospitals('', this.selectedRegion).then(res => {
            this.hospitalOutResults = res.data || []
          })
        }
      }).catch(error => {
        console.error('加载常用转出医院失败:', error)
        // 失败后降级为普通搜索
        searchHospitals('', this.selectedRegion).then(res => {
          this.hospitalOutResults = res.data || []
        })
      })
      // 转入医院:加载当前分公司的常用转入医院(本地区域优先)
      getFrequentInHospitals(this.selectedOrganizationServiceOrderClass, '').then(response => {
        const allHospitals = response.data || []
        // 将医院按地域排序:本地区域优先
        this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        console.log('加载常用转入医院:', this.selectedOrganizationServiceOrderClass, '数量:', this.hospitalInResults.length)
        // 如果没有常用医院,降级为普通搜索
        if (this.hospitalInResults.length === 0) {
          console.log('未找到常用转入医院,降级为全部医院')
          searchHospitals('', '').then(res => {
            const allHospitals = res.data || []
            this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
          })
        }
      }).catch(error => {
        console.error('加载常用转入医院失败:', error)
        // 失败后降级为普通搜索
        searchHospitals('', '').then(res => {
          const allHospitals = res.data || []
          this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        })
      })
    },
    // 降级加载医院(按地域过滤)
    loadDefaultHospitalsByRegion() {
      // 转出医院:只加载当前区域的医院(带地域过滤)
      searchHospitals('', this.selectedRegion).then(response => {
        this.hospitalOutResults = response.data || []
        console.log('加载转出医院(当前区域):', this.selectedRegion, '数量:', this.hospitalOutResults.length)
      }).catch(error => {
        console.error('加载转出医院列表失败:', error)
        this.hospitalOutResults = []
      })
      // 转入医院:加载所有医院(不带地域过滤,后续会按地域排序)
      searchHospitals('', '').then(response => {
        const allHospitals = response.data || []
        // 将医院按地域排序:本地区域优先
        this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        console.log('加载转入医院(全部区域):', '数量:', this.hospitalInResults.length)
      }).catch(error => {
        console.error('加载转入医院列表失败:', error)
        this.hospitalInResults = []
      })
    },
    // 按地域排序医院:本地区域优先,"家中"始终在最前面
    sortHospitalsByRegion(hospitals) {
      if (!hospitals || hospitals.length === 0) {
        return hospitals
      }
      const region = this.selectedRegion
      const homeHospital = []  // "家中"
      const localHospitals = []  // 本地医院
      const otherHospitals = []  // 其他医院
      hospitals.forEach(hospital => {
        // "家中"优先处理,放在最前面
        if (hospital.hospName === '家中') {
          homeHospital.push(hospital)
          return
        }
        // 判断医院是否在本地区域(省、市、区任一包含地域关键词)
        const isLocal = region && (
          (hospital.hopsProvince && hospital.hopsProvince.includes(region)) ||
          (hospital.hopsCity && hospital.hopsCity.includes(region)) ||
          (hospital.hopsArea && hospital.hopsArea.includes(region))
        )
        if (isLocal) {
          localHospitals.push(hospital)
        } else {
          otherHospitals.push(hospital)
        }
      })
      // "家中"在最前,本地医院其次,其他医院在后
      return [...homeHospital, ...localHospitals, ...otherHospitals]
    },
    // 转出医院输入框获得焦点
    onHospitalOutFocus() {
      // 如果没有搜索关键词,显示常用转出医院
      if (!this.hospitalOutSearchKeyword || this.hospitalOutSearchKeyword.trim() === '') {
        // 如果已经加载过常用医院,直接显示
        if (this.hospitalOutResults.length > 0) {
          this.showHospitalOutResults = true
          return
        }
        // 否则重新加载常用医院
        if (this.selectedOrganizationServiceOrderClass) {
          getFrequentOutHospitals(this.selectedOrganizationServiceOrderClass, this.selectedRegion).then(response => {
            const hospitals = response.data || []
            // 确保"家中"在最前面
            this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
            // 如果没有常用医院,降级为普通搜索
            if (this.hospitalOutResults.length === 0) {
              searchHospitals('', this.selectedRegion).then(res => {
                const hospitals = res.data || []
                this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
              })
            }
          }).catch(error => {
            console.error('加载常用转出医院失败:', error)
            searchHospitals('', this.selectedRegion).then(res => {
              const hospitals = res.data || []
              this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
            })
          })
        } else {
          // 没有服务单编码,使用普通搜索
          searchHospitals('', this.selectedRegion).then(response => {
            const hospitals = response.data || []
            this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
          }).catch(error => {
            console.error('加载转出医院失败:', error)
            this.hospitalOutResults = []
          })
        }
      }
      this.showHospitalOutResults = true
    },
    // 转出医院搜索
    onHospitalOutSearch(e) {
      const keyword = e.detail.value
      this.hospitalOutSearchKeyword = keyword
      // 防抖处理
      if (this.searchTimer) {
        clearTimeout(this.searchTimer)
      }
      // 如果关键词为空,显示当前区域的医院
      if (!keyword || keyword.trim() === '') {
        searchHospitals('', this.selectedRegion).then(response => {
          const hospitals = response.data || []
          // 确保"家中"在最前面
          this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
        }).catch(error => {
          console.error('加载转出医院失败:', error)
          this.hospitalOutResults = []
        })
        this.showHospitalOutResults = true
        return
      }
      // 有关键词时,去服务端搜索(仅限当前区域)
      this.searchTimer = setTimeout(() => {
        this.searchHospitalOut(keyword)
      }, 300)
    },
    // 搜索转出医院(仅限当前区域)
    searchHospitalOut(keyword) {
      // 传入关键词和地域过滤,只搜索当前区域的医院
      searchHospitals(keyword, this.selectedRegion).then(response => {
        const hospitals = response.data || []
        // 确保"家中"在最前面
        this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
        this.showHospitalOutResults = true
        console.log('搜索转出医院:', keyword, '区域:', this.selectedRegion, '结果数:', this.hospitalOutResults.length)
      }).catch(error => {
        console.error('搜索转出医院失败:', error)
        this.hospitalOutResults = []
      })
    },
    // 选择转出医院
    selectHospitalOut(hospital) {
      this.taskForm.hospitalOut.id = hospital.hospId  // 保存医院ID
      this.taskForm.hospitalOut.name = hospital.hospName
      // 如果选择的是"家中",清空地址让用户手动输入;否则自动填充地址
      if (hospital.hospName === '家中') {
        this.taskForm.hospitalOut.address = ''
        // 科室自动设置为"其它"
        this.taskForm.hospitalOut.department = '其它'
        this.taskForm.hospitalOut.departmentId = null
      } else {
        // 合并省市区 + 详细地址
        const fullAddress = this.buildFullAddress(hospital)
        this.taskForm.hospitalOut.address = fullAddress
        // 清空科室,让用户重新选择
        if (this.taskForm.hospitalOut.department === '其它') {
          this.taskForm.hospitalOut.department = ''
          this.taskForm.hospitalOut.departmentId = null
        }
      }
      this.hospitalOutSearchKeyword = hospital.hospName
      this.showHospitalOutResults = false
      this.hospitalOutResults = []
      // 保存转出医院的城市信息
      this.taskForm.hospitalOut.city = hospital.hopsCity || ''
    // 转出医院变化
    onHospitalOutChange(hospitalData) {
      console.log('转出医院变化:', hospitalData)
      // 组件已经通过 v-model 更新了 taskForm.hospitalOut
      
      // 如果转入地址已填写,自动计算距离
      if (this.taskForm.hospitalIn.address) {
        // 如果两个都不是"家中",使用医院距离计算
        if (hospital.hospName !== '家中' && this.taskForm.hospitalIn.name !== '家中') {
        if (hospitalData.name !== '家中' && this.taskForm.hospitalIn.name !== '家中') {
          this.calculateHospitalDistance()
        } else {
          // 有一个是"家中",使用地址计算
@@ -1105,130 +635,44 @@
      }
    },
    
    // 转入医院输入框获得焦点
    onHospitalInFocus() {
      // 如果没有搜索关键词,显示常用转入医院
      if (!this.hospitalInSearchKeyword || this.hospitalInSearchKeyword.trim() === '') {
        // 如果已经加载过常用医院,直接显示
        if (this.hospitalInResults.length > 0) {
          this.showHospitalInResults = true
          return
        }
    // 转出医院地址选择(当选择"家中"时使用百度地图地址建议)
    onHospitalOutAddressSelected(data) {
      // data 包含:address, location
      if (data.location) {
        this.addressCoordinates.hospitalOutAddress = data.location
        
        // 否则重新加载常用医院
        if (this.selectedOrganizationServiceOrderClass) {
          getFrequentInHospitals(this.selectedOrganizationServiceOrderClass, '').then(response => {
            const allHospitals = response.data || []
            // 按地域排序:本地区域优先
            this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
            // 如果没有常用医院,降级为普通搜索
            if (this.hospitalInResults.length === 0) {
              searchHospitals('', '').then(res => {
                const allHospitals = res.data || []
                this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
              })
            }
          }).catch(error => {
            console.error('加载常用转入医院失败:', error)
            searchHospitals('', '').then(res => {
              const allHospitals = res.data || []
              this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
            })
          })
        } else {
          // 没有服务单编码,使用普通搜索
          searchHospitals('', '').then(response => {
            const allHospitals = response.data || []
            // 按地域排序:本地区域优先
            this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
          }).catch(error => {
            console.error('加载转入医院失败:', error)
            this.hospitalInResults = []
          })
        // 如果转入地址也已填写,自动计算距离
        if (this.taskForm.hospitalIn.address) {
          this.calculateDistanceByManualAddress()
        }
      }
      this.showHospitalInResults = true
    },
    
    // 转入医院搜索
    onHospitalInSearch(e) {
      const keyword = e.detail.value
      this.hospitalInSearchKeyword = keyword
      // 防抖处理
      if (this.searchTimer) {
        clearTimeout(this.searchTimer)
      }
      // 如果关键词为空,显示所有医院(本地区域优先)
      if (!keyword || keyword.trim() === '') {
        searchHospitals('', '').then(response => {
          const allHospitals = response.data || []
          // 按地域排序:"家中"最前,本地区域优先
          this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        }).catch(error => {
          console.error('加载转入医院失败:', error)
          this.hospitalInResults = []
        })
        this.showHospitalInResults = true
        return
      }
      // 有关键词时,去服务端搜索(不限区域,但结果按地域排序)
      this.searchTimer = setTimeout(() => {
        this.searchHospitalIn(keyword)
      }, 300)
    },
    // 搜索转入医院(不限区域,但本地区域优先)
    searchHospitalIn(keyword) {
      // 传入关键词,不传地域过滤(搜索所有区域)
      searchHospitals(keyword, '').then(response => {
        const allHospitals = response.data || []
        // 按地域排序:"家中"最前,本地区域优先
        this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        this.showHospitalInResults = true
        console.log('搜索转入医院:', keyword, '结果数:', this.hospitalInResults.length)
      }).catch(error => {
        console.error('搜索转入医院失败:', error)
        this.hospitalInResults = []
      })
    },
    // 选择转入医院
    selectHospitalIn(hospital) {
      this.taskForm.hospitalIn.id = hospital.hospId  // 保存医院ID
      this.taskForm.hospitalIn.name = hospital.hospName
      // 如果选择的是"家中",清空地址让用户手动输入;否则自动填充地址
      if (hospital.hospName === '家中') {
        this.taskForm.hospitalIn.address = ''
        // 科室自动设置为"其它"
        this.taskForm.hospitalIn.department = '其它'
        this.taskForm.hospitalIn.departmentId = null
      } else {
        // 合并省市区 + 详细地址
        const fullAddress = this.buildFullAddress(hospital)
        this.taskForm.hospitalIn.address = fullAddress
        // 清空科室,让用户重新选择
        if (this.taskForm.hospitalIn.department === '其它') {
          this.taskForm.hospitalIn.department = ''
          this.taskForm.hospitalIn.departmentId = null
        }
      }
      this.hospitalInSearchKeyword = hospital.hospName
      this.showHospitalInResults = false
      this.hospitalInResults = []
      // 保存转入医院的城市信息
      this.taskForm.hospitalIn.city = hospital.hopsCity || ''
    // 转入医院变化
    onHospitalInChange(hospitalData) {
      console.log('转入医院变化:', hospitalData)
      // 组件已经通过 v-model 更新了 taskForm.hospitalIn
      
      // 如果转出地址已填写,自动计算距离
      if (this.taskForm.hospitalOut.address) {
        // 如果两个都不是"家中",使用医院距离计算
        if (hospital.hospName !== '家中' && this.taskForm.hospitalOut.name !== '家中') {
        if (hospitalData.name !== '家中' && this.taskForm.hospitalOut.name !== '家中') {
          this.calculateHospitalDistance()
        } else {
          // 有一个是"家中",使用地址计算
          this.calculateDistanceByManualAddress()
        }
      }
    },
    // 转入医院地址选择(当选择"家中"时使用百度地图地址建议)
    onHospitalInAddressSelected(data) {
      // data 包含:address, location
      if (data.location) {
        this.addressCoordinates.hospitalInAddress = data.location
        // 如果转出地址也已填写,自动计算距离
        if (this.taskForm.hospitalOut.address) {
          this.calculateDistanceByManualAddress()
        }
      }
@@ -1256,24 +700,14 @@
    
    // 加载当前用户所在分公司的所有人员
    loadDeptStaff() {
      const deptId = this.currentUser.deptId
      if (!deptId) {
        console.error('无法获取当前用户所在部门')
        this.$modal.showToast('无法获取所在部门信息')
        return
      }
      console.log('开始加载人员列表')
      
      // 直接查询当前用户部门下的所有用户
      // 后端SQL会自动处理:如果传入的是子部门,会查找其所属的分公司及其所有子部门的用户
      const queryParams = {
        deptId: deptId,
        status: '0', // 只查询正常状态的用户
        pageNum: 1,
        pageSize: 10000 // 设置足够大的页面大小,获取所有用户
      }
      listUser(queryParams).then(response => {
        const userList = response.rows || response.data || []
      // 调用新接口,自动根据当前用户的oaOrderClass获取分公司下的用户
      listBranchUsers().then(response => {
        console.log('人员列表API响应:', response)
        const userList = response.data || []
        console.log('解析出的用户列表:', userList, '数量:', userList.length)
        this.allStaffList = userList.map(user => ({
          userId: user.userId,
          nickName: user.nickName,
@@ -1284,6 +718,8 @@
          // 根据岗位名称或角色名称判断类型
          type: this.getUserType(user)
        }))
        console.log('处理后的人员列表:', this.allStaffList, '数量:', this.allStaffList.length)
        
        // 初始化过滤列表
        this.filterStaffList()
@@ -1303,14 +739,18 @@
      if (postName.includes('司机') || roleName.includes('司机') || deptName.includes('车队') || deptName.includes('司机')) {
        return 'driver'
      }
      // 判断是否为医生
      if (postName.includes('医生') || roleName.includes('医生') || deptName.includes('医生')) {
        return 'doctor'
      }
      // 判断是否为护士
      if (postName.includes('护士') || roleName.includes('护士') || deptName.includes('护士')) {
        return 'nurse'
      }
      // 判断是否为医生
      if (postName.includes('医生') || roleName.includes('医生') || deptName.includes('医生') ) {
        return 'doctor'
      }
      if( deptName.includes("医护")){
        return 'doctor'
      }
      // 其他类型,默认为司机
      return 'driver'
    },
@@ -1342,6 +782,7 @@
    
    // 过滤人员列表
    filterStaffList() {
      console.log('开始过滤人员列表,原始数量:', this.allStaffList.length)
      let list = [...this.allStaffList]
      
      // 按类型过滤
@@ -1353,6 +794,8 @@
        list = list.filter(staff => staff.type === 'nurse')
      }
      
      console.log('按类型过滤后:', this.staffFilterType, '数量:', list.length)
      // 按关键词搜索
      if (this.staffSearchKeyword && this.staffSearchKeyword.trim() !== '') {
        const keyword = this.staffSearchKeyword.trim().toLowerCase()
@@ -1362,7 +805,10 @@
        })
      }
      
      console.log('按关键词过滤后,数量:', list.length)
      this.filteredStaffList = list
      // console.log('最终过滤结果:', this.filteredStaffList)
    },
    
    // 切换人员选中状态
@@ -1409,168 +855,6 @@
    addStaff() {
      this.showStaffSelector()
    },
    // ==================== 地址输入联想相关方法 ====================
    // 转出地址输入监听
    onAddressOutInput(e) {
      const query = e.detail.value
      this.taskForm.hospitalOut.address = query
      // 防抖处理
      if (this.addressSearchTimer) {
        clearTimeout(this.addressSearchTimer)
      }
      // 如果输入为空,隐藏提示列表
      if (!query || query.trim() === '') {
        this.showAddressOutSuggestions = false
        this.addressOutSuggestions = []
        return
      }
      // 输入长度大于2才开始搜索
      if (query.trim().length < 2) {
        this.showAddressOutSuggestions = false
        return
      }
      // 延迟300ms搜索
      this.addressSearchTimer = setTimeout(() => {
        this.searchAddressOut(query)
      }, 300)
    },
    // 转出地址输入框获得焦点
    onAddressOutFocus() {
      // 如果有地址且有搜索结果,显示提示列表
      if (this.taskForm.hospitalOut.address && this.addressOutSuggestions.length > 0) {
        this.showAddressOutSuggestions = true
      }
    },
    // 搜索转出地址
    searchAddressOut(query) {
      // 获取当前区域(优先使用归属机构的区域)
      const region = this.selectedRegion || '广州'
      baiduPlaceSuggestion(query, region).then(response => {
        if (response.code === 200 && response.data) {
          this.addressOutSuggestions = response.data
          this.showAddressOutSuggestions = true
        } else {
          this.addressOutSuggestions = []
          this.showAddressOutSuggestions = false
        }
      }).catch(error => {
        console.error('搜索转出地址失败:', error)
        this.addressOutSuggestions = []
        this.showAddressOutSuggestions = false
      })
    },
    // 选择转出地址
    selectAddressOut(item) {
      // 填充完整地址
      const fullAddress = item.district + item.address
      this.taskForm.hospitalOut.address = fullAddress
      // 保存经纬度(如果有)
      if (item.location) {
        this.taskForm.hospitalOut.latitude = item.location.lat
        this.taskForm.hospitalOut.longitude = item.location.lng
      }
      // 隐藏提示列表
      this.showAddressOutSuggestions = false
      this.addressOutSuggestions = []
      // 如果转入地址也已填写,自动计算距离
      if (this.taskForm.hospitalIn.address) {
        this.calculateDistanceByManualAddress()
      }
    },
    // 转入地址输入监听
    onAddressInInput(e) {
      const query = e.detail.value
      this.taskForm.hospitalIn.address = query
      // 防抖处理
      if (this.addressSearchTimer) {
        clearTimeout(this.addressSearchTimer)
      }
      // 如果输入为空,隐藏提示列表
      if (!query || query.trim() === '') {
        this.showAddressInSuggestions = false
        this.addressInSuggestions = []
        return
      }
      // 输入长度大于2才开始搜索
      if (query.trim().length < 2) {
        this.showAddressInSuggestions = false
        return
      }
      // 延迟300ms搜索
      this.addressSearchTimer = setTimeout(() => {
        this.searchAddressIn(query)
      }, 300)
    },
    // 转入地址输入框获得焦点
    onAddressInFocus() {
      // 如果有地址且有搜索结果,显示提示列表
      if (this.taskForm.hospitalIn.address && this.addressInSuggestions.length > 0) {
        this.showAddressInSuggestions = true
      }
    },
    // 搜索转入地址
    searchAddressIn(query) {
      // 获取当前区域(优先使用归属机构的区域)
      const region = this.selectedRegion || '广州'
      baiduPlaceSuggestion(query, region).then(response => {
        if (response.code === 200 && response.data) {
          this.addressInSuggestions = response.data
          this.showAddressInSuggestions = true
        } else {
          this.addressInSuggestions = []
          this.showAddressInSuggestions = false
        }
      }).catch(error => {
        console.error('搜索转入地址失败:', error)
        this.addressInSuggestions = []
        this.showAddressInSuggestions = false
      })
    },
    // 选择转入地址
    selectAddressIn(item) {
      // 填充完整地址
      const fullAddress = item.district + item.address
      this.taskForm.hospitalIn.address = fullAddress
      // 保存经纬度(如果有)
      if (item.location) {
        this.taskForm.hospitalIn.latitude = item.location.lat
        this.taskForm.hospitalIn.longitude = item.location.lng
      }
      // 隐藏提示列表
      this.showAddressInSuggestions = false
      this.addressInSuggestions = []
      // 如果转出地址也已填写,自动计算距离
      if (this.taskForm.hospitalOut.address) {
        this.calculateDistanceByManualAddress()
      }
    },
    // 手动输入地址时计算距离
    calculateDistanceByManualAddress() {
      const fromAddress = this.taskForm.hospitalOut.address
      const toAddress = this.taskForm.hospitalIn.address
@@ -1600,6 +884,9 @@
            
            console.log('距离计算成功:', distanceInKm, 'km')
            this.$modal.showToast(`距离: ${distanceInKm}公里`)
            // 距离计算成功后,自动计算成交价
            this.calculatePrice()
          } else {
            console.error('距离计算失败:', response.msg)
            this.$modal.showToast('距离计算失败,请手动输入')
@@ -1612,106 +899,52 @@
        })
    },
    
    // ==================== 病情选择相关方法 ====================
    // 显示病情选择弹窗
    showDiseaseSelector() {
      // 初始化临时选择列表(复制当前已选择的病情)
      this.tempSelectedDiseases = [...this.selectedDiseases]
      this.diseaseSearchKeyword = ''
      // 默认加载所有病情
      this.loadAllDiseases()
      this.$refs.diseasePopup.open()
    // 距离输入框失焦时触发成交价计算
    onDistanceChange() {
      this.calculatePrice()
    },
    
    // 关闭病情选择弹窗
    closeDiseaseSelector() {
      this.$refs.diseasePopup.close()
      this.diseaseSearchKeyword = ''
      this.diseaseSearchResults = []
      this.tempSelectedDiseases = []
    },
    // 病情搜索
    onDiseaseSearch(e) {
      const keyword = e.detail.value
      this.diseaseSearchKeyword = keyword
    // 计算成交价
    calculatePrice() {
      const fromAddress = this.taskForm.hospitalOut.address
      const toAddress = this.taskForm.hospitalIn.address
      const distance = this.taskForm.transferDistance
      
      // 防抖处理
      if (this.diseaseSearchTimer) {
        clearTimeout(this.diseaseSearchTimer)
      }
      // 如果关键词为空,加载所有病情
      if (!keyword || keyword.trim() === '') {
        this.loadAllDiseases()
      // 如果地址或距离不完整,不进行计算
      if (!fromAddress || !toAddress || !distance || parseFloat(distance) <= 0) {
        console.log('地址或距离信息不完整,跳过成交价计算')
        return
      }
      
      // 有关键词时进行搜索
      this.diseaseSearchTimer = setTimeout(() => {
        this.searchDiseaseByKeyword(keyword)
      }, 300)
    },
    // 加载所有病情(默认显示)
    loadAllDiseases() {
      // 使用空字符串或特殊标识符来获取所有病情
      // 如果后端不支持空查询,可以传入一个通配符如'%'或者修改后端接口
      searchIcd10('').then(response => {
        this.diseaseSearchResults = response.data || []
      }).catch(error => {
        console.error('加载病情列表失败:', error)
        this.diseaseSearchResults = []
      })
    },
    // 根据关键词搜索病情
    searchDiseaseByKeyword(keyword) {
      searchIcd10(keyword).then(response => {
        this.diseaseSearchResults = response.data || []
      }).catch(error => {
        console.error('搜索病情失败:', error)
        this.diseaseSearchResults = []
      })
    },
    // 切换病情选中状态
    toggleDiseaseSelection(disease) {
      const index = this.tempSelectedDiseases.findIndex(d => d.id === disease.id)
      console.log('开始计算成交价:', fromAddress, '->', toAddress, '距离:', distance)
      
      if (index > -1) {
        // 已选中,移除
        this.tempSelectedDiseases.splice(index, 1)
      } else {
        // 未选中,添加
        this.tempSelectedDiseases.push({
          id: disease.id,
          icdCode: disease.icdCode,
          icdName: disease.icdName,
          sm: disease.sm
        })
      }
      // 调用成交价计算接口
      calculateTransferPrice({
        fromAddress: fromAddress,
        toAddress: toAddress,
        distance: parseFloat(distance),
        region: this.selectedRegion || ''
      }).then(response => {
        if (response.code === 200 && response.data) {
          const price = response.data.price
          // 只有当返回的价格大于0时,才自动填充成交价
          if (price && price > 0) {
            this.taskForm.price = price.toFixed(2)
            console.log('成交价计算成功:', price)
            this.$modal.showToast(`成交价: ¥${price.toFixed(2)}`)
          } else {
            console.log('成交价为0,不自动填充')
          }
        } else {
          console.log('成交价计算失败,保持手动输入')
        }
      }).catch(error => {
        console.error('成交价计算失败:', error)
        // 计算失败时不提示用户,允许用户手动输入
      })
    },
    // 判断病情是否已选中
    isDiseaseSelected(diseaseId) {
      return this.tempSelectedDiseases.some(d => d.id === diseaseId)
    },
    // 确认病情选择
    confirmDiseaseSelection() {
      // 将临时选择的病情复制到正式列表
      this.selectedDiseases = [...this.tempSelectedDiseases]
      this.closeDiseaseSelector()
    },
    // 移除病情
    removeDisease(index) {
      this.selectedDiseases.splice(index, 1)
    },
    // 设置默认转运时间为当前时间
    // 手动输入地址时计算距离
    setDefaultTransferTime() {
      const now = new Date()
      const year = now.getFullYear()
@@ -1803,8 +1036,14 @@
      // 合并病情信息:选中的ICD-10疾病 + 其他描述
      let conditionText = ''
      if (this.selectedDiseases.length > 0) {
        const diseaseNames = this.selectedDiseases.map(d => `${d.icdName}(${d.icdCode})`).join('、')
        conditionText = diseaseNames
        // 过滤掉病情名称为空的项,并构建病情字符串
        const diseaseNames = this.selectedDiseases
          .filter(d => d.icdName && d.icdName.trim())
          .map(d => `${d.icdName}(${d.icdCode})`)
          .join('、')
        if (diseaseNames) {
          conditionText = diseaseNames
        }
      }
      if (this.taskForm.patient.condition && this.taskForm.patient.condition.trim()) {
        if (conditionText) {
@@ -1831,18 +1070,20 @@
        documentTypeId: this.selectedDocumentTypeId, // 单据类型ID
        taskTypeId: this.selectedEmergencyTaskTypeId, // 任务类型ID
        // 病情ID列表(用于同步调度单的OrdICD_ID参数)
        diseaseIds: this.selectedDiseases.map(d => d.id),
        diseaseIds: this.selectedDiseases.filter(d => d.id !== null).map(d => d.id),
        // 将转出医院地址作为出发地,转入医院地址作为目的地
        departureAddress: this.taskForm.hospitalOut.address || '',
        destinationAddress: this.taskForm.hospitalIn.address || '',
        patient: {
          ...this.taskForm.patient,
          condition: conditionText, // 使用合并后的病情信息
          diseases: this.selectedDiseases.map(d => ({
            icdId: d.id,
            icdCode: d.icdCode,
            icdName: d.icdName
          }))
          diseases: this.selectedDiseases
            .filter(d => d.icdName && d.icdName.trim())
            .map(d => ({
              icdId: d.id,
              icdCode: d.icdCode,
              icdName: d.icdName
            }))
        },
        // 医院信息(包含医院ID、科室名称、科室ID等完整信息)
        hospitalOut: this.taskForm.hospitalOut,  // 包含: id, name, department, departmentId, bedNumber, address
@@ -1888,11 +1129,18 @@
        addTask(submitData).then(response => {
          this.loading = false
          this.$modal.showToast('任务创建成功')
          // 延迟跳转,让用户看到成功提示
          setTimeout(() => {
            // 跳转到任务列表并触发刷新
            uni.switchTab({
              url: '/pages/task/index'
              url: '/pages/task/index',
              success: () => {
                // 使用事件总线通知任务列表页面刷新
                uni.$emit('refreshTaskList')
              }
            })
          }, 1500)
          }, 1000)
        }).catch(error => {
          this.loading = false
          console.error('任务创建失败:', error)
@@ -1901,8 +1149,371 @@
      }).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
    },
    
    // 合并医院地址(省 + 市 + 区 + 详细地址)
@@ -1955,6 +1566,9 @@
            
            console.log('距离计算成功:', distanceInKm, 'km')
            // this.$modal.showToast(`距离计算成功: ${distanceInKm}公里`)
            // 距离计算成功后,自动计算成交价
            this.calculatePrice()
          } else {
            console.error('距离计算失败:', response.msg)
            this.$modal.showToast('距离计算失败,请手动输入')
@@ -1994,9 +1608,24 @@
    }
    
    .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;
      }
    }
  }
  
@@ -2431,8 +2060,8 @@
  }
}
// 病情选择弹窗样式
.disease-selector-popup {
// 智能识别弹窗样式
.smart-parse-popup {
  background-color: white;
  border-radius: 20rpx 20rpx 0 0;
  max-height: 80vh;
@@ -2458,89 +2087,36 @@
    }
  }
  
  .search-box {
    display: flex;
    align-items: center;
    margin: 20rpx 30rpx;
    padding: 15rpx 20rpx;
    background-color: #f5f5f5;
    border-radius: 10rpx;
    flex-shrink: 0;
    .search-input {
      flex: 1;
      margin-left: 10rpx;
      font-size: 28rpx;
    }
  }
  .disease-list-popup {
  .parse-content {
    flex: 1;
    padding: 30rpx;
    overflow-y: auto;
    padding: 0 30rpx;
    
    .disease-item-popup {
    .parse-tip {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 25rpx 20rpx;
      border-bottom: 1rpx solid #f0f0f0;
      &:active {
        background-color: #f5f5f5;
      }
      .disease-info {
        flex: 1;
        .disease-name-row {
          display: flex;
          align-items: center;
          margin-bottom: 8rpx;
          .disease-name {
            font-size: 30rpx;
            font-weight: bold;
            color: #333;
            margin-right: 15rpx;
          }
          .disease-code {
            font-size: 24rpx;
            color: #007AFF;
            background-color: #e6f2ff;
            padding: 4rpx 12rpx;
            border-radius: 6rpx;
          }
        }
        .disease-detail-row {
          .disease-desc {
            font-size: 24rpx;
            color: #999;
            line-height: 1.5;
          }
        }
      }
      .checkbox-empty {
        width: 40rpx;
        height: 40rpx;
        border: 2rpx solid #ddd;
        border-radius: 50%;
      }
    }
    .no-data {
      text-align: center;
      padding: 100rpx 0;
      color: #999;
      align-items: flex-start;
      padding: 20rpx;
      background-color: #f0f7ff;
      border-radius: 10rpx;
      margin-bottom: 20rpx;
      
      text {
        display: block;
        margin-top: 20rpx;
        font-size: 28rpx;
        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;
    }
  }
  
@@ -2566,6 +2142,11 @@
    .confirm-btn {
      background-color: #007AFF;
      color: white;
      &[disabled] {
        background-color: #ccc;
        color: #999;
      }
    }
  }
}