家政小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const $ = global;
  2. const colors = [
  3. 'blue',
  4. 'green',
  5. 'pink',
  6. 'orange',
  7. 'purple'
  8. ];
  9. new $.Page({
  10. data: {
  11. toView: '',
  12. list: []
  13. },
  14. onLoad() {
  15. $.request('classifies', 'GET', {}).then((res) => {
  16. const data = res.data;
  17. const list = [];
  18. if (data.length > 0) {
  19. data.forEach(d => {
  20. if (!d.pid) {
  21. d.array = [];
  22. list.push(d);
  23. }
  24. });
  25. data.forEach(d => {
  26. if (d.pid) {
  27. list.forEach((l, index) => {
  28. l.color = colors[index];
  29. if (l.id === d.pid) {
  30. l['array'].push(d);
  31. }
  32. });
  33. }
  34. });
  35. this.setData({
  36. list
  37. });
  38. }
  39. });
  40. },
  41. toIntroduce(e) {
  42. const {
  43. id
  44. } = e.currentTarget.dataset;
  45. if (id) {
  46. $.router.goto({
  47. path: `/pages/introduce/index`,
  48. query: {
  49. id
  50. }
  51. });
  52. }
  53. }
  54. });