AddressListItem.mjs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { createVNode as _createVNode } from "vue";
  2. import { defineComponent } from "vue";
  3. import { extend, createNamespace, makeRequiredProp } from "../utils/index.mjs";
  4. import { Tag } from "../tag/index.mjs";
  5. import { Icon } from "../icon/index.mjs";
  6. import { Cell } from "../cell/index.mjs";
  7. import { Radio } from "../radio/index.mjs";
  8. const [name, bem] = createNamespace("address-item");
  9. var stdin_default = defineComponent({
  10. name,
  11. props: {
  12. address: makeRequiredProp(Object),
  13. disabled: Boolean,
  14. switchable: Boolean,
  15. defaultTagText: String
  16. },
  17. emits: ["edit", "click", "select"],
  18. setup(props, {
  19. slots,
  20. emit
  21. }) {
  22. const onClick = () => {
  23. if (props.switchable) {
  24. emit("select");
  25. }
  26. emit("click");
  27. };
  28. const renderRightIcon = () => _createVNode(Icon, {
  29. "name": "edit",
  30. "class": bem("edit"),
  31. "onClick": (event) => {
  32. event.stopPropagation();
  33. emit("edit");
  34. emit("click");
  35. }
  36. }, null);
  37. const renderTag = () => {
  38. if (slots.tag) {
  39. return slots.tag(props.address);
  40. }
  41. if (props.address.isDefault && props.defaultTagText) {
  42. return _createVNode(Tag, {
  43. "type": "danger",
  44. "round": true,
  45. "class": bem("tag")
  46. }, {
  47. default: () => [props.defaultTagText]
  48. });
  49. }
  50. };
  51. const renderContent = () => {
  52. const {
  53. address,
  54. disabled,
  55. switchable
  56. } = props;
  57. const Info = [_createVNode("div", {
  58. "class": bem("name")
  59. }, [`${address.name} ${address.tel}`, renderTag()]), _createVNode("div", {
  60. "class": bem("address")
  61. }, [address.address])];
  62. if (switchable && !disabled) {
  63. return _createVNode(Radio, {
  64. "name": address.id,
  65. "iconSize": 18
  66. }, {
  67. default: () => [Info]
  68. });
  69. }
  70. return Info;
  71. };
  72. return () => {
  73. var _a;
  74. const {
  75. disabled
  76. } = props;
  77. return _createVNode("div", {
  78. "class": bem({
  79. disabled
  80. }),
  81. "onClick": onClick
  82. }, [_createVNode(Cell, {
  83. "border": false,
  84. "valueClass": bem("value")
  85. }, {
  86. value: renderContent,
  87. "right-icon": renderRightIcon
  88. }), (_a = slots.bottom) == null ? void 0 : _a.call(slots, extend({}, props.address, {
  89. disabled
  90. }))]);
  91. };
  92. }
  93. });
  94. export {
  95. stdin_default as default
  96. };