diff --git a/pgserver/application/admin/controller/Base.php b/pgserver/application/admin/controller/Base.php index d6fd5b6..ef2e8d1 100644 --- a/pgserver/application/admin/controller/Base.php +++ b/pgserver/application/admin/controller/Base.php @@ -59,7 +59,9 @@ class Base extends Controller { */ public function isAdmin() { - return in_array("Biz_system_admin", $this->userInfo['roleCode']); + return in_array("Biz_system_admin", $this->userInfo['roleCode']) || + in_array("admin", $this->userInfo['roleCode']) || + in_array("COM_TOP_ADMIN", $this->userInfo['roleCode']); } /** diff --git a/pgserver/application/admin/controller/Estimate.php b/pgserver/application/admin/controller/Estimate.php index dcbf39c..2d813d2 100644 --- a/pgserver/application/admin/controller/Estimate.php +++ b/pgserver/application/admin/controller/Estimate.php @@ -95,6 +95,7 @@ class Estimate extends Base // } $where[] = ['i.is_simple', '=', 0]; $where[] = ['i.estimate_status', '=', $estimate_status]; + $where[] = ['i.status', 'in', [9, 10, 11, 12]]; $start_time && $where[] = ['i.create_time', '>=', $start_time . " 00:00:00"]; $end_time && $where[] = ['i.create_time', '<=', $end_time . " 23:59:59"]; $is_multiple && $where[] = ['i.is_multiple', '=', $is_multiple]; @@ -540,6 +541,10 @@ class Estimate extends Base if (!$in_upd) { return $this->buildFailed('操作失败!'); } + + // 推送预估数量更新给所有客户端 + fetchAndPushEstimatePendingCount(); + return $this->buildSuccess(); } diff --git a/pgserver/application/admin/controller/Pending.php b/pgserver/application/admin/controller/Pending.php index 233e481..1b57964 100644 --- a/pgserver/application/admin/controller/Pending.php +++ b/pgserver/application/admin/controller/Pending.php @@ -44,6 +44,56 @@ class Pending extends Base return $this->buildSuccess(['count' => $count]); } + /** + * 获取报告制作数量(status=9) + * @return \think\Response + */ + public function getReportPendingCount() + { + $Inquiry = new Inquiry(); + + // 查询 status = 9 的数量 + $count = $Inquiry->where('status', 9)->count(); + + return $this->buildSuccess(['count' => $count]); + } + + /** + * 获取所有预估状态数量 + * @return \think\Response + */ + public function getEstimatePendingCount() + { + $Inquiry = new Inquiry(); + + // 待制作:status=9 + $pendingCount = $Inquiry->where('status', 9)->count(); + + // 二审待制作:status=10 且 estimate_status=2 + $secondReviewCount = $Inquiry->where('status', 10) + ->where('estimate_status', '=', '2', false) + ->count(); + + // 三审待制作:status=10 且 estimate_status=3 + $thirdReviewCount = $Inquiry->where('status', 10) + ->where('estimate_status', '=', '3', false) + ->count(); + + // 待签章:status=11 + $signCount = $Inquiry->where('status', 11)->count(); + + // 总和 + $total = $pendingCount + $secondReviewCount + $thirdReviewCount + $signCount; + + return $this->buildSuccess([ + 'pending' => $pendingCount, + 'secondReview' => $secondReviewCount, + 'thirdReview' => $thirdReviewCount, + 'sign' => $signCount, + 'total' => $total + ]); + } + //询价编号前缀 - 住宅 const INQUERY_NUMBER_RESIDENCE_PREFIX = "GZ01"; @@ -3687,6 +3737,9 @@ class Pending extends Base return $this->buildFailed("确认回价失败"); } + // 推送预估数量更新到前端 + fetchAndPushEstimatePendingCount(); + return $this->buildSuccess(); } diff --git a/pgserver/application/admin/controller/Property_cert_info.php b/pgserver/application/admin/controller/Property_cert_info.php index d00f000..71225f8 100644 --- a/pgserver/application/admin/controller/Property_cert_info.php +++ b/pgserver/application/admin/controller/Property_cert_info.php @@ -47,6 +47,15 @@ class Property_cert_info extends Base if ($result['code'] == -1) { return $this->buildFailed($result['msg']); } + + // 发起查勘成功后,推送查勘跟进中数量更新 + error_log("=== reqApplySurvey 推送调试 ==="); + error_log("用户ID: " . $this->userInfo['user_id']); + error_log("是否管理员: " . ($this->isAdmin() ? 'true' : 'false')); + + $pushResult = fetchAndPushSurveyFollowCount($this->userInfo['user_id'], $this->isAdmin()); + error_log("推送结果: " . ($pushResult ? '成功' : '失败')); + return $this->buildSuccess('发起查勘成功'); } diff --git a/pgserver/application/admin/controller/ReportManage.php b/pgserver/application/admin/controller/ReportManage.php index b57ac09..635f92e 100644 --- a/pgserver/application/admin/controller/ReportManage.php +++ b/pgserver/application/admin/controller/ReportManage.php @@ -2848,6 +2848,55 @@ EOF; return $page; } + /** + * 获取报告制作数量统计 + * @return \think\response\Json + */ + public function getReportProduceCount() { + $pendingCount = Db::name('report') + ->alias('r') + ->join('inquiry i', 'r.quot_id = i.id', 'LEFT') + ->where('r.report_source', 1) + ->where('r.status', 1) + ->where('r.create_time', 'gt', '2025-02-01 00:00:00'); + $pending = $pendingCount->count(); + + // 二审待制作:以 pg_report 为主表,review_status=1 且 status=2,关联 pg_inquiry + $secondReviewCount = Db::name('report') + ->alias('r') + ->join('inquiry i', 'r.quot_id = i.id', 'LEFT') + ->where('r.report_source', 1) + ->where('r.review_status', 1) + ->where('r.status', 2) + ->where('r.create_time', 'gt', '2025-02-01 00:00:00') + ->where('i.status', 7) + ->group('r.quot_id'); + + $secondReview = $secondReviewCount->count(); + + // 三审待制作:以 pg_report 为主表,review_status=2 且 review2_status=1 且 status=2,关联 pg_inquiry + $thirdReviewCount = Db::name('report') + ->alias('r') + ->join('inquiry i', 'r.quot_id = i.id', 'LEFT') + ->where('r.report_source', 1) + ->where('r.review_status', 2) + ->where('r.review2_status', 1) + ->where('r.create_time', 'gt', '2025-02-01 00:00:00') + ->where('r.status', 2); + + $thirdReview = $thirdReviewCount->count(); + + // 计算总数 + $total = $pending + $secondReview + $thirdReview; + + return $this->buildSuccess([ + 'pending' => $pending, + 'secondReview' => $secondReview, + 'thirdReview' => $thirdReview, + 'total' => $total + ]); + } + public function cancelAntiCounterfeitCode() { $reportid = $this->request->post("reportid"); diff --git a/pgserver/application/admin/controller/Survey.php b/pgserver/application/admin/controller/Survey.php index 227914f..81df799 100644 --- a/pgserver/application/admin/controller/Survey.php +++ b/pgserver/application/admin/controller/Survey.php @@ -561,9 +561,29 @@ class Survey extends Base if (is_array($list)) { $refer = array(); foreach ($list as $key => $data) { + // 跳过空数据或非数组数据 + if (!is_array($data) || empty($data)) { + continue; + } + // 确保主键字段存在 + if (!isset($data[$pk])) { + continue; + } $refer[$data[$pk]] = &$list[$key]; } foreach ($list as $key => $data) { + // 跳过空数据或非数组数据 + if (!is_array($data) || empty($data)) { + continue; + } + // 确保父ID字段存在 + if (!isset($data[$pid])) { + continue; + } + // 确保code字段存在 + if (!isset($data['code'])) { + continue; + } $parentId = $data[$pid]; if ($root == $parentId) { $tree[$data['code']] = &$list[$key]; @@ -759,4 +779,53 @@ class Survey extends Base } } + /** + * 获取查勘跟进中数量(当前登录人) + * @return \think\Response + */ + public function surveyFollowCount() + { + // 检查用户信息 + if (empty($this->userInfo)) { + error_log("surveyFollowCount: userInfo is empty"); + return $this->buildFailed('用户信息不存在'); + } + + // 检查用户ID + if (!isset($this->userInfo['user_id'])) { + error_log("surveyFollowCount: user_id is not set"); + return $this->buildFailed('用户ID不存在'); + } + + $Survey = new SurveyModel(); + + // 如果是管理员(admin 或 COM_TOP_ADMIN),不限制 user_id + if ($this->isAdmin()) { + $count = $Survey->alias('s') + ->join('pg_inquiry i', 's.order_no = i.order_no', 'INNER') + ->where('i.status', 4) + ->where('s.status', 2) + ->where('s.assign_time', 'gt', '2025-02-01 00:00:00') + ->group('s.id') + ->count(); + } else { + // 非管理员,只统计当前用户的查勘 + $userId = $this->userInfo['user_id']; + $count = $Survey->alias('s') + ->join('pg_inquiry i', 's.order_no = i.order_no', 'INNER') + ->where('i.status', 4) + ->where('s.status', 2) + ->where('s.user_id', $userId) + ->where('s.assign_time', 'gt', '2025-02-01 00:00:00') + ->group('s.id') + ->count(); + } + + error_log("surveyFollowCount: count = $count, userId = " . $this->userInfo['user_id'] . ", isAdmin = " . ($this->isAdmin() ? 'true' : 'false')); + + return $this->buildSuccess([ + 'count' => $count + ]); + } + } \ No newline at end of file diff --git a/pgserver/application/admin/service/SurveyService.php b/pgserver/application/admin/service/SurveyService.php index 9dfb773..cf68fe5 100644 --- a/pgserver/application/admin/service/SurveyService.php +++ b/pgserver/application/admin/service/SurveyService.php @@ -95,7 +95,7 @@ class SurveyService extends CommonService } //更新订单状态:查勘待派单 - if (!Db::name('inquiry')->where(['order_no' => $data['order_no']])->update(['status'=>4, 'update_time' => new \DateTime])) { + if (!Db::name('inquiry')->where(['order_no' => $data['order_no']])->update(['status'=>4, 'update_time' => date('Y-m-d H:i:s')])) { Db::rollback(); return ['code'=>-1, 'msg'=>'更新订单状态失败']; } @@ -146,7 +146,7 @@ class SurveyService extends CommonService } //更新订单状态:查勘待派单 - if (!Db::name('inquiry')->where(['order_no' => $data['order_no']])->update(['status'=>4, 'update_time' => new \DateTime])) { + if (!Db::name('inquiry')->where(['order_no' => $data['order_no']])->update(['status'=>4, 'update_time' => date('Y-m-d H:i:s')])) { Db::rollback(); return ['code'=>-1, 'msg'=>'更新订单状态失败']; } diff --git a/pgserver/application/common.php b/pgserver/application/common.php index e9e6b1d..675ebb0 100644 --- a/pgserver/application/common.php +++ b/pgserver/application/common.php @@ -1650,6 +1650,11 @@ function pushToAllClients($eventName, $data) { 'data' => json_encode($data) ]; + error_log("=== 推送调试 ==="); + error_log("目标地址: $socketUrl"); + error_log("事件名称: $eventName"); + error_log("推送数据: " . json_encode($data)); + $options = [ 'http' => [ 'header' => "Content-type: application/x-www-form-urlencoded\r\n", @@ -1660,9 +1665,11 @@ function pushToAllClients($eventName, $data) { ]; $context = stream_context_create($options); - $result = file_get_contents($socketUrl, false, $context); + $result = @file_get_contents($socketUrl, false, $context); - writeLog("Push result - event: $eventName, data: " . json_encode($data) . ", result: '$result'", 'push_log'); + error_log("推送结果: '" . ($result !== false ? $result : 'false') . "'"); + + writeLog("Push result - event: $eventName, data: " . json_encode($data) . ", result: '" . ($result !== false ? $result : 'false') . "'", 'push_log'); return $result === 'ok'; } @@ -1694,5 +1701,187 @@ function fetchAndPushUnreturnedPriceCount() { return pushUnreturnedPriceCount($count); } +/** + * 推送预估数量更新 + * @param array $counts 预估数量数组 + * @return bool + */ +function pushEstimatePendingCount($counts) { + return pushToAllClients('updateEstimatePendingCount', $counts); +} + +/** + * 获取预估数量 + * @return array + */ +function getEstimatePendingCount() { + $Inquiry = new \app\model\Inquiry(); + + // 待制作:status=9 + $pendingCount = $Inquiry->where('status', 9)->count(); + + // 二审待制作:status=10 且 estimate_status=2(兼容字符串和数字类型) + $secondReviewCount = $Inquiry->where('status', 10) + ->where('estimate_status', '=', '2', false) + ->count(); + + // 三审待制作:status=10 且 estimate_status=3(兼容字符串和数字类型) + $thirdReviewCount = $Inquiry->where('status', 10) + ->where('estimate_status', '=', '3', false) + ->count(); + + // 待签章:status=11 + $signCount = $Inquiry->where('status', 11)->count(); + + // 总和 + $total = $pendingCount + $secondReviewCount + $thirdReviewCount + $signCount; + + return [ + 'pending' => $pendingCount, + 'secondReview' => $secondReviewCount, + 'thirdReview' => $thirdReviewCount, + 'sign' => $signCount, + 'total' => $total + ]; +} + +/** + * 获取预估数量并推送给所有客户端 + * @return bool + */ +function fetchAndPushEstimatePendingCount() { + $counts = getEstimatePendingCount(); + return pushEstimatePendingCount($counts); +} + +/** + * 推送查勘跟进中数量更新(推送刷新事件,让客户端主动获取自己的数量) + * @param int $count 查勘跟进中数量(当前用户的数量,用于发起者立即显示) + * @return bool + */ +function pushSurveyFollowCount($count) { + // 推送刷新事件,让所有客户端重新获取自己的查勘数量 + return pushToAllClients('updateSurveyFollowCount', ['refresh' => true, 'count' => $count]); +} + +/** + * 推送报告制作数量更新 + * @param array $counts 报告制作数量数组 + * @return bool + */ +function pushReportProduceCount($counts) { + // 推送刷新事件,让所有客户端重新获取自己的报告制作数量 + return pushToAllClients('updateReportProduceCount', ['refresh' => true, 'counts' => $counts]); +} + +/** + * 获取报告制作数量并推送给所有客户端 + * @param int $userId 用户ID + * @param bool $isAdmin 是否管理员 + * @return bool + */ +function fetchAndPushReportProduceCount($userId, $isAdmin = false) { + $pendingCount = Db::name('report') + ->alias('r') + ->join('inquiry i', 'r.quot_id = i.id', 'LEFT') + ->where('r.report_source', 1) + ->where('r.status', 1) + ->where('r.create_time', 'gt', '2025-02-01 00:00:00'); + $pending = $pendingCount->count(); + + // 二审待制作:以 pg_report 为主表,review_status=1 且 status=2,关联 pg_inquiry + $secondReviewCount = Db::name('report') + ->alias('r') + ->join('inquiry i', 'r.quot_id = i.id', 'LEFT') + ->where('r.report_source', 1) + ->where('r.review_status', 1) + ->where('r.status', 2) + ->where('r.create_time', 'gt', '2025-02-01 00:00:00') + ->where('i.status', 7) + ->group('r.quot_id'); + + $secondReview = $secondReviewCount->count(); + + // 三审待制作:以 pg_report 为主表,review_status=2 且 review2_status=1 且 status=2,关联 pg_inquiry + $thirdReviewCount = Db::name('report') + ->alias('r') + ->join('inquiry i', 'r.quot_id = i.id', 'LEFT') + ->where('r.report_source', 1) + ->where('r.review_status', 2) + ->where('r.review2_status', 1) + ->where('r.create_time', 'gt', '2025-02-01 00:00:00') + ->where('r.status', 2); + + $thirdReview = $thirdReviewCount->count(); + + // 计算总数 + $total = $pending + $secondReview + $thirdReview; + + return [ + 'pending' => $pending, + 'secondReview' => $secondReview, + 'thirdReview' => $thirdReview, + 'total' => $total + ]; + + error_log("查询到的报告制作数量: " . json_encode($counts)); + + $pushResult = pushReportProduceCount($counts); + error_log("推送结果: " . ($pushResult ? '成功' : '失败')); + + return $pushResult; +} + +/** + * 获取查勘跟进中数量(当前登录人) + * @param int $userId 用户ID + * @param bool $isAdmin 是否管理员 + * @return int + */ +function getSurveyFollowCount($userId, $isAdmin = false) { + $Survey = new \app\model\Survey(); + + // 如果是管理员,不限制 user_id + if ($isAdmin) { + $count = $Survey->alias('s') + ->join('pg_inquiry i', 's.order_no = i.order_no', 'INNER') + ->where('i.status', 4) + ->where('s.status', 2) + ->where('s.assign_time', 'gt', '2025-02-01 00:00:00') + ->count(); + } else { + // 非管理员,只统计当前用户的查勘 + $count = $Survey->alias('s') + ->join('pg_inquiry i', 's.order_no = i.order_no', 'INNER') + ->where('i.status', 4) + ->where('s.status', 2) + ->where('s.user_id', $userId) + ->where('s.assign_time', 'gt', '2025-02-01 00:00:00') + ->count(); + } + + return $count; +} + +/** + * 获取查勘跟进中数量并推送给所有客户端 + * @param int $userId 用户ID + * @param bool $isAdmin 是否管理员 + * @return bool + */ +function fetchAndPushSurveyFollowCount($userId, $isAdmin = false) { + error_log("=== fetchAndPushSurveyFollowCount 调试 ==="); + error_log("用户ID: $userId"); + error_log("是否管理员: " . ($isAdmin ? 'true' : 'false')); + + $count = getSurveyFollowCount($userId, $isAdmin); + error_log("查询到的查勘数量: $count"); + + $pushResult = pushSurveyFollowCount($count); + error_log("推送结果: " . ($pushResult ? '成功' : '失败')); + + return $pushResult; +} + $GLOBALS['console'] = ''; diff --git a/pgserver/application/model/Survey.php b/pgserver/application/model/Survey.php index 59e1104..8a84505 100644 --- a/pgserver/application/model/Survey.php +++ b/pgserver/application/model/Survey.php @@ -69,10 +69,19 @@ class Survey extends Base ->order('id desc') ->field('eva_unit_price,eva_total_value,eva_net_value,eva_net_value2') ->find(); - $item['eva_unit_price'] = $return_price_info['eva_unit_price']; - $item['eva_total_value'] = $return_price_info['eva_total_value']; - $item['eva_net_value'] = $return_price_info['eva_net_value']; - $item['eva_net_value2'] = $return_price_info['eva_net_value2']; + // 检查是否找到数据 + if ($return_price_info) { + $item['eva_unit_price'] = $return_price_info['eva_unit_price']; + $item['eva_total_value'] = $return_price_info['eva_total_value']; + $item['eva_net_value'] = $return_price_info['eva_net_value']; + $item['eva_net_value2'] = $return_price_info['eva_net_value2']; + } else { + // 如果没有找到数据,设置默认值 + $item['eva_unit_price'] = null; + $item['eva_total_value'] = null; + $item['eva_net_value'] = null; + $item['eva_net_value2'] = null; + } $item['status_str'] = getDictionaryName('ORDER_STATUS', $item['status']); $item['survey_status_str'] = getDictionaryName('SURVEY_STATUS', $item['survey_status']); $item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']); @@ -576,8 +585,14 @@ class Survey extends Base ->order('id desc') ->field('external_remarks,appraiser_name') ->find(); - $item['external_remarks'] = $return_price_info['external_remarks']; - $item['appraiser_name'] = $return_price_info['appraiser_name']; + // 检查是否找到数据 + if ($return_price_info) { + $item['external_remarks'] = $return_price_info['external_remarks']; + $item['appraiser_name'] = $return_price_info['appraiser_name']; + } else { + $item['external_remarks'] = null; + $item['appraiser_name'] = null; + } // $item['status_str'] = getDictionaryName('ORDER_STATUS', $item['status']); $item['survey_status_str'] = getDictionaryName('SURVEY_STATUS', $item['status']); $item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']); diff --git a/pgserver/push.php b/pgserver/push.php index b055bc7..3053e67 100644 --- a/pgserver/push.php +++ b/pgserver/push.php @@ -28,30 +28,12 @@ $sender_io->on('connection', function($socket) use (&$push_value){ // 客户端连接时立即发送当前数值 $socket->emit('push_value', ['value' => $push_value]); - // 连接时自动推送最新的未回价数量 - try { - // 从ThinkPHP数据库配置文件读取数据库连接信息 - $db_config = require __DIR__ . '/config/database.php'; - $db_host = isset($db_config['hostname']) ? $db_config['hostname'] : 'localhost'; - $db_name = isset($db_config['database']) ? $db_config['database'] : 'pgserver'; - $db_user = isset($db_config['username']) ? $db_config['username'] : 'root'; - $db_pass = isset($db_config['password']) ? $db_config['password'] : ''; - $db_port = isset($db_config['hostport']) ? $db_config['hostport'] : '3306'; - $db_charset = isset($db_config['charset']) ? $db_config['charset'] : 'utf8'; - - // 使用PDO连接数据库查询最新数量 - $dsn = "mysql:host=$db_host;port=$db_port;dbname=$db_name;charset=$db_charset"; - $pdo = new PDO($dsn, $db_user, $db_pass); - $stmt = $pdo->query('SELECT COUNT(*) as count FROM pg_inquiry WHERE return_price_status = 2'); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - $count = $result['count'] ?? 0; - - // 推送未回价数量 - $socket->emit('updateUnreturnedCount', ['count' => $count]); - error_log("WebSocket连接时推送未回价数量: $count"); - } catch (Exception $e) { - error_log("WebSocket连接时获取未回价数量失败: " . $e->getMessage()); - } + // 连接时发送刷新事件,让客户端主动获取所有数量(避免重复查询逻辑) + error_log("WebSocket客户端连接,发送4个刷新事件"); + $socket->emit('updateUnreturnedCount', ['refresh' => true]); + $socket->emit('updateEstimatePendingCount', ['refresh' => true]); + $socket->emit('updateReportProduceCount', ['refresh' => true]); + $socket->emit('updateSurveyFollowCount', ['refresh' => true]); $socket->on('login', function ($uid)use($socket){ global $uidConnectionMap; @@ -65,6 +47,24 @@ $sender_io->on('connection', function($socket) use (&$push_value){ ++$uidConnectionMap[$uid]; $socket->join($uid); $socket->uid = $uid; + + // 登录时推送刷新事件,让客户端主动获取所有数量 + $socket->emit('updateSurveyFollowCount', ['refresh' => true]); + $socket->emit('updateUnreturnedCount', ['refresh' => true]); + $socket->emit('updateEstimatePendingCount', ['refresh' => true]); + $socket->emit('updateReportProduceCount', ['refresh' => true]); + error_log("WebSocket登录时推送用户{$uid}的4个刷新事件"); + }); + + // 处理客户端主动刷新请求 + $socket->on('refreshAllCounts', function()use($socket){ + error_log("收到客户端刷新请求"); + // 发送刷新事件给当前客户端 + $socket->emit('updateSurveyFollowCount', ['refresh' => true]); + $socket->emit('updateUnreturnedCount', ['refresh' => true]); + $socket->emit('updateEstimatePendingCount', ['refresh' => true]); + $socket->emit('updateReportProduceCount', ['refresh' => true]); + error_log("已向客户端发送刷新事件(包含报告数量)"); }); $socket->on('disconnect', function () use($socket) { @@ -128,15 +128,24 @@ $sender_io->on('workerStart', function()use ($sender_io, $http_port){ $event = isset($msgContent['event']) ? $msgContent['event'] : ''; $eventData = isset($msgContent['data']) ? $msgContent['data'] : ''; - error_log("Broadcast check - event: '$event', data: '$eventData'"); + error_log("=== WebSocket广播调试 ==="); + error_log("事件名称: '$event'"); + error_log("原始数据: '$eventData'"); if(!empty($event)){ if(is_string($eventData)){ $decoded = json_decode($eventData, true); $eventData = $decoded !== null ? $decoded : $eventData; } - $sender_io->emit($event, $eventData); - error_log("Broadcast sent - event: $event, data: " . print_r($eventData, true)); + error_log("解码后数据: " . print_r($eventData, true)); + + // 获取所有连接的客户端并发送消息 + // PHPSocketIO 1.x 使用 connections 数组获取所有连接 + foreach ($sender_io->connections as $connection) { + $connection->emit($event, $eventData); + } + error_log("广播已发送到所有客户端 - 事件: $event"); + return $http_connection->send('ok'); } } diff --git a/pgweb/src/api/businessManage/inquiry.js b/pgweb/src/api/businessManage/inquiry.js index dccd227..f60cde2 100644 --- a/pgweb/src/api/businessManage/inquiry.js +++ b/pgweb/src/api/businessManage/inquiry.js @@ -146,3 +146,21 @@ export async function getUnreturnedPriceCount (params) { const res = await post('admin/Pending/getUnreturnedPriceCount', params) return res } + +// 获取预估制作数量(status=9) +export async function getEstimatePendingCount (params) { + const res = await post('admin/Pending/getEstimatePendingCount', params) + return res +} + +// 获取查勘跟进中数量(当前登录人) +export async function getSurveyFollowCount (params) { + const res = await post('admin/Survey/surveyFollowCount', params) + return res +} + +// 获取报告制作数量统计 +export async function getReportProduceCount (params) { + const res = await post('admin/ReportManage/getReportProduceCount', params) + return res +} diff --git a/pgweb/src/components/menu/nxIconMenu.vue b/pgweb/src/components/menu/nxIconMenu.vue index 9fbf43d..cfe24fd 100644 --- a/pgweb/src/components/menu/nxIconMenu.vue +++ b/pgweb/src/components/menu/nxIconMenu.vue @@ -17,6 +17,9 @@ {{ replacePhrases(menuItem.title, replaceRule1) }}
{{ unreturnedCount }}
+
{{ estimateCounts.total }}
+
{{ surveyFollowCount }}
+
{{ reportProduceCounts.total }}
@@ -29,6 +32,7 @@ import "@/styles/globalSetting.less"; import { EventBus } from '@/libs/eventBus' import socket from '@/libs/socket' + import { getSurveyFollowCount, getUnreturnedPriceCount, getEstimatePendingCount, getReportProduceCount } from '@/api/businessManage/inquiry' export default { name: 'NxIconMenu', props: { @@ -45,6 +49,20 @@ return { activeMenu: '1-4-1', unreturnedCount: 0, + estimateCounts: { + pending: 0, + secondReview: 0, + thirdReview: 0, + sign: 0, + total: 0 + }, + surveyFollowCount: 0, + reportProduceCounts: { + pending: 0, + secondReview: 0, + thirdReview: 0, + total: 0 + }, replaceRule1:[ ['询价项目','询价'], ['回价项目','回价'], @@ -72,25 +90,179 @@ }; }, mounted() { - // 监听EventBus事件 + // 调试:打印左侧菜单数据 + console.log('=== 左侧图标菜单调试 ===') + console.log('menuData:', this.menuData) + console.log('estimateCounts初始值:', this.estimateCounts) + + // 主动获取所有数量,避免时序问题导致的红点不显示 + this.fetchUnreturnedCount() + this.fetchEstimateCount() + this.fetchSurveyFollowCount() + this.fetchReportCount() + + // 监听EventBus事件 - 未回价数量 this.eventBusCallback = (count) => { + console.log('=== 未回价EventBus事件 ===', count) this.$set(this, 'unreturnedCount', count) } this.socketCallback = (data) => { - if (data && data.count !== undefined) { + console.log('=== 未回价WebSocket事件 ===', data) + if (data && data.refresh) { + // 收到刷新事件,主动获取数据 + this.fetchUnreturnedCount() + } else if (data && data.count !== undefined) { this.$set(this, 'unreturnedCount', data.count) } } EventBus.$on('updateUnreturnedCount', this.eventBusCallback) socket.on('updateUnreturnedCount', this.socketCallback) + + // 监听EventBus事件 - 预估制作数量 + this.estimateEventBusCallback = (counts) => { + console.log('=== 预估EventBus事件 ===', counts) + this.$set(this, 'estimateCounts', counts) + } + this.estimateSocketCallback = (data) => { + console.log('=== 预估WebSocket事件 ===', data) + if (data && data.refresh) { + // 收到刷新事件,主动获取数据 + this.fetchEstimateCount() + } else if (data && data.pending !== undefined) { + this.$set(this, 'estimateCounts', data) + } + } + EventBus.$on('updateEstimatePendingCount', this.estimateEventBusCallback) + socket.on('updateEstimatePendingCount', this.estimateSocketCallback) + + // 监听EventBus事件 - 查勘跟进中数量 + this.surveyEventBusCallback = (count) => { + this.$set(this, 'surveyFollowCount', count) + } + this.surveySocketCallback = (data) => { + console.log('=== 查勘WebSocket事件 ===', data) + if (data && data.refresh) { + // 收到刷新事件,主动重新获取查勘数量 + console.log('收到查勘刷新事件,主动获取查勘数量') + this.fetchSurveyFollowCount() + } else if (data && data.count !== undefined) { + // 直接更新数量(兼容旧的推送格式) + console.log('收到查勘数量更新:', data.count) + this.$set(this, 'surveyFollowCount', data.count) + } + } + EventBus.$on('updateSurveyFollowCount', this.surveyEventBusCallback) + socket.on('updateSurveyFollowCount', this.surveySocketCallback) + + // 监听EventBus事件 - 报告制作数量 + this.reportEventBusCallback = (counts) => { + console.log('=== 报告EventBus事件 ===', counts) + this.$set(this, 'reportProduceCounts', counts) + } + this.reportSocketCallback = (data) => { + console.log('=== 报告WebSocket事件 ===', data) + if (data && data.refresh) { + // 收到刷新事件,主动获取数据 + this.fetchReportCount() + } else if (data && data.counts !== undefined) { + this.$set(this, 'reportProduceCounts', data.counts) + } + } + EventBus.$on('updateReportProduceCount', this.reportEventBusCallback) + socket.on('updateReportProduceCount', this.reportSocketCallback) }, beforeDestroy() { EventBus.$off('updateUnreturnedCount', this.eventBusCallback) socket.off('updateUnreturnedCount', this.socketCallback) + EventBus.$off('updateEstimatePendingCount', this.estimateEventBusCallback) + socket.off('updateEstimatePendingCount', this.estimateSocketCallback) + EventBus.$off('updateSurveyFollowCount', this.surveyEventBusCallback) + socket.off('updateSurveyFollowCount', this.surveySocketCallback) + EventBus.$off('updateReportProduceCount', this.reportEventBusCallback) + socket.off('updateReportProduceCount', this.reportSocketCallback) }, methods: { + // 主动获取未回价数量 + async fetchUnreturnedCount() { + try { + console.log('开始获取未回价数量...') + const res = await getUnreturnedPriceCount() + console.log('未回价数量接口返回:', res) + if (res && res.code === 1 && res.data) { + console.log('未回价数量获取成功:', res.data.count) + this.$set(this, 'unreturnedCount', res.data.count) + } else { + console.log('未回价数量获取失败,响应格式不正确') + } + } catch (error) { + console.error('获取未回价数量失败:', error) + } + }, + // 主动获取预估制作数量 + async fetchEstimateCount() { + try { + console.log('开始获取预估制作数量...') + const res = await getEstimatePendingCount() + console.log('预估制作数量接口返回:', res) + if (res && res.code === 1 && res.data) { + console.log('预估制作数量获取成功:', res.data) + this.$set(this, 'estimateCounts', res.data) + } else { + console.log('预估制作数量获取失败,响应格式不正确') + } + } catch (error) { + console.error('获取预估制作数量失败:', error) + } + }, + // 主动获取查勘跟进中数量 + async fetchSurveyFollowCount() { + try { + console.log('开始获取查勘跟进中数量...') + const res = await getSurveyFollowCount() + console.log('查勘跟进中数量接口返回:', res) + if (res && res.code === 1 && res.data) { + console.log('查勘跟进中数量获取成功:', res.data.count) + this.$set(this, 'surveyFollowCount', res.data.count) + } else { + console.log('查勘跟进中数量获取失败,响应格式不正确') + } + } catch (error) { + console.error('获取查勘跟进中数量失败:', error) + } + }, + // 主动获取报告制作数量 + async fetchReportCount() { + try { + console.log('===== 开始获取报告制作数量 =====') + const res = await getReportProduceCount() + console.log('报告制作数量接口返回:', JSON.stringify(res, null, 2)) + if (res && res.code === 1 && res.data) { + const data = res.data + console.log('===== 报告制作数量统计 =====') + console.log('待制作数量:', data.pending) + console.log('二审待制作数量:', data.secondReview) + console.log('三审待制作数量:', data.thirdReview) + console.log('总数:', data.total) + console.log('============================') + this.$set(this, 'reportProduceCounts', data) + } else { + console.log('报告制作数量获取失败,响应格式不正确') + } + } catch (error) { + console.error('获取报告制作数量失败:', error) + } + }, isHuiJiaMenu(menuItem) { - return menuItem.title === '回价项目' || menuItem.routerName === 'priceReturn' + return menuItem.title === '回价项目' || menuItem.title === '回价' || menuItem.routerName === 'priceReturn' + }, + isEstimateMenu(menuItem) { + return menuItem.title === '预估项目' || menuItem.routerName === 'estimate' || menuItem.name === 'estimate' + }, + isSurveyMenu(menuItem) { + return menuItem.title === '查勘' || menuItem.title === '查勘项目' || menuItem.routerName === 'survey' || menuItem.name === 'survey' + }, + isReportMenu(menuItem) { + return menuItem.title === '报告' || menuItem.routerName === 'report' || menuItem.name === 'report' }, handleSelect(key, item , externalInfo ) { this.$emit('menu-select', key, item.routerName, externalInfo); diff --git a/pgweb/src/components/menu/nxMenu.vue b/pgweb/src/components/menu/nxMenu.vue index 387609d..87484ff 100644 --- a/pgweb/src/components/menu/nxMenu.vue +++ b/pgweb/src/components/menu/nxMenu.vue @@ -5,10 +5,22 @@ @@ -16,10 +28,25 @@ - {{ item.title }} - + {{ unreturnedCount }} + + {{ estimateCounts.pending }} + + {{ estimateCounts.secondReview }} + + {{ estimateCounts.thirdReview }} + + {{ estimateCounts.sign }} + + {{ surveyFollowCount }} + + {{ reportProduceCounts.pending }} + + {{ reportProduceCounts.secondReview }} + + {{ reportProduceCounts.thirdReview }} @@ -28,6 +55,8 @@ import "@/styles/globalSetting.less"; import { EventBus } from '@/libs/eventBus' import socket from '@/libs/socket' + import { post } from '@/libs/request' + import { getEstimatePendingCount, getSurveyFollowCount, getReportProduceCount } from '@/api/businessManage/inquiry' export default { name: 'MenuItem', props: { @@ -35,28 +64,144 @@ }, data() { return { - unreturnedCount: 0 + unreturnedCount: 0, + estimateCounts: { + pending: 0, + secondReview: 0, + thirdReview: 0, + sign: 0, + total: 0 + }, + surveyFollowCount: 0, + reportProduceCounts: { + pending: 0, + secondReview: 0, + thirdReview: 0, + total: 0 + } } }, computed: { + // ==================== 回价项目 ==================== // 判断是否是一级菜单【回价项目】 isHuiJiaMenu() { - const isMatch = this.item.title === '回价项目' || this.item.routerName === 'priceReturn' - return isMatch + return this.item.routerName === 'priceReturn' || this.item.title === '回价项目' }, // 判断是否是二级菜单【未回价】 isUnreturnedPriceMenu() { - const isMatch = this.item.path === '/priceReturn/unreturnedPrice' || this.item.title === '未回价' || this.item.routerName === 'unreturnedPrice' - return isMatch + return this.item.routerName === 'unreturnedPrice' || this.item.title === '未回价' }, - // 判断是否是三级菜单【未回价列表】 + // 判断是否是三级菜单【未回价列表】- 使用routerName唯一标识 isUnreturnedPriceListMenu() { - const isMatch = this.item.title === '未回价列表' - return isMatch + return this.item.routerName && this.item.routerName.includes('unreturnedPrice') || + this.item.title === '未回价列表' + }, + + // ==================== 预估项目 ==================== + // 判断是否是一级菜单【预估】- 只有当不是预估单时才匹配 + isEstimateMenu() { + return (this.item.routerName === 'estimate' || this.item.title === '预估') && + !this.isEstimatePendingMenu + }, + // 判断是否是二级菜单【预估单】 + isEstimatePendingMenu() { + return this.item.routerName === 'estimateMake-estimate' || this.item.title === '预估单' + }, + // 判断是否是三级菜单【待制作】(预估)-使用routerName区分,避免与报告制作下的待制作混淆 + isEstimatePendingListMenu() { + return this.item.routerName === 'estimateMake-estimateWaitMakeList' || + this.item.routerName && this.item.routerName.includes('estimateWaitMakeList') + }, + // 判断是否是三级菜单【二审待制作】(预估)-使用routerName区分 + isSecondReviewListMenu() { + return this.item.routerName === 'estimateMake-estimateWaitMakeApprovalList' || + this.item.routerName && this.item.routerName.includes('estimateWaitMakeApprovalList') + }, + // 判断是否是三级菜单【三审待制作】(预估)-使用routerName区分 + isThirdReviewListMenu() { + return this.item.routerName === 'estimateMake-estimateWaitMakeApprovalThirdList' || + this.item.routerName && this.item.routerName.includes('estimateWaitMakeApprovalThirdList') + }, + // 判断是否是三级菜单【待签章】(预估) + isSignListMenu() { + return this.item.routerName === 'estimateMake-estimateWaitSignSignList' || + this.item.routerName && this.item.routerName.includes('estimateWaitSignSignList') || + this.item.title === '待签章' + }, + + // ==================== 查勘项目 ==================== + // 判断是否是一级菜单【查勘项目】 + isSurveyMenu() { + return this.item.routerName === 'surveyManage-surveyManage' || + this.item.routerName === 'survey' || + this.item.title === '查勘项目' || + this.item.title === '查勘' + }, + // 判断是否是二级菜单【查勘列表】 + isSurveyListMenu() { + return this.item.routerName && this.item.routerName.startsWith('surveyManage-') || + this.item.title === '查勘列表' + }, + // 判断是否是三级菜单【跟进中】(查勘)-使用routerName确保是查勘模块下的 + isSurveyFollowMenu() { + return this.item.routerName === 'surveyManage-surveyWaitFollowList' || + (this.item.title === '跟进中' && this.item.routerName && this.item.routerName.includes('survey')) + }, + + // ==================== 报告项目 ==================== + // 判断是否是一级菜单【报告项目】 + // isReportMenu() { + // return this.item.routerName === 'report' || + // this.item.title === '报告项目' || + // this.item.title === '报告制作' + // }, + // 判断是否是二级菜单【报告制作】 + isReportProduceMenu() { + return this.item.routerName && this.item.routerName.startsWith('report-') || + this.item.title === '报告制作' + }, + // 判断是否是三级菜单【待制作】(报告)-使用routerName区分,避免与预估单下的待制作混淆 + isReportPendingMenu() { + return this.item.routerName === 'waitMake' + }, + // 判断是否是三级菜单【二审待制作】(报告)-使用routerName区分 + isReportSecondReviewMenu() { + return this.item.routerName === 'waitApproval' + }, + // 判断是否是三级菜单【三审待制作】(报告)-使用routerName区分 + isReportThirdReviewMenu() { + return this.item.routerName === 'waitApprovalThird' } }, mounted() { - console.log('菜单组件mounted - item:', this.item) + // 获取所有数据,确保每个菜单项都能显示正确的数值 + // 回价相关菜单 + // if (this.isHuiJiaMenu || this.isUnreturnedPriceMenu || this.isUnreturnedPriceListMenu) { + this.fetchUnreturnedCount() + // } + // 预估相关菜单 - 包含预估模块下的所有菜单 + // if (this.isEstimateMenu || this.isEstimatePendingMenu || this.isEstimatePendingListMenu || this.isSecondReviewListMenu || this.isThirdReviewListMenu || this.isSignListMenu || + // this.item.title === '预估' || this.item.title === '预估单' || + // (this.item.title === '待制作' && this.item.parentName === '预估单') || + // (this.item.title && this.item.title.includes('二审') && this.item.parentName === '预估单') || + // (this.item.title && this.item.title.includes('三审') && this.item.parentName === '预估单') || + // this.item.title === '待签章') { + this.fetchEstimateCount() + // } + // 查勘相关菜单 - 包含查勘模块下的所有菜单 + // if (this.isSurveyMenu || this.isSurveyListMenu || this.isSurveyFollowMenu || + // this.item.title === '查勘项目' || this.item.title === '查勘' || + // this.item.title === '查勘列表' || this.item.title === '跟进中') { + this.fetchSurveyFollowCount() + // } + // 报告相关菜单 - 包含报告模块下的所有菜单 + // if (this.isReportMenu || this.isReportProduceMenu || this.isReportPendingMenu || this.isReportSecondReviewMenu || this.isReportThirdReviewMenu || + // this.item.title === '报告项目' || this.item.title === '报告制作' || + // (this.item.title === '待制作' && this.item.parentName === '报告制作') || + // (this.item.title && this.item.title.includes('二审') && this.item.parentName === '报告制作') || + // (this.item.title && this.item.title.includes('三审') && this.item.parentName === '报告制作')) { + this.fetchReportCount() + // } // 保存回调引用用于销毁时移除 this.eventBusCallback = (count) => { @@ -65,23 +210,135 @@ } this.socketCallback = (data) => { - if (data && data.count !== undefined) { - // 使用Vue.set确保响应式更新 + if (data && data.refresh) { + // 收到刷新事件,只有回价相关菜单才主动获取数据 + if (this.isHuiJiaMenu || this.isUnreturnedPriceMenu || this.isUnreturnedPriceListMenu) { + this.fetchUnreturnedCount() + } + } else if (data && data.count !== undefined) { this.$set(this, 'unreturnedCount', data.count) console.log('WebSocket收到未回价数量更新:', data.count, '当前item:', this.item.name || this.item.title) } } - // 监听EventBus事件(页面初始化时) - EventBus.$on('updateUnreturnedCount', this.eventBusCallback) + // 预估制作数量回调 + this.estimateEventBusCallback = (counts) => { + this.$set(this, 'estimateCounts', counts) + } - // 监听WebSocket推送的未回价数量更新 + this.estimateSocketCallback = (data) => { + if (data && data.refresh) { + // 收到刷新事件,只有预估相关菜单才主动获取数据 + if (this.isEstimateMenu || this.isEstimatePendingMenu || this.isEstimatePendingListMenu || this.isSecondReviewListMenu || this.isThirdReviewListMenu || this.isSignListMenu) { + this.fetchEstimateCount() + } + } else if (data && data.pending !== undefined) { + this.$set(this, 'estimateCounts', data) + console.log('WebSocket收到预估制作数量更新:', data, '当前item:', this.item.name || this.item.title) + } + } + + // 查勘跟进中数量回调 + this.surveyEventBusCallback = (count) => { + this.$set(this, 'surveyFollowCount', count) + } + + this.surveySocketCallback = (data) => { + if (data && data.refresh) { + // 收到刷新事件,只有查勘相关菜单才主动获取数据 + if (this.isSurveyMenu || this.isSurveyListMenu || this.isSurveyFollowMenu) { + this.fetchSurveyFollowCount() + } + } else if (data && data.count !== undefined) { + this.$set(this, 'surveyFollowCount', data.count) + console.log('WebSocket收到查勘跟进中数量更新:', data.count, '当前item:', this.item.name || this.item.title) + } + } + + // 报告制作数量回调 + this.reportEventBusCallback = (counts) => { + this.$set(this, 'reportProduceCounts', counts) + } + + this.reportSocketCallback = (data) => { + if (data && data.refresh) { + // 收到刷新事件,只有报告相关菜单才主动获取数据 + if (this.isReportMenu || this.isReportProduceMenu || this.isReportPendingMenu || this.isReportSecondReviewMenu || this.isReportThirdReviewMenu) { + this.fetchReportCount() + } + } else if (data && data.pending !== undefined) { + this.$set(this, 'reportProduceCounts', data) + } + } + + // 监听EventBus事件 + EventBus.$on('updateUnreturnedCount', this.eventBusCallback) + EventBus.$on('updateEstimatePendingCount', this.estimateEventBusCallback) + EventBus.$on('updateSurveyFollowCount', this.surveyEventBusCallback) + EventBus.$on('updateReportProduceCount', this.reportEventBusCallback) + + // 监听WebSocket事件 socket.on('updateUnreturnedCount', this.socketCallback) + socket.on('updateEstimatePendingCount', this.estimateSocketCallback) + socket.on('updateSurveyFollowCount', this.surveySocketCallback) + socket.on('updateReportProduceCount', this.reportSocketCallback) }, beforeDestroy() { // 移除监听 EventBus.$off('updateUnreturnedCount', this.eventBusCallback) socket.off('updateUnreturnedCount', this.socketCallback) + EventBus.$off('updateEstimatePendingCount', this.estimateEventBusCallback) + socket.off('updateEstimatePendingCount', this.estimateSocketCallback) + EventBus.$off('updateSurveyFollowCount', this.surveyEventBusCallback) + socket.off('updateSurveyFollowCount', this.surveySocketCallback) + EventBus.$off('updateReportProduceCount', this.reportEventBusCallback) + socket.off('updateReportProduceCount', this.reportSocketCallback) + }, + methods: { + async fetchUnreturnedCount() { + try { + const res = await post('admin/Pending/getUnreturnedPriceCount') + if (res && res.code === 1 && res.data) { + this.$set(this, 'unreturnedCount', res.data.count) + } + } catch (error) { + console.error('获取未回价数量失败:', error) + } + }, + async fetchEstimateCount() { + try { + const res = await getEstimatePendingCount() + if (res && res.code === 1 && res.data) { + this.$set(this, 'estimateCounts', res.data) + } + } catch (error) { + console.error('获取预估数量失败:', error) + } + }, + async fetchSurveyFollowCount() { + try { + const res = await getSurveyFollowCount() + if (res && res.code === 1 && res.data) { + this.$set(this, 'surveyFollowCount', res.data.count) + } + } catch (error) { + console.error('获取查勘跟进中数量失败:', error) + } + }, + async fetchReportCount() { + try { + console.log('===== nxMenu 获取报告制作数量 =====') + const res = await getReportProduceCount() + console.log('报告制作数量接口返回:', JSON.stringify(res, null, 2)) + if (res && res.code === 1 && res.data) { + const data = res.data + console.log('待制作:', data.pending, '二审:', data.secondReview, '三审:', data.thirdReview, '总数:', data.total) + this.$set(this, 'reportProduceCounts', data) + } + } catch (error) { + console.error('获取报告制作数量失败:', error) + } + } } } @@ -117,4 +374,4 @@ margin-left: 8px; margin-top: 4px; } - + \ No newline at end of file diff --git a/pgweb/src/libs/estimatePending.js b/pgweb/src/libs/estimatePending.js new file mode 100644 index 0000000..e240ee7 --- /dev/null +++ b/pgweb/src/libs/estimatePending.js @@ -0,0 +1,42 @@ +import { EventBus } from './eventBus' +import { getEstimatePendingCount } from '@/api/businessManage/inquiry' + +/** + * 获取并更新所有预估状态数量 + * 调用API获取最新数量,并通过EventBus广播给所有监听者 + */ +export const fetchAndUpdateEstimatePendingCount = async () => { + console.log('fetchAndUpdateEstimatePendingCount: 开始获取预估状态数量...') + try { + const response = await getEstimatePendingCount() + console.log('fetchAndUpdateEstimatePendingCount: 接口返回完整数据:', response) + if (response && response.code === 1) { + const data = response.data || {} + const pending = data.pending || 0 + const secondReview = data.secondReview || 0 + const thirdReview = data.thirdReview || 0 + const sign = data.sign || 0 + const total = data.total || 0 + + console.log('fetchAndUpdateEstimatePendingCount: 获取到预估状态数量:', { pending, secondReview, thirdReview, sign, total }) + console.log('fetchAndUpdateEstimatePendingCount: 调试数据:', data.debug || '无') + + // 通过事件总线传递数量给菜单组件 + EventBus.$emit('updateEstimatePendingCount', { + pending, + secondReview, + thirdReview, + sign, + total + }) + + return { pending, secondReview, thirdReview, sign, total } + } else { + console.warn('fetchAndUpdateEstimatePendingCount: 接口返回异常:', response) + return { pending: 0, secondReview: 0, thirdReview: 0, sign: 0, total: 0 } + } + } catch (error) { + console.error('fetchAndUpdateEstimatePendingCount: 获取预估状态数量失败:', error) + return { pending: 0, secondReview: 0, thirdReview: 0, sign: 0, total: 0 } + } +} \ No newline at end of file diff --git a/pgweb/src/libs/socket.js b/pgweb/src/libs/socket.js index 1910f28..18a187d 100644 --- a/pgweb/src/libs/socket.js +++ b/pgweb/src/libs/socket.js @@ -19,10 +19,14 @@ const socket = io(process.env.VUE_APP_SOCKET_URL, { // 添加连接状态监听 socket.on('connect', () => { console.log('WebSocket已成功连接到服务器:', process.env.VUE_APP_SOCKET_URL) + // 连接成功后启动定时轮询 + startPolling() }) socket.on('disconnect', (reason) => { console.log('WebSocket连接断开,原因:', reason) + // 断开连接后停止定时轮询 + stopPolling() }) socket.on('connect_error', (error) => { @@ -33,6 +37,30 @@ socket.on('connect_timeout', () => { console.error('WebSocket连接超时') }) +// 定时轮询定时器 +let pollingTimer = null + +// 启动定时轮询(每10秒) +function startPolling() { + if (pollingTimer) { + clearInterval(pollingTimer) + } + pollingTimer = setInterval(() => { + // 触发刷新事件,让客户端主动获取最新数据 + socket.emit('refreshAllCounts') + }, 10000) // 每10秒刷新一次 + console.log('定时轮询已启动,每5秒刷新一次') +} + +// 停止定时轮询 +function stopPolling() { + if (pollingTimer) { + clearInterval(pollingTimer) + pollingTimer = null + } + console.log('定时轮询已停止') +} + // 连接方法 export const connectSocket = () => { console.log('尝试启动WebSocket连接...') diff --git a/pgweb/src/router/index.js b/pgweb/src/router/index.js index d907be4..b3d6b6f 100644 --- a/pgweb/src/router/index.js +++ b/pgweb/src/router/index.js @@ -7,6 +7,7 @@ import * as localStore from 'store' import store from '@/store' import { connectSocket } from '@/libs/socket' import { fetchAndUpdateUnreturnedPriceCount } from '@/libs/unreturnedPrice' +import { fetchAndUpdateEstimatePendingCount } from '@/libs/estimatePending' Vue.use(Router) let routers = routes @@ -33,11 +34,13 @@ router.beforeEach((to, from, next) => { iView.LoadingBar.start() const token = getToken() - // 如果用户已登录,确保WebSocket连接已建立并获取最新未回价数量 + // 如果用户已登录,确保WebSocket连接已建立并获取最新数量 if (token && to.name !== LOGIN_PAGE_NAME) { connectSocket() // 每次刷新页面都获取最新的未回价数量 fetchAndUpdateUnreturnedPriceCount() + // 获取预估制作数量 + fetchAndUpdateEstimatePendingCount() } if (!token && to.name !== LOGIN_PAGE_NAME) { diff --git a/pgweb/src/views/businessManage/businessInfo/inquiry/list.vue b/pgweb/src/views/businessManage/businessInfo/inquiry/list.vue index 2470439..1577fd6 100644 --- a/pgweb/src/views/businessManage/businessInfo/inquiry/list.vue +++ b/pgweb/src/views/businessManage/businessInfo/inquiry/list.vue @@ -675,6 +675,9 @@ import{ getReportObjTypeList } from '@/api/report.js' +import { EventBus } from '@/libs/eventBus' +import { getSurveyFollowCount } from '@/api/businessManage/inquiry' + import { reqBankList, getProduct, @@ -2390,11 +2393,26 @@ export default { // init data this.initData() + + // 刷新查勘跟进中数量 + this.refreshSurveyFollowCount() } else { this.$Message.error(res.msg) } }) }, + // 刷新查勘跟进中数量 + async refreshSurveyFollowCount() { + try { + const res = await getSurveyFollowCount() + if (res && res.code === 1 && res.data) { + const count = res.data.count || 0 + EventBus.$emit('updateSurveyFollowCount', count) + } + } catch (error) { + console.error('刷新查勘跟进中数量失败:', error) + } + }, onCancelRejPress () { this.rejectModal = false this.$refs['rejFormRef'].resetFields() diff --git a/pgweb/src/views/home/home.vue b/pgweb/src/views/home/home.vue index aadaeb5..3dadb3a 100644 --- a/pgweb/src/views/home/home.vue +++ b/pgweb/src/views/home/home.vue @@ -26,7 +26,7 @@ import homePage from './components/message' import { connectSocket } from '@/libs/socket' import { EventBus } from '@/libs/eventBus' -import { getUnreturnedPriceCount } from '@/api/businessManage/inquiry' +import { getUnreturnedPriceCount, getEstimatePendingCount, getSurveyFollowCount } from '@/api/businessManage/inquiry' export default { components: { homePage }, mounted() { @@ -35,6 +35,10 @@ export default { // 获取未回价数量 this.getUnreturnedPriceCountData() + // 获取预估制作数量 + this.getEstimatePendingCountData() + // 获取查勘跟进中数量 + this.getSurveyFollowCountData() }, methods: { // 获取未回价数量 @@ -50,6 +54,41 @@ export default { } catch (error) { console.error('获取未回价数量失败:', error) } + }, + // 获取预估制作数量 + async getEstimatePendingCountData() { + try { + const response = await getEstimatePendingCount() + if (response && response.code === 1) { + const data = response.data || {} + const counts = { + pending: data.pending || 0, + secondReview: data.secondReview || 0, + thirdReview: data.thirdReview || 0, + sign: data.sign || 0, + total: data.total || 0 + } + console.log('预估制作数量:', counts) + // 通过事件总线传递数量给菜单组件 + EventBus.$emit('updateEstimatePendingCount', counts) + } + } catch (error) { + console.error('获取预估制作数量失败:', error) + } + }, + // 获取查勘跟进中数量 + async getSurveyFollowCountData() { + try { + const response = await getSurveyFollowCount() + if (response && response.code === 1) { + const count = response.data.count || 0 + console.log('查勘跟进中数量:', count) + // 通过事件总线传递数量给菜单组件 + EventBus.$emit('updateSurveyFollowCount', count) + } + } catch (error) { + console.error('获取查勘跟进中数量失败:', error) + } } } } diff --git a/pgweb/src/views/priceReturn/history/list.vue b/pgweb/src/views/priceReturn/history/list.vue index 06bd935..6851f43 100644 --- a/pgweb/src/views/priceReturn/history/list.vue +++ b/pgweb/src/views/priceReturn/history/list.vue @@ -160,8 +160,10 @@ import { reqBankList, getProduct, consultFiles, + getSurveyFollowCount } from '@/api/businessManage/inquiry' import { reqDistrict } from '@/api/basicData' +import { EventBus } from '@/libs/eventBus' import search from '@/mixins/search' import { getRole } from '@/api/surveyManage' import { getNowFormatDate } from '@/libs/tools' @@ -1783,11 +1785,26 @@ export default { // init data this.initData() + + // 刷新查勘跟进中数量 + this.refreshSurveyFollowCount() } else { this.$Message.error(res.msg) } }) }, + // 刷新查勘跟进中数量 + async refreshSurveyFollowCount() { + try { + const res = await getSurveyFollowCount() + if (res && res.code === 1 && res.data) { + const count = res.data.count || 0 + EventBus.$emit('updateSurveyFollowCount', count) + } + } catch (error) { + console.error('刷新查勘跟进中数量失败:', error) + } + }, onCancelRejPress () { this.rejectModal = false this.$refs['rejFormRef'].resetFields()