index.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { canIUseModel } from '../common/version';
  2. import { VantComponent } from '../common/component';
  3. import { useParent } from '../common/relation';
  4. VantComponent({
  5. field: true,
  6. relation: useParent('radio-group', function () {
  7. this.updateFromParent();
  8. }),
  9. classes: ['icon-class', 'label-class'],
  10. props: {
  11. name: null,
  12. value: null,
  13. disabled: Boolean,
  14. useIconSlot: Boolean,
  15. checkedColor: String,
  16. labelPosition: {
  17. type: String,
  18. value: 'right',
  19. },
  20. labelDisabled: Boolean,
  21. shape: {
  22. type: String,
  23. value: 'round',
  24. },
  25. iconSize: {
  26. type: null,
  27. value: 20,
  28. },
  29. },
  30. data: {
  31. direction: '',
  32. parentDisabled: false,
  33. },
  34. methods: {
  35. updateFromParent() {
  36. if (!this.parent) {
  37. return;
  38. }
  39. const { value, disabled: parentDisabled, direction } = this.parent.data;
  40. this.setData({
  41. value,
  42. direction,
  43. parentDisabled,
  44. });
  45. },
  46. emitChange(value) {
  47. const instance = this.parent || this;
  48. instance.$emit('input', value);
  49. instance.$emit('change', value);
  50. if (canIUseModel()) {
  51. instance.setData({ value });
  52. }
  53. },
  54. onChange() {
  55. if (!this.data.disabled && !this.data.parentDisabled) {
  56. this.emitChange(this.data.name);
  57. }
  58. },
  59. onClickLabel() {
  60. const { disabled, parentDisabled, labelDisabled, name } = this.data;
  61. if (!(disabled || parentDisabled) && !labelDisabled) {
  62. this.emitChange(name);
  63. }
  64. },
  65. },
  66. });