index.js 1012 B

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