index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. const { axios } = app.globalData;
  5. Page({
  6. data: {
  7. // 商品列表
  8. shoplist: [],
  9. },
  10. // 点击商品查看详情
  11. ShopSuccess (e) {
  12. let { id } = e.currentTarget.dataset;
  13. wx.navigateTo({
  14. url: `/pages/detail/detail?data=${JSON.stringify({ id })}`,
  15. })
  16. },
  17. //加载商品数据 模拟5条
  18. PageCount: 3,//总页数
  19. Page: 1,//当前页数
  20. ShopRequest () {
  21. if (this.Page > this.PageCount) return false;
  22. let that = this, { shoplist } = this.data;
  23. axios({
  24. url: "/commodity/wx_commodity/",
  25. method: "get",
  26. data: {
  27. page: that.Page,
  28. limit: 10,
  29. },
  30. success (res) {
  31. let { data, totalPage } = res.data;
  32. that.PageCount = totalPage;
  33. that.Page++;
  34. data.forEach(item => {
  35. shoplist.push({
  36. id: item.id,
  37. price: item.amount,
  38. desc: item.introduce,
  39. imgurl: item.list_image,
  40. title: item.name
  41. })
  42. })
  43. that.setData({
  44. shoplist
  45. })
  46. wx.stopPullDownRefresh();
  47. }
  48. })
  49. },
  50. onLoad () {
  51. wx.lxd.Ctr({
  52. // nav
  53. title: "首页", //标题
  54. back: false,//返回按钮,tabber必须false(除非会改)
  55. bgc: false,//使用更改后的颜色;配合json使用
  56. // tabber
  57. tabber: true, // 显示
  58. active: 0,//活动值
  59. })
  60. },
  61. onShow () {
  62. this.ShopRequest();
  63. },
  64. /**
  65. * 页面相关事件处理函数--监听用户下拉动作
  66. */
  67. onPullDownRefresh: function () {
  68. this.PageCount = 1;
  69. this.Page++;
  70. this.ShopRequest();
  71. },
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. onReachBottom: function () {
  76. this.ShopRequest();
  77. },
  78. /**
  79. * 用户点击右上角分享
  80. */
  81. onShareAppMessage: function () {
  82. }
  83. })