文件
yjyf/pages/merchant/batch.vue
linda 4e73c8164a fix(wxlogin): 修复微信登录 40029 + 新增商家(企业账号)全流程
微信登录修复:
- 根因:manifest.json 的 mp-weixin.appid 为空 → 开发者工具用测试号,code 与服务端 appid 不匹配
- 修复:填入 wx40ca4b02d4d1cb58
- WxLogin 增加错误码语义映射(40029 appid 不一致 / 40125 secret 错 / 45011 频繁 / 40226 风控)
- 登录页新增手机号登录兜底通道(微信不可用时业务不被卡住)

商家(企业账号):
- 新表 fa_merchant / fa_merchant_order / fa_invoice(纯新增,DB 40→45 表)
- Merchant 控制器:apply/info/update/bills/invoices/invoice/bindBatch
  入驻含企业信息+营业执照+开票信息+结算方式(预付/月结)
  账单按月汇总、开票额度按已付-已开票校验、批量下单按批次归属
- Auth::switchRole 支持 merchant(2001/2002/2003 语义码 + redirect)
- Auth::profile 增加 is_merchant / merchant

前端:
- 登录页角色扩为 业主/师傅/商家 三类
- pages/merchant/apply 企业入驻;workbench 商家工作台(经营数据+按月账单+近期订单+六宫格)
- pages/merchant/batch 批量下单(多地址×多数量)→ 逐单建单支付 → 绑定批次
- pages/merchant/invoice 开票申请与记录
- pages/mine 增加商家入驻/切换商家端入口;角色徽章三态

验证:163 项断言全通过(page_flow 47 + e2e 65 + phase2 27 + phase3 24)
2026-10-28 16:22:20 +08:00

190 行
8.1 KiB
Vue

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

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

<template>
<view class="page">
<view class="card">
<view class="card-title">选择服务</view>
<view class="fi">
<text class="fk">服务类目</text>
<picker :range="catNames" @change="onCat">
<view class="picker">{{ catNames[catIdx] || '请选择' }} ›</view>
</picker>
</view>
<view class="fi">
<text class="fk">服务项目</text>
<picker :range="svcNames" @change="onSvc">
<view class="picker">{{ svcNames[svcIdx] || '请选择' }} ›</view>
</picker>
</view>
<view class="hint" v-if="svc">单价 {{ svc.price_text }} · {{ svc.price_type_text }}</view>
</view>
<view class="card">
<view class="card-head">
<text class="card-title">服务地址({{ rows.length }} 个)</text>
<text class="card-more" @tap="addRow">+ 添加</text>
</view>
<view class="row" v-for="(r, i) in rows" :key="i">
<view class="row-head">
<text class="row-no">#{{ i + 1 }}</text>
<text class="row-del" @tap="delRow(i)">删除</text>
</view>
<input class="input" v-model="r.contact" placeholder="联系人" />
<input class="input" v-model="r.mobile" type="number" maxlength="11" placeholder="联系电话" />
<input class="input" v-model="r.address" placeholder="详细地址(小区/楼栋/门牌)" />
<view class="row-foot">
<view class="mini">
<text class="mini-k">楼层</text>
<view class="st"><view class="st-btn" @tap="step(r, 'floor', -1)">-</view><text class="st-v">{{ r.floor }}</text><view class="st-btn" @tap="step(r, 'floor', 1)">+</view></view>
</view>
<view class="mini">
<text class="mini-k">数量</text>
<view class="st"><view class="st-btn" @tap="step(r, 'num', -1)">-</view><text class="st-v">{{ r.num }}</text><view class="st-btn" @tap="step(r, 'num', 1)">+</view></view>
</view>
<view class="mini">
<text class="mini-k">电梯</text>
<view class="seg">
<view class="seg-i" :class="{ on: r.elevator === 1 }" @tap="r.elevator = 1">有</view>
<view class="seg-i" :class="{ on: r.elevator === 0 }" @tap="r.elevator = 0">无</view>
</view>
</view>
</view>
</view>
</view>
<view class="bar">
<view class="bar-l"><text class="bar-k">共 {{ rows.length }} 单</text><text class="bar-p">¥{{ estimate }}</text></view>
<view class="bar-btn" :class="{ disabled: submitting }" @tap="submit">{{ submitting ? '提交中...' : '批量提交并支付' }}</view>
</view>
</view>
</template>
<script setup>
import { ref, computed } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import api from '@/utils/api.js';
const cats = ref([]);
const catIdx = ref(0);
const svcs = ref([]);
const svcIdx = ref(0);
const submitting = ref(false);
const rows = ref([]);
const catNames = computed(() => cats.value.map(c => c.name));
const svcNames = computed(() => svcs.value.map(s => s.name + ' ' + s.price_text));
const svc = computed(() => svcs.value[svcIdx.value] || null);
const estimate = computed(() => {
if (!svc.value) return '0.00';
const base = Number(svc.value.base_price) || 0;
return rows.value.reduce((sum, r) => sum + base * r.num, 0).toFixed(2);
});
function newRow() {
return { contact: '', mobile: '', address: '', floor: 1, elevator: 1, num: 1 };
}
function addRow() { rows.value.push(newRow()); }
function delRow(i) { if (rows.value.length > 1) rows.value.splice(i, 1); }
function step(r, key, d) { r[key] = Math.max(1, r[key] + d); }
async function onCat(e) {
catIdx.value = Number(e.detail.value);
svcIdx.value = 0;
const res = await api.services({ cat_id: cats.value[catIdx.value].id });
svcs.value = res.list || [];
}
function onSvc(e) { svcIdx.value = Number(e.detail.value); }
async function loadCats() {
const res = await api.cats();
cats.value = res.list || [];
if (cats.value.length) {
const r2 = await api.services({ cat_id: cats.value[0].id });
svcs.value = r2.list || [];
}
}
async function submit() {
if (submitting.value) return;
if (!svc.value) { uni.showToast({ title: '请选择服务项目', icon: 'none' }); return; }
const valid = rows.value.filter(r => r.contact && r.mobile && r.address);
if (!valid.length) { uni.showToast({ title: '请至少填写一个完整地址', icon: 'none' }); return; }
submitting.value = true;
const orderIds = [];
let failed = 0;
for (const r of valid) {
try {
const addr = await api.addressSave({
contact: r.contact, mobile: r.mobile,
province: '贵州省', city: '遵义市', district: '', address: r.address,
floor: r.floor, has_elevator: r.elevator, is_default: 0
});
const order = await api.orderCreate({
service_id: svc.value.id, address_id: addr.id,
urgent: 0, goods_num: r.num, remark: '商家批量下单'
});
await api.orderPay({ order_id: order.order_id, pay_type: 'mock' });
orderIds.push(order.order_id);
} catch (e) {
failed++;
}
}
let batchNo = '';
if (orderIds.length) {
try {
const b = await api.merchantBindBatch({ order_ids: orderIds.join(','), batch_no: '' });
batchNo = b.batch_no;
} catch (e) {}
}
submitting.value = false;
uni.showModal({
title: '批量下单完成',
content: '成功 ' + orderIds.length + ' 单' + (failed ? ',失败 ' + failed + ' 单' : '') + (batchNo ? '\n批次号:' + batchNo : ''),
showCancel: false,
success: () => {
if (orderIds.length) uni.redirectTo({ url: '/pages/order/list' });
}
});
}
onLoad(() => {
rows.value = [newRow()];
loadCats();
});
</script>
<style scoped>
.page { min-height: 100vh; background: #F5F6F8; padding: 22rpx 28rpx 180rpx; }
.card { padding: 24rpx; background: #fff; border-radius: 20rpx; margin-bottom: 20rpx; box-shadow: 0 6rpx 20rpx rgba(240,129,31,.06); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6rpx; }
.card-title { font-size: 28rpx; font-weight: 700; color: #1F1F1F; }
.card-more { font-size: 24rpx; color: #F0710D; font-weight: 600; }
.fi { display: flex; align-items: center; min-height: 88rpx; border-bottom: 1rpx solid #F4F4F4; }
.fk { width: 170rpx; font-size: 26rpx; color: #666; }
.picker { font-size: 28rpx; color: #222; }
.hint { margin-top: 12rpx; font-size: 22rpx; color: #9A9A9A; }
.row { padding: 18rpx 0; border-bottom: 1rpx dashed #EDEDED; }
.row:last-child { border-bottom: none; }
.row-head { display: flex; justify-content: space-between; margin-bottom: 8rpx; }
.row-no { font-size: 24rpx; font-weight: 700; color: #F0710D; }
.row-del { font-size: 22rpx; color: #9A9A9A; }
.input { height: 80rpx; margin-bottom: 10rpx; padding: 0 20rpx; background: #F7F7F7; border-radius: 12rpx; font-size: 26rpx; color: #222; }
.row-foot { display: flex; align-items: center; justify-content: space-between; }
.mini { display: flex; align-items: center; }
.mini-k { font-size: 22rpx; color: #9A9A9A; margin-right: 8rpx; }
.st { display: flex; align-items: center; }
.st-btn { width: 48rpx; height: 48rpx; line-height: 46rpx; text-align: center; border-radius: 24rpx; background: #F0F0F0; color: #666; font-size: 24rpx; }
.st-v { min-width: 46rpx; text-align: center; font-size: 26rpx; color: #222; }
.seg { display: flex; }
.seg-i { padding: 0 18rpx; line-height: 48rpx; margin-right: 8rpx; border-radius: 24rpx; background: #F0F0F0; font-size: 22rpx; color: #666; }
.seg-i.on { background: linear-gradient(135deg,#FFA93F 0%,#F0710D 100%); color: #fff; }
.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,.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 44rpx; display: flex; align-items: center; border-radius: 42rpx; color: #fff; font-size: 28rpx; font-weight: 600; background: linear-gradient(135deg,#FFA93F 0%,#F0710D 100%); box-shadow: 0 8rpx 20rpx rgba(240,113,13,.3); }
.bar-btn.disabled { opacity: .7; }
</style>