index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
  2. // Utils
  3. import { createNamespace } from '../utils';
  4. import { emit, inherit } from '../utils/functional'; // Components
  5. import Button from '../button';
  6. import RadioGroup from '../radio-group';
  7. import AddressItem from './Item'; // Types
  8. var _createNamespace = createNamespace('address-list'),
  9. createComponent = _createNamespace[0],
  10. bem = _createNamespace[1],
  11. t = _createNamespace[2];
  12. function AddressList(h, props, slots, ctx) {
  13. function genList(list, disabled) {
  14. if (!list) {
  15. return;
  16. }
  17. return list.map(function (item, index) {
  18. return h(AddressItem, {
  19. "attrs": {
  20. "data": item,
  21. "disabled": disabled,
  22. "switchable": props.switchable,
  23. "defaultTagText": props.defaultTagText
  24. },
  25. "key": item.id,
  26. "scopedSlots": {
  27. bottom: slots['item-bottom'],
  28. tag: slots.tag
  29. },
  30. "on": {
  31. "select": function select() {
  32. emit(ctx, disabled ? 'select-disabled' : 'select', item, index);
  33. if (!disabled) {
  34. emit(ctx, 'input', item.id);
  35. }
  36. },
  37. "edit": function edit() {
  38. emit(ctx, disabled ? 'edit-disabled' : 'edit', item, index);
  39. },
  40. "click": function click() {
  41. emit(ctx, 'click-item', item, index);
  42. }
  43. }
  44. });
  45. });
  46. }
  47. var List = genList(props.list);
  48. var DisabledList = genList(props.disabledList, true);
  49. return h("div", _mergeJSXProps([{
  50. "class": bem()
  51. }, inherit(ctx)]), [slots.top == null ? void 0 : slots.top(), h(RadioGroup, {
  52. "attrs": {
  53. "value": props.value
  54. }
  55. }, [List]), props.disabledText && h("div", {
  56. "class": bem('disabled-text')
  57. }, [props.disabledText]), DisabledList, slots.default == null ? void 0 : slots.default(), h("div", {
  58. "class": bem('bottom')
  59. }, [h(Button, {
  60. "attrs": {
  61. "round": true,
  62. "block": true,
  63. "type": "danger",
  64. "text": props.addButtonText || t('add')
  65. },
  66. "class": bem('add'),
  67. "on": {
  68. "click": function click() {
  69. emit(ctx, 'add');
  70. }
  71. }
  72. })])]);
  73. }
  74. AddressList.props = {
  75. list: Array,
  76. value: [Number, String],
  77. disabledList: Array,
  78. disabledText: String,
  79. addButtonText: String,
  80. defaultTagText: String,
  81. switchable: {
  82. type: Boolean,
  83. default: true
  84. }
  85. };
  86. export default createComponent(AddressList);