index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { isPresetColor } from '../helpers/colors'
  2. Component({
  3. externalClasses: ['wux-class'],
  4. relations: {
  5. '../radio-group/index': {
  6. type: 'parent',
  7. },
  8. },
  9. properties: {
  10. thumb: {
  11. type: String,
  12. value: '',
  13. },
  14. title: {
  15. type: String,
  16. value: '',
  17. },
  18. label: {
  19. type: String,
  20. value: '',
  21. },
  22. value: {
  23. type: String,
  24. value: '',
  25. },
  26. checked: {
  27. type: Boolean,
  28. value: false,
  29. },
  30. disabled: {
  31. type: Boolean,
  32. value: false,
  33. },
  34. color: {
  35. type: String,
  36. value: 'balanced',
  37. observer(newVal) {
  38. this.setData({
  39. radioColor: isPresetColor(newVal),
  40. })
  41. },
  42. },
  43. },
  44. data: {
  45. index: 0,
  46. },
  47. methods: {
  48. radioChange() {
  49. const { value, checked, index, disabled } = this.data
  50. const parent = this.getRelationNodes('../radio-group/index')[0]
  51. const item = {
  52. checked: !checked,
  53. value,
  54. index,
  55. }
  56. if (disabled) {
  57. return false
  58. }
  59. parent ? parent.emitEvent(item) : this.triggerEvent('change', item)
  60. },
  61. changeValue(checked = false, index = 0) {
  62. this.setData({
  63. checked,
  64. index,
  65. })
  66. },
  67. },
  68. attached() {
  69. this.setData({
  70. radioColor: isPresetColor(this.data.color),
  71. })
  72. },
  73. })