index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. lifetimes: {
  29. attached: function () {
  30. getApp().globalData.Language.getLanguagePackage(this)
  31. }
  32. },
  33. methods: {
  34. onClick(e) {
  35. const {
  36. index,
  37. item
  38. } = e.currentTarget.dataset;
  39. if (this.data.active != index) {
  40. this.setData({
  41. active: index
  42. });
  43. this.triggerEvent("onChange", {
  44. item,
  45. index,
  46. rowIndex: this.data.rowIndex
  47. })
  48. this.setActive(index);
  49. }
  50. },
  51. setActive(active) {
  52. const that = this,
  53. query = wx.createSelectorQuery().in(this)
  54. query.select('#active' + active).boundingClientRect(function (res) {
  55. that.setData({
  56. scrollLeft: res.right - res.width
  57. })
  58. }).exec();
  59. },
  60. }
  61. })