index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/classNames'
  3. baseComponent({
  4. relations: {
  5. '../checkbox-group/index': {
  6. type: 'parent',
  7. },
  8. },
  9. properties: {
  10. prefixCls: {
  11. type: String,
  12. value: 'wux-checkbox',
  13. },
  14. cellPrefixCls: {
  15. type: String,
  16. value: 'wux-cell',
  17. },
  18. selectablePrefixCls: {
  19. type: String,
  20. value: 'wux-selectable',
  21. },
  22. title: {
  23. type: String,
  24. value: '',
  25. },
  26. label: {
  27. type: String,
  28. value: '',
  29. },
  30. extra: {
  31. type: String,
  32. value: '',
  33. },
  34. value: {
  35. type: String,
  36. value: '',
  37. },
  38. checked: {
  39. type: Boolean,
  40. value: false,
  41. observer(newVal) {
  42. this.setData({
  43. inputChecked: newVal,
  44. })
  45. },
  46. },
  47. disabled: {
  48. type: Boolean,
  49. value: false,
  50. },
  51. color: {
  52. type: String,
  53. value: 'balanced',
  54. },
  55. },
  56. data: {
  57. index: 0,
  58. inputChecked: false,
  59. },
  60. computed: {
  61. classes() {
  62. const { prefixCls } = this.data
  63. const cell = classNames(prefixCls)
  64. const selectable = `${prefixCls}__selectable`
  65. return {
  66. cell,
  67. selectable,
  68. }
  69. },
  70. },
  71. methods: {
  72. checkboxChange(e) {
  73. const { value, index, disabled } = this.data
  74. const parent = this.getRelationNodes('../checkbox-group/index')[0]
  75. const item = {
  76. checked: e.detail.checked,
  77. value,
  78. index,
  79. }
  80. if (disabled) return
  81. parent ? parent.emitEvent(item) : this.triggerEvent('change', item)
  82. },
  83. changeValue(inputChecked = false, index = 0) {
  84. this.setData({
  85. inputChecked,
  86. index,
  87. })
  88. },
  89. },
  90. })