- 新增用户消息中心组件 UserMessageView - 新增师傅消息中心组件 MasterMessageView - 新增用户订单列表组件 UserOrdersView - 重构订单列表页,复用独立组件 - 新增系统工具 getWindowInfoSafe 兼容多端系统信息获取 - 重构 TabBar 组件,支持单母页模式和事件回调 - 优化消息跳转逻辑,支持角色自适应 Tab 切换
470 行
17 KiB
Vue
470 行
17 KiB
Vue
<template>
|
||
<view class="orders-view">
|
||
<!-- 统一规范顶部橙色导航栏 -->
|
||
<YjyfNavBar theme="orange" title="接单管理" />
|
||
|
||
<!-- 顶部状态漏斗看板(对标工奇兵 4 态流转漏斗) -->
|
||
<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>
|
||
|
||
<!-- 订单列表 -->
|
||
<view class="list" v-if="list.length">
|
||
<view class="item" v-for="o in list" :key="o.id">
|
||
<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">2小时首联中</text>
|
||
</view>
|
||
</view>
|
||
<view class="status-badge" :class="'st-' + o.status">
|
||
<text class="status-txt">{{ o.status_text }}</text>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="bd">
|
||
<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 }} 层</text>
|
||
<text class="tag">{{ Number(o.has_elevator) ? '有电梯' : '步梯无电梯' }}</text>
|
||
<text class="tag" v-if="o.goods_model">型号:{{ o.goods_model }}</text>
|
||
</view>
|
||
<view class="customer-row">
|
||
<view class="cust-mobile" @tap="call(o)">
|
||
<image class="phone-ico" src="/static/icons/phone.svg" mode="aspectFit" />
|
||
<text class="phone-num">客户:{{ o.mobile }}</text>
|
||
</view>
|
||
<view class="amt-box">
|
||
<text class="amt-symbol">¥</text>
|
||
<text class="amt-val">{{ o.pay_amount }}</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 操作动作条 -->
|
||
<view class="ops">
|
||
<view class="op clickable-hover" v-if="Number(o.status) === 3 && !o.contact_time" @tap="act('contact', o)">标记已联系</view>
|
||
<view class="op clickable-hover" v-if="Number(o.status) === 3" @tap="act('schedule', o)">约定上门</view>
|
||
<view class="op clickable-hover" v-if="Number(o.status) === 4" @tap="act('arrive', o)">到达打卡</view>
|
||
<view class="op clickable-hover" v-if="Number(o.status) === 5" @tap="act('start', o)">开始服务</view>
|
||
<view class="op clickable-hover" v-if="Number(o.status) === 5 || Number(o.status) === 6" @tap="act('requestDiff', o)">增项补差</view>
|
||
<view class="op primary clickable-hover" v-if="Number(o.status) === 6" @tap="act('finish', o)">现场水印拍照完工</view>
|
||
<view class="op primary clickable-hover" v-if="Number(o.status) === 7" @tap="act('verifyCode', o)">输入验证码核销</view>
|
||
<view class="op clickable-hover" v-if="Number(o.status) === 7" @tap="call(o)">联系客户催码</view>
|
||
<view class="op clickable-hover" v-if="Number(o.status) === 3 || Number(o.status) === 4" @tap="call(o)">联系客户</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">当前无{{ curTabText }}工单</text>
|
||
<text class="empty-sub">前往订单大厅,海量订单实时抢</text>
|
||
<view class="empty-cta clickable-hover" @tap="goHall">前往大厅抢单</view>
|
||
</view>
|
||
|
||
<!-- 水印合成离屏 Canvas -->
|
||
<canvas canvas-id="watermarkCanvas" :style="{ width: canvasW + 'px', height: canvasH + 'px', position: 'fixed', left: '-9999px', top: '-9999px' }"></canvas>
|
||
</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';
|
||
|
||
const emit = defineEmits(['switch-tab']);
|
||
|
||
const cur = ref('active');
|
||
const list = ref([]);
|
||
const loading = ref(false);
|
||
const activeCount = ref(0);
|
||
const verifyCount = ref(0);
|
||
const completedCount = ref(0);
|
||
const quoteCount = ref(0);
|
||
const canvasW = ref(750);
|
||
const canvasH = ref(1000);
|
||
|
||
function getNowTimeStr() {
|
||
const d = new Date();
|
||
const pad = (n) => String(n).padStart(2, '0');
|
||
return `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
||
}
|
||
|
||
function createWatermarkPhoto(tempPath, o) {
|
||
return new Promise((resolve) => {
|
||
uni.getImageInfo({
|
||
src: tempPath,
|
||
success: (info) => {
|
||
let w = info.width;
|
||
let h = info.height;
|
||
const maxEdge = 1200;
|
||
if (w > maxEdge || h > maxEdge) {
|
||
if (w > h) {
|
||
h = Math.round((h * maxEdge) / w);
|
||
w = maxEdge;
|
||
} else {
|
||
w = Math.round((w * maxEdge) / h);
|
||
h = maxEdge;
|
||
}
|
||
}
|
||
canvasW.value = w;
|
||
canvasH.value = h;
|
||
|
||
setTimeout(() => {
|
||
const ctx = uni.createCanvasContext('watermarkCanvas');
|
||
ctx.drawImage(info.path, 0, 0, w, h);
|
||
|
||
const barHeight = Math.max(90, Math.round(h * 0.16));
|
||
ctx.setFillStyle('rgba(0, 0, 0, 0.65)');
|
||
ctx.fillRect(0, h - barHeight, w, barHeight);
|
||
|
||
const fontSize = Math.max(14, Math.round(w * 0.028));
|
||
ctx.setFillStyle('#FFFFFF');
|
||
ctx.setFontSize(fontSize);
|
||
|
||
const timeStr = getNowTimeStr();
|
||
const line1 = `【优匠优服·现场施工取证】 时间: ${timeStr}`;
|
||
const line2 = `施工地点: ${o.address || '客户服务现场'}`;
|
||
const line3 = `工单流水: ${o.order_no || o.id}`;
|
||
|
||
const paddingX = Math.round(w * 0.04);
|
||
const lineSpacing = Math.round(barHeight / 3.4);
|
||
const startY = h - barHeight + lineSpacing - 4;
|
||
|
||
ctx.fillText(line1, paddingX, startY);
|
||
ctx.fillText(line2, paddingX, startY + lineSpacing);
|
||
ctx.fillText(line3, paddingX, startY + lineSpacing * 2);
|
||
|
||
ctx.draw(false, () => {
|
||
uni.canvasToTempFilePath({
|
||
canvasId: 'watermarkCanvas',
|
||
fileType: 'jpg',
|
||
quality: 0.85,
|
||
success: (res) => resolve(res.tempFilePath),
|
||
fail: () => resolve(tempPath)
|
||
});
|
||
});
|
||
}, 150);
|
||
},
|
||
fail: () => resolve(tempPath)
|
||
});
|
||
});
|
||
}
|
||
|
||
const curTabText = computed(() => {
|
||
const m = { active: '待处理', verify: '待验收', completed: '已完成' };
|
||
return m[cur.value] || '';
|
||
});
|
||
|
||
async function loadCounts() {
|
||
try {
|
||
const infoRes = await api.masterInfo();
|
||
if (infoRes && infoRes.master) {
|
||
activeCount.value = infoRes.master.todo_count || 0;
|
||
verifyCount.value = infoRes.master.verify_count || 0;
|
||
}
|
||
const qRes = await api.masterQuotes();
|
||
quoteCount.value = (qRes.list || []).length;
|
||
} catch (e) {}
|
||
}
|
||
|
||
async function load() {
|
||
if (!isLogin()) { toLogin(); return; }
|
||
loading.value = true;
|
||
try {
|
||
const res = await api.masterOrders({ status: cur.value, limit: 20 });
|
||
list.value = res.list || [];
|
||
if (cur.value === 'completed') {
|
||
completedCount.value = (res.list || []).length;
|
||
}
|
||
} catch (e) {
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
}
|
||
|
||
function switchTab(k) {
|
||
cur.value = k;
|
||
load();
|
||
}
|
||
|
||
function goQuotes() {
|
||
uni.navigateTo({ url: '/pages/master/quote' });
|
||
}
|
||
|
||
function call(o) {
|
||
if (!o.mobile) return;
|
||
uni.makePhoneCall({ phoneNumber: String(o.mobile) });
|
||
}
|
||
|
||
function goHall() {
|
||
emit('switch-tab', 0);
|
||
}
|
||
|
||
function act(type, o) {
|
||
const id = o.id;
|
||
if (type === 'contact') {
|
||
api.masterContact({ order_id: id }).then(() => {
|
||
uni.showToast({ title: '已记录已联系' });
|
||
load();
|
||
loadCounts();
|
||
}).catch(() => {});
|
||
return;
|
||
}
|
||
if (type === 'arrive') {
|
||
api.masterArrive({ order_id: id }).then(() => {
|
||
uni.showToast({ title: '已到达打卡' });
|
||
load();
|
||
}).catch(() => {});
|
||
return;
|
||
}
|
||
if (type === 'start') {
|
||
api.masterStart({ order_id: id }).then(() => {
|
||
uni.showToast({ title: '已开始服务' });
|
||
load();
|
||
}).catch(() => {});
|
||
return;
|
||
}
|
||
if (type === 'finish') {
|
||
uni.chooseImage({
|
||
count: 1,
|
||
sourceType: ['camera'],
|
||
success: async (chooseRes) => {
|
||
const rawFile = chooseRes.tempFilePaths[0];
|
||
uni.showLoading({ title: '压印防伪水印中...' });
|
||
try {
|
||
const watermarkedFile = await createWatermarkPhoto(rawFile, o);
|
||
uni.showLoading({ title: '上传完工照片...' });
|
||
const uploadData = await api.upload(watermarkedFile, 'order');
|
||
const remoteImg = uploadData.fullurl || uploadData.url;
|
||
await api.masterFinish({
|
||
order_id: id,
|
||
'images[0]': remoteImg
|
||
});
|
||
uni.hideLoading();
|
||
uni.showModal({
|
||
title: '完工提交成功',
|
||
content: '系统已向客户手机发送 6 位验收码,请向客户索取核销码后点击【输入验证码核销】完成工费结算!',
|
||
showCancel: false
|
||
});
|
||
load();
|
||
loadCounts();
|
||
} catch (err) {
|
||
uni.hideLoading();
|
||
uni.showToast({ title: '上传失败,请重试', icon: 'none' });
|
||
}
|
||
},
|
||
fail: () => {}
|
||
});
|
||
return;
|
||
}
|
||
if (type === 'verifyCode') {
|
||
uni.showModal({
|
||
title: '客户验收码核销',
|
||
editable: true,
|
||
placeholderText: '请输入客户手机收到的 6 位核销码',
|
||
confirmText: '核销结算',
|
||
confirmColor: '#F0710D',
|
||
success: async (r) => {
|
||
if (!r.confirm) return;
|
||
const code = (r.content || '').trim();
|
||
if (!code) {
|
||
uni.showToast({ title: '核销码不能为空', icon: 'none' });
|
||
return;
|
||
}
|
||
uni.showLoading({ title: '核销验证中...' });
|
||
try {
|
||
const res = await api.masterVerifyCode({ order_id: id, verify_code: code });
|
||
uni.hideLoading();
|
||
uni.showModal({
|
||
title: '核销成功!',
|
||
content: `订单已正式完工!本次工费 ¥${res.settle_amount} 已划入您的钱包余额`,
|
||
showCancel: false
|
||
});
|
||
load();
|
||
loadCounts();
|
||
} catch (e) {
|
||
uni.hideLoading();
|
||
}
|
||
}
|
||
});
|
||
return;
|
||
}
|
||
if (type === 'requestDiff') {
|
||
uni.showModal({
|
||
title: '申请施工增项补差价',
|
||
editable: true,
|
||
placeholderText: '请输入增项金额(元),如: 50',
|
||
confirmText: '发起补差',
|
||
confirmColor: '#F0710D',
|
||
success: async (r) => {
|
||
if (!r.confirm) return;
|
||
const amt = parseFloat((r.content || '').trim());
|
||
if (!amt || amt <= 0) {
|
||
uni.showToast({ title: '请输入有效金额', icon: 'none' });
|
||
return;
|
||
}
|
||
uni.showLoading({ title: '提交申请中...' });
|
||
try {
|
||
await api.masterRequestDiff({ order_id: id, amount: amt, remark: '施工现场打孔/拆旧等增项补差' });
|
||
uni.hideLoading();
|
||
uni.showModal({
|
||
title: '补差申请已发起',
|
||
content: `已成功发起增项补差价 ¥${amt},请提醒客户在订单详情中点击【去支付补差】完成在线支付!`,
|
||
showCancel: false
|
||
});
|
||
load();
|
||
} catch (e) {
|
||
uni.hideLoading();
|
||
}
|
||
}
|
||
});
|
||
return;
|
||
}
|
||
if (type === 'schedule') {
|
||
const ts = Math.floor(Date.now() / 1000) + 7200;
|
||
api.masterSchedule({ order_id: id, appoint_time: ts }).then(() => {
|
||
uni.showToast({ title: '已约定 2 小时后上门' });
|
||
load();
|
||
}).catch(() => {});
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
load();
|
||
loadCounts();
|
||
});
|
||
|
||
defineExpose({
|
||
load: () => Promise.all([load(), loadCounts()]),
|
||
loadCounts
|
||
});
|
||
</script>
|
||
|
||
<style scoped>
|
||
.orders-view { min-height: 100vh; background: #F5F6F8; padding-bottom: 30rpx; }
|
||
|
||
/* 顶部工奇兵风格数据漏斗看板 */
|
||
.funnel-card {
|
||
background: #ffffff;
|
||
padding: 24rpx 20rpx 16rpx;
|
||
box-shadow: 0 4rpx 14rpx rgba(0,0,0,0.03);
|
||
position: sticky; top: 0; z-index: 10;
|
||
}
|
||
.funnel-row { display: flex; align-items: center; justify-content: space-around; }
|
||
.f-item {
|
||
flex: 1; display: flex; flex-direction: column; align-items: center;
|
||
position: relative; padding-bottom: 12rpx;
|
||
}
|
||
.f-num { font-size: 38rpx; font-weight: 700; color: #666; line-height: 1.1; }
|
||
.f-quote { color: #7A5AF8; }
|
||
.f-item.on .f-num { color: #F0710D; }
|
||
.f-lab { margin-top: 8rpx; font-size: 22rpx; color: #8E8E93; }
|
||
.f-item.on .f-lab { color: #F0710D; font-weight: 600; }
|
||
.f-line {
|
||
position: absolute; bottom: 0; width: 44rpx; height: 6rpx;
|
||
border-radius: 3rpx; background: #F0710D;
|
||
}
|
||
.f-divider { width: 1rpx; height: 38rpx; background: #EEEEEE; }
|
||
|
||
/* 列表卡片 */
|
||
.list { padding: 20rpx 24rpx; }
|
||
.item {
|
||
background: #fff; border-radius: 20rpx; margin-bottom: 20rpx; padding: 24rpx;
|
||
box-shadow: 0 6rpx 20rpx rgba(240,129,31,0.06);
|
||
}
|
||
.hd { display: flex; align-items: center; justify-content: space-between; padding-bottom: 16rpx; border-bottom: 1rpx solid #F4F4F4; }
|
||
.svc-box { display: flex; align-items: center; }
|
||
.svc { font-size: 30rpx; font-weight: 700; color: #1F1F1F; }
|
||
.time-urgent-pill {
|
||
display: inline-flex; align-items: center;
|
||
margin-left: 14rpx; padding: 2rpx 12rpx; border-radius: 16rpx;
|
||
background: #FFF1F0; border: 1rpx solid #FFA39E;
|
||
}
|
||
.time-urgent-ico { width: 22rpx; height: 22rpx; margin-right: 6rpx; }
|
||
.time-urgent-txt { font-size: 20rpx; color: #CF1322; font-weight: 600; }
|
||
.status-badge { padding: 4rpx 16rpx; border-radius: 20rpx; background: #FFF3E6; }
|
||
.status-txt { font-size: 22rpx; font-weight: 600; color: #E36B0C; }
|
||
.status-badge.st-7 { background: #FDEEEB; }
|
||
.status-badge.st-7 .status-txt { color: #E8331B; }
|
||
.status-badge.st-8 { background: #E9F7EE; }
|
||
.status-badge.st-8 .status-txt { color: #2FA84F; }
|
||
|
||
.bd { padding: 18rpx 0; display: flex; flex-direction: column; }
|
||
.info-line { display: flex; align-items: flex-start; margin-bottom: 10rpx; }
|
||
.info-ico { width: 28rpx; height: 28rpx; margin-right: 10rpx; margin-top: 4rpx; flex-shrink: 0; }
|
||
.addr-txt { font-size: 26rpx; color: #222; font-weight: 500; line-height: 36rpx; }
|
||
.meta-txt { font-size: 24rpx; color: #666; line-height: 36rpx; }
|
||
.meta-tags { display: flex; flex-wrap: wrap; margin-top: 6rpx; }
|
||
.tag { padding: 4rpx 14rpx; background: #F5F6F8; color: #777; font-size: 20rpx; border-radius: 8rpx; margin-right: 10rpx; margin-bottom: 6rpx; }
|
||
|
||
.customer-row {
|
||
display: flex; align-items: center; justify-content: space-between;
|
||
margin-top: 14rpx; padding-top: 14rpx; border-top: 1rpx dashed #EEEEEE;
|
||
}
|
||
.cust-mobile { display: flex; align-items: center; }
|
||
.phone-ico { width: 28rpx; height: 28rpx; margin-right: 8rpx; }
|
||
.phone-num { font-size: 24rpx; color: #4A7CFF; font-weight: 500; }
|
||
.amt-box { display: flex; align-items: baseline; }
|
||
.amt-symbol { font-size: 24rpx; font-weight: 700; color: #F0710D; }
|
||
.amt-val { font-size: 34rpx; font-weight: 700; color: #F0710D; line-height: 1; }
|
||
|
||
.ops { display: flex; flex-wrap: wrap; justify-content: flex-end; padding-top: 16rpx; border-top: 1rpx solid #F4F4F4; }
|
||
.op {
|
||
margin: 8rpx 0 0 14rpx; padding: 0 26rpx; height: 60rpx; line-height: 58rpx;
|
||
border-radius: 30rpx; border: 1.5rpx solid #DDD; font-size: 24rpx; color: #555;
|
||
}
|
||
.op.primary {
|
||
border-color: #F0710D; color: #fff;
|
||
background: linear-gradient(135deg,#FFA93F 0%,#F0710D 100%);
|
||
box-shadow: 0 4rpx 14rpx rgba(240,113,13,0.25);
|
||
}
|
||
|
||
/* 空状态 */
|
||
.empty-state { display: flex; flex-direction: column; align-items: center; padding: 120rpx 40rpx 40rpx; }
|
||
.empty-img { width: 180rpx; height: 180rpx; margin-bottom: 24rpx; }
|
||
.empty-title { font-size: 28rpx; font-weight: 600; color: #333; margin-bottom: 8rpx; }
|
||
.empty-sub { font-size: 22rpx; color: #9A9A9A; text-align: center; margin-bottom: 32rpx; }
|
||
.empty-cta {
|
||
padding: 0 48rpx; height: 74rpx; line-height: 74rpx; border-radius: 37rpx;
|
||
background: linear-gradient(135deg,#FFA93F 0%,#F0710D 100%);
|
||
color: #fff; font-size: 26rpx; font-weight: 600;
|
||
box-shadow: 0 6rpx 16rpx rgba(240,113,13,0.25);
|
||
}
|
||
</style>
|