message.js 2.7 KB

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