index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/libs/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: ['prefixCls, current, disabled', function(prefixCls, current, disabled) {
  45. const wrap = classNames(prefixCls, {
  46. [`${prefixCls}--current`]: current,
  47. [`${prefixCls}--disabled`]: disabled,
  48. })
  49. const hd = `${prefixCls}__hd`
  50. const thumb = `${prefixCls}__thumb`
  51. const title = `${prefixCls}__title`
  52. const arrow = `${prefixCls}__arrow`
  53. const bd = `${prefixCls}__bd`
  54. const content = `${prefixCls}__content`
  55. return {
  56. wrap,
  57. hd,
  58. thumb,
  59. title,
  60. arrow,
  61. bd,
  62. content,
  63. }
  64. }],
  65. },
  66. methods: {
  67. changeCurrent(current, index) {
  68. this.setData({
  69. current,
  70. index,
  71. })
  72. },
  73. onTap() {
  74. const { index, disabled } = this.data
  75. const parent = this.getRelationsByName('../accordion-group/index')[0]
  76. if (disabled || !parent) return
  77. parent.onClickItem(index)
  78. },
  79. },
  80. })