AddressList.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. var __create = Object.create;
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __getProtoOf = Object.getPrototypeOf;
  6. var __hasOwnProp = Object.prototype.hasOwnProperty;
  7. var __export = (target, all) => {
  8. for (var name2 in all)
  9. __defProp(target, name2, { get: all[name2], enumerable: true });
  10. };
  11. var __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. };
  19. var __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. ));
  27. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  28. var stdin_exports = {};
  29. __export(stdin_exports, {
  30. addressListProps: () => addressListProps,
  31. default: () => stdin_default
  32. });
  33. module.exports = __toCommonJS(stdin_exports);
  34. var import_vue = require("vue");
  35. var import_utils = require("../utils");
  36. var import_button = require("../button");
  37. var import_radio_group = require("../radio-group");
  38. var import_checkbox_group = require("../checkbox-group");
  39. var import_AddressListItem = __toESM(require("./AddressListItem"));
  40. const [name, bem, t] = (0, import_utils.createNamespace)("address-list");
  41. const 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. };
  52. var 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. });