index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. Component({
  2. properties: {
  3. list: {
  4. type: Array
  5. },
  6. name: {
  7. type: String,
  8. value: "brandname"
  9. },
  10. active: {
  11. type: String,
  12. value: 0
  13. },
  14. rowIndex: {
  15. type: Number,
  16. value: 0
  17. },
  18. onChange: {
  19. type: Function
  20. }
  21. },
  22. externalClasses: [
  23. "box-class", "tab-class", "active-class"
  24. ],
  25. data: {
  26. scrollLeft: 0,
  27. },
  28. methods: {
  29. onClick(e) {
  30. const {
  31. index,
  32. item
  33. } = e.currentTarget.dataset;
  34. if (this.data.active != index) {
  35. this.setData({
  36. active: index
  37. });
  38. this.triggerEvent("onChange", {
  39. item,
  40. index,
  41. rowIndex: this.data.rowIndex
  42. })
  43. this.setActive(index);
  44. }
  45. },
  46. setActive(active) {
  47. const that = this,
  48. query = wx.createSelectorQuery().in(this)
  49. query.select('#active' + active).boundingClientRect(function (res) {
  50. that.setData({
  51. scrollLeft: res.right - res.width
  52. })
  53. }).exec();
  54. },
  55. }
  56. })