index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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: 1,//总页数
  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. wx.stopPullDownRefresh();
  44. that.setData({
  45. shoplist
  46. })
  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 = 1;
  70. this.setData({ shoplist: [] })
  71. this.ShopRequest();
  72. },
  73. /**
  74. * 页面上拉触底事件的处理函数
  75. */
  76. onReachBottom: function () {
  77. this.ShopRequest();
  78. },
  79. /**
  80. * 用户点击右上角分享
  81. */
  82. onShareAppMessage: function () {
  83. },
  84. onShareTimeline: function (res) {
  85. }
  86. })