- 新增 invoice_title、showcase、wallet_log 模型及对应语言包 - 新增后台控制器、视图及搜索字段配置 - 修复服务类目删除保护逻辑 - 优化后台登录页面文案及样式 - 新增前端角色切换逻辑及页面拦截 - 新增 SVG 图标及样式变量 - 修复接口权限及下拉框默认值问题
527 行
12 KiB
Vue
527 行
12 KiB
Vue
<template>
|
||
<view class="drawer-mask" v-if="visible" @tap="close">
|
||
<view class="drawer-sheet" @tap.stop>
|
||
<!-- 抽屉标题栏 -->
|
||
<view class="drawer-head">
|
||
<view class="dh-left">
|
||
<text class="dh-title">常用商品模板</text>
|
||
<text class="dh-sub">快速复用常发商品规格与服务配置</text>
|
||
</view>
|
||
<view class="dh-close clickable-hover" @tap="close">
|
||
<image class="dh-close-img" src="/static/icons/close.svg" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 将当前编辑中的商品组保存为模板 -->
|
||
<view class="save-current-card" v-if="canSaveCurrent">
|
||
<view class="scc-top">
|
||
<image class="scc-ico" src="/static/icons/template-save.svg" mode="aspectFit" />
|
||
<text class="scc-label">将当前第 {{ groupIndex + 1 }} 组存为模板:{{ currentSummary }}</text>
|
||
</view>
|
||
<view class="scc-form-row">
|
||
<input
|
||
class="scc-input"
|
||
v-model="customTplName"
|
||
maxlength="40"
|
||
placeholder="模板名称(选填,默认使用商品规格名)"
|
||
/>
|
||
<view
|
||
class="scc-save-btn clickable-hover"
|
||
:class="{ disabled: saving }"
|
||
@tap="handleSaveCurrent"
|
||
>
|
||
<text class="scc-save-txt">{{ saving ? '保存中' : '存为模板' }}</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 模板列表 -->
|
||
<scroll-view class="drawer-body" scroll-y="true">
|
||
<view class="state-box" v-if="loading && list.length === 0">
|
||
<text class="state-txt">正在读取商品模板...</text>
|
||
</view>
|
||
|
||
<view class="state-box" v-else-if="list.length === 0">
|
||
<image class="empty-img" src="/static/icons/empty-gallery.svg" mode="aspectFit" />
|
||
<text class="empty-title">暂无已保存的商品模板</text>
|
||
<text class="empty-sub">在表单中选好商品、数量及服务项目后,可一键保存为常用模板</text>
|
||
</view>
|
||
|
||
<view class="tpl-list" v-else>
|
||
<view class="tpl-card" v-for="tpl in list" :key="tpl.id">
|
||
<image
|
||
class="tpl-thumb"
|
||
:src="tpl.cover_image || tpl.cat_icon_url || '/static/icons/service-default.svg'"
|
||
mode="aspectFill"
|
||
/>
|
||
<view class="tpl-main">
|
||
<view class="tpl-title-row">
|
||
<text class="tpl-name">{{ tpl.tpl_name }}</text>
|
||
<view
|
||
class="tpl-del-btn clickable-hover"
|
||
@tap.stop="handleDelete(tpl)"
|
||
>
|
||
<image class="tpl-del-ico" src="/static/icons/trash.svg" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
<text class="tpl-spec">
|
||
{{ tpl.cat_name ? tpl.cat_name + ' · ' : '' }}{{ tpl.item_name }}{{ tpl.spec_name && tpl.spec_name !== tpl.item_name ? `(${tpl.spec_name})` : '' }} x{{ tpl.num }}{{ tpl.unit || '个' }}
|
||
</text>
|
||
<text class="tpl-service">{{ formatTplService(tpl) }}</text>
|
||
<view class="tpl-foot">
|
||
<text class="tpl-price" v-if="tpl.price_type !== 'quote' && Number(tpl.base_price) > 0">¥{{ Number(tpl.base_price).toFixed(2) }}/{{ tpl.unit || '个' }}</text>
|
||
<text class="tpl-quote-tag" v-else>师傅报价项目</text>
|
||
<view class="tpl-apply-btn clickable-hover" @tap="applyTemplate(tpl)">
|
||
<text class="tpl-apply-txt">一键套用</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</scroll-view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, computed, watch } from 'vue';
|
||
import api from '@/utils/api.js';
|
||
import { isLogin, toLogin } from '@/utils/request.js';
|
||
|
||
const props = defineProps({
|
||
visible: { type: Boolean, default: false },
|
||
catId: { type: [Number, String], default: 0 },
|
||
catName: { type: String, default: '' },
|
||
groupIndex: { type: Number, default: 0 },
|
||
currentGroup: { type: Object, default: () => null }
|
||
});
|
||
|
||
const emit = defineEmits(['update:visible', 'apply']);
|
||
|
||
const list = ref([]);
|
||
const loading = ref(false);
|
||
const saving = ref(false);
|
||
const deletingId = ref(0);
|
||
const customTplName = ref('');
|
||
|
||
const canSaveCurrent = computed(() => {
|
||
const g = props.currentGroup;
|
||
if (!g) return false;
|
||
const name = (g.is_custom ? g.custom_name : g.item_name) || '';
|
||
return String(name).trim().length > 0;
|
||
});
|
||
|
||
const currentSummary = computed(() => {
|
||
const g = props.currentGroup;
|
||
if (!g) return '';
|
||
const baseName = (g.is_custom ? g.custom_name : g.item_name) || '';
|
||
const specPart = (g.spec_name && g.spec_name !== baseName) ? `(${g.spec_name})` : '';
|
||
return `${baseName}${specPart} x${g.num || 1}`;
|
||
});
|
||
|
||
function formatTplService(tpl) {
|
||
const parts = [tpl.service_type_name || '安装'];
|
||
if (Array.isArray(tpl.extras)) {
|
||
tpl.extras.filter(ex => Number(ex.num) > 0).forEach(ex => {
|
||
parts.push(`${ex.name}x${ex.num}`);
|
||
});
|
||
}
|
||
if (tpl.remark) {
|
||
parts.push(`备注:${tpl.remark}`);
|
||
}
|
||
return parts.join(' · ');
|
||
}
|
||
|
||
async function fetchTemplates() {
|
||
if (!isLogin()) return;
|
||
if (loading.value) return;
|
||
loading.value = true;
|
||
try {
|
||
const res = await api.goodsTemplates({ cat_id: props.catId || 0 });
|
||
list.value = (res && Array.isArray(res.list)) ? res.list : [];
|
||
} catch (e) {
|
||
uni.showToast({ title: (e && e.msg) ? e.msg : '获取商品模板失败', icon: 'none' });
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
}
|
||
|
||
watch(
|
||
() => props.visible,
|
||
(val) => {
|
||
if (val) {
|
||
customTplName.value = '';
|
||
if (!isLogin()) {
|
||
close();
|
||
toLogin();
|
||
return;
|
||
}
|
||
fetchTemplates();
|
||
}
|
||
}
|
||
);
|
||
|
||
async function handleSaveCurrent() {
|
||
if (!canSaveCurrent.value || saving.value) return;
|
||
const g = props.currentGroup;
|
||
const itemName = String((g.is_custom ? g.custom_name : g.item_name) || '').trim();
|
||
if (!itemName) {
|
||
uni.showToast({ title: '请先选择商品', icon: 'none' });
|
||
return;
|
||
}
|
||
saving.value = true;
|
||
try {
|
||
await api.saveGoodsTemplate({
|
||
tpl_name: customTplName.value.trim(),
|
||
cat_id: g.cat_id || props.catId || 0,
|
||
cat_name: g.cat_name || props.catName || '',
|
||
service_id: g.service_id || 0,
|
||
item_name: itemName,
|
||
spec_id: g.spec_id || 0,
|
||
spec_name: g.spec_name || '',
|
||
unit: g.unit || '个',
|
||
num: g.num || 1,
|
||
service_type: g.service_type || 'install',
|
||
service_type_name: g.service_type_name || '安装',
|
||
is_custom: g.is_custom ? 1 : 0,
|
||
custom_name: g.custom_name || '',
|
||
extras: JSON.stringify(g.extras || []),
|
||
images: JSON.stringify(g.images || []),
|
||
remark: g.remark || ''
|
||
});
|
||
customTplName.value = '';
|
||
uni.showToast({ title: '已保存为常用模板', icon: 'success' });
|
||
await fetchTemplates();
|
||
} catch (e) {
|
||
uni.showToast({ title: (e && e.msg) ? e.msg : '保存模板失败', icon: 'none' });
|
||
} finally {
|
||
saving.value = false;
|
||
}
|
||
}
|
||
|
||
function handleDelete(tpl) {
|
||
if (!tpl || deletingId.value) return;
|
||
uni.showModal({
|
||
title: '删除商品模板',
|
||
content: `确认删除模板“${tpl.tpl_name}”吗?`,
|
||
confirmColor: '#E8331B',
|
||
success: async (r) => {
|
||
if (!r.confirm || deletingId.value) return;
|
||
deletingId.value = tpl.id;
|
||
try {
|
||
await api.deleteGoodsTemplate({ id: tpl.id });
|
||
list.value = list.value.filter(x => x.id !== tpl.id);
|
||
uni.showToast({ title: '已删除', icon: 'none' });
|
||
} catch (e) {
|
||
uni.showToast({ title: (e && e.msg) ? e.msg : '删除模板失败', icon: 'none' });
|
||
} finally {
|
||
deletingId.value = 0;
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
function applyTemplate(tpl) {
|
||
if (!tpl) return;
|
||
emit('apply', tpl);
|
||
close();
|
||
}
|
||
|
||
function close() {
|
||
emit('update:visible', false);
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.drawer-mask {
|
||
position: fixed;
|
||
inset: 0;
|
||
background: rgba(0, 0, 0, 0.58);
|
||
z-index: 999;
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: flex-end;
|
||
}
|
||
|
||
.drawer-sheet {
|
||
background-color: $yjyf-bg-card;
|
||
border-top-left-radius: $yjyf-radius-lg;
|
||
border-top-right-radius: $yjyf-radius-lg;
|
||
padding: 32rpx 28rpx calc(28rpx + env(safe-area-inset-bottom));
|
||
max-height: 80vh;
|
||
display: flex;
|
||
flex-direction: column;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.drawer-head {
|
||
display: flex;
|
||
align-items: flex-start;
|
||
justify-content: space-between;
|
||
padding-bottom: 24rpx;
|
||
border-bottom: 1rpx solid $yjyf-border-color;
|
||
}
|
||
|
||
.dh-left {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 6rpx;
|
||
}
|
||
|
||
.dh-title {
|
||
font-size: 34rpx;
|
||
font-weight: 700;
|
||
color: $yjyf-text-main;
|
||
}
|
||
|
||
.dh-sub {
|
||
font-size: $yjyf-font-sub;
|
||
color: $yjyf-text-secondary;
|
||
}
|
||
|
||
.dh-close {
|
||
width: 56rpx;
|
||
height: 56rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-end;
|
||
}
|
||
|
||
.dh-close-img {
|
||
width: 32rpx;
|
||
height: 32rpx;
|
||
opacity: 0.72;
|
||
}
|
||
|
||
/* 快捷保存当前商品组卡片 */
|
||
.save-current-card {
|
||
margin-top: 20rpx;
|
||
padding: 20rpx;
|
||
border-radius: $yjyf-radius-md;
|
||
background-color: $yjyf-primary-bg;
|
||
border: 1rpx solid $yjyf-primary-border;
|
||
}
|
||
|
||
.scc-top {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12rpx;
|
||
margin-bottom: 16rpx;
|
||
}
|
||
|
||
.scc-ico {
|
||
width: 34rpx;
|
||
height: 34rpx;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.scc-label {
|
||
flex: 1;
|
||
font-size: 26rpx;
|
||
font-weight: 600;
|
||
color: $yjyf-text-main;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
|
||
.scc-form-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16rpx;
|
||
}
|
||
|
||
.scc-input {
|
||
flex: 1;
|
||
height: 68rpx;
|
||
padding: 0 20rpx;
|
||
border-radius: $yjyf-radius-sm;
|
||
background-color: $yjyf-bg-card;
|
||
border: 1rpx solid $yjyf-border-color;
|
||
font-size: $yjyf-font-sub;
|
||
color: $yjyf-text-main;
|
||
}
|
||
|
||
.scc-save-btn {
|
||
height: 68rpx;
|
||
padding: 0 28rpx;
|
||
border-radius: $yjyf-radius-sm;
|
||
background: $yjyf-gradient-primary;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.scc-save-txt {
|
||
font-size: 26rpx;
|
||
font-weight: 600;
|
||
color: $yjyf-text-inverse;
|
||
}
|
||
|
||
/* 模板滚动列表 */
|
||
.drawer-body {
|
||
flex: 1;
|
||
min-height: 320rpx;
|
||
max-height: 54vh;
|
||
margin-top: 20rpx;
|
||
}
|
||
|
||
.state-box {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 72rpx 32rpx;
|
||
text-align: center;
|
||
}
|
||
|
||
.empty-img {
|
||
width: 200rpx;
|
||
height: 160rpx;
|
||
margin-bottom: 16rpx;
|
||
}
|
||
|
||
.empty-title {
|
||
font-size: $yjyf-font-body;
|
||
font-weight: 600;
|
||
color: $yjyf-text-main;
|
||
margin-bottom: 8rpx;
|
||
}
|
||
|
||
.empty-sub {
|
||
font-size: $yjyf-font-sub;
|
||
color: $yjyf-text-secondary;
|
||
line-height: 1.5;
|
||
}
|
||
|
||
.state-txt {
|
||
font-size: 26rpx;
|
||
color: $yjyf-text-secondary;
|
||
}
|
||
|
||
.tpl-list {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 20rpx;
|
||
padding-bottom: 12rpx;
|
||
}
|
||
|
||
.tpl-card {
|
||
display: flex;
|
||
gap: 20rpx;
|
||
padding: 22rpx;
|
||
border-radius: $yjyf-radius-md;
|
||
background-color: $yjyf-bg-page;
|
||
border: 1rpx solid $yjyf-border-color;
|
||
}
|
||
|
||
.tpl-thumb {
|
||
width: 136rpx;
|
||
height: 136rpx;
|
||
border-radius: $yjyf-radius-sm;
|
||
background-color: $yjyf-bg-card;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.tpl-main {
|
||
flex: 1;
|
||
min-width: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.tpl-title-row {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12rpx;
|
||
}
|
||
|
||
.tpl-name {
|
||
flex: 1;
|
||
font-size: 30rpx;
|
||
font-weight: 600;
|
||
color: $yjyf-text-main;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
|
||
.tpl-del-btn {
|
||
width: 48rpx;
|
||
height: 48rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-end;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.tpl-del-ico {
|
||
width: 30rpx;
|
||
height: 30rpx;
|
||
opacity: 0.72;
|
||
}
|
||
|
||
.tpl-spec {
|
||
margin-top: 6rpx;
|
||
font-size: $yjyf-font-sub;
|
||
color: $yjyf-text-regular;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
|
||
.tpl-service {
|
||
margin-top: 6rpx;
|
||
font-size: 22rpx;
|
||
color: $yjyf-text-secondary;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
|
||
.tpl-foot {
|
||
margin-top: 14rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.tpl-price {
|
||
font-size: $yjyf-font-body;
|
||
font-weight: 700;
|
||
color: $yjyf-primary;
|
||
}
|
||
|
||
.tpl-quote-tag {
|
||
font-size: $yjyf-font-sub;
|
||
color: $yjyf-warning;
|
||
font-weight: 500;
|
||
}
|
||
|
||
.tpl-apply-btn {
|
||
height: 58rpx;
|
||
padding: 0 28rpx;
|
||
border-radius: $yjyf-radius-pill;
|
||
background: $yjyf-gradient-primary;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.tpl-apply-txt {
|
||
font-size: $yjyf-font-sub;
|
||
font-weight: 600;
|
||
color: $yjyf-text-inverse;
|
||
}
|
||
|
||
.disabled {
|
||
opacity: 0.55;
|
||
}
|
||
|
||
.clickable-hover:active {
|
||
opacity: 0.82;
|
||
}
|
||
</style>
|