index.js 2.0 KB

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