diff --git a/src/address-list/Item.js b/src/address-list/Item.js
index 8cf4833ab..5e8331b20 100644
--- a/src/address-list/Item.js
+++ b/src/address-list/Item.js
@@ -20,14 +20,14 @@ export default createComponent({
emits: ['edit', 'click', 'select'],
setup(props, { slots, emit }) {
- function onClick() {
+ const onClick = () => {
if (props.switchable) {
emit('select');
}
emit('click');
- }
+ };
- const genRightIcon = () => (
+ const renderRightIcon = () => (
);
- function genTag() {
+ const renderTag = () => {
if (props.data.isDefault && props.defaultTagText) {
return (
@@ -47,19 +47,20 @@ export default createComponent({
);
}
- }
+ };
+
+ const renderContent = () => {
+ const { data, disabled, switchable } = props;
- function genContent() {
- const { data } = props;
const Info = [
{`${data.name} ${data.tel}`}
- {genTag()}
+ {renderTag()}
,
{data.address}
,
];
- if (props.switchable && !props.disabled) {
+ if (switchable && !disabled) {
return (
{Info}
@@ -68,7 +69,7 @@ export default createComponent({
}
return Info;
- }
+ };
return () => {
const { disabled } = props;
@@ -77,8 +78,8 @@ export default createComponent({
{
- function genList(list, disabled) {
- if (!list) {
- return;
+ const renderItem = (item, index, disabled) => {
+ const onEdit = () => {
+ const name = disabled ? 'edit-disabled' : 'edit';
+ emit(name, item, index);
+ };
+
+ const onClick = () => {
+ emit('click-item', item, index);
+ };
+
+ const onSelect = () => {
+ const name = disabled ? 'select-disabled' : 'select';
+ emit(name, item, index);
+
+ if (!disabled) {
+ emit('update:modelValue', item.id);
}
+ };
- return list.map((item, index) => (
- {
- emit(disabled ? 'select-disabled' : 'select', item, index);
+ return (
+
+ );
+ };
- if (!disabled) {
- emit('update:modelValue', item.id);
- }
- }}
- onEdit={() => {
- emit(disabled ? 'edit-disabled' : 'edit', item, index);
- }}
- onClick={() => {
- emit('click-item', item, index);
- }}
- />
- ));
+ const renderList = (list, disabled) => {
+ if (list) {
+ return list.map((item, index) => renderItem(item, index, disabled));
}
+ };
- const List = genList(props.list);
- const DisabledList = genList(props.disabledList, true);
+ const renderBottom = () => {
+ const onClick = () => {
+ emit('add');
+ };
+
+ return (
+
+
+
+ );
+ };
+
+ return () => {
+ const List = renderList(props.list);
+ const DisabledList = renderList(props.disabledList, true);
+ const DisabledText = props.disabledText && (
+ {props.disabledText}
+ );
return (
{slots.top?.()}
{List}
- {props.disabledText && (
- {props.disabledText}
- )}
+ {DisabledText}
{DisabledList}
{slots.default?.()}
-
-
+ {renderBottom()}
);
};
|