wlzboy
2025-11-08 4dd78acfe298217ebc5dd247c5b45c6f33deea9b
feat:医院选择计算
6个文件已修改
444 ■■■■■ 已修改文件
app/api/map.js 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/pages/task/create-emergency.vue 337 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/HospDataController.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleGpsController.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/mapper/HospDataMapper.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/resources/mapper/system/HospDataMapper.xml 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/api/map.js
@@ -126,4 +126,21 @@
      toCity: toCity
    }
  })
}
// 百度地图地址搜索提示API(输入联想)
export function baiduPlaceSuggestion(query, region) {
  // 参数验证
  if (!query) {
    return Promise.reject(new Error('参数不完整,缺少搜索关键词'))
  }
  return request({
    url: '/system/gps/baidu/place/suggestion',
    method: 'get',
    params: {
      query: query,
      region: region || '广州'
    }
  })
}
app/pages/task/create-emergency.vue
@@ -217,7 +217,26 @@
      
      <view class="form-item">
        <view class="form-label">转出地址</view>
        <view class="form-input picker-input disabled">
        <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>
@@ -268,7 +287,26 @@
      
      <view class="form-item">
        <view class="form-label">转入地址</view>
        <view class="form-input picker-input disabled">
        <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>
@@ -443,7 +481,7 @@
import uniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue'
import { addTask } from "@/api/task"
import { listAvailableVehicles, getUserBoundVehicle } from "@/api/vehicle"
import { calculateDistance, baiduDistanceByAddress } from "@/api/map"
import { calculateDistance, baiduDistanceByAddress, baiduPlaceSuggestion } from "@/api/map"
import { searchHospitals, getFrequentOutHospitals, getFrequentInHospitals } from "@/api/hospital"
import { listUser } from "@/api/system/user"
import { searchIcd10 } from "@/api/icd10"
@@ -481,6 +519,12 @@
      showHospitalInResults: false,
      searchTimer: null,
      defaultHospitals: [], // 默认的100条医院数据
      // 地址搜索提示相关
      addressOutSuggestions: [], // 转出地址提示列表
      showAddressOutSuggestions: false,
      addressInSuggestions: [], // 转入地址提示列表
      showAddressInSuggestions: false,
      addressSearchTimer: null, // 地址搜索防抖定时器
      // 人员选择相关
      selectedStaff: [], // 已选择的人员列表
      allStaffList: [], // 所有人员列表
@@ -985,9 +1029,14 @@
    selectHospitalOut(hospital) {
      this.taskForm.hospitalOut.id = hospital.hospId  // 保存医院ID
      this.taskForm.hospitalOut.name = hospital.hospName
      // 合并省市区 + 详细地址
      const fullAddress = this.buildFullAddress(hospital)
      this.taskForm.hospitalOut.address = fullAddress
      // 如果选择的是"家中",清空地址让用户手动输入;否则自动填充地址
      if (hospital.hospName === '家中') {
        this.taskForm.hospitalOut.address = ''
      } else {
        // 合并省市区 + 详细地址
        const fullAddress = this.buildFullAddress(hospital)
        this.taskForm.hospitalOut.address = fullAddress
      }
      this.hospitalOutSearchKeyword = hospital.hospName
      this.showHospitalOutResults = false
      this.hospitalOutResults = []
@@ -995,9 +1044,15 @@
      // 保存转出医院的城市信息
      this.taskForm.hospitalOut.city = hospital.hopsCity || ''
      
      // 如果两个医院都已选择,自动计算距离
      // 如果转入地址已填写,自动计算距离
      if (this.taskForm.hospitalIn.address) {
        this.calculateHospitalDistance()
        // 如果两个都不是"家中",使用医院距离计算
        if (hospital.hospName !== '家中' && this.taskForm.hospitalIn.name !== '家中') {
          this.calculateHospitalDistance()
        } else {
          // 有一个是"家中",使用地址计算
          this.calculateDistanceByManualAddress()
        }
      }
    },
    
@@ -1095,9 +1150,14 @@
    selectHospitalIn(hospital) {
      this.taskForm.hospitalIn.id = hospital.hospId  // 保存医院ID
      this.taskForm.hospitalIn.name = hospital.hospName
      // 合并省市区 + 详细地址
      const fullAddress = this.buildFullAddress(hospital)
      this.taskForm.hospitalIn.address = fullAddress
      // 如果选择的是"家中",清空地址让用户手动输入;否则自动填充地址
      if (hospital.hospName === '家中') {
        this.taskForm.hospitalIn.address = ''
      } else {
        // 合并省市区 + 详细地址
        const fullAddress = this.buildFullAddress(hospital)
        this.taskForm.hospitalIn.address = fullAddress
      }
      this.hospitalInSearchKeyword = hospital.hospName
      this.showHospitalInResults = false
      this.hospitalInResults = []
@@ -1105,9 +1165,15 @@
      // 保存转入医院的城市信息
      this.taskForm.hospitalIn.city = hospital.hopsCity || ''
      
      // 如果两个医院都已选择,自动计算距离
      // 如果转出地址已填写,自动计算距离
      if (this.taskForm.hospitalOut.address) {
        this.calculateHospitalDistance()
        // 如果两个都不是"家中",使用医院距离计算
        if (hospital.hospName !== '家中' && this.taskForm.hospitalOut.name !== '家中') {
          this.calculateHospitalDistance()
        } else {
          // 有一个是"家中",使用地址计算
          this.calculateDistanceByManualAddress()
        }
      }
    },
    
@@ -1285,6 +1351,208 @@
    
    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
      if (!fromAddress || !toAddress) {
        return
      }
      console.log('计算手动输入地址距离:', fromAddress, '->', toAddress)
      // 显示加载提示
      uni.showLoading({
        title: '计算距离中...'
      })
      // 调用百度地图API计算距离
      const region = this.selectedRegion || '广州'
      baiduDistanceByAddress(fromAddress, region, toAddress, region)
        .then(response => {
          uni.hideLoading()
          if (response.code === 200 && response.data) {
            const distanceInMeters = response.data.distance
            // 转换为公里,保疙1位小数
            const distanceInKm = (distanceInMeters / 1000).toFixed(1)
            this.taskForm.transferDistance = distanceInKm
            console.log('距离计算成功:', distanceInKm, 'km')
            this.$modal.showToast(`距离: ${distanceInKm}公里`)
          } else {
            console.error('距离计算失败:', response.msg)
            this.$modal.showToast('距离计算失败,请手动输入')
          }
        })
        .catch(error => {
          uni.hideLoading()
          console.error('距离计算失败:', error)
          this.$modal.showToast('距离计算失败,请手动输入')
        })
    },
    
    // ==================== 病情选择相关方法 ====================
@@ -1748,6 +2016,49 @@
        }
      }
      
      .address-input-container {
        position: relative;
        .address-suggestions {
          position: absolute;
          top: 75rpx;
          left: 0;
          right: 0;
          max-height: 400rpx;
          background-color: white;
          border: 1rpx solid #eee;
          border-radius: 10rpx;
          box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
          z-index: 100;
          overflow-y: auto;
          .address-suggestion-item {
            padding: 20rpx 30rpx;
            border-bottom: 1rpx solid #f0f0f0;
            &:last-child {
              border-bottom: none;
            }
            &:active {
              background-color: #f5f5f5;
            }
            .suggestion-name {
              font-size: 28rpx;
              color: #333;
              font-weight: bold;
              margin-bottom: 8rpx;
            }
            .suggestion-address {
              font-size: 24rpx;
              color: #999;
            }
          }
        }
      }
      .form-input {
        height: 70rpx;
        padding: 0 20rpx;
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/HospDataController.java
@@ -62,6 +62,10 @@
        if (hospIds == null || hospIds.isEmpty()) {
            return success();
        }
        Integer homeHospId=hospDataMapper.getHomeHospId();
        if (!hospIds.contains(homeHospId)) {
            hospIds.add(0,homeHospId);
        }
        // 根据ID列表查询医院详情
        List<HospData> hospitals = hospDataMapper.selectHospDataByIds(hospIds, region);
        return success(hospitals);
@@ -81,6 +85,10 @@
        if (hospIds == null || hospIds.isEmpty()) {
            return success();
        }
        Integer homeHospId=hospDataMapper.getHomeHospId();
        if (!hospIds.contains(homeHospId)) {
            hospIds.add(0,homeHospId);
        }
        // 根据ID列表查询医院详情
        List<HospData> hospitals = hospDataMapper.selectHospDataByIds(hospIds, region);
        return success(hospitals);
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleGpsController.java
@@ -666,4 +666,78 @@
            return AjaxResult.error("计算距离失败:" + e.getMessage());
        }
    }
    /**
     * 百度地图地址搜索提示API(输入联想)
     * Place Suggestion API - 用于地址输入时的智能提示
     */
    @Anonymous()
    @GetMapping("/baidu/place/suggestion")
    public AjaxResult baiduPlaceSuggestion(String query, String region) {
        try {
            // 检查参数
            if (query == null || query.trim().isEmpty()) {
                return AjaxResult.error("参数不完整,缺少搜索关键词");
            }
            // 构建百度地图 Place Suggestion API URL
            String url = "https://api.map.baidu.com/place/v2/suggestion";
            String params = "query=" + URLEncoder.encode(query, StandardCharsets.UTF_8.toString()) +
                           (region != null && !region.trim().isEmpty() ?
                            "&region=" + URLEncoder.encode(region, StandardCharsets.UTF_8.toString()) : "") +
                           "&output=json" +
                           "&ak=" + baiduMapConfig.getAk();
            logger.info("百度地图地址搜索提示请求: query={}, region={}", query, region);
            // 发送HTTP请求
            String response = HttpUtils.sendGet(url, params);
            logger.debug("百度地图地址搜索提示响应: {}", response);
            // 解析响应
            com.alibaba.fastjson2.JSONObject jsonResponse = com.alibaba.fastjson2.JSONObject.parseObject(response);
            if (jsonResponse.getInteger("status") != 0) {
                logger.error("地址搜索提示失败: {}", response);
                return AjaxResult.error("地址搜索失败");
            }
            // 提取提示列表
            com.alibaba.fastjson2.JSONArray results = jsonResponse.getJSONArray("result");
            if (results == null || results.isEmpty()) {
                logger.info("未找到匹配的地址");
                return AjaxResult.success("查询成功", new ArrayList<>());
            }
            // 构建返回结果
            List<Map<String, Object>> suggestions = new ArrayList<>();
            for (int i = 0; i < results.size(); i++) {
                com.alibaba.fastjson2.JSONObject item = results.getJSONObject(i);
                Map<String, Object> suggestion = new HashMap<>();
                suggestion.put("name", item.getString("name")); // 名称
                suggestion.put("address", item.getString("address")); // 地址
                suggestion.put("province", item.getString("province")); // 省
                suggestion.put("city", item.getString("city")); // 市
                suggestion.put("district", item.getString("district")); // 区
                suggestion.put("uid", item.getString("uid")); // 地点UID
                // 经纬度信息
                com.alibaba.fastjson2.JSONObject location = item.getJSONObject("location");
                if (location != null) {
                    Map<String, Object> locationMap = new HashMap<>();
                    locationMap.put("lat", location.getDouble("lat"));
                    locationMap.put("lng", location.getDouble("lng"));
                    suggestion.put("location", locationMap);
                }
                suggestions.add(suggestion);
            }
            logger.info("地址搜索提示成功: 找到{}  条结果", suggestions.size());
            return AjaxResult.success("查询成功", suggestions);
        } catch (Exception e) {
            logger.error("地址搜索提示失败", e);
            return AjaxResult.error("地址搜索失败:" + e.getMessage());
        }
    }
}
ruoyi-system/src/main/java/com/ruoyi/system/mapper/HospDataMapper.java
@@ -41,6 +41,7 @@
     */
    List<Integer> selectFrequentOutHospitalIds(@Param("serviceOrdClass") String serviceOrdClass);
    
    Integer getHomeHospId();
    /**
     * 查询常用转入医院ID列表
     * 
ruoyi-system/src/main/resources/mapper/system/HospDataMapper.xml
@@ -53,7 +53,9 @@
        )
        </if>
        AND (HospState IS NULL OR HospState = 1)
        ORDER BY HospName
        ORDER BY
            CASE WHEN HospName = '家中' THEN 0 ELSE 1 END,
            HospName
    </select>
    
    <select id="selectHospDataById" parameterType="Integer" resultMap="HospDataResult">
@@ -75,6 +77,9 @@
        ) as t
        order by InCount desc
    </select>
    <select id="getHomeHospId" resultType="java.lang.Integer">
        select HospID from HospData where HospName='家中'
    </select>
    
    <!-- 查询常用转入医院ID列表 -->
    <select id="selectFrequentInHospitalIds" resultType="java.lang.Integer">