index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // pages/index/index.js
  2. var app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. indicatorDors: true,
  9. autoplay: true,
  10. interval: 4000,
  11. duration: 500,
  12. activeCategoryId: 0,
  13. imgurl: app.data.resturl
  14. },
  15. tabClick: function (e) {
  16. this.setData({
  17. activeCategoryId: e.currentTarget.id
  18. })
  19. this.getGoodsList(e.currentTarget.id)
  20. // this.getGoodsList(e.currentTarget.id)
  21. },
  22. getGoodsList: function (categoryId) {
  23. var that = this
  24. wx.request({
  25. url: app.data.resturl + '/glist.action',
  26. data: {
  27. cid: categoryId,
  28. openid: app.globalData.openid
  29. },
  30. success: function (res) {
  31. that.setData({
  32. goods: res.data.dlist
  33. })
  34. }
  35. })
  36. },
  37. tabDetails(e) {
  38. let kucun = e.currentTarget.dataset.kucun;
  39. let id = e.currentTarget.dataset.id;
  40. let cid = e.currentTarget.dataset.cid;
  41. console.log(kucun + " " + id + " " + cid);
  42. if (kucun <= 0) {
  43. wx.navigateTo({
  44. url: '../../pages/tjlist/tjlist?cid=' + cid + "&id=" + id,
  45. })
  46. } else {
  47. wx.navigateTo({
  48. url: '/pages/goods-details/index?id=' + e.currentTarget.dataset.id
  49. })
  50. }
  51. },
  52. /**
  53. * 生命周期函数--监听页面加载
  54. */
  55. onLoad: function (options) {
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow: function () {
  66. var that = this
  67. wx.request({
  68. url: app.data.resturl + '/cateloglist.action',
  69. data: {
  70. },
  71. success: function (res) {
  72. var category = [{ catelogId: 0, catelogName: '全部' }, { catelogId: -1, catelogName: '推荐' }]
  73. res.data.dlist.forEach(item => {
  74. category.push(item)
  75. })
  76. that.setData({
  77. categories: category
  78. })
  79. that.getGoodsList(0)
  80. }
  81. })
  82. },
  83. /**
  84. * 生命周期函数--监听页面隐藏
  85. */
  86. onHide: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面卸载
  90. */
  91. onUnload: function () {
  92. },
  93. /**
  94. * 页面相关事件处理函数--监听用户下拉动作
  95. */
  96. onPullDownRefresh: function () {
  97. },
  98. /**
  99. * 页面上拉触底事件的处理函数
  100. */
  101. onReachBottom: function () {
  102. },
  103. /**
  104. * 用户点击右上角分享
  105. */
  106. onShareAppMessage: function () {
  107. }
  108. })