wlzboy
2025-11-10 ae1e467411a786c37fb20b9bce2a7a4da64aa412
app/pages/task/create-emergency.vue
@@ -189,7 +189,10 @@
              :key="hospital.hospId"
              @click="selectHospitalOut(hospital)"
            >
              <view class="hospital-name">{{ hospital.hospName }}</view>
              <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>
@@ -198,12 +201,21 @@
      
      <view class="form-item">
        <view class="form-label required">科室</view>
        <picker mode="selector" :range="departmentOptions" range-key="text" @change="onHospitalOutDepartmentChange">
        <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">
@@ -259,7 +271,10 @@
              :key="hospital.hospId"
              @click="selectHospitalIn(hospital)"
            >
              <view class="hospital-name">{{ hospital.hospName }}</view>
              <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>
@@ -268,12 +283,21 @@
      
      <view class="form-item">
        <view class="form-label required">科室</view>
        <picker mode="selector" :range="departmentOptions" range-key="text" @change="onHospitalInDepartmentChange">
        <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">
@@ -318,6 +342,7 @@
          type="digit" 
          placeholder="请输入转运公里数" 
          v-model="taskForm.transferDistance"
          @blur="onDistanceChange"
        />
      </view>
      
@@ -482,9 +507,10 @@
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 { getDicts } from "@/api/dict"
import { getServiceOrdAreaTypes, getServiceOrderTypes, getHospitalDepartments } from "@/api/dictionary"
@@ -696,11 +722,14 @@
      this.selectedOrganizationServiceOrderClass = selected.serviceOrderClass || '' // 保存服务单编码
      // 从归属机构中提取地域关键词(去除“分公司”后缀)
      // 例如:“广州分公司” -> “广州”
      this.selectedRegion = selected.deptName.replace(/分公司$/g, '').trim()
      //如果出现广州总公司,也要去除“总公司”后缀
      this.selectedRegion = this.replaceRegion(selected.deptName);
      // 重新加载医院列表(带地域过滤)
      this.loadDefaultHospitals()
    },
    replaceRegion(region){
      return region.replace(/(分公司|总公司|总部)$/g, '').trim();
   },
    // 加载分公司数据(parent_id=100的部门)
    loadBranchCompanies() {
      listBranchCompany().then(response => {
@@ -720,7 +749,7 @@
            this.selectedOrganizationId = this.organizationOptions[index].deptId // 保存部门ID
            this.selectedOrganizationServiceOrderClass = this.organizationOptions[index].serviceOrderClass || '' // 保存服务单编码
            // 提取地域关键词
            this.selectedRegion = this.selectedOrganization.replace(/分公司$/g, '').trim()
            this.selectedRegion =this.replaceRegion(this.selectedOrganization);
            console.log('默认选中归属机构:', this.selectedOrganization, '部门ID:', this.selectedOrganizationId, '服务单编码:', this.selectedOrganizationServiceOrderClass, '地域:', this.selectedRegion)
            // 加载医院列表(带地域过滤)
            this.loadDefaultHospitals()
@@ -783,7 +812,7 @@
      switch(staffType){
        case "nurse":
          return "护士";
        case "doctor":
        case "doctor":
          return "医生";
        case "driver":
          return "司机";
@@ -841,57 +870,17 @@
    
    // 加载默认医院列表(常用医院)
    loadDefaultHospitals() {
      // 检查是否有服务单编码
      if (!this.selectedOrganizationServiceOrderClass) {
        console.warn('未找到服务单编码,无法加载常用医院')
        // 如果没有服务单编码,降级为普通搜索(按地域过滤)
        this.loadDefaultHospitalsByRegion()
      // 检查是否有归属机构ID
      if (!this.selectedOrganizationId) {
        console.warn('未选择归属机构,无法加载医院列表')
        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 || []
        })
      })
      // 转出医院:根据归属机构的区域配置加载
      this.loadHospitalsByDeptRegion('out')
      
      // 转入医院:加载当前分公司的常用转入医院(本地区域优先)
      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)
        })
      })
      // 转入医院:根据归属机构的区域配置加载
      this.loadHospitalsByDeptRegion('in')
    },
    
    // 降级加载医院(按地域过滤)
@@ -917,22 +906,57 @@
      })
    },
    
    // 按地域排序医院:本地区域优先
    // 根据部门区域配置加载医院
    loadHospitalsByDeptRegion(type) {
      const deptId = this.selectedOrganizationId
      if (!deptId) {
        console.warn('部门ID不存在')
        return
      }
      // 调用后端接口,根据部门的区域配置查询医院
      searchHospitalsByDeptRegion('', deptId).then(response => {
        const hospitals = response.data || []
        if (type === 'out') {
          this.hospitalOutResults = hospitals
          console.log('加载转出医院(区域配置):部门', deptId, '数量:', this.hospitalOutResults.length)
        } else if (type === 'in') {
          // 转入医院按地域排序
          this.hospitalInResults = this.sortHospitalsByRegion(hospitals)
          console.log('加载转入医院(区域配置):部门', deptId, '数量:', this.hospitalInResults.length)
        }
      }).catch(error => {
        console.error('加载医院失败(区域配置):', error)
        // 失败后降级为普通搜索
        this.loadDefaultHospitalsByRegion()
      })
    },
    // 按地域排序医院:本地区域优先,"家中"始终在最前面
    sortHospitalsByRegion(hospitals) {
      if (!this.selectedRegion || !hospitals || hospitals.length === 0) {
      if (!hospitals || hospitals.length === 0) {
        return hospitals
      }
      
      const region = this.selectedRegion
      const localHospitals = []
      const otherHospitals = []
      const homeHospital = []  // "家中"
      const localHospitals = []  // 本地医院
      const otherHospitals = []  // 其他医院
      
      hospitals.forEach(hospital => {
        // "家中"优先处理,放在最前面
        if (hospital.hospName === '家中') {
          homeHospital.push(hospital)
          return
        }
        // 判断医院是否在本地区域(省、市、区任一包含地域关键词)
        const isLocal =
        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)
@@ -941,8 +965,8 @@
        }
      })
      
      // 本地医院在前,其他医院在后
      return [...localHospitals, ...otherHospitals]
      // "家中"在最前,本地医院其次,其他医院在后
      return [...homeHospital, ...localHospitals, ...otherHospitals]
    },
    
    // 转出医院输入框获得焦点
@@ -958,23 +982,28 @@
        // 否则重新加载常用医院
        if (this.selectedOrganizationServiceOrderClass) {
          getFrequentOutHospitals(this.selectedOrganizationServiceOrderClass, this.selectedRegion).then(response => {
            this.hospitalOutResults = response.data || []
            const hospitals = response.data || []
            // 确保"家中"在最前面
            this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
            // 如果没有常用医院,降级为普通搜索
            if (this.hospitalOutResults.length === 0) {
              searchHospitals('', this.selectedRegion).then(res => {
                this.hospitalOutResults = res.data || []
              searchHospitals('', this.selectedOrganizationId).then(res => {
                const hospitals = res.data || []
                this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
              })
            }
          }).catch(error => {
            console.error('加载常用转出医院失败:', error)
            searchHospitals('', this.selectedRegion).then(res => {
              this.hospitalOutResults = res.data || []
            searchHospitals('', this.selectedOrganizationId).then(res => {
              const hospitals = res.data || []
              this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
            })
          })
        } else {
          // 没有服务单编码,使用普通搜索
          searchHospitals('', this.selectedRegion).then(response => {
            this.hospitalOutResults = response.data || []
          searchHospitals('', this.selectedOrganizationId).then(response => {
            const hospitals = response.data || []
            this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
          }).catch(error => {
            console.error('加载转出医院失败:', error)
            this.hospitalOutResults = []
@@ -994,10 +1023,12 @@
        clearTimeout(this.searchTimer)
      }
      
      // 如果关键词为空,只显示当前区域的医院
      // 如果关键词为空,显示当前区域的医院
      if (!keyword || keyword.trim() === '') {
        searchHospitals('', this.selectedRegion).then(response => {
          this.hospitalOutResults = response.data || []
        searchHospitals('', this.selectedOrganizationId).then(response => {
          const hospitals = response.data || []
          // 确保"家中"在最前面
          this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
        }).catch(error => {
          console.error('加载转出医院失败:', error)
          this.hospitalOutResults = []
@@ -1014,11 +1045,13 @@
    
    // 搜索转出医院(仅限当前区域)
    searchHospitalOut(keyword) {
      // 传入关键词和地域过滤,只搜索当前区域的医院
      searchHospitals(keyword, this.selectedRegion).then(response => {
        this.hospitalOutResults = response.data || []
      // 传入关键词和部门ID,只搜索当前区域的医院
      searchHospitals(keyword, this.selectedOrganizationId).then(response => {
        const hospitals = response.data || []
        // 确保"家中"在最前面
        this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
        this.showHospitalOutResults = true
        console.log('搜索转出医院:', keyword, '区域:', this.selectedRegion, '结果数:', this.hospitalOutResults.length)
        console.log('搜索转出医院:', keyword, '部门ID:', this.selectedOrganizationId, '结果数:', this.hospitalOutResults.length)
      }).catch(error => {
        console.error('搜索转出医院失败:', error)
        this.hospitalOutResults = []
@@ -1032,10 +1065,18 @@
      // 如果选择的是"家中",清空地址让用户手动输入;否则自动填充地址
      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
@@ -1074,21 +1115,21 @@
            this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
            // 如果没有常用医院,降级为普通搜索
            if (this.hospitalInResults.length === 0) {
              searchHospitals('', '').then(res => {
              searchHospitals('', null).then(res => {
                const allHospitals = res.data || []
                this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
              })
            }
          }).catch(error => {
            console.error('加载常用转入医院失败:', error)
            searchHospitals('', '').then(res => {
            searchHospitals('', null).then(res => {
              const allHospitals = res.data || []
              this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
            })
          })
        } else {
          // 没有服务单编码,使用普通搜索
          searchHospitals('', '').then(response => {
          searchHospitals('', null).then(response => {
            const allHospitals = response.data || []
            // 按地域排序:本地区域优先
            this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
@@ -1113,9 +1154,9 @@
      
      // 如果关键词为空,显示所有医院(本地区域优先)
      if (!keyword || keyword.trim() === '') {
        searchHospitals('', '').then(response => {
        searchHospitals('', null).then(response => {
          const allHospitals = response.data || []
          // 按地域排序:本地区域优先
          // 按地域排序:"家中"最前,本地区域优先
          this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        }).catch(error => {
          console.error('加载转入医院失败:', error)
@@ -1133,10 +1174,10 @@
    
    // 搜索转入医院(不限区域,但本地区域优先)
    searchHospitalIn(keyword) {
      // 传入关键词,不传地域过滤(搜索所有区域)
      searchHospitals(keyword, '').then(response => {
      // 传入关键词,不传部门ID(搜索所有区域)
      searchHospitals(keyword, null).then(response => {
        const allHospitals = response.data || []
        // 按地域排序:本地区域优先
        // 按地域排序:"家中"最前,本地区域优先
        this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        this.showHospitalInResults = true
        console.log('搜索转入医院:', keyword, '结果数:', this.hospitalInResults.length)
@@ -1153,10 +1194,18 @@
      // 如果选择的是"家中",清空地址让用户手动输入;否则自动填充地址
      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
@@ -1199,24 +1248,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,
@@ -1227,6 +1266,8 @@
          // 根据岗位名称或角色名称判断类型
          type: this.getUserType(user)
        }))
        console.log('处理后的人员列表:', this.allStaffList, '数量:', this.allStaffList.length)
        
        // 初始化过滤列表
        this.filterStaffList()
@@ -1246,14 +1287,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'
    },
@@ -1285,6 +1330,7 @@
    
    // 过滤人员列表
    filterStaffList() {
      console.log('开始过滤人员列表,原始数量:', this.allStaffList.length)
      let list = [...this.allStaffList]
      
      // 按类型过滤
@@ -1296,6 +1342,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()
@@ -1305,7 +1353,10 @@
        })
      }
      
      console.log('按关键词过滤后,数量:', list.length)
      this.filteredStaffList = list
      console.log('最终过滤结果:', this.filteredStaffList)
    },
    
    // 切换人员选中状态
@@ -1543,6 +1594,9 @@
            
            console.log('距离计算成功:', distanceInKm, 'km')
            this.$modal.showToast(`距离: ${distanceInKm}公里`)
            // 距离计算成功后,自动计算成交价
            this.calculatePrice()
          } else {
            console.error('距离计算失败:', response.msg)
            this.$modal.showToast('距离计算失败,请手动输入')
@@ -1553,6 +1607,52 @@
          console.error('距离计算失败:', error)
          this.$modal.showToast('距离计算失败,请手动输入')
        })
    },
    // 距离输入框失焦时触发成交价计算
    onDistanceChange() {
      this.calculatePrice()
    },
    // 计算成交价
    calculatePrice() {
      const fromAddress = this.taskForm.hospitalOut.address
      const toAddress = this.taskForm.hospitalIn.address
      const distance = this.taskForm.transferDistance
      // 如果地址或距离不完整,不进行计算
      if (!fromAddress || !toAddress || !distance || parseFloat(distance) <= 0) {
        console.log('地址或距离信息不完整,跳过成交价计算')
        return
      }
      console.log('开始计算成交价:', fromAddress, '->', toAddress, '距离:', distance)
      // 调用成交价计算接口
      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)
        // 计算失败时不提示用户,允许用户手动输入
      })
    },
    
    // ==================== 病情选择相关方法 ====================
@@ -1831,11 +1931,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)
@@ -1898,6 +2005,9 @@
            
            console.log('距离计算成功:', distanceInKm, 'km')
            // this.$modal.showToast(`距离计算成功: ${distanceInKm}公里`)
            // 距离计算成功后,自动计算成交价
            this.calculatePrice()
          } else {
            console.error('距离计算失败:', response.msg)
            this.$modal.showToast('距离计算失败,请手动输入')
@@ -2006,6 +2116,14 @@
              color: #333;
              font-weight: bold;
              margin-bottom: 8rpx;
              .hospital-short {
                display: block;
                font-size: 22rpx;
                color: #999;
                font-weight: normal;
                margin-top: 6rpx;
              }
            }
            
            .hospital-address {