ContactList.mjs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { createVNode as _createVNode } from "vue";
  2. import { defineComponent } from "vue";
  3. import { createNamespace, unknownProp } 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. import { Button } from "../button/index.mjs";
  9. import { RadioGroup } from "../radio-group/index.mjs";
  10. const [name, bem, t] = createNamespace("contact-list");
  11. const contactListProps = {
  12. list: Array,
  13. addText: String,
  14. modelValue: unknownProp,
  15. defaultTagText: String
  16. };
  17. var stdin_default = defineComponent({
  18. name,
  19. props: contactListProps,
  20. emits: ["add", "edit", "select", "update:modelValue"],
  21. setup(props, {
  22. emit
  23. }) {
  24. const renderItem = (item, index) => {
  25. const onClick = () => {
  26. emit("update:modelValue", item.id);
  27. emit("select", item, index);
  28. };
  29. const renderRightIcon = () => _createVNode(Radio, {
  30. "class": bem("radio"),
  31. "name": item.id,
  32. "iconSize": 16
  33. }, null);
  34. const renderEditIcon = () => _createVNode(Icon, {
  35. "name": "edit",
  36. "class": bem("edit"),
  37. "onClick": (event) => {
  38. event.stopPropagation();
  39. emit("edit", item, index);
  40. }
  41. }, null);
  42. const renderContent = () => {
  43. const nodes = [`${item.name}\uFF0C${item.tel}`];
  44. if (item.isDefault && props.defaultTagText) {
  45. nodes.push(_createVNode(Tag, {
  46. "type": "danger",
  47. "round": true,
  48. "class": bem("item-tag")
  49. }, {
  50. default: () => [props.defaultTagText]
  51. }));
  52. }
  53. return nodes;
  54. };
  55. return _createVNode(Cell, {
  56. "key": item.id,
  57. "isLink": true,
  58. "center": true,
  59. "class": bem("item"),
  60. "valueClass": bem("item-value"),
  61. "onClick": onClick
  62. }, {
  63. icon: renderEditIcon,
  64. value: renderContent,
  65. "right-icon": renderRightIcon
  66. });
  67. };
  68. return () => _createVNode("div", {
  69. "class": bem()
  70. }, [_createVNode(RadioGroup, {
  71. "modelValue": props.modelValue,
  72. "class": bem("group")
  73. }, {
  74. default: () => [props.list && props.list.map(renderItem)]
  75. }), _createVNode("div", {
  76. "class": [bem("bottom"), "van-safe-area-bottom"]
  77. }, [_createVNode(Button, {
  78. "round": true,
  79. "block": true,
  80. "type": "danger",
  81. "class": bem("add"),
  82. "text": props.addText || t("addContact"),
  83. "onClick": () => emit("add")
  84. }, null)])]);
  85. }
  86. });
  87. export {
  88. stdin_default as default
  89. };