message.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // pages/message/message.js
  2. const app = getApp()
  3. var host = app.globalData.host;
  4. const $api = require('../../utils/api.js').API;
  5. var timer;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. focus:false,
  12. scrollTop:0
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. this.getData()
  19. },
  20. getData(){
  21. var _this=this;
  22. f()
  23. timer=setInterval(f,10000)
  24. function f(){
  25. $api.getconsult().then(res=>{
  26. _this.setData({
  27. list:res.data.data.list
  28. })
  29. })
  30. }
  31. },
  32. inputchange(e) {
  33. this.setData({
  34. comment: e.detail.value
  35. })
  36. },
  37. post(){
  38. var data={
  39. cotent:this.data.comment
  40. }
  41. if(!data.cotent){
  42. return
  43. }
  44. $api.consult(data).then(res=>{
  45. this.getData()
  46. this.setData({
  47. comment:''
  48. })
  49. })
  50. },
  51. /**
  52. * 生命周期函数--监听页面初次渲染完成
  53. */
  54. onReady: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面显示
  58. */
  59. onShow: function () {
  60. let that = this;
  61. wx.createSelectorQuery().select("#messageScroll").boundingClientRect(function(rect){
  62. wx.pageScrollTo({
  63. scrollTop:rect.height,
  64. duration:100
  65. })
  66. that.setData({
  67. scrollTop:rect.height - that.data.scrollTop
  68. })
  69. }).exec()
  70. },
  71. /**
  72. * 生命周期函数--监听页面隐藏
  73. */
  74. onHide: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面卸载
  78. */
  79. onUnload: function () {
  80. clearInterval(timer)
  81. },
  82. /**
  83. * 页面相关事件处理函数--监听用户下拉动作
  84. */
  85. onPullDownRefresh: function () {
  86. },
  87. /**
  88. * 页面上拉触底事件的处理函数
  89. */
  90. onReachBottom: function () {
  91. },
  92. /**
  93. * 用户点击右上角分享
  94. */
  95. onShareAppMessage: function () {
  96. }
  97. })