index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. const { axios } = app.globalData;
  5. Page({
  6. data: {
  7. // 商品列表
  8. shoplist: [],
  9. // 广告
  10. datalist: []
  11. },
  12. // 点击商品查看详情
  13. ShopSuccess (e) {
  14. let { id } = e.currentTarget.dataset;
  15. wx.navigateTo({
  16. url: `/pages/detail/detail?data=${JSON.stringify({ id })}`,
  17. })
  18. },
  19. // 请求广告
  20. hotrequest () {
  21. let that = this;
  22. axios({
  23. url: '/notices/wx_notices/',
  24. method: 'get',
  25. success (res) {
  26. let { data } = res.data, datalist = [];
  27. data.forEach(item => {
  28. datalist.push({
  29. name: item.title,
  30. url: `/pages/hot/hot?data=${JSON.stringify({ hot: item })}`
  31. })
  32. })
  33. that.setData({
  34. datalist
  35. })
  36. }
  37. }).then(res => {
  38. wx.lxd.NoticeBar({
  39. datalist: that.data.datalist
  40. })
  41. if (app.globalData.hot) {
  42. this.hot();
  43. app.globalData.hot = false;
  44. }
  45. })
  46. },
  47. //加载商品数据 模拟5条
  48. PageCount: 1,//总页数
  49. Page: 1,//当前页数
  50. ShopRequest () {
  51. if (this.Page > this.PageCount) return false;
  52. let that = this, { shoplist } = this.data;
  53. axios({
  54. url: "/commodity/wx_commodity/",
  55. method: "get",
  56. data: {
  57. page: that.Page,
  58. limit: 10,
  59. },
  60. success (res) {
  61. let { data, totalPage } = res.data;
  62. that.PageCount = totalPage;
  63. that.Page++;
  64. data.forEach(item => {
  65. shoplist.push({
  66. id: item.id,
  67. price: item.amount,
  68. desc: item.introduce,
  69. imgurl: item.list_image,
  70. title: item.name
  71. })
  72. })
  73. wx.stopPullDownRefresh();
  74. that.setData({
  75. shoplist
  76. })
  77. }
  78. })
  79. },
  80. // 广告
  81. hot () {
  82. let { datalist } = this.data;
  83. if (datalist.length == 0) return false;
  84. wx.showModal({
  85. title: '通知',
  86. content: datalist[0]['name'],
  87. confirmText: '查看',
  88. success (res) {
  89. if (res.confirm) {
  90. wx.navigateTo({
  91. url: datalist[0]["url"],
  92. })
  93. }
  94. }
  95. })
  96. },
  97. onLoad () {
  98. wx.lxd.Ctr({
  99. // nav
  100. title: "我要订餐", //标题
  101. back: false,//返回按钮,tabber必须false(除非会改)
  102. bgc: false,//使用更改后的颜色;配合json使用
  103. // tabber
  104. tabber: true, // 显示
  105. active: 0,//活动值
  106. })
  107. this.hotrequest();
  108. },
  109. onReady: function () {
  110. },
  111. onShow () {
  112. this.ShopRequest();
  113. },
  114. /**
  115. * 页面相关事件处理函数--监听用户下拉动作
  116. */
  117. onPullDownRefresh: function () {
  118. this.PageCount = 1;
  119. this.Page = 1;
  120. this.setData({ shoplist: [] })
  121. this.ShopRequest();
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom: function () {
  127. this.ShopRequest();
  128. },
  129. /**
  130. * 用户点击右上角分享
  131. */
  132. onShareAppMessage: function () {
  133. },
  134. onShareTimeline: function (res) {
  135. }
  136. })