@didaoktv/didaoui-uniapp 2.4.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/components/dd-cart-bar/cart-bar.ts +15 -0
- package/components/dd-cart-bar/dd-cart-bar.vue +494 -0
- package/components/dd-goods-card/dd-goods-card.vue +40 -11
- package/components/dd-goods-sku/dd-goods-sku.vue +47 -10
- package/components/dd-package-sku/dd-package-sku.vue +124 -9
- package/components/dd-package-sku/package-sku.ts +35 -6
- package/index.ts +7 -1
- package/libs/utils.ts +17 -0
- package/package.json +1 -1
- package/scss/_mixins.scss +11 -0
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
- **帝王级配色** — 帝王金 `#F5A623` + 皇家蓝 `#2D4BA0` 双主色,暗色主题默认
|
|
8
8
|
- **玻璃拟态设计** — 多层级玻璃拟态效果,打造高端夜店沉浸感
|
|
9
|
-
- **
|
|
9
|
+
- **98 个精心打磨的组件** — 覆盖表单、导航、布局卡片、数据展示、浮层反馈、交互、画布七大类,含 KTV 业务组件(房态卡、账单明细、工单卡、日历、二维码)
|
|
10
10
|
- **Vue3 + TypeScript** — 完整类型定义,Composition API
|
|
11
11
|
- **多端兼容** — H5 / 微信小程序 / 抖音小程序 / Android / iOS
|
|
12
12
|
|
|
@@ -52,7 +52,7 @@ import { DdButton, DdInput } from '@didaoktv/didaoui-uniapp'
|
|
|
52
52
|
| ----- | -- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
53
53
|
| 表单输入 | 25 | Button, CodeButton, Input, Form, Field, Switch, Checkbox, CheckboxGroup, Radio, RadioGroup, Stepper, SearchBar, Slider, DatePicker, Picker, Rate, Upload, Icon, Keyboard, NumberKeyboard, CarKeyboard, Cascader, GoodsSku, PackageSku, TreeSelect |
|
|
54
54
|
| 导航 | 14 | Navigation, TopNavbar, SegmentedTab, SwipeableTab, Drawer, Tabbar, TabbarItem, Backtop, Collapse, CollapseItem, DropdownMenu, DropdownItem, Sidebar, SidebarItem | |
|
|
55
|
-
| 布局/卡片 |
|
|
55
|
+
| 布局/卡片 | 11 | Card, RoomCard, GoodsCard, FeatureGrid, Sticky, BillDetail, WorkorderCard, Calendar, Qrcode, SubmitBar, CartBar |
|
|
56
56
|
| 数据展示 | 25 | Tag, StatCard, ChampionCard, Avatar, AvatarGroup, Badge, ListCell, Cell, CellGroup, CountDown, Divider, Image, Progress, Skeleton, EmptyState, Step, Steps, Text, Link, Copy, Album, Coupon, Parse, Markdown, Price |
|
|
57
57
|
| 浮层反馈 | 11 | Modal, ActionSheet, Toast, Alert, Loading, Dialog, Overlay, Popup, Popover, PopoverItem, Portal |
|
|
58
58
|
| 交互 | 5 | SwipeAction, Swipe, SwipeItem, PullRefresh, Loadmore |
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** 购物车条目(dd-cart-bar 配套;price 单位与全库一致为「分」) */
|
|
2
|
+
export interface DdCartItem {
|
|
3
|
+
/** 唯一标识 */
|
|
4
|
+
id: string | number
|
|
5
|
+
/** 商品名 */
|
|
6
|
+
name: string
|
|
7
|
+
/** 商品图(不传渲染占位图标) */
|
|
8
|
+
image?: string
|
|
9
|
+
/** 单价,单位:分 */
|
|
10
|
+
price: number
|
|
11
|
+
/** 数量(减到 1 再减 = 移除该项,由 change 回传剔除后的数组) */
|
|
12
|
+
count: number
|
|
13
|
+
/** 已选规格/备注文案(如「大杯 / 少冰」) */
|
|
14
|
+
specs?: string
|
|
15
|
+
}
|
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
v-if="placeholder"
|
|
4
|
+
class="dd-cart-bar__placeholder"
|
|
5
|
+
:class="{ 'dd-cart-bar__placeholder--safe': safeAreaInsetBottom }"
|
|
6
|
+
></view>
|
|
7
|
+
|
|
8
|
+
<!-- 弹层打开时栏抬升到 popup 档 +1:遮罩(overlay 档)盖不住栏,弹层面板(popup 档)从栏下方弹出,栏始终可点 -->
|
|
9
|
+
<view
|
|
10
|
+
class="dd-cart-bar"
|
|
11
|
+
:class="[{ 'dd-cart-bar--safe': safeAreaInsetBottom }, customClass]"
|
|
12
|
+
:style="[barStyle, customStyle]"
|
|
13
|
+
>
|
|
14
|
+
<view class="dd-cart-bar__bar">
|
|
15
|
+
<slot></slot>
|
|
16
|
+
<!-- 购物车入口:圆钮 + 数量角标(数量变化时 :key 重建触发弹跳动画重放) -->
|
|
17
|
+
<view class="dd-cart-bar__entry" @click="togglePopup">
|
|
18
|
+
<view class="dd-cart-bar__cart" :class="{ 'dd-cart-bar__cart--empty': totalCount === 0 }">
|
|
19
|
+
<dd-icon :name="totalCount > 0 ? 'cart' : 'cart-o'" class="dd-cart-bar__cart-icon" />
|
|
20
|
+
</view>
|
|
21
|
+
<view :key="totalCount" class="dd-cart-bar__count">
|
|
22
|
+
<dd-badge :content="totalCount" :max="99" />
|
|
23
|
+
</view>
|
|
24
|
+
</view>
|
|
25
|
+
<view class="dd-cart-bar__text">
|
|
26
|
+
<text class="dd-cart-bar__label">{{ label }}</text>
|
|
27
|
+
<dd-price class="dd-cart-bar__price" :rate="totalYuan" :currency="currency" />
|
|
28
|
+
<text v-if="suffixLabel" class="dd-cart-bar__suffix-label">{{ suffixLabel }}</text>
|
|
29
|
+
</view>
|
|
30
|
+
<slot name="button">
|
|
31
|
+
<dd-button
|
|
32
|
+
class="dd-cart-bar__button"
|
|
33
|
+
round
|
|
34
|
+
:type="buttonType"
|
|
35
|
+
:style="buttonStyle"
|
|
36
|
+
:loading="loading"
|
|
37
|
+
:disabled="buttonDisabled"
|
|
38
|
+
@click="onSubmit"
|
|
39
|
+
>{{ buttonText }}</dd-button>
|
|
40
|
+
</slot>
|
|
41
|
+
</view>
|
|
42
|
+
</view>
|
|
43
|
+
|
|
44
|
+
<dd-popup
|
|
45
|
+
:model-value="modelValue"
|
|
46
|
+
position="bottom"
|
|
47
|
+
round
|
|
48
|
+
:safe-area-inset-bottom="false"
|
|
49
|
+
@update:model-value="onPopupUpdate"
|
|
50
|
+
@open="emit('open')"
|
|
51
|
+
@close="emit('close')"
|
|
52
|
+
>
|
|
53
|
+
<view class="dd-cart-bar__panel">
|
|
54
|
+
<view class="dd-cart-bar__header">
|
|
55
|
+
<text class="dd-cart-bar__title">{{ title }}</text>
|
|
56
|
+
<view class="dd-cart-bar__clear" @click="onClear">
|
|
57
|
+
<dd-icon name="delete-o" class="dd-cart-bar__clear-icon" />
|
|
58
|
+
<text class="dd-cart-bar__clear-text">{{ clearText }}</text>
|
|
59
|
+
</view>
|
|
60
|
+
</view>
|
|
61
|
+
<view v-if="tips" class="dd-cart-bar__tips">
|
|
62
|
+
<text class="dd-cart-bar__tips-text">{{ tips }}</text>
|
|
63
|
+
</view>
|
|
64
|
+
<scroll-view
|
|
65
|
+
v-if="items.length"
|
|
66
|
+
class="dd-cart-bar__list"
|
|
67
|
+
scroll-y
|
|
68
|
+
:style="{ maxHeight: maxListHeight }"
|
|
69
|
+
>
|
|
70
|
+
<view
|
|
71
|
+
v-for="item in items"
|
|
72
|
+
:key="item.id"
|
|
73
|
+
class="dd-cart-bar__item"
|
|
74
|
+
@click="emit('item-click', item)"
|
|
75
|
+
>
|
|
76
|
+
<dd-image
|
|
77
|
+
v-if="item.image"
|
|
78
|
+
class="dd-cart-bar__item-image"
|
|
79
|
+
:src="item.image"
|
|
80
|
+
width="120rpx"
|
|
81
|
+
height="120rpx"
|
|
82
|
+
radius="16rpx"
|
|
83
|
+
fit="cover"
|
|
84
|
+
/>
|
|
85
|
+
<view v-else class="dd-cart-bar__item-image dd-cart-bar__item-image--empty">
|
|
86
|
+
<dd-icon name="shopping-cart-o" class="dd-cart-bar__item-image-icon" />
|
|
87
|
+
</view>
|
|
88
|
+
<view class="dd-cart-bar__item-info">
|
|
89
|
+
<text class="dd-cart-bar__item-name">{{ item.name }}</text>
|
|
90
|
+
<text v-if="item.specs" class="dd-cart-bar__item-specs">{{ item.specs }}</text>
|
|
91
|
+
<view class="dd-cart-bar__item-footer">
|
|
92
|
+
<dd-price
|
|
93
|
+
class="dd-cart-bar__item-price"
|
|
94
|
+
:rate="item.price / 100"
|
|
95
|
+
:currency="currency"
|
|
96
|
+
/>
|
|
97
|
+
<!-- 减到 1 再减由 onMinus 移除该项(min=1 时 stepper 只发 minus 不发 change) -->
|
|
98
|
+
<dd-stepper
|
|
99
|
+
:model-value="item.count"
|
|
100
|
+
:min="1"
|
|
101
|
+
size="sm"
|
|
102
|
+
@click.stop
|
|
103
|
+
@change="onCountChange(item, $event)"
|
|
104
|
+
@minus="onMinus(item)"
|
|
105
|
+
/>
|
|
106
|
+
</view>
|
|
107
|
+
</view>
|
|
108
|
+
</view>
|
|
109
|
+
</scroll-view>
|
|
110
|
+
<view v-else class="dd-cart-bar__empty">
|
|
111
|
+
<dd-icon name="shopping-cart-o" class="dd-cart-bar__empty-icon" />
|
|
112
|
+
<text class="dd-cart-bar__empty-text">购物车还是空的,快去挑选商品吧</text>
|
|
113
|
+
</view>
|
|
114
|
+
</view>
|
|
115
|
+
</dd-popup>
|
|
116
|
+
</template>
|
|
117
|
+
|
|
118
|
+
<script setup lang="ts">
|
|
119
|
+
import { computed } from 'vue'
|
|
120
|
+
import type { CSSProperties } from 'vue'
|
|
121
|
+
import DdBadge from '../dd-badge/dd-badge.vue'
|
|
122
|
+
import DdButton from '../dd-button/dd-button.vue'
|
|
123
|
+
import DdIcon from '../dd-icon/dd-icon.vue'
|
|
124
|
+
import DdImage from '../dd-image/dd-image.vue'
|
|
125
|
+
import DdPopup from '../dd-popup/dd-popup.vue'
|
|
126
|
+
import DdPrice from '../dd-price/dd-price.vue'
|
|
127
|
+
import DdStepper from '../dd-stepper/dd-stepper.vue'
|
|
128
|
+
import type { DdCartItem } from './cart-bar'
|
|
129
|
+
// z-index 统一取 libs/config/zIndex.js(底栏 sticky 档;弹层打开时 popup 档内 +1 派生抬升)
|
|
130
|
+
import zIndexConfig from '../../libs/config/zIndex.js'
|
|
131
|
+
|
|
132
|
+
interface Props {
|
|
133
|
+
/** 购物车条目(受控);增减/清空经 change 回传新数组 */
|
|
134
|
+
items: DdCartItem[]
|
|
135
|
+
/** 购物车弹层显隐(v-model) */
|
|
136
|
+
modelValue?: boolean
|
|
137
|
+
/** 合计左侧文案 */
|
|
138
|
+
label?: string
|
|
139
|
+
/** 合计右侧附加文案(如「共减¥19」) */
|
|
140
|
+
suffixLabel?: string
|
|
141
|
+
/** 弹层顶部提示条(如凑单/温馨提示) */
|
|
142
|
+
tips?: string
|
|
143
|
+
/** 弹层标题 */
|
|
144
|
+
title?: string
|
|
145
|
+
/** 清空按钮文案 */
|
|
146
|
+
clearText?: string
|
|
147
|
+
/** 清空前是否二次确认(uni.showModal) */
|
|
148
|
+
clearConfirm?: boolean
|
|
149
|
+
/** 货币符号 */
|
|
150
|
+
currency?: string
|
|
151
|
+
/** 结算按钮文案 */
|
|
152
|
+
buttonText?: string
|
|
153
|
+
/** 结算按钮类型(dd-button type) */
|
|
154
|
+
buttonType?: 'default' | 'primary' | 'secondary' | 'ghost' | 'text' | 'success' | 'warning' | 'danger'
|
|
155
|
+
/** 结算按钮自定义背景色 */
|
|
156
|
+
buttonColor?: string
|
|
157
|
+
/** 结算按钮加载态 */
|
|
158
|
+
loading?: boolean
|
|
159
|
+
/** 禁用结算(不影响数量增减;空车时自动禁用) */
|
|
160
|
+
disabled?: boolean
|
|
161
|
+
/** 列表最大高(默认 50vh) */
|
|
162
|
+
maxListHeight?: string
|
|
163
|
+
/** 固定在底部时是否生成占位视图 */
|
|
164
|
+
placeholder?: boolean
|
|
165
|
+
/** 是否预留底部安全区 */
|
|
166
|
+
safeAreaInsetBottom?: boolean
|
|
167
|
+
customStyle?: CSSProperties | string
|
|
168
|
+
customClass?: string
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
172
|
+
modelValue: false,
|
|
173
|
+
label: '合计:',
|
|
174
|
+
suffixLabel: '',
|
|
175
|
+
tips: '',
|
|
176
|
+
title: '已选商品',
|
|
177
|
+
clearText: '清空购物车',
|
|
178
|
+
clearConfirm: true,
|
|
179
|
+
currency: '¥',
|
|
180
|
+
buttonText: '结算',
|
|
181
|
+
buttonType: 'primary',
|
|
182
|
+
buttonColor: '',
|
|
183
|
+
loading: false,
|
|
184
|
+
disabled: false,
|
|
185
|
+
maxListHeight: '50vh',
|
|
186
|
+
placeholder: false,
|
|
187
|
+
safeAreaInsetBottom: true,
|
|
188
|
+
customStyle: undefined,
|
|
189
|
+
customClass: '',
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
const emit = defineEmits<{
|
|
193
|
+
(e: 'update:modelValue', val: boolean): void
|
|
194
|
+
(e: 'open'): void
|
|
195
|
+
(e: 'close'): void
|
|
196
|
+
/** 数量增减/清空后的最新条目(减到 0 的项已剔除) */
|
|
197
|
+
(e: 'change', items: DdCartItem[]): void
|
|
198
|
+
(e: 'clear'): void
|
|
199
|
+
(e: 'submit'): void
|
|
200
|
+
(e: 'item-click', item: DdCartItem): void
|
|
201
|
+
}>()
|
|
202
|
+
|
|
203
|
+
const totalCount = computed(() => props.items.reduce((sum, it) => sum + (it.count || 0), 0))
|
|
204
|
+
|
|
205
|
+
// 合计(分→元),dd-price 直接展示
|
|
206
|
+
const totalYuan = computed(() => props.items.reduce((sum, it) => sum + (it.price || 0) * (it.count || 0), 0) / 100)
|
|
207
|
+
|
|
208
|
+
const buttonDisabled = computed(() => props.disabled || totalCount.value === 0)
|
|
209
|
+
|
|
210
|
+
const barStyle = computed<CSSProperties>(() => ({
|
|
211
|
+
zIndex: props.modelValue ? zIndexConfig.popup + 1 : zIndexConfig.sticky,
|
|
212
|
+
}))
|
|
213
|
+
|
|
214
|
+
const buttonStyle = computed(() => (props.buttonColor ? { background: props.buttonColor } : undefined))
|
|
215
|
+
|
|
216
|
+
function onPopupUpdate(val: boolean) {
|
|
217
|
+
emit('update:modelValue', val)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function togglePopup() {
|
|
221
|
+
// 空车不允许撑开弹层(业界惯例:角标为 0 时入口不可点)
|
|
222
|
+
if (!props.modelValue && totalCount.value === 0) return
|
|
223
|
+
emit('update:modelValue', !props.modelValue)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function onCountChange(item: DdCartItem, val: number) {
|
|
227
|
+
if (val === item.count) return
|
|
228
|
+
emitChange(props.items.map((it) => (it.id === item.id ? { ...it, count: val } : it)))
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// min=1 拦下减号:数量为 1 再减 = 移除该商品(stepper 此时不再发 change,只发 minus)
|
|
232
|
+
function onMinus(item: DdCartItem) {
|
|
233
|
+
if (item.count > 1) return
|
|
234
|
+
emitChange(props.items.filter((it) => it.id !== item.id))
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function emitChange(items: DdCartItem[]) {
|
|
238
|
+
emit('change', items)
|
|
239
|
+
// 减空/清空后自动收起弹层
|
|
240
|
+
if (items.length === 0 && props.modelValue) emit('update:modelValue', false)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function onClear() {
|
|
244
|
+
if (!props.items.length) return
|
|
245
|
+
if (!props.clearConfirm) return doClear()
|
|
246
|
+
uni.showModal({
|
|
247
|
+
title: '提示',
|
|
248
|
+
content: '确定清空购物车吗?',
|
|
249
|
+
success: (res) => {
|
|
250
|
+
if (res.confirm) doClear()
|
|
251
|
+
},
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function doClear() {
|
|
256
|
+
emitChange([])
|
|
257
|
+
emit('clear')
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function onSubmit() {
|
|
261
|
+
if (buttonDisabled.value || props.loading) return
|
|
262
|
+
emit('submit')
|
|
263
|
+
}
|
|
264
|
+
</script>
|
|
265
|
+
|
|
266
|
+
<style lang="scss" scoped>
|
|
267
|
+
@import '../../scss/variables';
|
|
268
|
+
@import '../../scss/mixins';
|
|
269
|
+
|
|
270
|
+
.dd-cart-bar {
|
|
271
|
+
position: fixed;
|
|
272
|
+
left: 0;
|
|
273
|
+
right: 0;
|
|
274
|
+
bottom: 0;
|
|
275
|
+
background: var(--dd-bg-card, #{$dd-bg-card});
|
|
276
|
+
|
|
277
|
+
&--safe {
|
|
278
|
+
@include dd-safe-area-bottom;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.dd-cart-bar__placeholder {
|
|
283
|
+
width: 100%;
|
|
284
|
+
height: 100rpx;
|
|
285
|
+
box-sizing: content-box;
|
|
286
|
+
|
|
287
|
+
&--safe {
|
|
288
|
+
@include dd-safe-area-bottom;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.dd-cart-bar__bar {
|
|
293
|
+
display: flex;
|
|
294
|
+
align-items: center;
|
|
295
|
+
min-height: 100rpx;
|
|
296
|
+
padding: $dd-space-2 $dd-space-3;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// 入口圆钮:微凸出栏顶(外卖购物车标志视觉)
|
|
300
|
+
.dd-cart-bar__entry {
|
|
301
|
+
position: relative;
|
|
302
|
+
flex-shrink: 0;
|
|
303
|
+
margin-right: $dd-space-3;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.dd-cart-bar__cart {
|
|
307
|
+
display: flex;
|
|
308
|
+
align-items: center;
|
|
309
|
+
justify-content: center;
|
|
310
|
+
width: 88rpx;
|
|
311
|
+
height: 88rpx;
|
|
312
|
+
transform: translateY(-14rpx);
|
|
313
|
+
border-radius: $dd-radius-full;
|
|
314
|
+
background: var(--dd-primary, #{$dd-primary});
|
|
315
|
+
color: var(--dd-primary-contrast, #{$dd-primary-contrast});
|
|
316
|
+
box-shadow: var(--dd-shadow-1, #{$dd-shadow-1});
|
|
317
|
+
|
|
318
|
+
&--empty {
|
|
319
|
+
background: var(--dd-surface-container-low, #{$dd-surface-container-low});
|
|
320
|
+
color: var(--dd-text-secondary, #{$dd-text-secondary});
|
|
321
|
+
box-shadow: none;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.dd-cart-bar__cart-icon {
|
|
326
|
+
font-size: 44rpx;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.dd-cart-bar__count {
|
|
330
|
+
position: absolute;
|
|
331
|
+
top: -6rpx;
|
|
332
|
+
right: -10rpx;
|
|
333
|
+
animation: dd-cart-bar-bounce 0.3s;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
@keyframes dd-cart-bar-bounce {
|
|
337
|
+
0% { transform: scale(0.5); }
|
|
338
|
+
60% { transform: scale(1.25); }
|
|
339
|
+
100% { transform: scale(1); }
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
.dd-cart-bar__text {
|
|
343
|
+
flex: 1;
|
|
344
|
+
padding-right: $dd-space-3;
|
|
345
|
+
color: var(--dd-text-primary, #{$dd-text-primary});
|
|
346
|
+
font-size: $dd-font-size-body;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.dd-cart-bar__price {
|
|
350
|
+
margin-left: $dd-space-1;
|
|
351
|
+
color: var(--dd-error, #{$dd-error});
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
.dd-cart-bar__suffix-label {
|
|
355
|
+
margin-left: $dd-space-1;
|
|
356
|
+
color: var(--dd-text-secondary, #{$dd-text-secondary});
|
|
357
|
+
font-size: $dd-font-size-caption;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
.dd-cart-bar__button {
|
|
361
|
+
flex-shrink: 0;
|
|
362
|
+
min-width: 200rpx;
|
|
363
|
+
margin-left: $dd-space-2;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
.dd-cart-bar__panel {
|
|
367
|
+
// 底部留出栏高 + 安全区:弹层面板(popup 档)压在栏下方,内容不被栏遮挡
|
|
368
|
+
padding: $dd-space-3 $dd-space-3 calc(100rpx + constant(safe-area-inset-bottom));
|
|
369
|
+
padding: $dd-space-3 $dd-space-3 calc(100rpx + env(safe-area-inset-bottom));
|
|
370
|
+
box-sizing: border-box;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
.dd-cart-bar__header {
|
|
374
|
+
display: flex;
|
|
375
|
+
align-items: center;
|
|
376
|
+
justify-content: space-between;
|
|
377
|
+
padding-bottom: $dd-space-2;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
.dd-cart-bar__title {
|
|
381
|
+
color: var(--dd-text-primary, #{$dd-text-primary});
|
|
382
|
+
font-size: $dd-font-size-h4;
|
|
383
|
+
font-weight: $dd-font-weight-h4;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
.dd-cart-bar__clear {
|
|
387
|
+
display: flex;
|
|
388
|
+
align-items: center;
|
|
389
|
+
color: var(--dd-text-secondary, #{$dd-text-secondary});
|
|
390
|
+
font-size: $dd-font-size-caption;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
.dd-cart-bar__clear-icon {
|
|
394
|
+
margin-right: $dd-space-1;
|
|
395
|
+
font-size: 28rpx;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
.dd-cart-bar__tips {
|
|
399
|
+
margin-bottom: $dd-space-2;
|
|
400
|
+
padding: $dd-space-2 $dd-space-3;
|
|
401
|
+
border-radius: $dd-radius-md;
|
|
402
|
+
background: var(--dd-surface-container-low, #{$dd-surface-container-low});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
.dd-cart-bar__tips-text {
|
|
406
|
+
color: var(--dd-text-secondary, #{$dd-text-secondary});
|
|
407
|
+
font-size: $dd-font-size-caption;
|
|
408
|
+
line-height: $dd-line-height-caption;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
.dd-cart-bar__list {
|
|
412
|
+
box-sizing: border-box;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
.dd-cart-bar__item {
|
|
416
|
+
display: flex;
|
|
417
|
+
align-items: center;
|
|
418
|
+
padding: $dd-space-3 0;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
.dd-cart-bar__item-image {
|
|
422
|
+
flex-shrink: 0;
|
|
423
|
+
margin-right: $dd-space-3;
|
|
424
|
+
overflow: hidden;
|
|
425
|
+
|
|
426
|
+
&--empty {
|
|
427
|
+
display: flex;
|
|
428
|
+
align-items: center;
|
|
429
|
+
justify-content: center;
|
|
430
|
+
width: 120rpx;
|
|
431
|
+
height: 120rpx;
|
|
432
|
+
border-radius: 16rpx;
|
|
433
|
+
background: var(--dd-surface-container-low, #{$dd-surface-container-low});
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
.dd-cart-bar__item-image-icon {
|
|
438
|
+
color: var(--dd-text-secondary, #{$dd-text-secondary});
|
|
439
|
+
font-size: 48rpx;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
.dd-cart-bar__item-info {
|
|
443
|
+
flex: 1;
|
|
444
|
+
min-width: 0;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
.dd-cart-bar__item-name {
|
|
448
|
+
display: block;
|
|
449
|
+
overflow: hidden;
|
|
450
|
+
color: var(--dd-text-primary, #{$dd-text-primary});
|
|
451
|
+
font-size: $dd-font-size-body;
|
|
452
|
+
white-space: nowrap;
|
|
453
|
+
text-overflow: ellipsis;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
.dd-cart-bar__item-specs {
|
|
457
|
+
display: block;
|
|
458
|
+
margin-top: $dd-space-1;
|
|
459
|
+
overflow: hidden;
|
|
460
|
+
color: var(--dd-text-secondary, #{$dd-text-secondary});
|
|
461
|
+
font-size: $dd-font-size-caption;
|
|
462
|
+
white-space: nowrap;
|
|
463
|
+
text-overflow: ellipsis;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
.dd-cart-bar__item-footer {
|
|
467
|
+
display: flex;
|
|
468
|
+
align-items: center;
|
|
469
|
+
justify-content: space-between;
|
|
470
|
+
margin-top: $dd-space-2;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
.dd-cart-bar__item-price {
|
|
474
|
+
color: var(--dd-error, #{$dd-error});
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
.dd-cart-bar__empty {
|
|
478
|
+
display: flex;
|
|
479
|
+
flex-direction: column;
|
|
480
|
+
align-items: center;
|
|
481
|
+
padding: $dd-space-8 0;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
.dd-cart-bar__empty-icon {
|
|
485
|
+
margin-bottom: $dd-space-2;
|
|
486
|
+
color: var(--dd-text-secondary, #{$dd-text-secondary});
|
|
487
|
+
font-size: 80rpx;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
.dd-cart-bar__empty-text {
|
|
491
|
+
color: var(--dd-text-secondary, #{$dd-text-secondary});
|
|
492
|
+
font-size: $dd-font-size-caption;
|
|
493
|
+
}
|
|
494
|
+
</style>
|
|
@@ -10,14 +10,16 @@
|
|
|
10
10
|
:hover-stay-time="120"
|
|
11
11
|
@click="onClick"
|
|
12
12
|
>
|
|
13
|
-
<!-- 缩略图 +
|
|
14
|
-
<view class="dd-goods-card__thumb">
|
|
13
|
+
<!-- 缩略图 + 金色角标(缺图时文字占位:随机主题底色 + 名称前 2 字) -->
|
|
14
|
+
<view class="dd-goods-card__thumb" :class="'dd-goods-card__thumb--' + avatarHue">
|
|
15
15
|
<slot name="thumb">
|
|
16
16
|
<image
|
|
17
|
+
v-if="thumb"
|
|
17
18
|
class="dd-goods-card__thumb-img"
|
|
18
19
|
:src="thumb"
|
|
19
20
|
:mode="thumbMode"
|
|
20
21
|
></image>
|
|
22
|
+
<text v-else class="dd-goods-card__thumb-text">{{ avatarText }}</text>
|
|
21
23
|
</slot>
|
|
22
24
|
<text v-if="tag" class="dd-goods-card__tag" :style="{ zIndex: zIndexConfig.base }">{{ tag }}</text>
|
|
23
25
|
</view>
|
|
@@ -41,9 +43,11 @@
|
|
|
41
43
|
</text>
|
|
42
44
|
</view>
|
|
43
45
|
<!-- 价格行右侧扩展位(步进器/加购等与价格同排贴底);未用时回退已选数量 -->
|
|
44
|
-
<
|
|
45
|
-
<
|
|
46
|
-
|
|
46
|
+
<view class="dd-goods-card__price-right">
|
|
47
|
+
<slot name="price-right">
|
|
48
|
+
<text v-if="num" class="dd-goods-card__num">×{{ num }}</text>
|
|
49
|
+
</slot>
|
|
50
|
+
</view>
|
|
47
51
|
</view>
|
|
48
52
|
|
|
49
53
|
<view v-if="$slots.bottom" class="dd-goods-card__bottom">
|
|
@@ -55,9 +59,11 @@
|
|
|
55
59
|
</template>
|
|
56
60
|
|
|
57
61
|
<script setup lang="ts">
|
|
62
|
+
import { computed, ref } from 'vue'
|
|
58
63
|
import DdPrice from '../dd-price/dd-price.vue'
|
|
59
64
|
// z-index 统一取 libs/config/zIndex.js(角标抬到缩略图之上取 base 档)
|
|
60
65
|
import zIndexConfig from '../../libs/config/zIndex.js'
|
|
66
|
+
import { pickAvatarHue, avatarText as calcAvatarText } from '../../libs/utils'
|
|
61
67
|
|
|
62
68
|
interface Props {
|
|
63
69
|
/** 商品图片地址 */
|
|
@@ -109,6 +115,10 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
109
115
|
|
|
110
116
|
const emit = defineEmits<{ (e: 'click', val: Event): void }>()
|
|
111
117
|
|
|
118
|
+
// 缺图文字占位(与 dd-goods-sku / dd-package-sku 同规则):随机主题底色 + 名称前 2 字(实例化时随机一次)
|
|
119
|
+
const avatarHue = ref<string>(pickAvatarHue())
|
|
120
|
+
const avatarText = computed(() => calcAvatarText(props.title))
|
|
121
|
+
|
|
112
122
|
function onClick(e: Event) {
|
|
113
123
|
if (props.disabled) return
|
|
114
124
|
emit('click', e)
|
|
@@ -143,12 +153,23 @@ function onClick(e: Event) {
|
|
|
143
153
|
position: relative;
|
|
144
154
|
flex-shrink: 0;
|
|
145
155
|
overflow: hidden;
|
|
156
|
+
display: flex;
|
|
157
|
+
align-items: center;
|
|
158
|
+
justify-content: center;
|
|
146
159
|
|
|
147
160
|
&-img {
|
|
148
161
|
display: block;
|
|
149
162
|
width: 100%;
|
|
150
163
|
height: 100%;
|
|
151
164
|
}
|
|
165
|
+
|
|
166
|
+
&-text {
|
|
167
|
+
font-size: 40rpx;
|
|
168
|
+
font-weight: bold;
|
|
169
|
+
line-height: 1;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@include dd-avatar-colors;
|
|
152
173
|
}
|
|
153
174
|
|
|
154
175
|
&__tag {
|
|
@@ -187,11 +208,8 @@ function onClick(e: Event) {
|
|
|
187
208
|
color: var(--dd-text-secondary, #{$dd-text-secondary});
|
|
188
209
|
font-size: 24rpx;
|
|
189
210
|
line-height: 1.4;
|
|
190
|
-
//
|
|
191
|
-
|
|
192
|
-
-webkit-box-orient: vertical;
|
|
193
|
-
-webkit-line-clamp: 2;
|
|
194
|
-
overflow: hidden;
|
|
211
|
+
// 单行省略:给价格行(现价+划线价)留足横向空间,避免挤出右侧操作位
|
|
212
|
+
@include dd-ellipsis;
|
|
195
213
|
}
|
|
196
214
|
|
|
197
215
|
&__price-row {
|
|
@@ -202,6 +220,9 @@ function onClick(e: Event) {
|
|
|
202
220
|
}
|
|
203
221
|
|
|
204
222
|
&__price {
|
|
223
|
+
// 占满剩余宽度且可收缩,划线价过长时自身省略,不把右侧操作位挤出
|
|
224
|
+
flex: 1;
|
|
225
|
+
min-width: 0;
|
|
205
226
|
display: inline-flex;
|
|
206
227
|
align-items: baseline;
|
|
207
228
|
color: var(--dd-error-400, #{$dd-error-400});
|
|
@@ -214,10 +235,18 @@ function onClick(e: Event) {
|
|
|
214
235
|
font-size: 22rpx;
|
|
215
236
|
font-weight: 400;
|
|
216
237
|
text-decoration: line-through;
|
|
238
|
+
// 空间不足时划线价自身省略
|
|
239
|
+
overflow: hidden;
|
|
240
|
+
white-space: nowrap;
|
|
241
|
+
text-overflow: ellipsis;
|
|
217
242
|
}
|
|
218
243
|
|
|
219
|
-
&
|
|
244
|
+
&__price-right {
|
|
245
|
+
flex-shrink: 0;
|
|
220
246
|
margin-left: $dd-space-2;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
&__num {
|
|
221
250
|
color: var(--dd-text-tertiary, #{$dd-text-tertiary});
|
|
222
251
|
font-size: 24rpx;
|
|
223
252
|
}
|
|
@@ -14,13 +14,15 @@
|
|
|
14
14
|
<view class="dd-goods-sku__container" :style="{ padding: pageInline ? '0px' : '' }">
|
|
15
15
|
<view class="dd-goods-sku__header">
|
|
16
16
|
<slot name="header">
|
|
17
|
-
<view class="dd-goods-sku__header__image">
|
|
18
|
-
<image :src="
|
|
17
|
+
<view class="dd-goods-sku__header__image" :class="'dd-goods-sku__header__image--' + avatarHue">
|
|
18
|
+
<image v-if="headerImage" :src="headerImage" mode="aspectFill"></image>
|
|
19
|
+
<text v-else class="dd-goods-sku__header__image__text">{{ avatarText }}</text>
|
|
19
20
|
</view>
|
|
20
21
|
<view class="dd-goods-sku__header__info">
|
|
21
22
|
<view class="dd-goods-sku__header__info__price">
|
|
22
23
|
<text class="dd-goods-sku__header__info__price__symbol">¥</text>
|
|
23
24
|
<text class="dd-goods-sku__header__info__price__value">{{ price }}</text>
|
|
25
|
+
<text v-if="originPrice" class="dd-goods-sku__header__info__price__origin">¥{{ originPrice }}</text>
|
|
24
26
|
</view>
|
|
25
27
|
<view class="dd-goods-sku__header__info__stock">库存 {{ stock }} 件</view>
|
|
26
28
|
<view class="dd-goods-sku__header__info__selected">已选: {{ selectedSkuText }}</view>
|
|
@@ -75,6 +77,7 @@ import { computed, reactive, ref } from 'vue'
|
|
|
75
77
|
import DdPopup from '../dd-popup/dd-popup.vue'
|
|
76
78
|
import DdStepper from '../dd-stepper/dd-stepper.vue'
|
|
77
79
|
import DdButton from '../dd-button/dd-button.vue'
|
|
80
|
+
import { pickAvatarHue, avatarText as calcAvatarText } from '../../libs/utils'
|
|
78
81
|
|
|
79
82
|
interface SkuLeaf {
|
|
80
83
|
id: string | number
|
|
@@ -137,11 +140,23 @@ const price = computed(() => {
|
|
|
137
140
|
return props.goodsInfo.price || props.goodsInfo.price_fee || 0
|
|
138
141
|
})
|
|
139
142
|
|
|
140
|
-
//
|
|
143
|
+
// 划线原价:随选中组合(originPrice|origin_price),缺省回退商品级;不传不显示
|
|
144
|
+
const originPrice = computed(() => {
|
|
145
|
+
const comb = getSelectedSkuComb()
|
|
146
|
+
if (comb) return comb.originPrice || comb.origin_price || ''
|
|
147
|
+
return props.goodsInfo.originPrice || props.goodsInfo.origin_price || ''
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
// 头图:缺图时文字占位(与 dd-package-sku / dd-goods-card 同规则)——随机主题底色 + 名称前 2 字
|
|
151
|
+
const headerImage = computed(() => props.goodsInfo.image || props.goodsInfo.picture || '')
|
|
152
|
+
const avatarHue = ref<string>(pickAvatarHue())
|
|
153
|
+
const avatarText = computed(() => calcAvatarText(props.goodsInfo.name))
|
|
154
|
+
|
|
155
|
+
// 当前库存:库存 0 是合法值(售罄规格),必须用 ?? 兜底——|| 会把 0 误判缺省落到 undefined,模板渲染成「库存 件」
|
|
141
156
|
const stock = computed(() => {
|
|
142
157
|
const comb = getSelectedSkuComb()
|
|
143
|
-
if (comb) return comb.stock
|
|
144
|
-
return props.goodsInfo.stock
|
|
158
|
+
if (comb) return comb.stock ?? comb.quantity ?? 0
|
|
159
|
+
return props.goodsInfo.stock ?? props.goodsInfo.quantity ?? 0
|
|
145
160
|
})
|
|
146
161
|
|
|
147
162
|
// 最大购买数量
|
|
@@ -180,21 +195,23 @@ function isSelected(skuKey: string, skuValueId: string | number) {
|
|
|
180
195
|
return selectedSku[skuKey] === skuValueId
|
|
181
196
|
}
|
|
182
197
|
|
|
183
|
-
// 判断SKU
|
|
198
|
+
// 判断SKU是否禁用:组合不存在或库存为 0(售罄)均不可选;库存 0 是合法值,取值须用 ?? 防穿透
|
|
184
199
|
function isDisabled(skuKey: string, skuValueId: string | number) {
|
|
185
200
|
// 构造一个临时的已选中SKU对象
|
|
186
201
|
const tempSelected: Record<string, any> = { ...selectedSku, [skuKey]: skuValueId }
|
|
202
|
+
const stockOf = (s: Record<string, any>) => s.stock ?? s.quantity ?? 0
|
|
187
203
|
|
|
188
204
|
// 检查是否还有未选择的SKU维度
|
|
189
205
|
const selectedCount = Object.keys(tempSelected).filter((key) => tempSelected[key]).length
|
|
190
206
|
const totalSkuCount = props.skuTree.length
|
|
191
207
|
|
|
192
|
-
// 如果所有SKU
|
|
208
|
+
// 如果所有SKU都已选择,则检查组合是否存在且有货
|
|
193
209
|
if (selectedCount === totalSkuCount) {
|
|
194
|
-
|
|
210
|
+
const comb = getSkuComb(tempSelected)
|
|
211
|
+
return !comb || stockOf(comb) <= 0
|
|
195
212
|
}
|
|
196
213
|
|
|
197
|
-
//
|
|
214
|
+
// 部分选择预检:存在任一有货的匹配行即可选;匹配行全售罄等同组合不存在,一并禁用
|
|
198
215
|
for (let i = 0; i < props.skuList.length; i++) {
|
|
199
216
|
const sku = props.skuList[i]
|
|
200
217
|
let match = true
|
|
@@ -206,7 +223,7 @@ function isDisabled(skuKey: string, skuValueId: string | number) {
|
|
|
206
223
|
}
|
|
207
224
|
}
|
|
208
225
|
|
|
209
|
-
if (match) {
|
|
226
|
+
if (match && stockOf(sku) > 0) {
|
|
210
227
|
return false
|
|
211
228
|
}
|
|
212
229
|
}
|
|
@@ -329,11 +346,22 @@ defineExpose({ open, close, reset })
|
|
|
329
346
|
border-radius: 10rpx;
|
|
330
347
|
overflow: hidden;
|
|
331
348
|
margin-right: 20rpx;
|
|
349
|
+
display: flex;
|
|
350
|
+
align-items: center;
|
|
351
|
+
justify-content: center;
|
|
332
352
|
|
|
333
353
|
image {
|
|
334
354
|
width: 100%;
|
|
335
355
|
height: 100%;
|
|
336
356
|
}
|
|
357
|
+
|
|
358
|
+
&__text {
|
|
359
|
+
font-size: 56rpx;
|
|
360
|
+
font-weight: bold;
|
|
361
|
+
line-height: 1;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
@include dd-avatar-colors;
|
|
337
365
|
}
|
|
338
366
|
|
|
339
367
|
&__info {
|
|
@@ -356,6 +384,15 @@ defineExpose({ open, close, reset })
|
|
|
356
384
|
color: var(--dd-error-400, #{$dd-error-400});
|
|
357
385
|
font-weight: bold;
|
|
358
386
|
}
|
|
387
|
+
|
|
388
|
+
// 划线原价(样式对齐 dd-goods-card)
|
|
389
|
+
&__origin {
|
|
390
|
+
margin-left: $dd-space-2;
|
|
391
|
+
color: var(--dd-text-tertiary, #{$dd-text-tertiary});
|
|
392
|
+
font-size: 22rpx;
|
|
393
|
+
font-weight: 400;
|
|
394
|
+
text-decoration: line-through;
|
|
395
|
+
}
|
|
359
396
|
}
|
|
360
397
|
|
|
361
398
|
&__stock {
|
|
@@ -13,6 +13,24 @@
|
|
|
13
13
|
<view class="dd-package-sku__container">
|
|
14
14
|
<view class="dd-package-sku__title">{{ title }}</view>
|
|
15
15
|
|
|
16
|
+
<view v-if="hasHeader" class="dd-package-sku__header">
|
|
17
|
+
<view class="dd-package-sku__header__image" :class="'dd-package-sku__header__image--' + avatarHue">
|
|
18
|
+
<image v-if="headerImage" :src="headerImage" mode="aspectFill" />
|
|
19
|
+
<text v-else class="dd-package-sku__header__image__text">{{ avatarText }}</text>
|
|
20
|
+
</view>
|
|
21
|
+
<view class="dd-package-sku__header__info">
|
|
22
|
+
<view class="dd-package-sku__header__info__price">
|
|
23
|
+
<text class="dd-package-sku__header__info__price__symbol">¥</text>
|
|
24
|
+
<text class="dd-package-sku__header__info__price__value">{{ price }}</text>
|
|
25
|
+
<text v-if="originPrice" class="dd-package-sku__header__info__price__origin">¥{{ originPrice }}</text>
|
|
26
|
+
</view>
|
|
27
|
+
<view v-if="stock !== undefined && stock !== null" class="dd-package-sku__header__info__stock">
|
|
28
|
+
库存 {{ stock }} 件
|
|
29
|
+
</view>
|
|
30
|
+
<view class="dd-package-sku__header__info__selected">已选: {{ selectedText || '未选择' }}</view>
|
|
31
|
+
</view>
|
|
32
|
+
</view>
|
|
33
|
+
|
|
16
34
|
<scroll-view class="dd-package-sku__content" scroll-y>
|
|
17
35
|
<view v-for="group in groups" :key="group.id" class="dd-package-sku__group">
|
|
18
36
|
<view class="dd-package-sku__group__header">
|
|
@@ -52,13 +70,15 @@
|
|
|
52
70
|
|
|
53
71
|
<script setup lang="ts">
|
|
54
72
|
/**
|
|
55
|
-
* 套餐可选组选择弹层(N选M 多选 + 加价 + 售罄置灰)
|
|
73
|
+
* 套餐可选组选择弹层(N选M 多选 + N选1 单选直接替换 + 加价 + 售罄置灰)
|
|
56
74
|
* - groups 通用形状,不绑业务 DTO;FIXED 组只读展示,OPTIONAL 组按 minSel/maxSel 校验
|
|
75
|
+
* - goodsInfo 传入时头部展示图片/价格(底价+已选加价)/库存/已选项,对齐 dd-goods-sku;图块必有,缺图时以主题随机色块 + 套餐名前 2 字占位
|
|
57
76
|
* - confirm emit { options:[{groupId,skuId}], surchargeFen, selectedText };确认后不自动关闭,由调用方 ref.close()
|
|
58
77
|
*/
|
|
59
78
|
import { computed, reactive, ref } from 'vue'
|
|
60
79
|
import DdPopup from '../dd-popup/dd-popup.vue'
|
|
61
80
|
import DdButton from '../dd-button/dd-button.vue'
|
|
81
|
+
import { pickAvatarHue, avatarText as calcAvatarText } from '../../libs/utils'
|
|
62
82
|
import {
|
|
63
83
|
type PackageSkuGroup,
|
|
64
84
|
type PackageSkuItem,
|
|
@@ -68,6 +88,7 @@ import {
|
|
|
68
88
|
isItemDisabled,
|
|
69
89
|
groupHint,
|
|
70
90
|
groupMax,
|
|
91
|
+
nextSelection,
|
|
71
92
|
isGroupSatisfied,
|
|
72
93
|
canConfirm as calcCanConfirm,
|
|
73
94
|
unmetText,
|
|
@@ -80,6 +101,8 @@ import {
|
|
|
80
101
|
interface Props {
|
|
81
102
|
/** 选择组列表 */
|
|
82
103
|
groups?: PackageSkuGroup[]
|
|
104
|
+
/** 套餐主图/底价/库存(与 dd-goods-sku 对齐:image|picture / price|price_fee / stock|quantity) */
|
|
105
|
+
goodsInfo?: Record<string, any>
|
|
83
106
|
/** 弹层标题 */
|
|
84
107
|
title?: string
|
|
85
108
|
/** 确认按钮文字 */
|
|
@@ -90,6 +113,7 @@ interface Props {
|
|
|
90
113
|
|
|
91
114
|
const props = withDefaults(defineProps<Props>(), {
|
|
92
115
|
groups: () => [],
|
|
116
|
+
goodsInfo: () => ({}),
|
|
93
117
|
title: '选择套餐内容',
|
|
94
118
|
confirmText: '确定',
|
|
95
119
|
closeable: true,
|
|
@@ -108,6 +132,28 @@ const selections = reactive<PackageSkuSelections>({})
|
|
|
108
132
|
const canConfirmNow = computed(() => calcCanConfirm(props.groups, selections))
|
|
109
133
|
const unmetTip = computed(() => unmetText(props.groups, selections))
|
|
110
134
|
|
|
135
|
+
/** 头部(对齐 dd-goods-sku):传了 goodsInfo 才渲染,存量调用方零改动不显示 */
|
|
136
|
+
const hasHeader = computed(() => Object.keys(props.goodsInfo).length > 0)
|
|
137
|
+
const headerImage = computed(() => props.goodsInfo.image || props.goodsInfo.picture || '')
|
|
138
|
+
/** 缺图时文字占位块:每次 open 从主题 6 档基色随机取底色(libs/utils + dd-avatar-colors mixin) */
|
|
139
|
+
const avatarHue = ref<string>(pickAvatarHue())
|
|
140
|
+
/** 占位文字:取套餐名前 2 字 */
|
|
141
|
+
const avatarText = computed(() => calcAvatarText(props.goodsInfo.name))
|
|
142
|
+
/** 展示价(元)= 套餐底价 + 已选 OPTIONAL 项加价合计;按分相加再除 100,避免浮点误差 */
|
|
143
|
+
const surchargeFen = computed(() => computeSurchargeFen(props.groups, selections))
|
|
144
|
+
const price = computed(
|
|
145
|
+
() =>
|
|
146
|
+
(Math.round((props.goodsInfo.price ?? props.goodsInfo.price_fee ?? 0) * 100) +
|
|
147
|
+
surchargeFen.value) /
|
|
148
|
+
100,
|
|
149
|
+
)
|
|
150
|
+
/** 划线原价(元):套餐级营销价,不随加价联动;originPrice|origin_price,缺省不显示 */
|
|
151
|
+
const originPrice = computed(() => props.goodsInfo.originPrice || props.goodsInfo.origin_price || '')
|
|
152
|
+
/** 库存:缺省不显示库存行(套餐可能无台账库存,如房时套餐) */
|
|
153
|
+
const stock = computed(() => props.goodsInfo.stock ?? props.goodsInfo.quantity)
|
|
154
|
+
/** 已选项实时摘要(确认前即联动展示) */
|
|
155
|
+
const selectedText = computed(() => buildSelectedText(props.groups, selections))
|
|
156
|
+
|
|
111
157
|
// 模板内避免复杂表达式(小程序约束),逐一下沉为方法
|
|
112
158
|
function isFixedGroup(group: PackageSkuGroup): boolean {
|
|
113
159
|
return isFixed(group)
|
|
@@ -132,17 +178,12 @@ function isSelected(group: PackageSkuGroup, item: PackageSkuItem): boolean {
|
|
|
132
178
|
function onItemClick(group: PackageSkuGroup, item: PackageSkuItem): void {
|
|
133
179
|
if (isFixed(group) || isItemDisabled(item)) return
|
|
134
180
|
const key = String(group.id)
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
if (at >= 0) {
|
|
138
|
-
selected.splice(at, 1)
|
|
139
|
-
} else if (selected.length >= groupMax(group)) {
|
|
181
|
+
const next = nextSelection(group, selections[key] ?? [], item.id)
|
|
182
|
+
if (next === null) {
|
|
140
183
|
uni.showToast({ title: `最多选择${groupMax(group)}项`, icon: 'none' })
|
|
141
184
|
return
|
|
142
|
-
} else {
|
|
143
|
-
selected.push(item.id)
|
|
144
185
|
}
|
|
145
|
-
selections[key] =
|
|
186
|
+
selections[key] = next
|
|
146
187
|
}
|
|
147
188
|
|
|
148
189
|
function reset(): void {
|
|
@@ -150,6 +191,7 @@ function reset(): void {
|
|
|
150
191
|
}
|
|
151
192
|
|
|
152
193
|
function open(): void {
|
|
194
|
+
avatarHue.value = pickAvatarHue()
|
|
153
195
|
show.value = true
|
|
154
196
|
emit('open')
|
|
155
197
|
}
|
|
@@ -190,6 +232,79 @@ defineExpose({ open, close, reset })
|
|
|
190
232
|
color: var(--dd-text-primary, #{$dd-text-primary});
|
|
191
233
|
}
|
|
192
234
|
|
|
235
|
+
&__header {
|
|
236
|
+
display: flex;
|
|
237
|
+
flex-direction: row;
|
|
238
|
+
padding: 20rpx 0;
|
|
239
|
+
|
|
240
|
+
&__image {
|
|
241
|
+
width: 180rpx;
|
|
242
|
+
height: 180rpx;
|
|
243
|
+
border-radius: 10rpx;
|
|
244
|
+
overflow: hidden;
|
|
245
|
+
margin-right: 20rpx;
|
|
246
|
+
display: flex;
|
|
247
|
+
align-items: center;
|
|
248
|
+
justify-content: center;
|
|
249
|
+
|
|
250
|
+
image {
|
|
251
|
+
width: 100%;
|
|
252
|
+
height: 100%;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
&__text {
|
|
256
|
+
font-size: 56rpx;
|
|
257
|
+
font-weight: bold;
|
|
258
|
+
line-height: 1;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
@include dd-avatar-colors;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
&__info {
|
|
265
|
+
flex: 1;
|
|
266
|
+
|
|
267
|
+
&__price {
|
|
268
|
+
display: flex;
|
|
269
|
+
flex-direction: row;
|
|
270
|
+
align-items: baseline;
|
|
271
|
+
margin-bottom: 20rpx;
|
|
272
|
+
|
|
273
|
+
&__symbol {
|
|
274
|
+
font-size: 24rpx;
|
|
275
|
+
color: var(--dd-error-400, #{$dd-error-400});
|
|
276
|
+
margin-right: 4rpx;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
&__value {
|
|
280
|
+
font-size: 36rpx;
|
|
281
|
+
color: var(--dd-error-400, #{$dd-error-400});
|
|
282
|
+
font-weight: bold;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// 划线原价(样式对齐 dd-goods-card / dd-goods-sku)
|
|
286
|
+
&__origin {
|
|
287
|
+
margin-left: $dd-space-2;
|
|
288
|
+
color: var(--dd-text-tertiary, #{$dd-text-tertiary});
|
|
289
|
+
font-size: 22rpx;
|
|
290
|
+
font-weight: 400;
|
|
291
|
+
text-decoration: line-through;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
&__stock {
|
|
296
|
+
font-size: 26rpx;
|
|
297
|
+
color: var(--dd-text-tertiary, #{$dd-text-tertiary});
|
|
298
|
+
margin-bottom: 20rpx;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
&__selected {
|
|
302
|
+
font-size: 26rpx;
|
|
303
|
+
color: var(--dd-text-primary, #{$dd-text-primary});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
193
308
|
&__content {
|
|
194
309
|
max-height: 640rpx;
|
|
195
310
|
padding-bottom: 10rpx;
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
export interface PackageSkuItem {
|
|
5
5
|
id: string | number
|
|
6
6
|
name: string
|
|
7
|
-
/**
|
|
7
|
+
/** 加价金额(分/每份,ADR-0026),0/缺省 = 不加价 */
|
|
8
8
|
priceFen?: number
|
|
9
9
|
/** 库存数量,<=0 置灰;缺省视为有货 */
|
|
10
10
|
qty?: number
|
|
11
|
+
/** 单次选中份数(选中一次即 N 份,仅影响摘要文案与加价合计),缺省 1;与 qty(库存)正交 */
|
|
12
|
+
perQty?: number
|
|
11
13
|
/** false 置灰;缺省视为可用 */
|
|
12
14
|
enabled?: boolean
|
|
13
15
|
}
|
|
@@ -58,6 +60,31 @@ export function groupHint(group: PackageSkuGroup): string {
|
|
|
58
60
|
return `最多选${max}项`
|
|
59
61
|
}
|
|
60
62
|
|
|
63
|
+
/** 单选组:上限为 1 的 OPTIONAL 组(N选1),点非选中项直接替换选中,无需先取消 */
|
|
64
|
+
export function isSingleSelect(group: PackageSkuGroup): boolean {
|
|
65
|
+
return !isFixed(group) && groupMax(group) === 1
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 点击可选项后的新选中集(纯逻辑,供组件与自检共用)
|
|
70
|
+
* 返回 null 表示多选上限拦截;FIXED/售罄由调用方先行拦截,不在此处理
|
|
71
|
+
*/
|
|
72
|
+
export function nextSelection(
|
|
73
|
+
group: PackageSkuGroup,
|
|
74
|
+
selected: (string | number)[],
|
|
75
|
+
itemId: string | number,
|
|
76
|
+
): (string | number)[] | null {
|
|
77
|
+
const at = selected.indexOf(itemId)
|
|
78
|
+
if (at >= 0) {
|
|
79
|
+
const copy = selected.slice()
|
|
80
|
+
copy.splice(at, 1)
|
|
81
|
+
return copy
|
|
82
|
+
}
|
|
83
|
+
if (isSingleSelect(group)) return [itemId]
|
|
84
|
+
if (selected.length >= groupMax(group)) return null
|
|
85
|
+
return [...selected, itemId]
|
|
86
|
+
}
|
|
87
|
+
|
|
61
88
|
/** 组是否已选满最低要求(上限在点击时拦截,不会超) */
|
|
62
89
|
export function isGroupSatisfied(group: PackageSkuGroup, selections: PackageSkuSelections): boolean {
|
|
63
90
|
if (isFixed(group)) return true
|
|
@@ -90,33 +117,35 @@ export function buildOptions(groups: PackageSkuGroup[], selections: PackageSkuSe
|
|
|
90
117
|
return options
|
|
91
118
|
}
|
|
92
119
|
|
|
93
|
-
/** 已选 OPTIONAL
|
|
120
|
+
/** 已选 OPTIONAL 项加价合计(分):每份加价 × 单次选中份数(与服务端口径同源,ADR-0026) */
|
|
94
121
|
export function computeSurchargeFen(groups: PackageSkuGroup[], selections: PackageSkuSelections): number {
|
|
95
122
|
let sum = 0
|
|
96
123
|
for (const g of groups) {
|
|
97
124
|
if (isFixed(g)) continue
|
|
98
125
|
for (const skuId of selections[String(g.id)] ?? []) {
|
|
99
126
|
const item = g.items.find((it) => it.id === skuId)
|
|
100
|
-
sum += item?.priceFen ?? 0
|
|
127
|
+
sum += (item?.priceFen ?? 0) * (item?.perQty ?? 1)
|
|
101
128
|
}
|
|
102
129
|
}
|
|
103
130
|
return sum
|
|
104
131
|
}
|
|
105
132
|
|
|
106
|
-
/** 已选 OPTIONAL
|
|
133
|
+
/** 已选 OPTIONAL 项名称顿号拼接;单次选中份数 >1 时带 ×N */
|
|
107
134
|
export function buildSelectedText(groups: PackageSkuGroup[], selections: PackageSkuSelections): string {
|
|
108
135
|
const names: string[] = []
|
|
109
136
|
for (const g of groups) {
|
|
110
137
|
if (isFixed(g)) continue
|
|
111
138
|
for (const skuId of selections[String(g.id)] ?? []) {
|
|
112
139
|
const item = g.items.find((it) => it.id === skuId)
|
|
113
|
-
if (item)
|
|
140
|
+
if (!item) continue
|
|
141
|
+
const n = item.perQty ?? 1
|
|
142
|
+
names.push(n > 1 ? `${item.name}×${n}` : item.name)
|
|
114
143
|
}
|
|
115
144
|
}
|
|
116
145
|
return names.join('、')
|
|
117
146
|
}
|
|
118
147
|
|
|
119
|
-
/** 加价标签:「+¥X
|
|
148
|
+
/** 加价标签:「+¥X」(元,去尾零)——每份口径(perQty>1 时实收为 X×N,合计预览兜底),无加价返回空串 */
|
|
120
149
|
export function surchargeLabel(item: PackageSkuItem): string {
|
|
121
150
|
const fen = item.priceFen ?? 0
|
|
122
151
|
if (fen <= 0) return ''
|
package/index.ts
CHANGED
|
@@ -43,7 +43,7 @@ import DdDropdownItem from './components/dd-dropdown-item/dd-dropdown-item.vue'
|
|
|
43
43
|
import DdSidebar from './components/dd-sidebar/dd-sidebar.vue'
|
|
44
44
|
import DdSidebarItem from './components/dd-sidebar-item/dd-sidebar-item.vue'
|
|
45
45
|
|
|
46
|
-
// === Layout (
|
|
46
|
+
// === Layout (11) ===
|
|
47
47
|
import DdCard from './components/dd-card/dd-card.vue'
|
|
48
48
|
import DdRoomCard from './components/dd-room-card/dd-room-card.vue'
|
|
49
49
|
import DdGoodsCard from './components/dd-goods-card/dd-goods-card.vue'
|
|
@@ -54,6 +54,7 @@ import DdWorkorderCard from './components/dd-workorder-card/dd-workorder-card.vu
|
|
|
54
54
|
import DdCalendar from './components/dd-calendar/dd-calendar.vue'
|
|
55
55
|
import DdQrcode from './components/dd-qrcode/dd-qrcode.vue'
|
|
56
56
|
import DdSubmitBar from './components/dd-submit-bar/dd-submit-bar.vue'
|
|
57
|
+
import DdCartBar from './components/dd-cart-bar/dd-cart-bar.vue'
|
|
57
58
|
|
|
58
59
|
// === Display (25) ===
|
|
59
60
|
import DdTag from './components/dd-tag/dd-tag.vue'
|
|
@@ -124,6 +125,7 @@ const components = {
|
|
|
124
125
|
DdSidebar, DdSidebarItem,
|
|
125
126
|
DdCard, DdRoomCard, DdGoodsCard, DdFeatureGrid, DdSticky, DdBillDetail, DdWorkorderCard, DdCalendar, DdQrcode,
|
|
126
127
|
DdSubmitBar,
|
|
128
|
+
DdCartBar,
|
|
127
129
|
DdTag, DdStatCard, DdChampionCard, DdAvatar, DdAvatarGroup, DdBadge,
|
|
128
130
|
DdListCell, DdCell, DdCellGroup, DdCountDown, DdDivider,
|
|
129
131
|
DdImage, DdProgress, DdSkeleton, DdEmptyState, DdStep, DdSteps,
|
|
@@ -156,6 +158,7 @@ export {
|
|
|
156
158
|
DdSidebar, DdSidebarItem,
|
|
157
159
|
DdCard, DdRoomCard, DdGoodsCard, DdFeatureGrid, DdSticky, DdBillDetail, DdWorkorderCard, DdCalendar, DdQrcode,
|
|
158
160
|
DdSubmitBar,
|
|
161
|
+
DdCartBar,
|
|
159
162
|
DdTag, DdStatCard, DdChampionCard, DdAvatar, DdAvatarGroup, DdBadge,
|
|
160
163
|
DdListCell, DdCell, DdCellGroup, DdCountDown, DdDivider,
|
|
161
164
|
DdImage, DdProgress, DdSkeleton, DdEmptyState, DdStep, DdSteps,
|
|
@@ -184,5 +187,8 @@ export type {
|
|
|
184
187
|
PackageSkuOption,
|
|
185
188
|
} from './components/dd-package-sku/package-sku'
|
|
186
189
|
|
|
190
|
+
// 购物车条目类型(dd-cart-bar 配套)
|
|
191
|
+
export type { DdCartItem } from './components/dd-cart-bar/cart-bar'
|
|
192
|
+
|
|
187
193
|
// 图标元数据(供 demo/文档消费,与 dd-icon.vue 内 SCSS &-- 规则保持一致)
|
|
188
194
|
export { iconNames, iconGroups, iconLabels } from './components/dd-icon/dd-icon.vue'
|
package/libs/utils.ts
CHANGED
|
@@ -136,6 +136,23 @@ export function daysInMonth(year: number, month: number): number {
|
|
|
136
136
|
return new Date(year, month + 1, 0).getDate()
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
// ============================================================
|
|
140
|
+
// 缺图文字占位(供 dd-goods-sku / dd-goods-card / dd-package-sku 图块使用)
|
|
141
|
+
// 底色档位与 scss 的 dd-avatar-colors mixin 一一对应:bg=主题基色、文字=各自 contrast
|
|
142
|
+
// ============================================================
|
|
143
|
+
export const AVATAR_HUES = ['primary', 'accent', 'success', 'warning', 'error', 'info'] as const
|
|
144
|
+
export type AvatarHue = (typeof AVATAR_HUES)[number]
|
|
145
|
+
|
|
146
|
+
/** 随机取一种占位底色档位 */
|
|
147
|
+
export function pickAvatarHue(): AvatarHue {
|
|
148
|
+
return AVATAR_HUES[Math.floor(Math.random() * AVATAR_HUES.length)]
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** 占位文字:取名称前 2 字 */
|
|
152
|
+
export function avatarText(name?: string): string {
|
|
153
|
+
return String(name ?? '').slice(0, 2)
|
|
154
|
+
}
|
|
155
|
+
|
|
139
156
|
// ============================================================
|
|
140
157
|
// 二维码(QR Code)生成 — 纯 JS,无三方依赖
|
|
141
158
|
// port: 移植自 Project Nayuki QR Code generator(public domain,qrcodegen)。
|
package/package.json
CHANGED
package/scss/_mixins.scss
CHANGED
|
@@ -152,3 +152,14 @@
|
|
|
152
152
|
pointer-events: none;
|
|
153
153
|
user-select: none;
|
|
154
154
|
}
|
|
155
|
+
|
|
156
|
+
// 缺图文字占位底色:6 档主题基色 + 各自 contrast 文字色(配套 libs/utils.ts 的 AVATAR_HUES,
|
|
157
|
+
// 随机命中其一;运行时可换肤,明暗主题自动跟随)
|
|
158
|
+
@mixin dd-avatar-colors {
|
|
159
|
+
&--primary { background-color: var(--dd-primary, #{$dd-primary}); color: var(--dd-primary-contrast, #{$dd-primary-contrast}); }
|
|
160
|
+
&--accent { background-color: var(--dd-accent, #{$dd-accent}); color: var(--dd-accent-contrast, #{$dd-accent-contrast}); }
|
|
161
|
+
&--success { background-color: var(--dd-success, #{$dd-success}); color: var(--dd-success-contrast, #{$dd-success-contrast}); }
|
|
162
|
+
&--warning { background-color: var(--dd-warning, #{$dd-warning}); color: var(--dd-warning-contrast, #{$dd-warning-contrast}); }
|
|
163
|
+
&--error { background-color: var(--dd-error, #{$dd-error}); color: var(--dd-error-contrast, #{$dd-error-contrast}); }
|
|
164
|
+
&--info { background-color: var(--dd-info, #{$dd-info}); color: var(--dd-info-contrast, #{$dd-info-contrast}); }
|
|
165
|
+
}
|