index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
  2. // Utils
  3. import { createNamespace } from '../utils';
  4. import { RED } from '../utils/constant';
  5. import { emit, inherit } from '../utils/functional'; // Components
  6. import Tag from '../tag';
  7. import Icon from '../icon';
  8. import Cell from '../cell';
  9. import Radio from '../radio';
  10. import Button from '../button';
  11. import RadioGroup from '../radio-group'; // Types
  12. var _createNamespace = createNamespace('contact-list'),
  13. createComponent = _createNamespace[0],
  14. bem = _createNamespace[1],
  15. t = _createNamespace[2];
  16. function ContactList(h, props, slots, ctx) {
  17. var List = props.list && props.list.map(function (item, index) {
  18. function onClick() {
  19. emit(ctx, 'input', item.id);
  20. emit(ctx, 'select', item, index);
  21. }
  22. function RightIcon() {
  23. return h(Radio, {
  24. "attrs": {
  25. "name": item.id,
  26. "iconSize": 16,
  27. "checkedColor": RED
  28. },
  29. "on": {
  30. "click": onClick
  31. }
  32. });
  33. }
  34. function LeftIcon() {
  35. return h(Icon, {
  36. "attrs": {
  37. "name": "edit"
  38. },
  39. "class": bem('edit'),
  40. "on": {
  41. "click": function click(event) {
  42. event.stopPropagation();
  43. emit(ctx, 'edit', item, index);
  44. }
  45. }
  46. });
  47. }
  48. function Content() {
  49. var nodes = [item.name + "\uFF0C" + item.tel];
  50. if (item.isDefault && props.defaultTagText) {
  51. nodes.push(h(Tag, {
  52. "attrs": {
  53. "type": "danger",
  54. "round": true
  55. },
  56. "class": bem('item-tag')
  57. }, [props.defaultTagText]));
  58. }
  59. return nodes;
  60. }
  61. return h(Cell, {
  62. "key": item.id,
  63. "attrs": {
  64. "isLink": true,
  65. "center": true,
  66. "valueClass": bem('item-value')
  67. },
  68. "class": bem('item'),
  69. "scopedSlots": {
  70. icon: LeftIcon,
  71. default: Content,
  72. 'right-icon': RightIcon
  73. },
  74. "on": {
  75. "click": onClick
  76. }
  77. });
  78. });
  79. return h("div", _mergeJSXProps([{
  80. "class": bem()
  81. }, inherit(ctx)]), [h(RadioGroup, {
  82. "attrs": {
  83. "value": props.value
  84. },
  85. "class": bem('group')
  86. }, [List]), h("div", {
  87. "class": bem('bottom')
  88. }, [h(Button, {
  89. "attrs": {
  90. "round": true,
  91. "block": true,
  92. "type": "danger",
  93. "text": props.addText || t('addText')
  94. },
  95. "class": bem('add'),
  96. "on": {
  97. "click": function click() {
  98. emit(ctx, 'add');
  99. }
  100. }
  101. })])]);
  102. }
  103. ContactList.props = {
  104. value: null,
  105. list: Array,
  106. addText: String,
  107. defaultTagText: String
  108. };
  109. export default createComponent(ContactList);