index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. Component({
  2. externalClasses: ['wr-class'],
  3. properties: {
  4. goodsList: {
  5. type: Array,
  6. value: [],
  7. },
  8. id: {
  9. type: String,
  10. value: '',
  11. observer: (id) => {
  12. this.genIndependentID(id);
  13. },
  14. },
  15. thresholds: {
  16. type: Array,
  17. value: [],
  18. },
  19. },
  20. data: {
  21. independentID: '',
  22. },
  23. lifetimes: {
  24. ready() {
  25. this.init();
  26. },
  27. },
  28. methods: {
  29. onClickGoods(e) {
  30. const { index } = e.currentTarget.dataset;
  31. this.triggerEvent('click', { ...e.detail, index });
  32. },
  33. onAddCart(e) {
  34. const { index } = e.currentTarget.dataset;
  35. this.triggerEvent('addcart', { ...e.detail, index });
  36. },
  37. onClickGoodsThumb(e) {
  38. const { index } = e.currentTarget.dataset;
  39. this.triggerEvent('thumb', { ...e.detail, index });
  40. },
  41. init() {
  42. this.genIndependentID(this.id || '');
  43. },
  44. genIndependentID(id) {
  45. if (id) {
  46. this.setData({ independentID: id });
  47. } else {
  48. this.setData({
  49. independentID: `goods-list-${~~(Math.random() * 10 ** 8)}`,
  50. });
  51. }
  52. },
  53. },
  54. });