mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore: prettier js codes
This commit is contained in:
parent
2adcfd8b8b
commit
1e864a445f
@ -112,12 +112,12 @@ export default createComponent({
|
|||||||
|
|
||||||
if (this.placeholderMap[type] && result.length) {
|
if (this.placeholderMap[type] && result.length) {
|
||||||
// set columns placeholder
|
// set columns placeholder
|
||||||
const codeFill =
|
let codeFill = '';
|
||||||
type === 'province'
|
if (type === 'city') {
|
||||||
? ''
|
codeFill = PLACEHOLDER_CODE.slice(2, 4);
|
||||||
: type === 'city'
|
} else if (type === 'county') {
|
||||||
? PLACEHOLDER_CODE.slice(2, 4)
|
codeFill = PLACEHOLDER_CODE.slice(4, 6);
|
||||||
: PLACEHOLDER_CODE.slice(4, 6);
|
}
|
||||||
|
|
||||||
result.unshift({
|
result.unshift({
|
||||||
code: `${code}${codeFill}`,
|
code: `${code}${codeFill}`,
|
||||||
|
@ -4,16 +4,21 @@ import { CheckboxMixin } from '../mixins/checkbox';
|
|||||||
const [createComponent, bem] = createNamespace('checkbox');
|
const [createComponent, bem] = createNamespace('checkbox');
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
mixins: [CheckboxMixin({
|
mixins: [
|
||||||
bem,
|
CheckboxMixin({
|
||||||
role: 'checkbox',
|
bem,
|
||||||
parent: 'vanCheckbox',
|
role: 'checkbox',
|
||||||
})],
|
parent: 'vanCheckbox',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
checked: {
|
checked: {
|
||||||
get() {
|
get() {
|
||||||
return this.parent ? this.parent.value.indexOf(this.name) !== -1 : this.value;
|
if (this.parent) {
|
||||||
|
return this.parent.value.indexOf(this.name) !== -1;
|
||||||
|
}
|
||||||
|
return this.value;
|
||||||
},
|
},
|
||||||
|
|
||||||
set(val) {
|
set(val) {
|
||||||
|
@ -106,9 +106,10 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { parent, currentName } = this;
|
const { parent, currentName } = this;
|
||||||
const name = parent.accordion && currentName === parent.value ? '' : currentName;
|
const close = parent.accordion && currentName === parent.value;
|
||||||
|
const name = close ? '' : currentName;
|
||||||
|
|
||||||
this.parent.switch(name, !this.expanded);
|
parent.switch(name, !this.expanded);
|
||||||
},
|
},
|
||||||
|
|
||||||
onTransitionEnd() {
|
onTransitionEnd() {
|
||||||
|
@ -182,7 +182,10 @@ export default createComponent({
|
|||||||
|
|
||||||
const CouponTab = (
|
const CouponTab = (
|
||||||
<Tab title={title}>
|
<Tab title={title}>
|
||||||
<div class={bem('list', { 'with-bottom': this.showCloseButton })} style={this.listStyle}>
|
<div
|
||||||
|
class={bem('list', { 'with-bottom': this.showCloseButton })}
|
||||||
|
style={this.listStyle}
|
||||||
|
>
|
||||||
{coupons.map((coupon, index) => (
|
{coupons.map((coupon, index) => (
|
||||||
<Coupon
|
<Coupon
|
||||||
ref="card"
|
ref="card"
|
||||||
@ -200,7 +203,10 @@ export default createComponent({
|
|||||||
|
|
||||||
const DisabledCouponTab = (
|
const DisabledCouponTab = (
|
||||||
<Tab title={disabledTitle}>
|
<Tab title={disabledTitle}>
|
||||||
<div class={bem('list', { 'with-bottom': this.showCloseButton })} style={this.listStyle}>
|
<div
|
||||||
|
class={bem('list', { 'with-bottom': this.showCloseButton })}
|
||||||
|
style={this.listStyle}
|
||||||
|
>
|
||||||
{disabledCoupons.map(coupon => (
|
{disabledCoupons.map(coupon => (
|
||||||
<Coupon
|
<Coupon
|
||||||
disabled
|
disabled
|
||||||
|
@ -17,7 +17,9 @@ function formatDiscount(discount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatAmount(amount) {
|
function formatAmount(amount) {
|
||||||
return (amount / 100).toFixed(amount % 100 === 0 ? 0 : amount % 10 === 0 ? 1 : 2);
|
return (amount / 100).toFixed(
|
||||||
|
amount % 100 === 0 ? 0 : amount % 10 === 0 ? 1 : 2
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
@ -45,7 +47,8 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (coupon.denominations) {
|
if (coupon.denominations) {
|
||||||
return `<span>${this.currency}</span> ${formatAmount(this.coupon.denominations)}`;
|
const denominations = formatAmount(this.coupon.denominations);
|
||||||
|
return `<span>${this.currency}</span> ${denominations}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coupon.discount) {
|
if (coupon.discount) {
|
||||||
@ -70,13 +73,20 @@ export default createComponent({
|
|||||||
<div class={bem('content')}>
|
<div class={bem('content')}>
|
||||||
<div class={bem('head')}>
|
<div class={bem('head')}>
|
||||||
<h2 class={bem('amount')} domPropsInnerHTML={this.faceAmount} />
|
<h2 class={bem('amount')} domPropsInnerHTML={this.faceAmount} />
|
||||||
<p class={bem('condition')}>{this.coupon.condition || this.conditionMessage}</p>
|
<p class={bem('condition')}>
|
||||||
|
{this.coupon.condition || this.conditionMessage}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class={bem('body')}>
|
<div class={bem('body')}>
|
||||||
<p class={bem('name')}>{coupon.name}</p>
|
<p class={bem('name')}>{coupon.name}</p>
|
||||||
<p class={bem('valid')}>{this.validPeriod}</p>
|
<p class={bem('valid')}>{this.validPeriod}</p>
|
||||||
{!this.disabled && (
|
{!this.disabled && (
|
||||||
<Checkbox value={this.chosen} class={bem('corner')} size={18} checked-color={RED} />
|
<Checkbox
|
||||||
|
value={this.chosen}
|
||||||
|
class={bem('corner')}
|
||||||
|
size={18}
|
||||||
|
checked-color={RED}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -44,15 +44,21 @@ export default createComponent({
|
|||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
ranges() {
|
ranges() {
|
||||||
const { maxYear, maxDate, maxMonth, maxHour, maxMinute } = this.getBoundary(
|
const {
|
||||||
'max',
|
maxYear,
|
||||||
this.innerValue
|
maxDate,
|
||||||
);
|
maxMonth,
|
||||||
|
maxHour,
|
||||||
|
maxMinute,
|
||||||
|
} = this.getBoundary('max', this.innerValue);
|
||||||
|
|
||||||
const { minYear, minDate, minMonth, minHour, minMinute } = this.getBoundary(
|
const {
|
||||||
'min',
|
minYear,
|
||||||
this.innerValue
|
minDate,
|
||||||
);
|
minMonth,
|
||||||
|
minHour,
|
||||||
|
minMinute,
|
||||||
|
} = this.getBoundary('min', this.innerValue);
|
||||||
|
|
||||||
const result = [
|
const result = [
|
||||||
{
|
{
|
||||||
@ -134,7 +140,11 @@ export default createComponent({
|
|||||||
|
|
||||||
updateInnerValue() {
|
updateInnerValue() {
|
||||||
const indexes = this.getPicker().getIndexes();
|
const indexes = this.getPicker().getIndexes();
|
||||||
const getValue = index => getTrueValue(this.originColumns[index].values[indexes[index]]);
|
|
||||||
|
const getValue = index => {
|
||||||
|
const { values } = this.originColumns[index];
|
||||||
|
return getTrueValue(values[indexes[index]]);
|
||||||
|
};
|
||||||
|
|
||||||
const year = getValue(0);
|
const year = getValue(0);
|
||||||
const month = getValue(1);
|
const month = getValue(1);
|
||||||
|
@ -75,11 +75,12 @@ export default createComponent({
|
|||||||
|
|
||||||
updateInnerValue() {
|
updateInnerValue() {
|
||||||
const [hourIndex, minuteIndex] = this.getPicker().getIndexes();
|
const [hourIndex, minuteIndex] = this.getPicker().getIndexes();
|
||||||
const hour = this.originColumns[0].values[hourIndex] || this.originColumns[0].values[0];
|
const [hourColumn, minuteColumn] = this.originColumns;
|
||||||
const minute = this.originColumns[1].values[minuteIndex] || this.originColumns[1].values[0];
|
|
||||||
const value = `${hour}:${minute}`;
|
|
||||||
|
|
||||||
this.innerValue = this.formatValue(value);
|
const hour = hourColumn.values[hourIndex] || hourColumn.values[0];
|
||||||
|
const minute = minuteColumn.values[minuteIndex] || minuteColumn.values[0];
|
||||||
|
|
||||||
|
this.innerValue = this.formatValue(`${hour}:${minute}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange(picker) {
|
onChange(picker) {
|
||||||
|
@ -103,7 +103,9 @@ export default createComponent({
|
|||||||
const title = this.slots('title') || this.title;
|
const title = this.slots('title') || this.title;
|
||||||
|
|
||||||
const Title = title && (
|
const Title = title && (
|
||||||
<div class={bem('header', { isolated: !message && !messageSlot })}>{title}</div>
|
<div class={bem('header', { isolated: !message && !messageSlot })}>
|
||||||
|
{title}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const Content = (messageSlot || message) && (
|
const Content = (messageSlot || message) && (
|
||||||
@ -111,7 +113,10 @@ export default createComponent({
|
|||||||
{messageSlot || (
|
{messageSlot || (
|
||||||
<div
|
<div
|
||||||
domPropsInnerHTML={message}
|
domPropsInnerHTML={message}
|
||||||
class={bem('message', { 'has-title': title, [messageAlign]: messageAlign })}
|
class={bem('message', {
|
||||||
|
'has-title': title,
|
||||||
|
[messageAlign]: messageAlign,
|
||||||
|
})}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -73,10 +73,11 @@ Dialog.defaultOptions = {
|
|||||||
|
|
||||||
Dialog.alert = Dialog;
|
Dialog.alert = Dialog;
|
||||||
|
|
||||||
Dialog.confirm = options => Dialog({
|
Dialog.confirm = options =>
|
||||||
showCancelButton: true,
|
Dialog({
|
||||||
...options,
|
showCancelButton: true,
|
||||||
});
|
...options,
|
||||||
|
});
|
||||||
|
|
||||||
Dialog.close = () => {
|
Dialog.close = () => {
|
||||||
if (instance) {
|
if (instance) {
|
||||||
|
@ -102,7 +102,9 @@ export default createComponent({
|
|||||||
]}
|
]}
|
||||||
style={{ color: item.showPopup ? this.activeColor : '' }}
|
style={{ color: item.showPopup ? this.activeColor : '' }}
|
||||||
>
|
>
|
||||||
<div class="van-ellipsis">{item.slots('title') || item.displayTitle}</div>
|
<div class="van-ellipsis">
|
||||||
|
{item.slots('title') || item.displayTitle}
|
||||||
|
</div>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
));
|
));
|
||||||
|
@ -87,6 +87,18 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getText() {
|
||||||
|
const textSlot = this.slots('text');
|
||||||
|
|
||||||
|
if (textSlot) {
|
||||||
|
return textSlot;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.text) {
|
||||||
|
return <span class={bem('text')}>{this.text}</span>;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
genContent() {
|
genContent() {
|
||||||
const slot = this.slots();
|
const slot = this.slots();
|
||||||
|
|
||||||
@ -94,10 +106,7 @@ export default createComponent({
|
|||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [this.genIcon(), this.getText()];
|
||||||
this.genIcon(),
|
|
||||||
this.slots('text') || (this.text && <span class={bem('text')}>{this.text}</span>),
|
|
||||||
];
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -109,9 +109,21 @@ export default createComponent({
|
|||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
const iconName = mode === 'closeable' ? 'cross' : mode === 'link' ? 'arrow' : '';
|
let iconName;
|
||||||
|
if (mode === 'closeable') {
|
||||||
|
iconName = 'cross';
|
||||||
|
} else if (mode === 'link') {
|
||||||
|
iconName = 'arrow';
|
||||||
|
}
|
||||||
|
|
||||||
if (iconName) {
|
if (iconName) {
|
||||||
return <Icon class={bem('right-icon')} name={iconName} onClick={onClickIcon} />;
|
return (
|
||||||
|
<Icon
|
||||||
|
class={bem('right-icon')}
|
||||||
|
name={iconName}
|
||||||
|
onClick={onClickIcon}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,10 +145,17 @@ export default createComponent({
|
|||||||
|
|
||||||
const Title = showTitle && (
|
const Title = showTitle && (
|
||||||
<div class={[bem('title'), BORDER_TOP]}>
|
<div class={[bem('title'), BORDER_TOP]}>
|
||||||
{titleLeftSlot && <span class={bem('title-left')}>{titleLeftSlot}</span>}
|
{titleLeftSlot && (
|
||||||
|
<span class={bem('title-left')}>{titleLeftSlot}</span>
|
||||||
|
)}
|
||||||
{title && <span>{title}</span>}
|
{title && <span>{title}</span>}
|
||||||
{showTitleClose && (
|
{showTitleClose && (
|
||||||
<span role="button" tabindex="0" class={bem('close')} onClick={this.onClose}>
|
<span
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
class={bem('close')}
|
||||||
|
onClick={this.onClose}
|
||||||
|
>
|
||||||
{closeButtonText}
|
{closeButtonText}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
@ -192,7 +199,10 @@ export default createComponent({
|
|||||||
<div
|
<div
|
||||||
vShow={this.show}
|
vShow={this.show}
|
||||||
style={{ zIndex: this.zIndex }}
|
style={{ zIndex: this.zIndex }}
|
||||||
class={bem([theme, { 'safe-area-inset-bottom': this.safeAreaInsetBottom }])}
|
class={bem([
|
||||||
|
theme,
|
||||||
|
{ 'safe-area-inset-bottom': this.safeAreaInsetBottom },
|
||||||
|
])}
|
||||||
onTouchstart={stopPropagation}
|
onTouchstart={stopPropagation}
|
||||||
onAnimationend={this.onAnimationEnd}
|
onAnimationend={this.onAnimationEnd}
|
||||||
onWebkitAnimationEnd={this.onAnimationEnd}
|
onWebkitAnimationEnd={this.onAnimationEnd}
|
||||||
|
@ -40,7 +40,8 @@ export default createComponent({
|
|||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
count() {
|
count() {
|
||||||
const count = this.pageCount || Math.ceil(this.totalItems / this.itemsPerPage);
|
const count =
|
||||||
|
this.pageCount || Math.ceil(this.totalItems / this.itemsPerPage);
|
||||||
return Math.max(1, count);
|
return Math.max(1, count);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -55,7 +56,8 @@ export default createComponent({
|
|||||||
// Default page limits
|
// Default page limits
|
||||||
let startPage = 1;
|
let startPage = 1;
|
||||||
let endPage = pageCount;
|
let endPage = pageCount;
|
||||||
const isMaxSized = this.showPageSize !== undefined && this.showPageSize < pageCount;
|
const isMaxSized =
|
||||||
|
this.showPageSize !== undefined && this.showPageSize < pageCount;
|
||||||
|
|
||||||
// recompute if showPageSize
|
// recompute if showPageSize
|
||||||
if (isMaxSized) {
|
if (isMaxSized) {
|
||||||
@ -140,10 +142,16 @@ export default createComponent({
|
|||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
{simple && (
|
{simple && (
|
||||||
<li class={bem('page-desc')}>{this.slots('pageDesc') || `${value}/${this.count}`}</li>
|
<li class={bem('page-desc')}>
|
||||||
|
{this.slots('pageDesc') || `${value}/${this.count}`}
|
||||||
|
</li>
|
||||||
)}
|
)}
|
||||||
<li
|
<li
|
||||||
class={[bem('item', { disabled: value === this.count }), bem('next'), BORDER]}
|
class={[
|
||||||
|
bem('item', { disabled: value === this.count }),
|
||||||
|
bem('next'),
|
||||||
|
BORDER,
|
||||||
|
]}
|
||||||
onClick={onSelect(value + 1)}
|
onClick={onSelect(value + 1)}
|
||||||
>
|
>
|
||||||
{this.nextText || t('next')}
|
{this.nextText || t('next')}
|
||||||
|
@ -180,11 +180,7 @@ export default createComponent({
|
|||||||
return (
|
return (
|
||||||
<div class={[BORDER_TOP_BOTTOM, bem('toolbar')]}>
|
<div class={[BORDER_TOP_BOTTOM, bem('toolbar')]}>
|
||||||
{this.slots() || [
|
{this.slots() || [
|
||||||
<button
|
<button type="button" class={bem('cancel')} onClick={this.cancel}>
|
||||||
type="button"
|
|
||||||
class={bem('cancel')}
|
|
||||||
onClick={this.cancel}
|
|
||||||
>
|
|
||||||
{this.cancelButtonText || t('cancel')}
|
{this.cancelButtonText || t('cancel')}
|
||||||
</button>,
|
</button>,
|
||||||
this.genTitle(),
|
this.genTitle(),
|
||||||
|
@ -4,11 +4,13 @@ import { CheckboxMixin } from '../mixins/checkbox';
|
|||||||
const [createComponent, bem] = createNamespace('radio');
|
const [createComponent, bem] = createNamespace('radio');
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
mixins: [CheckboxMixin({
|
mixins: [
|
||||||
bem,
|
CheckboxMixin({
|
||||||
role: 'radio',
|
bem,
|
||||||
parent: 'vanRadio',
|
role: 'radio',
|
||||||
})],
|
parent: 'vanRadio',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
currentValue: {
|
currentValue: {
|
||||||
|
@ -27,7 +27,9 @@ export default createComponent({
|
|||||||
const { align, justify } = this;
|
const { align, justify } = this;
|
||||||
const flex = this.type === 'flex';
|
const flex = this.type === 'flex';
|
||||||
const margin = `-${Number(this.gutter) / 2}px`;
|
const margin = `-${Number(this.gutter) / 2}px`;
|
||||||
const style = this.gutter ? { marginLeft: margin, marginRight: margin } : {};
|
const style = this.gutter
|
||||||
|
? { marginLeft: margin, marginRight: margin }
|
||||||
|
: {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<this.tag
|
<this.tag
|
||||||
|
@ -162,7 +162,9 @@ export default createComponent({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 属性未全选
|
// 属性未全选
|
||||||
if (this.propList.some(it => (this.selectedProp[it.k_id] || []).length < 1)) {
|
if (
|
||||||
|
this.propList.some(it => (this.selectedProp[it.k_id] || []).length < 1)
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -193,8 +195,14 @@ export default createComponent({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (skuComb) {
|
if (skuComb) {
|
||||||
skuComb.properties = getSelectedProperties(this.propList, this.selectedProp);
|
skuComb.properties = getSelectedProperties(
|
||||||
skuComb.property_price = this.selectedPropValues.reduce((acc, cur) => acc + (cur.price || 0), 0);
|
this.propList,
|
||||||
|
this.selectedProp
|
||||||
|
);
|
||||||
|
skuComb.property_price = this.selectedPropValues.reduce(
|
||||||
|
(acc, cur) => acc + (cur.price || 0),
|
||||||
|
0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return skuComb;
|
return skuComb;
|
||||||
@ -210,7 +218,10 @@ export default createComponent({
|
|||||||
|
|
||||||
price() {
|
price() {
|
||||||
if (this.selectedSkuComb) {
|
if (this.selectedSkuComb) {
|
||||||
return ((this.selectedSkuComb.price + this.selectedSkuComb.property_price) / 100).toFixed(2);
|
return (
|
||||||
|
(this.selectedSkuComb.price + this.selectedSkuComb.property_price) /
|
||||||
|
100
|
||||||
|
).toFixed(2);
|
||||||
}
|
}
|
||||||
// sku.price是一个格式化好的价格区间
|
// sku.price是一个格式化好的价格区间
|
||||||
return this.sku.price;
|
return this.sku.price;
|
||||||
@ -218,7 +229,11 @@ export default createComponent({
|
|||||||
|
|
||||||
originPrice() {
|
originPrice() {
|
||||||
if (this.selectedSkuComb && this.selectedSkuComb.origin_price) {
|
if (this.selectedSkuComb && this.selectedSkuComb.origin_price) {
|
||||||
return ((this.selectedSkuComb.origin_price + this.selectedSkuComb.property_price) / 100).toFixed(2);
|
return (
|
||||||
|
(this.selectedSkuComb.origin_price +
|
||||||
|
this.selectedSkuComb.property_price) /
|
||||||
|
100
|
||||||
|
).toFixed(2);
|
||||||
}
|
}
|
||||||
return this.sku.origin_price;
|
return this.sku.origin_price;
|
||||||
},
|
},
|
||||||
@ -269,7 +284,11 @@ export default createComponent({
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
`${t('stock')} `,
|
`${t('stock')} `,
|
||||||
<span class={bem('stock-num', { highlight: this.stock < this.stockThreshold })}>
|
<span
|
||||||
|
class={bem('stock-num', {
|
||||||
|
highlight: this.stock < this.stockThreshold,
|
||||||
|
})}
|
||||||
|
>
|
||||||
{this.stock}
|
{this.stock}
|
||||||
</span>,
|
</span>,
|
||||||
` ${t('stockUnit')}`,
|
` ${t('stockUnit')}`,
|
||||||
@ -289,7 +308,9 @@ export default createComponent({
|
|||||||
.filter(item => (this.selectedProp[item.k_id] || []).length < 1)
|
.filter(item => (this.selectedProp[item.k_id] || []).length < 1)
|
||||||
.map(item => item.k);
|
.map(item => item.k);
|
||||||
|
|
||||||
return `${t('select')} ${unselectedSku.concat(unselectedProp).join(';')}`;
|
return `${t('select')} ${unselectedSku
|
||||||
|
.concat(unselectedProp)
|
||||||
|
.join(';')}`;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -335,7 +356,8 @@ export default createComponent({
|
|||||||
|
|
||||||
// 重置 selectedSku
|
// 重置 selectedSku
|
||||||
this.skuTree.forEach(item => {
|
this.skuTree.forEach(item => {
|
||||||
this.selectedSku[item.k_s] = this.initialSku[item.k_s] || UNSELECTED_SKU_VALUE_ID;
|
this.selectedSku[item.k_s] =
|
||||||
|
this.initialSku[item.k_s] || UNSELECTED_SKU_VALUE_ID;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 只有一个 sku 规格值时默认选中
|
// 只有一个 sku 规格值时默认选中
|
||||||
@ -389,11 +411,15 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getSkuCartMessages() {
|
getSkuCartMessages() {
|
||||||
return this.$refs.skuMessages ? this.$refs.skuMessages.getCartMessages() : {};
|
return this.$refs.skuMessages
|
||||||
|
? this.$refs.skuMessages.getCartMessages()
|
||||||
|
: {};
|
||||||
},
|
},
|
||||||
|
|
||||||
validateSkuMessages() {
|
validateSkuMessages() {
|
||||||
return this.$refs.skuMessages ? this.$refs.skuMessages.validateMessages() : '';
|
return this.$refs.skuMessages
|
||||||
|
? this.$refs.skuMessages.validateMessages()
|
||||||
|
: '';
|
||||||
},
|
},
|
||||||
|
|
||||||
validateSku() {
|
validateSku() {
|
||||||
@ -418,7 +444,10 @@ export default createComponent({
|
|||||||
// 点击已选中的sku时则取消选中
|
// 点击已选中的sku时则取消选中
|
||||||
this.selectedSku =
|
this.selectedSku =
|
||||||
this.selectedSku[skuValue.skuKeyStr] === skuValue.id
|
this.selectedSku[skuValue.skuKeyStr] === skuValue.id
|
||||||
? { ...this.selectedSku, [skuValue.skuKeyStr]: UNSELECTED_SKU_VALUE_ID }
|
? {
|
||||||
|
...this.selectedSku,
|
||||||
|
[skuValue.skuKeyStr]: UNSELECTED_SKU_VALUE_ID,
|
||||||
|
}
|
||||||
: { ...this.selectedSku, [skuValue.skuKeyStr]: skuValue.id };
|
: { ...this.selectedSku, [skuValue.skuKeyStr]: skuValue.id };
|
||||||
|
|
||||||
this.$emit('sku-selected', {
|
this.$emit('sku-selected', {
|
||||||
@ -575,19 +604,27 @@ export default createComponent({
|
|||||||
const slots = name => this.slots(name, slotsProps);
|
const slots = name => this.slots(name, slotsProps);
|
||||||
|
|
||||||
const Header = slots('sku-header') || (
|
const Header = slots('sku-header') || (
|
||||||
<SkuHeader sku={sku} goods={goods} skuEventBus={skuEventBus} selectedSku={selectedSku}>
|
<SkuHeader
|
||||||
|
sku={sku}
|
||||||
|
goods={goods}
|
||||||
|
skuEventBus={skuEventBus}
|
||||||
|
selectedSku={selectedSku}
|
||||||
|
>
|
||||||
{slots('sku-header-price') || (
|
{slots('sku-header-price') || (
|
||||||
<div class="van-sku__goods-price">
|
<div class="van-sku__goods-price">
|
||||||
<span class="van-sku__price-symbol">¥</span>
|
<span class="van-sku__price-symbol">¥</span>
|
||||||
<span class="van-sku__price-num">{price}</span>
|
<span class="van-sku__price-num">{price}</span>
|
||||||
{this.priceTag && <span class="van-sku__price-tag">{this.priceTag}</span>}
|
{this.priceTag && (
|
||||||
|
<span class="van-sku__price-tag">{this.priceTag}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{slots('sku-header-origin-price') || (
|
{slots('sku-header-origin-price') ||
|
||||||
originPrice && (
|
(originPrice && (
|
||||||
<SkuHeaderItem>{t('originPrice')} ¥{originPrice}</SkuHeaderItem>
|
<SkuHeaderItem>
|
||||||
)
|
{t('originPrice')} ¥{originPrice}
|
||||||
)}
|
</SkuHeaderItem>
|
||||||
|
))}
|
||||||
{!this.hideStock && (
|
{!this.hideStock && (
|
||||||
<SkuHeaderItem>
|
<SkuHeaderItem>
|
||||||
<span class="van-sku__stock">{this.stockText}</span>
|
<span class="van-sku__stock">{this.stockText}</span>
|
||||||
|
@ -53,9 +53,7 @@ export default createComponent({
|
|||||||
maxSize={this.maxSize * 1024 * 1024}
|
maxSize={this.maxSize * 1024 * 1024}
|
||||||
onOversize={this.onOversize}
|
onOversize={this.onOversize}
|
||||||
>
|
>
|
||||||
<div class={bem('img')}>
|
<div class={bem('img')}>{content}</div>
|
||||||
{content}
|
|
||||||
</div>
|
|
||||||
</Uploader>
|
</Uploader>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -63,15 +61,14 @@ export default createComponent({
|
|||||||
genMask() {
|
genMask() {
|
||||||
return (
|
return (
|
||||||
<div class={bem('mask')}>
|
<div class={bem('mask')}>
|
||||||
{this.uploadFail
|
{this.uploadFail ? (
|
||||||
? (
|
[
|
||||||
[
|
<Icon name="warning-o" size="20px" />,
|
||||||
<Icon name="warning-o" size="20px" />,
|
<div class={bem('warn-text')} domPropsInnerHTML={t('fail')} />,
|
||||||
<div class={bem('warn-text')} domPropsInnerHTML={t('fail')} />,
|
]
|
||||||
]
|
) : (
|
||||||
) : (
|
<Loading type="spinner" size="20px" color="white" />
|
||||||
<Loading type="spinner" size="20px" color="white" />
|
)}
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -80,33 +77,34 @@ export default createComponent({
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div class={bem()}>
|
<div class={bem()}>
|
||||||
{this.value && this.genUploader(
|
{this.value &&
|
||||||
[
|
this.genUploader(
|
||||||
<img src={this.value} />,
|
[
|
||||||
<Icon
|
<img src={this.value} />,
|
||||||
name="clear"
|
<Icon
|
||||||
class={bem('delete')}
|
name="clear"
|
||||||
onClick={() => {
|
class={bem('delete')}
|
||||||
this.$emit('input', '');
|
onClick={() => {
|
||||||
}}
|
this.$emit('input', '');
|
||||||
/>,
|
}}
|
||||||
],
|
/>,
|
||||||
true
|
],
|
||||||
)}
|
true
|
||||||
|
)}
|
||||||
|
|
||||||
{this.paddingImg && this.genUploader(
|
{this.paddingImg &&
|
||||||
[
|
this.genUploader(
|
||||||
<img src={this.paddingImg} />,
|
[<img src={this.paddingImg} />, this.genMask()],
|
||||||
this.genMask(),
|
!this.uploadFail
|
||||||
],
|
)}
|
||||||
!this.uploadFail
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!this.value && !this.paddingImg && this.genUploader(
|
{!this.value &&
|
||||||
<div class={bem('trigger')}>
|
!this.paddingImg &&
|
||||||
<Icon name="photograph" size="22px" />
|
this.genUploader(
|
||||||
</div>
|
<div class={bem('trigger')}>
|
||||||
)}
|
<Icon name="photograph" size="22px" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -103,43 +103,54 @@ export default createComponent({
|
|||||||
if (message.type === 'email' && !isEmail(value)) {
|
if (message.type === 'email' && !isEmail(value)) {
|
||||||
return t('invalid.email');
|
return t('invalid.email');
|
||||||
}
|
}
|
||||||
if (message.type === 'id_no' && (value.length < 15 || value.length > 18)) {
|
if (
|
||||||
|
message.type === 'id_no' &&
|
||||||
|
(value.length < 15 || value.length > 18)
|
||||||
|
) {
|
||||||
return t('invalid.id_no');
|
return t('invalid.id_no');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
genMessage(message, index) {
|
||||||
|
if (message.type === 'image') {
|
||||||
|
return (
|
||||||
|
<Cell
|
||||||
|
key={`${this.goodsId}-${index}`}
|
||||||
|
title={message.name}
|
||||||
|
label={t('imageLabel')}
|
||||||
|
class={bem('image-cell')}
|
||||||
|
required={String(message.required) === '1'}
|
||||||
|
valueClass={bem('image-cell-value')}
|
||||||
|
>
|
||||||
|
<SkuImgUploader
|
||||||
|
vModel={this.messageValues[index].value}
|
||||||
|
maxSize={this.messageConfig.uploadMaxSize}
|
||||||
|
uploadImg={this.messageConfig.uploadImg}
|
||||||
|
/>
|
||||||
|
</Cell>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Field
|
||||||
|
vModel={this.messageValues[index].value}
|
||||||
|
maxlength="200"
|
||||||
|
label={message.name}
|
||||||
|
key={`${this.goodsId}-${index}`}
|
||||||
|
required={String(message.required) === '1'}
|
||||||
|
placeholder={this.getPlaceholder(message)}
|
||||||
|
type={this.getType(message)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<CellGroup class={bem()} border={this.messages.length > 0}>
|
<CellGroup class={bem()} border={this.messages.length > 0}>
|
||||||
{this.messages.map((message, index) => (message.type === 'image' ? (
|
{this.messages.map(this.genMessage)}
|
||||||
<Cell
|
|
||||||
class={bem('image-cell')}
|
|
||||||
value-class={bem('image-cell-value')}
|
|
||||||
label={t('imageLabel')}
|
|
||||||
title={message.name}
|
|
||||||
key={`${this.goodsId}-${index}`}
|
|
||||||
required={String(message.required) === '1'}
|
|
||||||
>
|
|
||||||
<SkuImgUploader
|
|
||||||
vModel={this.messageValues[index].value}
|
|
||||||
uploadImg={this.messageConfig.uploadImg}
|
|
||||||
maxSize={this.messageConfig.uploadMaxSize}
|
|
||||||
/>
|
|
||||||
</Cell>
|
|
||||||
) : (
|
|
||||||
<Field
|
|
||||||
vModel={this.messageValues[index].value}
|
|
||||||
maxlength="200"
|
|
||||||
label={message.name}
|
|
||||||
key={`${this.goodsId}-${index}`}
|
|
||||||
required={String(message.required) === '1'}
|
|
||||||
placeholder={this.getPlaceholder(message)}
|
|
||||||
type={this.getType(message)}
|
|
||||||
/>
|
|
||||||
)))}
|
|
||||||
</CellGroup>
|
</CellGroup>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -11,6 +11,18 @@ export default createComponent({
|
|||||||
multiple: Boolean,
|
multiple: Boolean,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
choosed() {
|
||||||
|
const { selectedProp, skuKeyStr, skuValue } = this;
|
||||||
|
|
||||||
|
if (selectedProp && selectedProp[skuKeyStr]) {
|
||||||
|
return selectedProp[skuKeyStr].indexOf(skuValue.id) > -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onSelect() {
|
onSelect() {
|
||||||
this.skuEventBus.$emit('sku:propSelect', {
|
this.skuEventBus.$emit('sku:propSelect', {
|
||||||
@ -22,14 +34,11 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const choosed = this.selectedProp && (this.selectedProp[this.skuKeyStr] || []).indexOf(this.skuValue.id) > -1;
|
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
class={[
|
class={[
|
||||||
'van-sku-row__item',
|
'van-sku-row__item',
|
||||||
{
|
{ 'van-sku-row__item--active': this.choosed },
|
||||||
'van-sku-row__item--active': choosed,
|
|
||||||
},
|
|
||||||
]}
|
]}
|
||||||
onClick={this.onSelect}
|
onClick={this.onSelect}
|
||||||
>
|
>
|
||||||
|
@ -157,7 +157,9 @@ export default createComponent({
|
|||||||
return (
|
return (
|
||||||
<div class="van-sku-stepper-stock">
|
<div class="van-sku-stepper-stock">
|
||||||
<div class="van-sku-stepper-container">
|
<div class="van-sku-stepper-container">
|
||||||
<div class="van-sku__stepper-title">{this.stepperTitle || t('num')}</div>
|
<div class="van-sku__stepper-title">
|
||||||
|
{this.stepperTitle || t('num')}
|
||||||
|
</div>
|
||||||
<Stepper
|
<Stepper
|
||||||
vModel={this.currentNum}
|
vModel={this.currentNum}
|
||||||
class="van-sku__stepper"
|
class="van-sku__stepper"
|
||||||
@ -168,7 +170,9 @@ export default createComponent({
|
|||||||
onOverlimit={this.onOverLimit}
|
onOverlimit={this.onOverLimit}
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
/>
|
/>
|
||||||
{!this.hideQuotaText && this.quotaText && <span class="van-sku__stepper-quota">({this.quotaText})</span>}
|
{!this.hideQuotaText && this.quotaText && (
|
||||||
|
<span class="van-sku__stepper-quota">({this.quotaText})</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -65,11 +65,11 @@ export const isAllSelected = (skuTree, selectedSku) => {
|
|||||||
|
|
||||||
// 根据已选择的 sku 获取 skuComb
|
// 根据已选择的 sku 获取 skuComb
|
||||||
export const getSkuComb = (skuList, selectedSku) => {
|
export const getSkuComb = (skuList, selectedSku) => {
|
||||||
const skuComb = skuList.filter(item => (
|
const skuComb = skuList.filter(item =>
|
||||||
Object.keys(selectedSku).every(
|
Object.keys(selectedSku).every(
|
||||||
skuKeyStr => String(item[skuKeyStr]) === String(selectedSku[skuKeyStr])
|
skuKeyStr => String(item[skuKeyStr]) === String(selectedSku[skuKeyStr])
|
||||||
)
|
)
|
||||||
));
|
);
|
||||||
return skuComb[0];
|
return skuComb[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -103,11 +103,11 @@ export const isSkuChoosable = (skuList, selectedSku, skuToChoose) => {
|
|||||||
skuKey => matchedSku[skuKey] !== UNSELECTED_SKU_VALUE_ID
|
skuKey => matchedSku[skuKey] !== UNSELECTED_SKU_VALUE_ID
|
||||||
);
|
);
|
||||||
|
|
||||||
const filteredSku = skuList.filter(sku => (
|
const filteredSku = skuList.filter(sku =>
|
||||||
skusToCheck.every(
|
skusToCheck.every(
|
||||||
skuKey => String(matchedSku[skuKey]) === String(sku[skuKey])
|
skuKey => String(matchedSku[skuKey]) === String(sku[skuKey])
|
||||||
)
|
)
|
||||||
));
|
);
|
||||||
|
|
||||||
const stock = filteredSku.reduce((total, sku) => {
|
const stock = filteredSku.reduce((total, sku) => {
|
||||||
total += sku.stock_num;
|
total += sku.stock_num;
|
||||||
|
@ -107,7 +107,9 @@ export default createComponent({
|
|||||||
if (this.disabled) return;
|
if (this.disabled) return;
|
||||||
|
|
||||||
const rect = this.$el.getBoundingClientRect();
|
const rect = this.$el.getBoundingClientRect();
|
||||||
const delta = this.vertical ? event.clientY - rect.top : event.clientX - rect.left;
|
const delta = this.vertical
|
||||||
|
? event.clientY - rect.top
|
||||||
|
: event.clientX - rect.left;
|
||||||
const total = this.vertical ? rect.height : rect.width;
|
const total = this.vertical ? rect.height : rect.width;
|
||||||
const value = (delta / total) * this.range + this.min;
|
const value = (delta / total) * this.range + this.min;
|
||||||
|
|
||||||
@ -129,7 +131,8 @@ export default createComponent({
|
|||||||
|
|
||||||
format(value) {
|
format(value) {
|
||||||
return (
|
return (
|
||||||
Math.round(Math.max(this.min, Math.min(value, this.max)) / this.step) * this.step
|
Math.round(Math.max(this.min, Math.min(value, this.max)) / this.step) *
|
||||||
|
this.step
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -34,7 +34,9 @@ export default createComponent({
|
|||||||
const inactiveIconSlot = this.slots('inactive-icon');
|
const inactiveIconSlot = this.slots('inactive-icon');
|
||||||
|
|
||||||
if (inactiveIcon || inactiveIconSlot) {
|
if (inactiveIcon || inactiveIconSlot) {
|
||||||
return inactiveIconSlot || <Icon class={bem('icon')} name={inactiveIcon} />;
|
return (
|
||||||
|
inactiveIconSlot || <Icon class={bem('icon')} name={inactiveIcon} />
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <i class={bem('circle')} />;
|
return <i class={bem('circle')} />;
|
||||||
|
@ -78,7 +78,9 @@ export default createComponent({
|
|||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
minusDisabled() {
|
minusDisabled() {
|
||||||
return this.disabled || this.disableMinus || this.currentValue <= this.min;
|
return (
|
||||||
|
this.disabled || this.disableMinus || this.currentValue <= this.min
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
plusDisabled() {
|
plusDisabled() {
|
||||||
|
@ -85,10 +85,16 @@ export default createComponent({
|
|||||||
|
|
||||||
genIcon() {
|
genIcon() {
|
||||||
const { icon, type, iconPrefix, loadingType } = this;
|
const { icon, type, iconPrefix, loadingType } = this;
|
||||||
const hasIcon = icon || (type === 'success' || type === 'fail');
|
const hasIcon = icon || type === 'success' || type === 'fail';
|
||||||
|
|
||||||
if (hasIcon) {
|
if (hasIcon) {
|
||||||
return <Icon class={bem('icon')} classPrefix={iconPrefix} name={icon || type} />;
|
return (
|
||||||
|
<Icon
|
||||||
|
class={bem('icon')}
|
||||||
|
classPrefix={iconPrefix}
|
||||||
|
name={icon || type}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'loading') {
|
if (type === 'loading') {
|
||||||
@ -120,7 +126,10 @@ export default createComponent({
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
vShow={this.value}
|
vShow={this.value}
|
||||||
class={[bem([this.position, { [this.type]: !this.icon }]), this.className]}
|
class={[
|
||||||
|
bem([this.position, { [this.type]: !this.icon }]),
|
||||||
|
this.className,
|
||||||
|
]}
|
||||||
onClick={this.onClick}
|
onClick={this.onClick}
|
||||||
>
|
>
|
||||||
{this.genIcon()}
|
{this.genIcon()}
|
||||||
|
@ -117,19 +117,21 @@ export default createComponent({
|
|||||||
files = files.slice(0, maxCount);
|
files = files.slice(0, maxCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(files.map(file => readFile(file, this.resultType))).then(contents => {
|
Promise.all(files.map(file => readFile(file, this.resultType))).then(
|
||||||
const fileList = files.map((file, index) => {
|
contents => {
|
||||||
const result = { file };
|
const fileList = files.map((file, index) => {
|
||||||
|
const result = { file };
|
||||||
|
|
||||||
if (contents[index]) {
|
if (contents[index]) {
|
||||||
result.content = contents[index];
|
result.content = contents[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.onAfterRead(fileList, oversize);
|
this.onAfterRead(fileList, oversize);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
readFile(files, this.resultType).then(content => {
|
readFile(files, this.resultType).then(content => {
|
||||||
const result = { file: files };
|
const result = { file: files };
|
||||||
@ -317,7 +319,9 @@ export default createComponent({
|
|||||||
return (
|
return (
|
||||||
<div class={bem('upload')} style={style}>
|
<div class={bem('upload')} style={style}>
|
||||||
<Icon name="plus" class={bem('upload-icon')} />
|
<Icon name="plus" class={bem('upload-icon')} />
|
||||||
{this.uploadText && <span class={bem('upload-text')}>{this.uploadText}</span>}
|
{this.uploadText && (
|
||||||
|
<span class={bem('upload-text')}>{this.uploadText}</span>
|
||||||
|
)}
|
||||||
{Input}
|
{Input}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user