strategyDetail.js 2.8 KB

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