Item.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
  2. import _extends from "@babel/runtime/helpers/esm/extends";
  3. // Utils
  4. import { createNamespace } from '../utils';
  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'; // Types
  10. var _createNamespace = createNamespace('address-item'),
  11. createComponent = _createNamespace[0],
  12. bem = _createNamespace[1];
  13. function AddressItem(h, props, slots, ctx) {
  14. var disabled = props.disabled,
  15. switchable = props.switchable;
  16. function onClick() {
  17. if (switchable) {
  18. emit(ctx, 'select');
  19. }
  20. emit(ctx, 'click');
  21. }
  22. var genRightIcon = function genRightIcon() {
  23. return h(Icon, {
  24. "attrs": {
  25. "name": "edit"
  26. },
  27. "class": bem('edit'),
  28. "on": {
  29. "click": function click(event) {
  30. event.stopPropagation();
  31. emit(ctx, 'edit');
  32. emit(ctx, 'click');
  33. }
  34. }
  35. });
  36. };
  37. function genTag() {
  38. if (slots.tag) {
  39. return slots.tag(_extends({}, props.data));
  40. }
  41. if (props.data.isDefault && props.defaultTagText) {
  42. return h(Tag, {
  43. "attrs": {
  44. "type": "danger",
  45. "round": true
  46. },
  47. "class": bem('tag')
  48. }, [props.defaultTagText]);
  49. }
  50. }
  51. function genContent() {
  52. var data = props.data;
  53. var Info = [h("div", {
  54. "class": bem('name')
  55. }, [data.name + " " + data.tel, genTag()]), h("div", {
  56. "class": bem('address')
  57. }, [data.address])];
  58. if (switchable && !disabled) {
  59. return h(Radio, {
  60. "attrs": {
  61. "name": data.id,
  62. "iconSize": 18
  63. }
  64. }, [Info]);
  65. }
  66. return Info;
  67. }
  68. return h("div", {
  69. "class": bem({
  70. disabled: disabled
  71. }),
  72. "on": {
  73. "click": onClick
  74. }
  75. }, [h(Cell, _mergeJSXProps([{
  76. "attrs": {
  77. "border": false,
  78. "valueClass": bem('value')
  79. },
  80. "scopedSlots": {
  81. default: genContent,
  82. 'right-icon': genRightIcon
  83. }
  84. }, inherit(ctx)])), slots.bottom == null ? void 0 : slots.bottom(_extends({}, props.data, {
  85. disabled: disabled
  86. }))]);
  87. }
  88. AddressItem.props = {
  89. data: Object,
  90. disabled: Boolean,
  91. switchable: Boolean,
  92. defaultTagText: String
  93. };
  94. export default createComponent(AddressItem);