details.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // pages/details/details.js
  2. const getReq = require('./../../config.js').getReq
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrls: [],
  9. datas: {},
  10. getOneSummary: [],
  11. webViewUrl: '',
  12. indicatorDots: true,
  13. vertical: false,
  14. autoplay: true,
  15. interval: 2000,
  16. duration: 500,
  17. animation_flag: false,
  18. sec_index: 0
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. let webViewUrl = `https://passport.lrlz.com/mobile/index.php?act=goods_common&op=detail&goods_id=${options.goods_id}&client_type=ios`
  25. this.setData({
  26. webViewUrl
  27. })
  28. this.getDatas(options.goods_id)
  29. // this.getDatas(6417)
  30. },
  31. getDatas(goods_id) {
  32. var self = this
  33. getReq({
  34. act: 'goods_common',
  35. op: 'index',
  36. goods_id
  37. }, function (res) {
  38. if (res.code == 200) {
  39. let oneSummary = self.getOneSummary(res.datas.summary,goods_id)
  40. console.log('---')
  41. console.log(oneSummary)
  42. self.setData({
  43. datas: res.datas,
  44. getOneSummary: oneSummary,
  45. imgUrls: res.datas.common_info.images
  46. })
  47. }
  48. })
  49. },
  50. getOneSummary(sumarys,goods_id) {
  51. let getOneSummary = sumarys.filter((item, index) => {
  52. return item.goods_id == goods_id
  53. })
  54. return getOneSummary[0]
  55. },
  56. secSku(e) {
  57. let skus = e.currentTarget.dataset.skus
  58. let goodsId = e.currentTarget.dataset.goodsid
  59. let sec_index = e.currentTarget.dataset.secindex
  60. let getOneSummary = this.getOneSummary(this.data.datas.summary, goodsId)
  61. this.setData({
  62. sec_index,
  63. getOneSummary
  64. })
  65. },
  66. toWebView() {
  67. let webViewUrl = encodeURIComponent(this.data.webViewUrl)
  68. wx.navigateTo({
  69. url: `/pages/webView/webView?url=${webViewUrl}`
  70. })
  71. },
  72. animation_flag(e) {
  73. let flag = e.currentTarget.dataset.flag
  74. let animation_flag = flag == 'true' ? true : false
  75. this.setData({
  76. animation_flag
  77. })
  78. },
  79. /**
  80. * 生命周期函数--监听页面初次渲染完成
  81. */
  82. onReady: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面显示
  86. */
  87. onShow: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面隐藏
  91. */
  92. onHide: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面卸载
  96. */
  97. onUnload: function () {
  98. },
  99. /**
  100. * 页面相关事件处理函数--监听用户下拉动作
  101. */
  102. onPullDownRefresh: function () {
  103. },
  104. /**
  105. * 页面上拉触底事件的处理函数
  106. */
  107. onReachBottom: function () {
  108. },
  109. /**
  110. * 用户点击右上角分享
  111. */
  112. onShareAppMessage: function () {
  113. }
  114. })