mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-25 07:49:15 +08:00
feat(Sku): add stockThreshold prop (#4444)
This commit is contained in:
parent
927bf464bf
commit
54353f4210
@ -126,6 +126,7 @@ export default {
|
||||
| hide-stock | Whether to hide stock | *boolean* | `false` | - |
|
||||
| hide-quota-text | Whether to hide quota text | *boolean* | `false` | - |
|
||||
| hide-selected-text | Whether to hide selected text | *boolean* | `false` | - |
|
||||
| stock-threshold | stock threshold | *boolean* | `50` | - |
|
||||
| show-add-cart-btn | Whether to show cart button | *boolean* | `true` | - |
|
||||
| buy-text | Buy button text | *string* | - | - | - |
|
||||
| add-cart-text | Add cart button text | *string* | - | - | - |
|
||||
|
@ -128,6 +128,7 @@ export default {
|
||||
| hide-stock | 是否显示商品剩余库存 | *boolean* | `false` | - |
|
||||
| hide-quota-text | 是否显示限购提示 | *boolean* | `false` | - |
|
||||
| hide-selected-text | 是否隐藏已选提示 | *boolean* | `false` | - |
|
||||
| stock-threshold | 库存阈值。低于这个值会把库存数高亮显示 | *boolean* | `50` | - |
|
||||
| show-add-cart-btn | 是否显示加入购物车按钮 | *boolean* | `true` | - |
|
||||
| buy-text | 购买按钮文字 | *string* | `立即购买` | - |
|
||||
| add-cart-text | 加入购物车按钮文字 | *string* | `加入购物车` | - |
|
||||
|
@ -14,8 +14,7 @@ import { isAllSelected, isSkuChoosable, getSkuComb, getSelectedSkuValues } from
|
||||
import { LIMIT_TYPE, UNSELECTED_SKU_VALUE_ID } from './constants';
|
||||
|
||||
const namespace = createNamespace('sku');
|
||||
const createComponent = namespace[0];
|
||||
const t = namespace[2];
|
||||
const [createComponent, bem, t] = namespace;
|
||||
const { QUOTA_LIMIT } = LIMIT_TYPE;
|
||||
|
||||
export default createComponent({
|
||||
@ -50,6 +49,10 @@ export default createComponent({
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
stockThreshold: {
|
||||
type: Number,
|
||||
default: 50,
|
||||
},
|
||||
showSoldoutSku: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
@ -224,7 +227,13 @@ export default createComponent({
|
||||
const { stockFormatter } = this.customStepperConfig;
|
||||
if (stockFormatter) return stockFormatter(this.stock);
|
||||
|
||||
return t('stock', this.stock);
|
||||
return [
|
||||
`${t('stock')} `,
|
||||
<span class={bem('stock-num', { highlight: this.stock < this.stockThreshold })}>
|
||||
{this.stock}
|
||||
</span>,
|
||||
` ${t('stockUnit')}`
|
||||
];
|
||||
},
|
||||
|
||||
quotaText() {
|
||||
|
@ -213,6 +213,10 @@
|
||||
margin-right: @padding-xs;
|
||||
color: @gray-dark;
|
||||
font-size: @font-size-sm;
|
||||
|
||||
&-num--highlight {
|
||||
color: @red;
|
||||
}
|
||||
}
|
||||
|
||||
&__quota {
|
||||
|
@ -12,7 +12,8 @@ export default {
|
||||
originPrice: '原价',
|
||||
minusTip: '至少选择一件',
|
||||
unavailable: '商品已经无法购买啦',
|
||||
stock: (stock: number) => `剩余 ${stock}件`,
|
||||
stock: '剩余',
|
||||
stockUnit: '件',
|
||||
quotaLimit: (quota: number) => `每人限购${quota}件`,
|
||||
quotaCount: (count: number) => `你已购买${count}件`
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user