前端: - utils/request.js 统一请求层(token/错误码/401 引导登录) - utils/api.js 接口清单(与后端控制器一一对应) - pages/login 登录(手机号+验证码+角色选择) - pages/service/list|detail 服务列表/详情 - pages/order/create 下单(地址/预约/急单/费用试算/自动支付) - pages/order/list|detail|review 订单列表/详情轨迹/评价 - pages/master/apply|hall|orders 师傅入驻/订单大厅/接单履约 - YJYF/YJYF 首页接 home/index 真实类目 + 路由跳转 后端 Bug 修复(严重): - TP5 中 count() 会重置查询条件,导致 Order::index / Master::hall / Master::orders 在 select 时丢失 where 条件 → 泄漏全部用户订单/跨用户数据 - 改为闭包重建查询,已验证修复
267 行
12 KiB
Vue
267 行
12 KiB
Vue
<template>
|
||
<view class="page">
|
||
<view class="svc">
|
||
<view class="svc-thumb"><text class="svc-txt">{{ svc ? svc.name.slice(0, 2) : '' }}</text></view>
|
||
<view class="svc-info">
|
||
<text class="svc-name">{{ svc ? svc.name : '' }}</text>
|
||
<text class="svc-price">{{ svc ? svc.price_text : '' }}</text>
|
||
</view>
|
||
<view class="urgent" :class="{ on: urgent }" @tap="urgent = !urgent">
|
||
<text class="urgent-txt">{{ urgent ? '已加急 +20%' : '加急' }}</text>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="sec">
|
||
<view class="sec-title">服务地址</view>
|
||
<view class="addr" v-if="address">
|
||
<view class="addr-main">
|
||
<text class="addr-c">{{ address.contact }} {{ address.mobile }}</text>
|
||
<text class="addr-d">{{ address.province }}{{ address.city }}{{ address.district }}{{ address.address }}</text>
|
||
<text class="addr-x">楼层 {{ address.floor }} · {{ Number(address.has_elevator) ? '有电梯' : '无电梯' }}</text>
|
||
</view>
|
||
<text class="link" @tap="pickAddress">更换</text>
|
||
</view>
|
||
|
||
<view class="form" v-if="!address">
|
||
<view class="fi"><text class="fk">联系人</text><input class="fv" v-model="form.contact" placeholder="收货人姓名" /></view>
|
||
<view class="fi"><text class="fk">手机号</text><input class="fv" v-model="form.mobile" type="number" maxlength="11" placeholder="联系手机号" /></view>
|
||
<view class="fi"><text class="fk">详细地址</text><input class="fv" v-model="form.address" placeholder="小区/楼栋/门牌号" /></view>
|
||
<view class="fi">
|
||
<text class="fk">楼层</text>
|
||
<view class="stepper">
|
||
<view class="st-btn" @tap="stepFloor(-1)">-</view>
|
||
<text class="st-val">{{ form.floor }}</text>
|
||
<view class="st-btn" @tap="stepFloor(1)">+</view>
|
||
</view>
|
||
</view>
|
||
<view class="fi">
|
||
<text class="fk">有无电梯</text>
|
||
<view class="seg">
|
||
<view class="seg-i" :class="{ on: form.has_elevator === 1 }" @tap="form.has_elevator = 1">有</view>
|
||
<view class="seg-i" :class="{ on: form.has_elevator === 0 }" @tap="form.has_elevator = 0">无</view>
|
||
</view>
|
||
</view>
|
||
<view class="save-btn" @tap="saveAddress">保存地址</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="sec">
|
||
<view class="sec-title">预约与服务信息</view>
|
||
<picker mode="date" :value="date" :start="today" @change="onDate">
|
||
<view class="fi"><text class="fk">预约日期</text><text class="fv2">{{ date }}</text><text class="arrow">›</text></view>
|
||
</picker>
|
||
<picker mode="time" :value="time" @change="onTime">
|
||
<view class="fi"><text class="fk">预约时段</text><text class="fv2">{{ time }}</text><text class="arrow">›</text></view>
|
||
</picker>
|
||
<view class="fi" v-if="svc && svc.need_model === 1"><text class="fk">商品型号</text><input class="fv" v-model="form.goods_model" placeholder="如:三人位布艺沙发" /></view>
|
||
<view class="fi"><text class="fk">数量</text><view class="stepper">
|
||
<view class="st-btn" @tap="stepNum(-1)">-</view><text class="st-val">{{ form.goods_num }}</text><view class="st-btn" @tap="stepNum(1)">+</view>
|
||
</view></view>
|
||
<view class="fi"><text class="fk">备注</text><input class="fv" v-model="form.remark" placeholder="施工要求 / 门禁 / 宠物等" /></view>
|
||
</view>
|
||
|
||
<view class="sec" v-if="amount">
|
||
<view class="sec-title">费用明细</view>
|
||
<view class="li"><text class="k">基础价</text><text class="v">¥{{ amount.base_amount }}</text></view>
|
||
<view class="li"><text class="k">楼层费</text><text class="v">¥{{ amount.floor_amount }}</text></view>
|
||
<view class="li" v-if="amount.urgent_amount > 0"><text class="k">加急费</text><text class="v">¥{{ amount.urgent_amount }}</text></view>
|
||
<view class="li total"><text class="k">应付合计</text><text class="v big">¥{{ amount.pay_amount }}</text></view>
|
||
</view>
|
||
|
||
<view class="bar">
|
||
<view class="bar-l"><text class="bar-k">合计</text><text class="bar-p">¥{{ amount ? amount.pay_amount : 0 }}</text></view>
|
||
<view class="bar-btn" :class="{ disabled: submitting }" @tap="submit">{{ submitting ? '提交中...' : '提交并支付' }}</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, reactive, watch } from 'vue';
|
||
import { onLoad } from '@dcloudio/uni-app';
|
||
import api from '@/utils/api.js';
|
||
import { isLogin, toLogin } from '@/utils/request.js';
|
||
|
||
const svc = ref(null);
|
||
const address = ref(null);
|
||
const addresses = ref([]);
|
||
const amount = ref(null);
|
||
const urgent = ref(false);
|
||
const submitting = ref(false);
|
||
|
||
const now = new Date();
|
||
const pad = (n) => (n < 10 ? '0' + n : '' + n);
|
||
const today = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
||
const date = ref(today);
|
||
const time = ref('14:00');
|
||
|
||
const form = reactive({
|
||
contact: '', mobile: '', address: '', floor: 1, has_elevator: 1,
|
||
goods_model: '', goods_num: 1, remark: ''
|
||
});
|
||
|
||
let serviceId = 0;
|
||
|
||
async function calc() {
|
||
if (!serviceId) return;
|
||
const floor = address.value ? address.value.floor : form.floor;
|
||
const elev = address.value ? address.value.has_elevator : form.has_elevator;
|
||
try {
|
||
amount.value = await api.calc({
|
||
service_id: serviceId, floor: floor, has_elevator: elev, urgent: urgent.value ? 1 : 0
|
||
});
|
||
} catch (e) {}
|
||
}
|
||
|
||
watch([urgent, () => form.floor, () => form.has_elevator], () => calc());
|
||
|
||
function onDate(e) { date.value = e.detail.value; }
|
||
function onTime(e) { time.value = e.detail.value; }
|
||
function stepFloor(d) { form.floor = Math.max(1, form.floor + d); }
|
||
function stepNum(d) { form.goods_num = Math.max(1, form.goods_num + d); }
|
||
|
||
async function loadAddress() {
|
||
try {
|
||
const res = await api.addressList();
|
||
addresses.value = res.list || [];
|
||
address.value = addresses.value.find(a => Number(a.is_default) === 1) || addresses.value[0] || null;
|
||
} catch (e) {}
|
||
}
|
||
|
||
function pickAddress() {
|
||
const names = addresses.value.map(a => (a.contact + ' ' + a.address).slice(0, 14));
|
||
names.push('+ 新增地址');
|
||
uni.showActionSheet({
|
||
itemList: names,
|
||
success: (r) => {
|
||
if (r.tapIndex === addresses.value.length) {
|
||
address.value = null;
|
||
form.contact = '';
|
||
form.address = '';
|
||
} else {
|
||
address.value = addresses.value[r.tapIndex];
|
||
calc();
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
async function saveAddress() {
|
||
if (!form.contact || !form.mobile || !form.address) {
|
||
uni.showToast({ title: '请填写联系人/手机号/地址', icon: 'none' });
|
||
return;
|
||
}
|
||
try {
|
||
const res = await api.addressSave({
|
||
contact: form.contact, mobile: form.mobile,
|
||
province: '贵州省', city: '遵义市', district: '', address: form.address,
|
||
floor: form.floor, has_elevator: form.has_elevator, is_default: 1
|
||
});
|
||
await loadAddress();
|
||
const hit = addresses.value.find(a => Number(a.id) === Number(res.id));
|
||
if (hit) address.value = hit;
|
||
calc();
|
||
uni.showToast({ title: '地址已保存' });
|
||
} catch (e) {}
|
||
}
|
||
|
||
async function submit() {
|
||
if (submitting.value) return;
|
||
if (!isLogin()) { toLogin(); return; }
|
||
if (!address.value) { uni.showToast({ title: '请先保存服务地址', icon: 'none' }); return; }
|
||
submitting.value = true;
|
||
try {
|
||
const appoint = Math.floor(new Date(date.value.replace(/-/g, '/') + ' ' + time.value + ':00').getTime() / 1000);
|
||
const res = await api.orderCreate({
|
||
service_id: serviceId,
|
||
address_id: address.value.id,
|
||
appoint_time: appoint,
|
||
urgent: urgent.value ? 1 : 0,
|
||
goods_model: form.goods_model,
|
||
goods_num: form.goods_num,
|
||
remark: form.remark
|
||
});
|
||
await api.orderPay({ order_id: res.order_id, pay_type: 'mock' });
|
||
uni.showToast({ title: '支付成功,等待师傅接单' });
|
||
setTimeout(() => {
|
||
uni.redirectTo({ url: '/pages/order/detail?id=' + res.order_id });
|
||
}, 600);
|
||
} catch (e) {
|
||
} finally {
|
||
submitting.value = false;
|
||
}
|
||
}
|
||
|
||
onLoad(async (options) => {
|
||
if (!isLogin()) { toLogin(); return; }
|
||
serviceId = Number(options.service_id || 0);
|
||
const res = await api.serviceDetail(serviceId);
|
||
svc.value = res.detail;
|
||
await loadAddress();
|
||
calc();
|
||
});
|
||
</script>
|
||
<style scoped>
|
||
.page { min-height: 100vh; background: #F5F6F8; padding-bottom: 180rpx; }
|
||
.svc {
|
||
display: flex; align-items: center; padding: 26rpx 28rpx;
|
||
background: linear-gradient(160deg, #FFB85C 0%, #F98D25 60%, #ED6F0E 100%);
|
||
}
|
||
.svc-thumb {
|
||
width: 96rpx; height: 96rpx; border-radius: 18rpx; flex-shrink: 0;
|
||
background: rgba(255,255,255,0.92); display: flex; align-items: center; justify-content: center;
|
||
}
|
||
.svc-txt { font-size: 28rpx; font-weight: 700; color: #B85E2A; }
|
||
.svc-info { flex: 1; margin-left: 18rpx; display: flex; flex-direction: column; }
|
||
.svc-name { font-size: 32rpx; font-weight: 700; color: #fff; }
|
||
.svc-price { margin-top: 6rpx; font-size: 24rpx; color: rgba(255,255,255,0.9); }
|
||
.urgent {
|
||
flex-shrink: 0; padding: 0 22rpx; line-height: 56rpx; border-radius: 28rpx;
|
||
background: rgba(255,255,255,0.2); border: 2rpx solid rgba(255,255,255,0.5);
|
||
}
|
||
.urgent.on { background: #fff; border-color: #fff; }
|
||
.urgent-txt { font-size: 22rpx; color: #fff; }
|
||
.urgent.on .urgent-txt { color: #E36B0C; font-weight: 600; }
|
||
.sec { margin: 22rpx 28rpx 0; padding: 22rpx 24rpx; background: #fff; border-radius: 20rpx; box-shadow: 0 6rpx 20rpx rgba(240,129,31,0.06); }
|
||
.sec-title { font-size: 28rpx; font-weight: 700; color: #1F1F1F; margin-bottom: 10rpx; }
|
||
.addr { display: flex; align-items: center; }
|
||
.addr-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
|
||
.addr-c { font-size: 28rpx; font-weight: 600; color: #222; }
|
||
.addr-d { margin-top: 6rpx; font-size: 24rpx; color: #666; line-height: 34rpx; }
|
||
.addr-x { margin-top: 6rpx; font-size: 22rpx; color: #9A9A9A; }
|
||
.link { flex-shrink: 0; margin-left: 16rpx; font-size: 24rpx; color: #F0710D; }
|
||
.fi { display: flex; align-items: center; min-height: 88rpx; border-bottom: 1rpx solid #F4F4F4; }
|
||
.fk { width: 150rpx; font-size: 26rpx; color: #666; }
|
||
.fv { flex: 1; height: 88rpx; font-size: 28rpx; color: #222; }
|
||
.fv2 { flex: 1; font-size: 28rpx; color: #222; }
|
||
.arrow { font-size: 30rpx; color: #C4C4C4; }
|
||
.stepper { display: flex; align-items: center; }
|
||
.st-btn { width: 52rpx; height: 52rpx; line-height: 50rpx; text-align: center; border-radius: 26rpx; background: #F5F5F5; color: #666; font-size: 26rpx; }
|
||
.st-val { min-width: 60rpx; text-align: center; font-size: 28rpx; color: #222; }
|
||
.seg { display: flex; }
|
||
.seg-i { padding: 0 26rpx; line-height: 52rpx; margin-right: 12rpx; border-radius: 26rpx; background: #F5F5F5; font-size: 24rpx; color: #666; }
|
||
.seg-i.on { background: linear-gradient(135deg, #FFA93F 0%, #F0710D 100%); color: #fff; }
|
||
.save-btn { margin-top: 20rpx; height: 76rpx; display: flex; align-items: center; justify-content: center; border-radius: 38rpx; background: #FFF3E6; color: #E36B0C; font-size: 26rpx; font-weight: 600; }
|
||
.li { display: flex; justify-content: space-between; padding: 14rpx 0; border-bottom: 1rpx solid #F4F4F4; }
|
||
.li.total { border-bottom: none; }
|
||
.k { font-size: 26rpx; color: #666; }
|
||
.v { font-size: 26rpx; color: #333; }
|
||
.v.big { font-size: 34rpx; font-weight: 700; color: #F0710D; }
|
||
.bar {
|
||
position: fixed; left: 0; right: 0; bottom: 0; height: 120rpx;
|
||
padding: 0 28rpx; padding-bottom: env(safe-area-inset-bottom);
|
||
display: flex; align-items: center; justify-content: space-between;
|
||
background: #fff; box-shadow: 0 -6rpx 24rpx rgba(0,0,0,0.07);
|
||
}
|
||
.bar-l { display: flex; align-items: baseline; }
|
||
.bar-k { font-size: 24rpx; color: #666; }
|
||
.bar-p { margin-left: 8rpx; font-size: 38rpx; font-weight: 700; color: #F0710D; }
|
||
.bar-btn {
|
||
height: 84rpx; padding: 0 48rpx; display: flex; align-items: center;
|
||
border-radius: 42rpx; color: #fff; font-size: 30rpx; font-weight: 600;
|
||
background: linear-gradient(135deg, #FFA93F 0%, #F0710D 100%);
|
||
box-shadow: 0 8rpx 20rpx rgba(240,113,13,0.3);
|
||
}
|
||
.bar-btn.disabled { opacity: 0.7; }
|
||
</style>
|
||
|