UNPKG

5.36 kBJavaScriptView Raw
1var __create = Object.create;
2var __defProp = Object.defineProperty;
3var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4var __getOwnPropNames = Object.getOwnPropertyNames;
5var __getProtoOf = Object.getPrototypeOf;
6var __hasOwnProp = Object.prototype.hasOwnProperty;
7var __export = (target, all) => {
8 for (var name2 in all)
9 __defProp(target, name2, { get: all[name2], enumerable: true });
10};
11var __copyProps = (to, from, except, desc) => {
12 if (from && typeof from === "object" || typeof from === "function") {
13 for (let key of __getOwnPropNames(from))
14 if (!__hasOwnProp.call(to, key) && key !== except)
15 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16 }
17 return to;
18};
19var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20 // If the importer is in node compatibility mode or this is not an ESM
21 // file that has been converted to a CommonJS file using a Babel-
22 // compatible transform (i.e. "__esModule" has not been set), then set
23 // "default" to the CommonJS "module.exports" for node compatibility.
24 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25 mod
26));
27var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28var stdin_exports = {};
29__export(stdin_exports, {
30 addressListProps: () => addressListProps,
31 default: () => stdin_default
32});
33module.exports = __toCommonJS(stdin_exports);
34var import_vue = require("vue");
35var import_utils = require("../utils");
36var import_button = require("../button");
37var import_radio_group = require("../radio-group");
38var import_checkbox_group = require("../checkbox-group");
39var import_AddressListItem = __toESM(require("./AddressListItem"));
40const [name, bem, t] = (0, import_utils.createNamespace)("address-list");
41const addressListProps = {
42 list: (0, import_utils.makeArrayProp)(),
43 modelValue: [...import_utils.numericProp, Array],
44 switchable: import_utils.truthProp,
45 disabledText: String,
46 disabledList: (0, import_utils.makeArrayProp)(),
47 showAddButton: import_utils.truthProp,
48 addButtonText: String,
49 defaultTagText: String,
50 rightIcon: (0, import_utils.makeStringProp)("edit")
51};
52var stdin_default = (0, import_vue.defineComponent)({
53 name,
54 props: addressListProps,
55 emits: ["add", "edit", "select", "clickItem", "editDisabled", "selectDisabled", "update:modelValue"],
56 setup(props, {
57 slots,
58 emit
59 }) {
60 const singleChoice = (0, import_vue.computed)(() => !Array.isArray(props.modelValue));
61 const renderItem = (item, index, disabled) => {
62 const onEdit = () => emit(disabled ? "editDisabled" : "edit", item, index);
63 const onClick = (event) => emit("clickItem", item, index, {
64 event
65 });
66 const onSelect = () => {
67 emit(disabled ? "selectDisabled" : "select", item, index);
68 if (!disabled) {
69 if (singleChoice.value) {
70 emit("update:modelValue", item.id);
71 } else {
72 const value = props.modelValue;
73 if (value.includes(item.id)) {
74 emit("update:modelValue", value.filter((id) => id !== item.id));
75 } else {
76 emit("update:modelValue", [...value, item.id]);
77 }
78 }
79 }
80 };
81 return (0, import_vue.createVNode)(import_AddressListItem.default, {
82 "key": item.id,
83 "address": item,
84 "disabled": disabled,
85 "switchable": props.switchable,
86 "singleChoice": singleChoice.value,
87 "defaultTagText": props.defaultTagText,
88 "rightIcon": props.rightIcon,
89 "onEdit": onEdit,
90 "onClick": onClick,
91 "onSelect": onSelect
92 }, {
93 bottom: slots["item-bottom"],
94 tag: slots.tag
95 });
96 };
97 const renderList = (list, disabled) => {
98 if (list) {
99 return list.map((item, index) => renderItem(item, index, disabled));
100 }
101 };
102 const renderBottom = () => props.showAddButton ? (0, import_vue.createVNode)("div", {
103 "class": [bem("bottom"), "van-safe-area-bottom"]
104 }, [(0, import_vue.createVNode)(import_button.Button, {
105 "round": true,
106 "block": true,
107 "type": "primary",
108 "text": props.addButtonText || t("add"),
109 "class": bem("add"),
110 "onClick": () => emit("add")
111 }, null)]) : void 0;
112 return () => {
113 var _a, _b;
114 const List = renderList(props.list);
115 const DisabledList = renderList(props.disabledList, true);
116 const DisabledText = props.disabledText && (0, import_vue.createVNode)("div", {
117 "class": bem("disabled-text")
118 }, [props.disabledText]);
119 return (0, import_vue.createVNode)("div", {
120 "class": bem()
121 }, [(_a = slots.top) == null ? void 0 : _a.call(slots), !singleChoice.value && Array.isArray(props.modelValue) ? (0, import_vue.createVNode)(import_checkbox_group.CheckboxGroup, {
122 "modelValue": props.modelValue
123 }, {
124 default: () => [List]
125 }) : (0, import_vue.createVNode)(import_radio_group.RadioGroup, {
126 "modelValue": props.modelValue
127 }, {
128 default: () => [List]
129 }), DisabledText, DisabledList, (_b = slots.default) == null ? void 0 : _b.call(slots), renderBottom()]);
130 };
131 }
132});