家政小程序
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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const $ = global;
  2. new $.Page({
  3. data: {
  4. tabs: [],
  5. goods: [],
  6. selected: 0
  7. },
  8. onLoad() {
  9. this.init();
  10. },
  11. init() {
  12. $.request('products', 'GET', {}).then((res) => {
  13. if (res.data) {
  14. const tabs = [];
  15. for (let key in res.data) {
  16. tabs.push(key);
  17. }
  18. this.setData({
  19. products: res.data,
  20. tabs,
  21. goods: tabs.length > 0 ? res.data[tabs[0]] : []
  22. });
  23. }
  24. });
  25. },
  26. changeTab(e) {
  27. const {
  28. name
  29. } = e.target.dataset;
  30. if (name) {
  31. let selected = 0;
  32. const products = this.data.products;
  33. for (let key in products) {
  34. if (key == name) {
  35. break;
  36. } else {
  37. selected++;
  38. }
  39. }
  40. this.setData({
  41. selected,
  42. goods: products[name]
  43. })
  44. }
  45. },
  46. toDetail(e) {
  47. const {
  48. id
  49. } = e.currentTarget.dataset;
  50. if (id || id == 0) {
  51. $.router.goto({
  52. path: '/pages/goodsDetail/index',
  53. query: {
  54. id
  55. }
  56. })
  57. }
  58. }
  59. });