家政小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. const $ = global;
  2. new $.Page({
  3. data: {
  4. tabs: [],
  5. goods: [],
  6. selected: 0,
  7. list: []
  8. },
  9. onLoad() {
  10. this.init();
  11. },
  12. init() {
  13. $.request('product/home', 'GET', {}).then((res) => {
  14. const list = res.data;
  15. if (list && list.length > 0) {
  16. this.setData({
  17. list
  18. });
  19. }
  20. });
  21. $.request('products', 'GET', {}).then((res) => {
  22. if (res.data) {
  23. const tabs = [];
  24. for (let key in res.data) {
  25. tabs.push(key);
  26. }
  27. this.setData({
  28. products: res.data,
  29. tabs,
  30. goods: tabs.length > 0 ? res.data[tabs[0]] : []
  31. });
  32. }
  33. });
  34. },
  35. changeTab(e) {
  36. const {
  37. name
  38. } = e.target.dataset;
  39. if (name) {
  40. let selected = 0;
  41. const products = this.data.products;
  42. for (let key in products) {
  43. if (key == name) {
  44. break;
  45. } else {
  46. selected++;
  47. }
  48. }
  49. this.setData({
  50. selected,
  51. goods: products[name]
  52. })
  53. }
  54. },
  55. toDetail(e) {
  56. const {
  57. id
  58. } = e.target.dataset;
  59. if (id) {
  60. $.router.goto({
  61. path: `/pages/detail/index`,
  62. query: {
  63. id
  64. }
  65. });
  66. }
  67. },
  68. toProduct(e) {
  69. const {
  70. id
  71. } = e.currentTarget.dataset;
  72. if (id || id == 0) {
  73. $.router.goto({
  74. path: '/pages/goodsDetail/index',
  75. query: {
  76. id
  77. }
  78. })
  79. }
  80. }
  81. });