zyShop.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. listClassify:[],//分类
  8. goodId:1,
  9. goodsByClassifyList:[],//商品列表
  10. filePath:app.globalData.$filePath
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. this.getListClassify();
  17. },
  18. getListClassify(){
  19. app.requestP({
  20. url:'/zy/goods/listClassify',
  21. method:'get',
  22. }).then(res=>{
  23. this.setData({
  24. listClassify:res.data.data,
  25. goodId:res.data.data[0].id || ''
  26. })
  27. this.getListGoodsByClassify({
  28. classifyId:res.data.data[0].id || '',
  29. pageSize:999,
  30. pageNum:1
  31. })
  32. }).catch(err=>{
  33. app.showToptip(this,'error',err.data.msg)
  34. })
  35. },
  36. getListGoodsByClassify(params={}){
  37. app.requestP({
  38. url:'/zy/goods/listGoodsByClassify',
  39. method:'post',
  40. contentType:'application/json',
  41. data:params
  42. }).then(res=>{
  43. this.setData({
  44. goodsByClassifyList:res.data.rows.map(item=>{
  45. return {...item,banners:this.data.filePath+JSON.parse(item.banners)[0]}
  46. })
  47. })
  48. }).catch(err=>{
  49. app.showToptip(this,'error',err.data.msg)
  50. })
  51. },
  52. goIfy(e){
  53. var that = this;
  54. const id = e.currentTarget.dataset.id;
  55. this.setData({
  56. goodId:id
  57. },()=>{
  58. that.getListGoodsByClassify({
  59. classifyId:id+'',
  60. pageSize:999,
  61. pageNum:1
  62. })
  63. })
  64. },
  65. goGoodsInfo(e){
  66. const item = e.currentTarget.dataset.item;
  67. wx.navigateTo({
  68. url: '/pages/zyShop/zyShopInfo/zyShopInfo?content='+encodeURIComponent(JSON.stringify(item.content || '暂无'))+'&icon='+item.banners+'&name='+item.name+'&id='+item.id+'&tags='+item.tags+'&classifyId='+item.classifyId+'&price='+item.price,
  69. })
  70. },
  71. /**
  72. * 生命周期函数--监听页面初次渲染完成
  73. */
  74. onReady: function () {
  75. },
  76. exchange(){
  77. wx.navigateTo({
  78. url: '/pages/zyShop/recordList/recordList',
  79. })
  80. },
  81. /**
  82. * 生命周期函数--监听页面显示
  83. */
  84. onShow: function () {
  85. },
  86. /**
  87. * 生命周期函数--监听页面隐藏
  88. */
  89. onHide: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面卸载
  93. */
  94. onUnload: function () {
  95. },
  96. /**
  97. * 页面相关事件处理函数--监听用户下拉动作
  98. */
  99. onPullDownRefresh: function () {
  100. },
  101. /**
  102. * 页面上拉触底事件的处理函数
  103. */
  104. onReachBottom: function () {
  105. },
  106. /**
  107. * 用户点击右上角分享
  108. */
  109. onShareAppMessage: function () {
  110. }
  111. })