message.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. wx.getSetting({
  20. withSubscriptions:true,
  21. success (res) {
  22. console.log(res)
  23. console.log(res.subscriptionsSetting)
  24. }
  25. })
  26. },
  27. getData(){
  28. var _this=this;
  29. f()
  30. timer=setInterval(f,10000)
  31. function f(){
  32. $api.getconsult().then(res=>{
  33. _this.setData({
  34. list:res.data.data.list
  35. })
  36. })
  37. }
  38. },
  39. inputchange(e) {
  40. this.setData({
  41. comment: e.detail.value
  42. })
  43. },
  44. subscribe(){
  45. wx.requestSubscribeMessage({
  46. tmplIds: ['RIsv-Kj_Aws7OnbOxv_v1iQDDESXo0ePPLJQpjkHuus'],
  47. success (res) {
  48. console.log(res)
  49. }
  50. })
  51. },
  52. post(){
  53. var data={
  54. cotent:this.data.comment
  55. }
  56. if(!data.cotent){
  57. return
  58. }
  59. $api.consult(data).then(res=>{
  60. this.getData()
  61. this.setData({
  62. comment:''
  63. })
  64. })
  65. },
  66. /**
  67. * 生命周期函数--监听页面初次渲染完成
  68. */
  69. onReady: function () {
  70. },
  71. /**
  72. * 生命周期函数--监听页面显示
  73. */
  74. onShow: function () {
  75. let that = this;
  76. wx.createSelectorQuery().select("#messageScroll").boundingClientRect(function(rect){
  77. wx.pageScrollTo({
  78. scrollTop:rect.height,
  79. duration:100
  80. })
  81. that.setData({
  82. scrollTop:rect.height - that.data.scrollTop
  83. })
  84. }).exec()
  85. },
  86. /**
  87. * 生命周期函数--监听页面隐藏
  88. */
  89. onHide: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面卸载
  93. */
  94. onUnload: function () {
  95. clearInterval(timer)
  96. },
  97. /**
  98. * 页面相关事件处理函数--监听用户下拉动作
  99. */
  100. onPullDownRefresh: function () {
  101. },
  102. /**
  103. * 页面上拉触底事件的处理函数
  104. */
  105. onReachBottom: function () {
  106. },
  107. /**
  108. * 用户点击右上角分享
  109. */
  110. onShareAppMessage: function () {
  111. }
  112. })