index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. const util = require('../../utils/util.js');
  2. const api = require('../../config/api.js');
  3. const user = require('../../services/user.js');
  4. //获取应用实例
  5. const app = getApp()
  6. Page({
  7. data: {
  8. newGoods: [],
  9. hotGoods: [],
  10. topics: [],
  11. brands: [],
  12. floorGoods: [],
  13. banner: [],
  14. channel: []
  15. },
  16. onShareAppMessage: function () {
  17. return {
  18. title: 'NideShop',
  19. desc: '仿网易严选微信小程序商城',
  20. path: '/pages/index/index'
  21. }
  22. },onPullDownRefresh(){
  23. // 增加下拉刷新数据的功能
  24. var self = this;
  25. this.getIndexData();
  26. },
  27. getIndexData: function () {
  28. let that = this;
  29. var data = new Object();
  30. util.request(api.IndexUrlNewGoods).then(function (res) {
  31. if (res.errno === 0) {
  32. data.newGoods= res.data.newGoodsList
  33. that.setData(data);
  34. }
  35. });
  36. util.request(api.IndexUrlHotGoods).then(function (res) {
  37. if (res.errno === 0) {
  38. data.hotGoods = res.data.hotGoodsList
  39. that.setData(data);
  40. }
  41. });
  42. util.request(api.IndexUrlTopic).then(function (res) {
  43. if (res.errno === 0) {
  44. data.topics = res.data.topicList
  45. that.setData(data);
  46. }
  47. });
  48. util.request(api.IndexUrlBrand).then(function (res) {
  49. if (res.errno === 0) {
  50. data.brand = res.data.brandList
  51. that.setData(data);
  52. }
  53. });
  54. util.request(api.IndexUrlCategory).then(function (res) {
  55. if (res.errno === 0) {
  56. data.floorGoods = res.data.categoryList
  57. that.setData(data);
  58. }
  59. });
  60. util.request(api.IndexUrlBanner).then(function (res) {
  61. if (res.errno === 0) {
  62. data.banner = res.data.banner
  63. that.setData(data);
  64. }
  65. });
  66. util.request(api.IndexUrlChannel).then(function (res) {
  67. if (res.errno === 0) {
  68. data.channel = res.data.channel
  69. that.setData(data);
  70. }
  71. });
  72. },
  73. onLoad: function (options) {
  74. this.getIndexData();
  75. },
  76. onReady: function () {
  77. // 页面渲染完成
  78. },
  79. onShow: function () {
  80. // 页面显示
  81. },
  82. onHide: function () {
  83. // 页面隐藏
  84. },
  85. onUnload: function () {
  86. // 页面关闭
  87. },
  88. })