文件
yjyf/yjyf-master-app/components/master/MasterOrdersView.vue
MiAn 14533eadb7 feat: 用户端与师傅端双小程序架构解耦,新增师傅独立认证及超时自动关单机制
1. 账号体系与数据库解耦:
   - 师傅表 fa_master 解除对 fa_user.id 的外键依赖,升级为独立认证账号主表;
   - 新增师傅端独立支撑表:fa_master_security、fa_master_token、fa_master_wechat、fa_master_agreement_read;
   - 新增工单超时未接单自动关闭与原路退款配置(order_unaccepted_close_days)。

2. 服务端(Server):
   - 新增师傅端独立 API 控制器与认证库(MasterAuth, MasterBase, MasterMessage, MasterSecurity, MasterToken);
   - WxLogin 支持双小程序端(user/master)独立换取 session_key、openid 与 access_token;
   - 新增控制台调度命令 php think order:autoclose,支持订单超时自动关闭与售后退款闭环;
   - 修复 PHP 8.5 兼容性问题(Request.php 的 (bool) 强制转换);
   - 系统业务配置全面收敛至数据库 fa_config 及 site.php。

3. 小程序端:
   - yjyf-app(用户端):彻底剥离师傅端路由、组件及静态资源,增加隐私授权弹窗与评价模块;
   - yjyf-master-app(师傅端):全新独立微信小程序工程(wx140d90ceda786107),实现工作台、接单大厅、资质认证、工单协同与钱包提现完整闭环。
2026-11-23 15:10:30 +08:00

716 行
16 KiB
Vue

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

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

<template>
<view class="orders-view">
<!-- 统一品牌橙色导航栏 -->
<YjyfNavBar theme="orange" title="接单管理">
<template #left>
<view class="service-btn clickable-hover" @tap="openServicePopup">
<image class="service-icon" src="/static/icons/customer-service-white.svg" mode="aspectFit" />
<text class="service-txt">客服</text>
</view>
</template>
</YjyfNavBar>
<!-- 顶部状态漏斗看板 -->
<view class="funnel-card">
<view class="funnel-row">
<view class="f-item clickable-hover" :class="{ on: cur === 'active' }" @tap="switchTab('active')">
<text class="f-num">{{ activeCount }}</text>
<text class="f-lab">待处理</text>
<view class="f-line" v-if="cur === 'active'"></view>
</view>
<view class="f-divider"></view>
<view class="f-item clickable-hover" :class="{ on: cur === 'verify' }" @tap="switchTab('verify')">
<text class="f-num">{{ verifyCount }}</text>
<text class="f-lab">待验收</text>
<view class="f-line" v-if="cur === 'verify'"></view>
</view>
<view class="f-divider"></view>
<view class="f-item clickable-hover" :class="{ on: cur === 'completed' }" @tap="switchTab('completed')">
<text class="f-num">{{ completedCount }}</text>
<text class="f-lab">已完成</text>
<view class="f-line" v-if="cur === 'completed'"></view>
</view>
<view class="f-divider"></view>
<view class="f-item clickable-hover" @tap="goQuotes">
<text class="f-num f-quote">{{ quoteCount }}</text>
<text class="f-lab">我的报价</text>
</view>
</view>
</view>
<YjyfRefreshScroll
class="orders-scroll"
theme="light"
:refresh-task="refreshAll"
@scrolltolower="loadMore"
>
<!-- 工单摘要列表(整卡点击进入履约详情,底部仅保留唯一主行动按钮) -->
<view class="list" v-if="list.length">
<view
class="item clickable-hover"
v-for="o in list"
:key="o.id"
@tap="goDetail(o)"
>
<view class="hd">
<view class="svc-box">
<text class="svc">{{ o.service_name }}</text>
<view class="time-urgent-pill" v-if="Number(o.status) === 3 && !o.contact_time">
<image class="time-urgent-ico" src="/static/icons/master/order-time.svg" mode="aspectFit" />
<text class="time-urgent-txt">待首联</text>
</view>
</view>
<view class="hd-right">
<view class="status-badge" :class="'st-' + o.status">
<text class="status-txt">{{ o.status_text }}</text>
</view>
<image class="arrow-ico" src="/static/icons/arrow-right.svg" mode="aspectFit" />
</view>
</view>
<view class="bd">
<image v-if="o.service_image" class="order-thumb" :src="o.service_image" mode="aspectFill" lazy-load />
<view class="order-info">
<view class="info-line">
<image class="info-ico" src="/static/icons/master/order-loc.svg" mode="aspectFit" />
<text class="addr-txt">{{ o.address }}</text>
</view>
<view class="info-line">
<image class="info-ico" src="/static/icons/master/order-time.svg" mode="aspectFit" />
<text class="meta-txt">预约时间:{{ o.appoint_text }}</text>
</view>
<view class="meta-tags">
<text class="tag">楼层 {{ o.floor || 1 }} 层</text>
<text class="tag">{{ Number(o.has_elevator) ? '有电梯' : '步梯无电梯' }}</text>
<text class="tag" v-if="o.goods_model">规格:{{ o.goods_model }}</text>
</view>
</view>
</view>
<view class="ft">
<view class="amt-box">
<text class="amt-label">订单金额</text>
<text class="amt-symbol">¥</text>
<text class="amt-val">{{ Number(o.pay_amount || o.total_amount || 0).toFixed(2) }}</text>
</view>
<view class="ops" @tap.stop>
<view
class="op outline clickable-hover"
v-if="Number(o.status) >= 3 && Number(o.status) <= 7"
@tap="call(o)"
>联系客户</view>
<view
class="op primary clickable-hover"
v-if="Number(o.status) === 3"
@tap="goDetail(o, 'schedule')"
>约定上门</view>
<view
class="op primary clickable-hover"
v-else-if="Number(o.status) === 4"
@tap="quickArrive(o)"
>到达打卡</view>
<view
class="op primary clickable-hover"
v-else-if="Number(o.status) === 5"
@tap="quickStart(o)"
>开始服务</view>
<view
class="op primary clickable-hover"
v-else-if="Number(o.status) === 6"
@tap="goDetail(o, 'finish')"
>拍照完工</view>
<view
class="op primary clickable-hover"
v-else-if="Number(o.status) === 7"
@tap="goDetail(o, 'verify')"
>核销结算</view>
<view
class="op outline clickable-hover"
v-else
@tap="goDetail(o)"
>工单详情</view>
</view>
</view>
</view>
<view class="more-tip">
<text class="more-txt">{{ loadingMore ? '正在加载更多...' : (hasMore ? '上拉加载更多工单' : '已展示全部工单') }}</text>
</view>
</view>
<!-- 未登录或空状态引导 -->
<view class="empty-state" v-if="!loggedIn">
<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="empty-cta clickable-hover" @tap="goMasterLogin">立即登录</view>
</view>
<view class="empty-state" v-else-if="!loading && !list.length">
<image class="empty-img" src="/static/icons/master/empty-orders.svg" mode="aspectFit" />
<text class="empty-title">暂无{{ curTabText }}工单</text>
<text class="empty-sub">前往抢单大厅查看周边新发布的工单</text>
<view class="empty-cta clickable-hover" @tap="goHall">前往抢单大厅</view>
</view>
</YjyfRefreshScroll>
<YjyfServicePopup :visible="servicePopupVisible" @update:visible="servicePopupVisible = $event" />
</view>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue';
import api from '@/utils/api.js';
import { isLogin, toLogin } from '@/utils/request.js';
import YjyfNavBar from '@/components/YjyfNavBar.vue';
import YjyfRefreshScroll from '@/components/YjyfRefreshScroll.vue';
import YjyfServicePopup from '@/components/YjyfServicePopup.vue';
const props = defineProps({
inContainer: {
type: Boolean,
default: false
}
});
const emit = defineEmits(['switch-tab']);
const servicePopupVisible = ref(false);
function openServicePopup() {
servicePopupVisible.value = true;
}
const cur = ref('active');
const loggedIn = ref(isLogin());
const list = ref([]);
const page = ref(1);
const hasMore = ref(false);
const loading = ref(false);
const loadingMore = ref(false);
const actingId = ref(0);
const activeCount = ref(0);
const verifyCount = ref(0);
const completedCount = ref(0);
const quoteCount = ref(0);
const curTabText = computed(() => {
const map = { active: '待处理', verify: '待验收', completed: '已完成' };
return map[cur.value] || '';
});
async function loadCounts() {
if (!isLogin()) return;
try {
const [a, v, c, q] = await Promise.all([
api.masterOrders({ status: 'active', page: 1, limit: 1 }),
api.masterOrders({ status: 'verify', page: 1, limit: 1 }),
api.masterOrders({ status: 'completed', page: 1, limit: 1 }),
api.masterQuotes()
]);
activeCount.value = Number(a && a.total ? a.total : 0);
verifyCount.value = Number(v && v.total ? v.total : 0);
completedCount.value = Number(c && c.total ? c.total : 0);
quoteCount.value = (q && q.list) ? q.list.length : 0;
} catch (e) {}
}
function goMasterLogin() {
toLogin('/pages/master/hall?tab=1');
}
async function load() {
loggedIn.value = isLogin();
if (!loggedIn.value) {
list.value = [];
hasMore.value = false;
loading.value = false;
return;
}
page.value = 1;
loading.value = true;
try {
const res = await api.masterOrders({ status: cur.value, page: 1, limit: 15 });
list.value = (res && res.list) ? res.list : [];
hasMore.value = !!(res && res.has_more);
} catch (e) {
} finally {
loading.value = false;
}
}
async function loadMore() {
if (loading.value || loadingMore.value || !hasMore.value) return;
const nextPage = page.value + 1;
loadingMore.value = true;
try {
const res = await api.masterOrders({ status: cur.value, page: nextPage, limit: 15 });
const rows = (res && res.list) ? res.list : [];
list.value = list.value.concat(rows);
page.value = nextPage;
hasMore.value = !!(res && res.has_more);
} catch (e) {
} finally {
loadingMore.value = false;
}
}
async function refreshAll() {
await Promise.all([load(), loadCounts()]);
}
function switchTab(k) {
if (cur.value === k) return;
cur.value = k;
load();
}
function goDetail(o, action = '') {
const q = action ? `?id=${o.id}&action=${action}` : `?id=${o.id}`;
uni.navigateTo({ url: `/pages/master/detail${q}` });
}
const callingId = ref(0);
async function call(o) {
if (!o || !o.mobile) return;
if (!o.contact_time && callingId.value !== o.id) {
callingId.value = o.id;
try {
await api.masterContact({ order_id: o.id });
o.contact_time = Math.floor(Date.now() / 1000);
} catch (e) {
} finally {
callingId.value = 0;
}
}
uni.makePhoneCall({ phoneNumber: o.mobile, fail: () => {} });
}
async function quickArrive(o) {
if (actingId.value === o.id) return;
actingId.value = o.id;
try {
const loc = await new Promise((resolve) => {
uni.getLocation({
type: 'gcj02',
success: (r) => resolve({ lat: r.latitude, lng: r.longitude }),
fail: () => resolve({})
});
});
await api.masterArrive({ order_id: o.id, lat: loc.lat || '', lng: loc.lng || '' });
uni.showToast({ title: '已打卡到达' });
refreshAll();
} catch (e) {
} finally {
actingId.value = 0;
}
}
async function quickStart(o) {
if (actingId.value === o.id) return;
actingId.value = o.id;
try {
await api.masterStart({ order_id: o.id });
uni.showToast({ title: '已开始服务' });
refreshAll();
} catch (e) {
} finally {
actingId.value = 0;
}
}
function goQuotes() {
if (!isLogin()) {
goMasterLogin();
return;
}
uni.navigateTo({ url: '/pages/master/quote' });
}
function goHall() {
if (props.inContainer) {
emit('switch-tab', 0);
return;
}
uni.reLaunch({ url: '/pages/master/hall' });
}
onMounted(() => {
refreshAll();
});
defineExpose({ load: refreshAll, reload: refreshAll });
</script>
<style lang="scss" scoped>
@import '@/uni.scss';
.orders-view {
height: 100vh;
display: flex;
flex-direction: column;
background: $yjyf-bg-page;
overflow: hidden;
}
.orders-scroll {
flex: 1;
min-height: 0;
}
.service-btn {
display: inline-flex;
align-items: center;
gap: 6rpx;
padding: 8rpx 16rpx;
border-radius: 999rpx;
background: rgba(255, 255, 255, 0.22);
}
.service-icon {
width: 30rpx;
height: 30rpx;
}
.service-txt {
font-size: 24rpx;
color: #FFFFFF;
font-weight: 500;
}
/* 顶部状态漏斗看板 */
.funnel-card {
background: $yjyf-bg-card;
padding: 20rpx 16rpx 0;
border-bottom: 1rpx solid $yjyf-border-color;
flex-shrink: 0;
}
.funnel-row {
display: flex;
align-items: center;
justify-content: space-around;
}
.f-item {
flex: 1;
position: relative;
padding-bottom: 20rpx;
display: flex;
flex-direction: column;
align-items: center;
gap: 6rpx;
}
.f-num {
font-size: 36rpx;
font-weight: 800;
color: $yjyf-text-main;
line-height: 1.1;
&.f-quote {
color: $yjyf-info;
}
}
.f-lab {
font-size: $yjyf-font-sm;
color: $yjyf-text-secondary;
}
.f-item.on .f-num,
.f-item.on .f-lab {
color: $yjyf-primary;
font-weight: 700;
}
.f-line {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 44rpx;
height: 6rpx;
border-radius: 3rpx;
background: $yjyf-primary;
}
.f-divider {
width: 1rpx;
height: 44rpx;
background: $yjyf-border-color;
margin-bottom: 18rpx;
}
/* 列表卡片 */
.list {
padding: 24rpx 24rpx calc(140rpx + env(safe-area-inset-bottom));
display: flex;
flex-direction: column;
gap: 20rpx;
}
.item {
background: $yjyf-bg-card;
border-radius: $yjyf-radius-card;
padding: 28rpx;
box-shadow: $yjyf-shadow-card;
}
.hd {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
padding-bottom: 20rpx;
border-bottom: 1rpx solid $yjyf-border-color;
}
.svc-box {
flex: 1;
min-width: 0;
display: flex;
align-items: center;
gap: 12rpx;
}
.svc {
font-size: $yjyf-font-md;
font-weight: 700;
color: $yjyf-text-main;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.time-urgent-pill {
padding: 4rpx 14rpx;
border-radius: $yjyf-radius-pill;
background: rgba(232, 51, 27, 0.1);
display: flex;
align-items: center;
gap: 6rpx;
flex-shrink: 0;
}
.time-urgent-ico {
width: 22rpx;
height: 22rpx;
}
.time-urgent-txt {
font-size: $yjyf-font-xs;
color: $yjyf-danger;
font-weight: 600;
}
.hd-right {
display: flex;
align-items: center;
gap: 8rpx;
flex-shrink: 0;
}
.status-badge {
padding: 6rpx 18rpx;
border-radius: $yjyf-radius-pill;
background: $yjyf-primary-bg;
}
.status-txt {
font-size: $yjyf-font-xs;
font-weight: 600;
color: $yjyf-primary;
}
.status-badge.st-8 {
background: rgba(47, 168, 79, 0.1);
.status-txt {
color: $yjyf-success;
}
}
.arrow-ico {
width: 26rpx;
height: 26rpx;
}
.bd {
padding: 20rpx 0;
display: flex;
align-items: flex-start;
gap: 20rpx;
}
.order-thumb {
width: 120rpx;
height: 120rpx;
flex-shrink: 0;
border-radius: 12rpx;
background: $yjyf-bg-page;
}
.order-info {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 12rpx;
}
.info-line {
display: flex;
align-items: flex-start;
gap: 12rpx;
}
.info-ico {
width: 30rpx;
height: 30rpx;
margin-top: 4rpx;
flex-shrink: 0;
}
.addr-txt {
flex: 1;
font-size: $yjyf-font-base;
font-weight: 600;
color: $yjyf-text-main;
line-height: 1.45;
}
.meta-txt {
font-size: $yjyf-font-sm;
color: $yjyf-text-regular;
}
.meta-tags {
padding-left: 42rpx;
display: flex;
flex-wrap: wrap;
gap: 12rpx;
}
.tag {
max-width: 100%;
box-sizing: border-box;
overflow-wrap: anywhere;
padding: 4rpx 14rpx;
border-radius: 8rpx;
background: $yjyf-bg-page;
font-size: $yjyf-font-xs;
color: $yjyf-text-secondary;
}
.ft {
padding-top: 20rpx;
border-top: 1rpx solid $yjyf-border-color;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.amt-box {
display: flex;
align-items: baseline;
}
.amt-label {
font-size: $yjyf-font-xs;
color: $yjyf-text-secondary;
margin-right: 8rpx;
}
.amt-symbol {
font-size: $yjyf-font-sm;
font-weight: 700;
color: $yjyf-primary;
}
.amt-val {
font-size: 36rpx;
font-weight: 800;
color: $yjyf-primary;
}
.ops {
display: flex;
align-items: center;
gap: 14rpx;
}
.op {
height: 64rpx;
padding: 0 28rpx;
border-radius: $yjyf-radius-pill;
font-size: $yjyf-font-sm;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
&.outline {
background: $yjyf-bg-card;
border: 1rpx solid $yjyf-border-color;
color: $yjyf-text-regular;
}
&.primary {
background: $yjyf-gradient-primary;
color: $yjyf-text-inverse;
box-shadow: $yjyf-shadow-button;
}
}
.more-tip {
padding: 20rpx 0;
text-align: center;
}
.more-txt {
font-size: $yjyf-font-xs;
color: $yjyf-text-muted;
}
.empty-state {
padding: 160rpx 48rpx;
display: flex;
flex-direction: column;
align-items: center;
gap: 16rpx;
}
.empty-img {
width: 200rpx;
height: 200rpx;
}
.empty-title {
font-size: $yjyf-font-md;
font-weight: 700;
color: $yjyf-text-main;
}
.empty-sub {
font-size: $yjyf-font-sm;
color: $yjyf-text-secondary;
}
.empty-cta {
margin-top: 20rpx;
height: 76rpx;
padding: 0 48rpx;
border-radius: $yjyf-radius-pill;
background: $yjyf-gradient-primary;
color: $yjyf-text-inverse;
font-size: $yjyf-font-base;
font-weight: 700;
box-shadow: $yjyf-shadow-button;
display: flex;
align-items: center;
justify-content: center;
}
</style>