文件
yjyf/yjyf-app/components/master/MasterHallView.vue
YuanWen cd0da0324b feat: 新增用户和师傅消息中心及订单页重构
- 新增用户消息中心组件 UserMessageView
- 新增师傅消息中心组件 MasterMessageView
- 新增用户订单列表组件 UserOrdersView
- 重构订单列表页,复用独立组件
- 新增系统工具 getWindowInfoSafe 兼容多端系统信息获取
- 重构 TabBar 组件,支持单母页模式和事件回调
- 优化消息跳转逻辑,支持角色自适应 Tab 切换
2026-11-05 16:52:12 +08:00

721 行
17 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="hall-view">
<!-- 顶部一体化沉浸式头部(单一连续背景渐变,彻底消除分层割裂) -->
<view class="hall-hero">
<YjyfNavBar theme="transparent" title="接单大厅" :fixed="false" />
<view class="hall-header-body">
<view class="header-main">
<view class="h-user">
<view class="name-line">
<text class="h-name">{{ info ? info.realname : '优匠师傅' }}</text>
<view class="level-badge" v-if="info">
<text class="level-txt">Lv{{ info.level }}</text>
</view>
</view>
<text class="h-stats">{{ info ? ('综合评分 ' + info.score + ' · 累计完成 ' + info.order_count + ' 单') : '优匠优服师傅工作端' }}</text>
</view>
<view class="work-toggle clickable-hover" :class="{ paused: info && info.work_status === 'off' }" @tap="toggleWork">
<view class="dot"></view>
<text class="toggle-txt">{{ info && info.work_status === 'off' ? '已暂停' : '听单中' }}</text>
</view>
</view>
</view>
</view>
<!-- 跑马灯动态通知广播(对标工奇兵广播条) -->
<view class="broadcast-bar" v-if="list.length">
<image class="broadcast-ico" src="/static/icons/nav-bell.svg" mode="aspectFit" />
<swiper class="broadcast-swiper" :vertical="true" :autoplay="true" :interval="3500" :circular="true">
<swiper-item class="swiper-item" v-for="(item, idx) in broadcastList" :key="idx">
<text class="broadcast-txt">{{ item }}</text>
</swiper-item>
</swiper>
</view>
<!-- 工奇兵风格筛选导航栏:全部 / 一口价 / 师傅竞价 / 用户定价 -->
<view class="filter-sticky">
<view class="type-tabs">
<view v-for="t in typeTabs" :key="t.key" class="t-tab clickable-hover" :class="{ on: type === t.key }" @tap="type = t.key">
<text class="t-txt">{{ t.name }}</text>
<view class="t-dot" v-if="t.badge && list.length"></view>
</view>
</view>
<view class="sort-tabs">
<view v-for="s in sortTabs" :key="s.key" class="s-tab clickable-hover" :class="{ on: sort === s.key }" @tap="sort = s.key">
{{ s.name }}
</view>
</view>
</view>
<!-- 订单列表(工奇兵高密度信息流卡片,点击卡片进详情) -->
<view class="list">
<view class="item clickable-hover" v-for="o in list" :key="o.id" @tap="goDetail(o)">
<view class="hd">
<view class="hd-left">
<text class="tag-urgent" v-if="Number(o.urgent)">急单</text>
<text class="tag-mode quote" v-if="o.price_type === 'quote'">师傅竞价</text>
<text class="tag-mode custom" v-if="o.price_type === 'custom'">用户定价</text>
<text class="tag-mode fixed" v-if="o.price_type === 'fixed'">一口价</text>
<text class="svc">{{ o.service_name }}</text>
</view>
<view class="amt-box">
<text class="amt-symbol" v-if="o.price_type !== 'quote'">¥</text>
<text class="amt">{{ o.price_type === 'quote' ? '竞价中' : o.pay_amount }}</text>
</view>
</view>
<view class="bd">
<!-- 地址与距离 -->
<view class="info-row">
<image class="row-icon" src="/static/icons/master/order-loc.svg" mode="aspectFit" />
<text class="row-txt addr-txt">{{ o.address }}</text>
<text class="distance-txt" v-if="o.distance_text">{{ o.distance_text }}</text>
</view>
<!-- 预约上门时间 -->
<view class="info-row">
<image class="row-icon" src="/static/icons/master/order-time.svg" mode="aspectFit" />
<text class="row-txt">期望上门:{{ o.appoint_text }}</text>
</view>
<!-- 服务规格与条件微徽标 -->
<view class="badge-row">
<text class="badge">楼层 {{ o.floor }} 层</text>
<text class="badge">{{ Number(o.has_elevator) ? '有电梯' : '步梯无电梯' }}</text>
<text class="badge" v-if="o.goods_model">型号:{{ o.goods_model }}</text>
</view>
<!-- 客户工单要求备注 -->
<view class="remark-row" v-if="o.remark">
<text class="remark-tag">工单要求</text>
<text class="remark-txt">{{ o.remark }}</text>
</view>
</view>
<view class="ft" @tap.stop>
<view class="time-left">
<text class="left-label">有效倒计时:</text>
<text class="left-val" :class="{ urgent: o.left_seconds <= 1800 }">
{{ o.left_seconds > 0 ? countdown(o.left_seconds) : '即将超时' }}
</text>
</view>
<view class="ft-btns">
<view class="quote-btn clickable-hover" v-if="o.price_type === 'quote'" @tap="goDetail(o)">
立即报价({{ o.quote_count }})
</view>
<view class="grab-btn clickable-hover" v-else @tap="openGrabConfirm(o)">
{{ o.price_type === 'custom' ? '按此价接单' : '立即抢单' }}
</view>
</view>
</view>
</view>
</view>
<!-- 空状态 -->
<view class="empty-state" v-if="!loading && !list.length">
<image class="empty-img" src="/static/icons/master/empty-orders.svg" mode="aspectFit" />
<text class="empty-title">当前大厅暂无待接工单</text>
<text class="empty-sub">保持听单中状态,有新订单将第一时间呈现</text>
<view class="refresh-cta clickable-hover" @tap="load">立即刷新大厅</view>
</view>
<!-- 抢单防误点二次确认弹窗(100% 对标工奇兵实机图3) -->
<view class="confirm-mask" v-if="selectedOrder" @tap="selectedOrder = null">
<view class="confirm-dialog" @tap.stop>
<text class="cd-title">提示</text>
<text class="cd-content">请确定已经了解清楚订单服务要求、商品数量、服务地址等信息。您确定可以承揽,并能完成工作,如随意抢单,将影响您的订单推送优先级。</text>
<view class="cd-actions">
<view class="cd-btn cancel clickable-hover" @tap="selectedOrder = null">
<text class="cd-btn-txt cancel">再看看</text>
</view>
<view class="cd-btn ok clickable-hover" :class="{ disabled: grabbing }" @tap="confirmGrab">
<text class="cd-btn-txt ok">{{ grabbing ? '抢单中...' : '确定' }}</text>
</view>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed, watch, onMounted } from 'vue';
import api from '@/utils/api.js';
import { isLogin, toLogin } from '@/utils/request.js';
import YjyfNavBar from '@/components/YjyfNavBar.vue';
const list = ref([]);
const info = ref(null);
const loading = ref(false);
const type = ref('all');
const sort = ref('new');
const selectedOrder = ref(null);
const grabbing = ref(false);
const typeTabs = [
{ key: 'all', name: '全部订单', badge: true },
{ key: 'fixed', name: '一口价' },
{ key: 'quote', name: '师傅竞价' },
{ key: 'custom', name: '用户定价' }
];
const sortTabs = [
{ key: 'new', name: '最新发布' },
{ key: 'amount', name: '报酬最高' },
{ key: 'urgent', name: '急单优先' },
{ key: 'time', name: '时效最近' }
];
// 根据真实订单列表动态生成走马灯播报(拒绝假数据)
const broadcastList = computed(() => {
if (!list.value.length) return [];
return list.value.slice(0, 5).map((o) => {
const addrPart = (o.address || '本地').slice(0, 6);
const priceDesc = o.price_type === 'quote' ? '需师傅竞价' : `报酬 ¥${o.pay_amount}`;
return `${addrPart}发布【${o.service_name}】工单,${priceDesc} · 开放接单`;
});
});
watch([type, sort], () => load());
function countdown(sec) {
const s = Number(sec) || 0;
if (s <= 0) return '已结束';
const h = Math.floor(s / 3600);
const m = Math.floor((s % 3600) / 60);
if (h > 0) {
return `${h}小时${m}分`;
}
return `${m}分钟`;
}
function goDetail(o) {
uni.navigateTo({ url: '/pages/master/detail?id=' + o.id });
}
function openGrabConfirm(o) {
selectedOrder.value = o;
}
async function confirmGrab() {
if (grabbing.value || !selectedOrder.value) return;
grabbing.value = true;
const o = selectedOrder.value;
try {
const res = await api.masterGrab({ order_id: o.id });
selectedOrder.value = null;
uni.showToast({ title: '抢单成功!', icon: 'success' });
setTimeout(() => {
uni.navigateTo({
url: `/pages/master/success?order_id=${o.id}&mobile=${res.user_mobile || ''}`
});
}, 500);
} catch (e) {
uni.showToast({ title: e.msg || '手慢了,该订单已被抢', icon: 'none' });
} finally {
grabbing.value = false;
}
}
async function load() {
if (!isLogin()) { toLogin(); return; }
loading.value = true;
try {
const res = await api.masterHall({ limit: 20, type: type.value, sort: sort.value });
list.value = res.list || [];
} catch (e) {
}
try {
const me = await api.masterInfo();
info.value = me.applied ? me.master : null;
} catch (e) {}
loading.value = false;
}
async function toggleWork() {
if (!info.value) return;
const next = info.value.work_status === 'off' ? 'on' : 'off';
try {
await api.masterToggle({ work_status: next });
info.value.work_status = next;
uni.showToast({ title: next === 'on' ? '已开启接单听单' : '已暂停接单', icon: 'none' });
} catch (e) {}
}
onMounted(() => {
load();
});
defineExpose({
load
});
</script>
<style scoped>
.hall-view {
min-height: 100vh;
background: #F5F6F8;
padding-bottom: 20rpx;
}
/* 顶部一体化沉浸师傅状态区(单一连续渐变) */
.hall-hero {
background: linear-gradient(135deg, #FFA93F 0%, #F0710D 100%);
position: relative;
overflow: hidden;
}
.hall-header-body {
padding: 6rpx 28rpx 24rpx;
}
.header-main {
display: flex;
align-items: center;
justify-content: space-between;
}
.h-user {
flex: 1;
min-width: 0;
}
.name-line {
display: flex;
align-items: center;
}
.h-name {
font-size: 34rpx;
font-weight: 700;
color: #FFFFFF;
}
.level-badge {
margin-left: 12rpx;
padding: 2rpx 12rpx;
background: rgba(255, 255, 255, 0.25);
border-radius: 8rpx;
}
.level-txt {
font-size: 20rpx;
color: #FFFFFF;
font-weight: 600;
}
.h-stats {
display: block;
margin-top: 6rpx;
font-size: 22rpx;
color: rgba(255, 255, 255, 0.9);
}
.work-toggle {
display: flex;
align-items: center;
background: #FFFFFF;
padding: 0 20rpx;
height: 52rpx;
border-radius: 26rpx;
box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.08);
}
.work-toggle.paused {
background: rgba(255, 255, 255, 0.35);
}
.dot {
width: 12rpx;
height: 12rpx;
border-radius: 50%;
background: #2FA84F;
margin-right: 8rpx;
}
.work-toggle.paused .dot {
background: #E8331B;
}
.toggle-txt {
font-size: 24rpx;
font-weight: 600;
color: #E36B0C;
}
.work-toggle.paused .toggle-txt {
color: #FFFFFF;
}
/* 跑马灯通知栏 */
.broadcast-bar {
display: flex;
align-items: center;
background: #FFF7F0;
height: 64rpx;
padding: 0 24rpx;
border-bottom: 1rpx solid #FEE5D2;
}
.broadcast-ico {
width: 28rpx;
height: 28rpx;
margin-right: 12rpx;
flex-shrink: 0;
}
.broadcast-swiper {
flex: 1;
height: 64rpx;
}
.swiper-item {
display: flex;
align-items: center;
}
.broadcast-txt {
font-size: 22rpx;
color: #E36B0C;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
/* 筛选切换栏 */
.filter-sticky {
background: #FFFFFF;
position: sticky;
top: 0;
z-index: 10;
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.04);
}
.type-tabs {
display: flex;
border-bottom: 1rpx solid #F0F0F2;
}
.t-tab {
flex: 1;
height: 80rpx;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.t-txt {
font-size: 28rpx;
color: #444444;
font-weight: 500;
transition: all 0.2s ease;
}
.t-tab.on .t-txt {
color: #F0710D;
font-weight: 700;
font-size: 30rpx;
}
.t-tab.on::after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 48rpx;
height: 4rpx;
background: #F0710D;
border-radius: 2rpx;
}
.t-dot {
width: 10rpx;
height: 10rpx;
border-radius: 50%;
background: #E8331B;
margin-left: 6rpx;
margin-top: -12rpx;
}
.sort-tabs {
display: flex;
padding: 16rpx 24rpx;
gap: 16rpx;
}
.s-tab {
padding: 8rpx 20rpx;
background: #F5F6F8;
border-radius: 20rpx;
font-size: 22rpx;
color: #888888;
}
.s-tab.on {
background: #FFF7F0;
color: #F0710D;
font-weight: 600;
}
/* 订单列表卡片 */
.list {
padding: 16rpx 24rpx;
}
.item {
background: #FFFFFF;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 18rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
}
.hd {
display: flex;
align-items: center;
justify-content: space-between;
padding-bottom: 18rpx;
border-bottom: 1rpx solid #F0F0F2;
}
.hd-left {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 10rpx;
flex: 1;
}
.tag-urgent {
font-size: 20rpx;
background: #FFE8E5;
color: #E8331B;
padding: 2rpx 10rpx;
border-radius: 6rpx;
font-weight: 600;
}
.tag-mode {
font-size: 20rpx;
padding: 2rpx 10rpx;
border-radius: 6rpx;
font-weight: 600;
}
.tag-mode.fixed {
background: #E6F4EA;
color: #2FA84F;
}
.tag-mode.quote {
background: #EBF1FF;
color: #4A7CFF;
}
.tag-mode.custom {
background: #FFF3E6;
color: #F0710D;
}
.svc {
font-size: 30rpx;
font-weight: 700;
color: #1F1F1F;
}
.amt-box {
display: flex;
align-items: baseline;
}
.amt-symbol {
font-size: 24rpx;
font-weight: 700;
color: #E8331B;
}
.amt {
font-size: 36rpx;
font-weight: 700;
color: #E8331B;
}
.bd {
padding: 18rpx 0;
}
.info-row {
display: flex;
align-items: center;
margin-bottom: 12rpx;
}
.row-icon {
width: 26rpx;
height: 26rpx;
margin-right: 12rpx;
flex-shrink: 0;
}
.row-txt {
font-size: 24rpx;
color: #444444;
}
.addr-txt {
flex: 1;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.distance-txt {
font-size: 22rpx;
color: #F0710D;
background: #FFF7F0;
padding: 2rpx 8rpx;
border-radius: 6rpx;
margin-left: 10rpx;
}
.badge-row {
display: flex;
flex-wrap: wrap;
gap: 10rpx;
margin-top: 14rpx;
}
.badge {
font-size: 20rpx;
color: #888888;
background: #F5F6F8;
padding: 4rpx 12rpx;
border-radius: 6rpx;
}
.remark-row {
margin-top: 14rpx;
background: #F9F9FA;
padding: 10rpx 14rpx;
border-radius: 8rpx;
display: flex;
align-items: flex-start;
}
.remark-tag {
font-size: 20rpx;
color: #FFA93F;
font-weight: 600;
margin-right: 10rpx;
flex-shrink: 0;
}
.remark-txt {
font-size: 22rpx;
color: #666666;
line-height: 1.4;
}
.ft {
display: flex;
align-items: center;
justify-content: space-between;
padding-top: 16rpx;
border-top: 1rpx solid #F0F0F2;
}
.time-left {
display: flex;
align-items: center;
}
.left-label {
font-size: 22rpx;
color: #AAAAAA;
}
.left-val {
font-size: 22rpx;
color: #F0710D;
font-weight: 600;
}
.left-val.urgent {
color: #E8331B;
}
.ft-btns {
display: flex;
gap: 14rpx;
}
.grab-btn {
background: linear-gradient(135deg, #FFA93F 0%, #F0710D 100%);
color: #FFFFFF;
font-size: 24rpx;
font-weight: 600;
padding: 12rpx 32rpx;
border-radius: 28rpx;
box-shadow: 0 4rpx 12rpx rgba(240, 113, 13, 0.3);
}
.quote-btn {
background: #EBF1FF;
color: #4A7CFF;
font-size: 24rpx;
font-weight: 600;
padding: 12rpx 28rpx;
border-radius: 28rpx;
}
/* 空状态 */
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
padding: 80rpx 40rpx;
}
.empty-img {
width: 200rpx;
height: 200rpx;
margin-bottom: 24rpx;
}
.empty-title {
font-size: 28rpx;
font-weight: 600;
color: #1F1F1F;
margin-bottom: 10rpx;
}
.empty-sub {
font-size: 22rpx;
color: #888888;
margin-bottom: 30rpx;
}
.refresh-cta {
background: #FFF7F0;
color: #F0710D;
font-size: 24rpx;
font-weight: 600;
padding: 14rpx 36rpx;
border-radius: 28rpx;
border: 1rpx solid #FEE5D2;
}
/* 抢单二次确认弹窗 */
.confirm-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.6);
z-index: 999;
display: flex;
align-items: center;
justify-content: center;
padding: 40rpx;
}
.confirm-dialog {
background: #FFFFFF;
border-radius: 24rpx;
padding: 36rpx;
width: 100%;
max-width: 600rpx;
}
.cd-title {
font-size: 32rpx;
font-weight: 700;
color: #1F1F1F;
display: block;
text-align: center;
margin-bottom: 20rpx;
}
.cd-content {
font-size: 26rpx;
color: #444444;
line-height: 1.6;
display: block;
margin-bottom: 36rpx;
}
.cd-actions {
display: flex;
gap: 20rpx;
}
.cd-btn {
flex: 1;
height: 72rpx;
border-radius: 36rpx;
display: flex;
align-items: center;
justify-content: center;
}
.cd-btn.cancel {
background: #F5F6F8;
}
.cd-btn.ok {
background: linear-gradient(135deg, #FFA93F 0%, #F0710D 100%);
}
.cd-btn.ok.disabled {
opacity: 0.6;
}
.cd-btn-txt.cancel {
color: #888888;
font-size: 26rpx;
}
.cd-btn-txt.ok {
color: #FFFFFF;
font-size: 26rpx;
font-weight: 600;
}
.clickable-hover:active {
opacity: 0.85;
transform: scale(0.98);
}
</style>