strategy.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import request from "../../utils/request"
  2. // pages/strategy/strategy.js
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. strategyList:[]
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad:async function(options) {
  14. // 进入页面时,提示“数据加载中”
  15. wx.showLoading({
  16. title: '数据加载中',
  17. mask:true
  18. })
  19. let result = await request('/front/strategyFront').catch(err=>{
  20. wx.hideLoading()
  21. wx.showModal({
  22. title: '数据加载失败',
  23. content: '当前网络不佳,请稍后再试',
  24. complete: (res) => {
  25. if (res.cancel) {
  26. wx.navigateBack()
  27. }
  28. if (res.confirm) {
  29. wx.navigateBack()
  30. }
  31. }
  32. })
  33. })
  34. // console.log(result);
  35. var strategy = []
  36. for(let i = 0;i < result.length;i++){
  37. if(result[i].status == 1){
  38. strategy.push(result[i])
  39. }
  40. // console.log(strategy);
  41. }
  42. this.setData({
  43. strategyList:strategy
  44. })
  45. // console.log(this.data.strategyList);
  46. // 关闭“数据加载中”的提示
  47. if(this.data.strategyList.length != 0){
  48. wx.hideLoading()
  49. }else{
  50. setTimeout(function () {
  51. wx.hideLoading()
  52. }, 2000)
  53. }
  54. },
  55. //点击跳转到攻略详情
  56. toStrategyDetail(e){
  57. // console.log(e);
  58. // console.log(e.currentTarget.dataset.item.id);
  59. let currentId = e.currentTarget.dataset.item.id
  60. wx.navigateTo({
  61. url: '/pages/strategyDetail/strategyDetail?id='+currentId,
  62. })
  63. },
  64. /**
  65. * 生命周期函数--监听页面初次渲染完成
  66. */
  67. onReady() {
  68. },
  69. /**
  70. * 生命周期函数--监听页面显示
  71. */
  72. onShow() {
  73. },
  74. /**
  75. * 生命周期函数--监听页面隐藏
  76. */
  77. onHide() {
  78. },
  79. /**
  80. * 生命周期函数--监听页面卸载
  81. */
  82. onUnload() {
  83. },
  84. /**
  85. * 页面相关事件处理函数--监听用户下拉动作
  86. */
  87. onPullDownRefresh() {
  88. },
  89. /**
  90. * 页面上拉触底事件的处理函数
  91. */
  92. onReachBottom() {
  93. },
  94. /**
  95. * 用户点击右上角分享
  96. */
  97. onShareAppMessage() {
  98. }
  99. })