- 新增商品服务定价配置表,支持多规格服务价格体系 - 新增步梯搬运费配置功能,可按楼层阶梯收费 - 重构支付订单台账,新增核心数据统计卡片 - 优化下单流程,支持定价配置校验与增项计算 - 整合财务配置,移除独立充值配置菜单
559 行
14 KiB
Vue
559 行
14 KiB
Vue
<template>
|
||
<view class="drawer-mask" v-if="visible" @tap="close">
|
||
<view class="drawer-sheet" @tap.stop>
|
||
<!-- 抽屉头部:「选择商品」+ 简练关闭图标(参考 frame_008 1:1) -->
|
||
<view class="drawer-head">
|
||
<text class="dh-title">选择商品</text>
|
||
<view class="dh-close clickable-hover" @tap="close">
|
||
<image class="dh-close-img" src="/static/icons/close.svg" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 搜索栏:快速检索商品名称(参考 frame_008 1:1) -->
|
||
<view class="drawer-search">
|
||
<view class="ds-box">
|
||
<image class="ds-icon-img" src="/static/icons/search-gray.svg" mode="aspectFit" />
|
||
<input
|
||
class="ds-input"
|
||
v-model="keyword"
|
||
placeholder="请输入商品名称搜索"
|
||
confirm-type="search"
|
||
@confirm="onSearchConfirm"
|
||
@input="onSearchInput"
|
||
/>
|
||
<view class="ds-clear clickable-hover" v-if="keyword" @tap="clearSearch">
|
||
<image class="ds-clear-img" src="/static/icons/close.svg" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 双栏联动:左侧项目分类,右侧标准规格选项(整行可点击直接选定) -->
|
||
<view class="drawer-body">
|
||
<!-- 左侧:对应类目下的商品列表 -->
|
||
<scroll-view class="left-col" scroll-y="true">
|
||
<view
|
||
v-for="goods in displayGoodsList"
|
||
:key="goods.id"
|
||
class="goods-item clickable-hover"
|
||
:class="{ on: activeGoodsId === goods.id }"
|
||
@tap="selectGoods(goods)"
|
||
>
|
||
<text class="goods-name">{{ goods.name }}</text>
|
||
</view>
|
||
<view class="left-empty" v-if="!loading && displayGoodsList.length === 0">
|
||
<text class="le-txt">暂无商品</text>
|
||
</view>
|
||
</scroll-view>
|
||
|
||
<!-- 右侧:当前商品的规格选项列表(纯文字列表,整行可点击直接选定) -->
|
||
<scroll-view class="right-col" scroll-y="true">
|
||
<view class="loading-state" v-if="loading">
|
||
<view class="loading-ring"></view>
|
||
<text class="loading-txt">加载中...</text>
|
||
</view>
|
||
|
||
<view class="spec-list" v-else-if="currentGoods && displaySpecs.length > 0">
|
||
<view
|
||
class="spec-row clickable-hover"
|
||
v-for="spec in displaySpecs"
|
||
:key="spec.id"
|
||
@tap="onChooseSpec(spec)"
|
||
>
|
||
<text class="spec-text">{{ spec.name }}</text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 该商品下暂无多规格时的默认项 -->
|
||
<view class="spec-list" v-else-if="currentGoods">
|
||
<view class="spec-row clickable-hover" @tap="onChooseDefault(currentGoods)">
|
||
<text class="spec-text">{{ currentGoods.name }}</text>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="empty-tip" v-else-if="!loading && goodsList.length === 0">
|
||
<text class="empty-txt">暂无规格选项</text>
|
||
</view>
|
||
|
||
<!-- 找不到商品?点这里下单(对标奇兵到家 1:1 兜底通道) -->
|
||
<view class="drawer-custom-link clickable-hover" @tap="onCustomOrder">
|
||
<text class="dcl-hint">找不到商品?</text>
|
||
<text class="dcl-action">点这里下单</text>
|
||
<image class="dcl-arrow" src="/static/icons/arrow-right-orange.svg" mode="aspectFit" />
|
||
</view>
|
||
</scroll-view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, computed, watch } from 'vue';
|
||
import api from '@/utils/api.js';
|
||
|
||
const props = defineProps({
|
||
visible: { type: Boolean, default: false },
|
||
catId: { type: [Number, String], default: '' },
|
||
catName: { type: String, default: '' }
|
||
});
|
||
|
||
const emit = defineEmits(['update:visible', 'select', 'custom']);
|
||
|
||
const keyword = ref('');
|
||
const goodsList = ref([]);
|
||
const activeGoodsId = ref(0);
|
||
const loading = ref(false);
|
||
|
||
let searchTimer = null;
|
||
|
||
// 当前选中的商品对象
|
||
const currentGoods = computed(() => {
|
||
if (!goodsList.value || goodsList.value.length === 0) return null;
|
||
const hit = goodsList.value.find((g) => g.id === activeGoodsId.value);
|
||
return hit || goodsList.value[0];
|
||
});
|
||
|
||
// 根据搜索框过滤的左侧商品列表
|
||
const displayGoodsList = computed(() => {
|
||
const kw = keyword.value.trim().toLowerCase();
|
||
if (!kw) return goodsList.value;
|
||
return goodsList.value.filter((g) => {
|
||
const nameMatch = (g.name || '').toLowerCase().includes(kw);
|
||
const specMatch = g.specs && g.specs.some((sp) => (sp.name || '').toLowerCase().includes(kw) || (sp.description || '').toLowerCase().includes(kw));
|
||
return nameMatch || specMatch;
|
||
});
|
||
});
|
||
|
||
// 当前选中的商品下的规格列表(支持根据搜索框实时过滤)
|
||
const displaySpecs = computed(() => {
|
||
if (!currentGoods.value || !currentGoods.value.specs) return [];
|
||
const specs = currentGoods.value.specs;
|
||
const kw = keyword.value.trim().toLowerCase();
|
||
if (!kw) return specs;
|
||
const isGoodsMatched = (currentGoods.value.name || '').toLowerCase().includes(kw);
|
||
if (isGoodsMatched) return specs;
|
||
return specs.filter((sp) => {
|
||
return (sp.name || '').toLowerCase().includes(kw) || (sp.description || '').toLowerCase().includes(kw);
|
||
});
|
||
});
|
||
|
||
// 加载当前类目下的真实服务商品(包含真实规格)
|
||
async function loadCategoryGoods(catId, kw = '') {
|
||
loading.value = true;
|
||
try {
|
||
const params = {};
|
||
if (catId > 0) params.cat_id = catId;
|
||
if (kw) params.keyword = kw;
|
||
const res = await api.services(params);
|
||
if (res && res.list) {
|
||
goodsList.value = res.list;
|
||
if (res.list.length > 0) {
|
||
const stillExists = res.list.some((g) => g.id === activeGoodsId.value);
|
||
if (!stillExists) {
|
||
activeGoodsId.value = res.list[0].id;
|
||
}
|
||
} else {
|
||
activeGoodsId.value = 0;
|
||
}
|
||
} else {
|
||
goodsList.value = [];
|
||
activeGoodsId.value = 0;
|
||
}
|
||
} catch (e) {
|
||
goodsList.value = [];
|
||
activeGoodsId.value = 0;
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
}
|
||
|
||
function selectGoods(goods) {
|
||
activeGoodsId.value = goods.id;
|
||
}
|
||
|
||
function onSearchInput() {
|
||
clearTimeout(searchTimer);
|
||
searchTimer = setTimeout(() => {
|
||
const kw = keyword.value.trim();
|
||
if (!goodsList.value.length || kw.length > 3) {
|
||
loadCategoryGoods(props.catId, kw);
|
||
}
|
||
}, 200);
|
||
}
|
||
|
||
function onSearchConfirm() {
|
||
clearTimeout(searchTimer);
|
||
loadCategoryGoods(props.catId, keyword.value.trim());
|
||
}
|
||
|
||
function clearSearch() {
|
||
keyword.value = '';
|
||
loadCategoryGoods(props.catId, '');
|
||
}
|
||
|
||
// 监听抽屉打开与外部传入的 catId 变动
|
||
watch(
|
||
[() => props.visible, () => props.catId],
|
||
async ([newVisible, newCatId]) => {
|
||
if (!newVisible) return;
|
||
keyword.value = '';
|
||
let targetId = Number(newCatId);
|
||
if (!targetId || targetId <= 0) {
|
||
try {
|
||
const cRes = await api.cats();
|
||
if (cRes && cRes.list && cRes.list.length > 0) {
|
||
targetId = cRes.list[0].id;
|
||
}
|
||
} catch (e) {}
|
||
}
|
||
if (targetId > 0) {
|
||
await loadCategoryGoods(targetId);
|
||
} else {
|
||
goodsList.value = [];
|
||
activeGoodsId.value = 0;
|
||
}
|
||
},
|
||
{ immediate: true }
|
||
);
|
||
|
||
function close() {
|
||
emit('update:visible', false);
|
||
}
|
||
|
||
// 奇兵到家同款:用户点击某一具体规格(整行直接选定)
|
||
function onChooseSpec(spec) {
|
||
const goods = currentGoods.value;
|
||
if (!goods) return;
|
||
const gBase = Number(goods.base_price) || 0;
|
||
const hasCustomSpecPrice = Number(spec.base_price) > 0;
|
||
const sBase = hasCustomSpecPrice ? Number(spec.base_price) : gBase;
|
||
const specPrices = (spec.service_prices && typeof spec.service_prices === 'object') ? spec.service_prices : {};
|
||
const rawTypes = goods.service_types || [];
|
||
const hasExplicitDefault = rawTypes.some(x => Number(x.is_default) === 1);
|
||
const revision = spec.pricing_revision ?? goods.pricing_revision;
|
||
const configured = revision != null;
|
||
const resolvedTypes = configured ? (spec.service_types || []) : rawTypes.map((st, idx) => {
|
||
const isDef = Number(st.is_default) === 1 || (!hasExplicitDefault && idx === 0);
|
||
const sCode = st.code || '';
|
||
let effectivePrice = Number(st.price) || 0;
|
||
if (typeof specPrices[sCode] !== 'undefined' && Number(specPrices[sCode]) > 0) {
|
||
effectivePrice = Number(specPrices[sCode]);
|
||
} else if (isDef && hasCustomSpecPrice) {
|
||
effectivePrice = sBase;
|
||
}
|
||
return {
|
||
...st,
|
||
price: effectivePrice
|
||
};
|
||
});
|
||
const defType = resolvedTypes.find(st => Number(st.is_default) === 1)
|
||
|| (configured ? null : resolvedTypes[0] || { code: 'install', name: '安装', price: sBase });
|
||
if (!defType) {
|
||
uni.showToast({ title: '该规格暂未配置可用的默认服务', icon: 'none' });
|
||
return;
|
||
}
|
||
emit('select', {
|
||
service_id: goods.id,
|
||
item_name: goods.name,
|
||
spec_id: spec.id,
|
||
spec_name: spec.name,
|
||
cat_id: goods.cat_id || props.catId,
|
||
cat_name: props.catName || '',
|
||
unit: goods.unit || '件',
|
||
base_price: configured ? defType.price : (Number(defType.price) || sBase),
|
||
price_type: configured ? defType.mode : (goods.price_type || 'fixed'),
|
||
description: spec.description || goods.description || '',
|
||
service_types: resolvedTypes,
|
||
pricing_revision: revision,
|
||
addons: configured ? defType.addons : (goods.addons || []),
|
||
default_service_type: defType.code,
|
||
default_service_name: defType.name
|
||
});
|
||
close();
|
||
}
|
||
|
||
function onChooseDefault(goods) {
|
||
if (!goods) return;
|
||
const configured = goods.pricing_revision != null;
|
||
const serviceTypes = goods.service_types || [];
|
||
const defType = serviceTypes.find(st => Number(st.is_default) === 1)
|
||
|| (configured ? null : serviceTypes[0] || { code: 'install', name: '安装' });
|
||
if (!defType) {
|
||
uni.showToast({ title: '该商品暂未配置可用的默认服务', icon: 'none' });
|
||
return;
|
||
}
|
||
emit('select', {
|
||
service_id: goods.id,
|
||
item_name: goods.name,
|
||
spec_id: 0,
|
||
spec_name: goods.name,
|
||
cat_id: goods.cat_id || props.catId,
|
||
cat_name: props.catName || '',
|
||
unit: goods.unit || '件',
|
||
base_price: configured ? defType.price : (Number(goods.base_price) || 0),
|
||
price_type: configured ? defType.mode : (goods.price_type || 'fixed'),
|
||
description: goods.description || '',
|
||
service_types: serviceTypes,
|
||
pricing_revision: goods.pricing_revision,
|
||
addons: configured ? defType.addons : (goods.addons || []),
|
||
default_service_type: defType.code,
|
||
default_service_name: defType.name
|
||
});
|
||
close();
|
||
}
|
||
|
||
// 找不到商品自定义需求通道(由父页面切换至自定义需求模式)
|
||
function onCustomOrder() {
|
||
emit('custom');
|
||
close();
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
.drawer-mask {
|
||
position: fixed;
|
||
inset: 0;
|
||
background: rgba(0, 0, 0, 0.6);
|
||
backdrop-filter: blur(2px);
|
||
z-index: 999;
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: flex-end;
|
||
animation: drawerFadeIn 0.22s ease-out;
|
||
}
|
||
|
||
@keyframes drawerFadeIn {
|
||
from { opacity: 0; }
|
||
to { opacity: 1; }
|
||
}
|
||
|
||
.drawer-sheet {
|
||
background: #FFFFFF;
|
||
border-radius: 28rpx 28rpx 0 0;
|
||
height: 78vh;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
box-shadow: 0 -8rpx 32rpx rgba(0, 0, 0, 0.08);
|
||
animation: drawerSlideUp 0.26s cubic-bezier(0.16, 1, 0.3, 1);
|
||
}
|
||
|
||
@keyframes drawerSlideUp {
|
||
from { transform: translateY(100%); }
|
||
to { transform: translateY(0); }
|
||
}
|
||
|
||
/* 抽屉头部 */
|
||
.drawer-head {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
padding: 34rpx 36rpx 20rpx;
|
||
}
|
||
|
||
.dh-title {
|
||
font-size: 34rpx;
|
||
font-weight: 700;
|
||
color: #1A1A1A;
|
||
letter-spacing: 0.5rpx;
|
||
}
|
||
|
||
.dh-close {
|
||
width: 56rpx;
|
||
height: 56rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-end;
|
||
}
|
||
|
||
.dh-close-img {
|
||
width: 32rpx;
|
||
height: 32rpx;
|
||
opacity: 0.75;
|
||
}
|
||
|
||
/* 搜索栏 */
|
||
.drawer-search {
|
||
padding: 0 36rpx 24rpx;
|
||
}
|
||
|
||
.ds-box {
|
||
background: #F4F4F4;
|
||
border-radius: 36rpx;
|
||
height: 72rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
padding: 0 26rpx;
|
||
}
|
||
|
||
.ds-icon-img {
|
||
width: 30rpx;
|
||
height: 30rpx;
|
||
margin-right: 14rpx;
|
||
opacity: 0.45;
|
||
}
|
||
|
||
.ds-input {
|
||
flex: 1;
|
||
font-size: 26rpx;
|
||
color: #1A1A1A;
|
||
}
|
||
|
||
.ds-clear {
|
||
width: 44rpx;
|
||
height: 44rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.ds-clear-img {
|
||
width: 24rpx;
|
||
height: 24rpx;
|
||
opacity: 0.5;
|
||
}
|
||
|
||
/* 主体联动结构 */
|
||
.drawer-body {
|
||
display: flex;
|
||
flex: 1;
|
||
min-height: 0;
|
||
border-top: 1rpx solid #F0F0F0;
|
||
}
|
||
|
||
/* 左侧:对应类目下的商品列表(浅灰底,参考 frame_008) */
|
||
.left-col {
|
||
width: 220rpx;
|
||
background: #F7F7F7;
|
||
height: 100%;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.goods-item {
|
||
padding: 32rpx 24rpx;
|
||
font-size: 28rpx;
|
||
color: #4A4A4A;
|
||
text-align: left;
|
||
background: transparent;
|
||
box-sizing: border-box;
|
||
position: relative;
|
||
transition: all 0.15s ease;
|
||
}
|
||
|
||
.goods-item.on {
|
||
background: #FFFFFF;
|
||
color: #F0710D;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.goods-name {
|
||
font-size: 28rpx;
|
||
line-height: 1.4;
|
||
word-break: break-all;
|
||
}
|
||
|
||
.left-empty {
|
||
padding: 60rpx 0;
|
||
text-align: center;
|
||
}
|
||
|
||
.le-txt {
|
||
font-size: 24rpx;
|
||
color: #9CA3AF;
|
||
}
|
||
|
||
/* 右侧:纯文本规格列表(纯白底,参考 frame_008) */
|
||
.right-col {
|
||
flex: 1;
|
||
background: #FFFFFF;
|
||
height: 100%;
|
||
padding: 0 20rpx 0 32rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.loading-state {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 80rpx 0;
|
||
}
|
||
|
||
.loading-ring {
|
||
width: 40rpx;
|
||
height: 40rpx;
|
||
border: 4rpx solid #F0F2F5;
|
||
border-top-color: #F0710D;
|
||
border-radius: 50%;
|
||
animation: spin 0.8s linear infinite;
|
||
}
|
||
|
||
@keyframes spin {
|
||
to { transform: rotate(360deg); }
|
||
}
|
||
|
||
.loading-txt {
|
||
font-size: 24rpx;
|
||
color: #9CA3AF;
|
||
margin-top: 16rpx;
|
||
}
|
||
|
||
.spec-list {
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.spec-row {
|
||
padding: 32rpx 12rpx;
|
||
border-bottom: 1rpx solid #F5F5F5;
|
||
display: flex;
|
||
align-items: center;
|
||
transition: background 0.1s ease;
|
||
}
|
||
|
||
.spec-row:active {
|
||
background: #FAFAFA;
|
||
}
|
||
|
||
.spec-text {
|
||
font-size: 28rpx;
|
||
color: #222222;
|
||
line-height: 1.45;
|
||
word-break: break-all;
|
||
}
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
padding: 100rpx 0 40rpx;
|
||
}
|
||
|
||
.empty-txt {
|
||
color: #9CA3AF;
|
||
font-size: 26rpx;
|
||
}
|
||
|
||
/* 奇兵到家同款:找不到商品底部跳转链接 */
|
||
.drawer-custom-link {
|
||
padding: 32rpx 20rpx 50rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
font-size: 26rpx;
|
||
}
|
||
.dcl-hint {
|
||
color: #333333;
|
||
margin-right: 8rpx;
|
||
}
|
||
.dcl-action {
|
||
color: #F0710D;
|
||
font-weight: 500;
|
||
}
|
||
.dcl-arrow {
|
||
width: 24rpx;
|
||
height: 24rpx;
|
||
margin-left: 4rpx;
|
||
}
|
||
|
||
.clickable-hover:active {
|
||
opacity: 0.75;
|
||
}
|
||
</style>
|