index.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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: -1
  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. }
  36. this.setData({
  37. active: index
  38. });
  39. this.triggerEvent("onChange", {
  40. item,
  41. index,
  42. rowIndex: this.data.rowIndex
  43. })
  44. this.setActive(index);
  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. })