mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
import { use } from '../utils';
|
|
import Button from '../button';
|
|
import RadioGroup from '../radio-group';
|
|
import AddressItem from './Item';
|
|
|
|
const [sfc, bem, t] = use('address-list');
|
|
|
|
export default sfc({
|
|
props: {
|
|
list: Array,
|
|
disabledList: Array,
|
|
disabledText: String,
|
|
addButtonText: String,
|
|
value: [String, Number],
|
|
switchable: {
|
|
type: Boolean,
|
|
default: true
|
|
}
|
|
},
|
|
|
|
render(h) {
|
|
const getList = (list, disabled) =>
|
|
list.map((item, index) => (
|
|
<AddressItem
|
|
data={item}
|
|
key={item.id}
|
|
disabled={disabled}
|
|
switchable={this.switchable && !disabled}
|
|
onSelect={() => {
|
|
this.$emit(disabled ? 'select-disabled' : 'select', item, index);
|
|
}}
|
|
onEdit={() => {
|
|
this.$emit(disabled ? 'edit-disabled' : 'edit', item, index);
|
|
}}
|
|
/>
|
|
));
|
|
|
|
const List = getList(this.list);
|
|
const DisabledList = getList(this.disabledList, true);
|
|
|
|
return (
|
|
<div class={bem()}>
|
|
{this.slots('top')}
|
|
<RadioGroup value={this.value} onInput={event => this.$emit('input', event)}>
|
|
{List}
|
|
</RadioGroup>
|
|
{this.disabledText && <div class={bem('disabled-text')}>{this.disabledText}</div>}
|
|
{DisabledList}
|
|
{this.slots()}
|
|
<Button
|
|
square
|
|
size="large"
|
|
type="danger"
|
|
class={bem('add')}
|
|
text={this.addButtonText || t('add')}
|
|
onClick={() => {
|
|
this.$emit('add');
|
|
}}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
});
|