message.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. timer:null
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. this.getData()
  19. },
  20. getData(){
  21. var _this=this;
  22. f()
  23. timer=setInterval(f,1000)
  24. this.setData({
  25. timer:timer
  26. })
  27. function f(){
  28. $api.getconsult().then(res=>{
  29. _this.setData({
  30. list:res.data.data.list
  31. })
  32. })
  33. }
  34. },
  35. inputchange(e) {
  36. this.setData({
  37. comment: e.detail.value
  38. })
  39. },
  40. post(){
  41. var data={
  42. cotent:this.data.comment
  43. }
  44. if(!data.cotent){
  45. return
  46. }
  47. $api.consult(data).then(res=>{
  48. this.getData()
  49. this.setData({
  50. comment:''
  51. })
  52. })
  53. },
  54. /**
  55. * 生命周期函数--监听页面初次渲染完成
  56. */
  57. onReady: function () {
  58. },
  59. /**
  60. * 生命周期函数--监听页面显示
  61. */
  62. onShow: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面隐藏
  66. */
  67. onHide: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面卸载
  71. */
  72. onUnload: function () {
  73. clearInterval(this.data.timer)
  74. },
  75. /**
  76. * 页面相关事件处理函数--监听用户下拉动作
  77. */
  78. onPullDownRefresh: function () {
  79. },
  80. /**
  81. * 页面上拉触底事件的处理函数
  82. */
  83. onReachBottom: function () {
  84. },
  85. /**
  86. * 用户点击右上角分享
  87. */
  88. onShareAppMessage: function () {
  89. }
  90. })