index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/classNames'
  3. baseComponent({
  4. relations: {
  5. '../accordion-group/index': {
  6. type: 'parent',
  7. },
  8. },
  9. properties: {
  10. prefixCls: {
  11. type: String,
  12. value: 'wux-accordion',
  13. },
  14. key: {
  15. type: String,
  16. value: '',
  17. },
  18. thumb: {
  19. type: String,
  20. value: '',
  21. },
  22. title: {
  23. type: String,
  24. value: '',
  25. },
  26. content: {
  27. type: String,
  28. value: '',
  29. },
  30. disabled: {
  31. type: Boolean,
  32. value: false,
  33. },
  34. showArrow: {
  35. type: Boolean,
  36. value: true,
  37. },
  38. },
  39. data: {
  40. current: false,
  41. index: '0',
  42. },
  43. computed: {
  44. classes() {
  45. const { prefixCls, current, disabled } = this.data
  46. const wrap = classNames(prefixCls, {
  47. [`${prefixCls}--current`]: current,
  48. [`${prefixCls}--disabled`]: disabled,
  49. })
  50. const hd = `${prefixCls}__hd`
  51. const thumb = `${prefixCls}__thumb`
  52. const title = `${prefixCls}__title`
  53. const arrow = `${prefixCls}__arrow`
  54. const bd = `${prefixCls}__bd`
  55. const content = `${prefixCls}__content`
  56. return {
  57. wrap,
  58. hd,
  59. thumb,
  60. title,
  61. arrow,
  62. bd,
  63. content,
  64. }
  65. },
  66. },
  67. methods: {
  68. changeCurrent(current, index) {
  69. this.setData({
  70. current,
  71. index,
  72. })
  73. },
  74. onTap() {
  75. const { index, disabled } = this.data
  76. const parent = this.getRelationNodes('../accordion-group/index')[0]
  77. if (disabled || !parent) {
  78. return false
  79. }
  80. parent.onClickItem(index)
  81. },
  82. },
  83. })