customerServe.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // pages/customerServe/customerServe.js
  2. const app = getApp();
  3. var inputVal = '';
  4. var msgList = [];
  5. var windowWidth = wx.getSystemInfoSync().windowWidth;
  6. var windowHeight = wx.getSystemInfoSync().windowHeight;
  7. var keyHeight = 0;
  8. /**
  9. * 初始化数据
  10. */
  11. function initData(that) {
  12. inputVal = '';
  13. msgList = [{
  14. speaker: 'server',
  15. contentType: 'text',
  16. content: '您好!我是小喃,有什么可以帮您?'
  17. },
  18. {
  19. speaker: 'customer',
  20. contentType: 'text',
  21. content: '南岸区核酸检测'
  22. }
  23. ]
  24. that.setData({
  25. msgList,
  26. inputVal
  27. })
  28. }
  29. Page({
  30. /**
  31. * 页面的初始数据
  32. */
  33. data: {
  34. scrollHeight: '100vh',
  35. inputBottom: 0
  36. },
  37. /**
  38. * 生命周期函数--监听页面加载
  39. */
  40. onLoad: function(options) {
  41. initData(this);
  42. this.setData({
  43. // cusHeadIcon: app.globalData.userInfo.avatarUrl,
  44. });
  45. },
  46. /**
  47. * 生命周期函数--监听页面显示
  48. */
  49. onShow: function() {
  50. },
  51. /**
  52. * 页面相关事件处理函数--监听用户下拉动作
  53. */
  54. onPullDownRefresh: function() {
  55. },
  56. /**
  57. * 页面上拉触底事件的处理函数
  58. */
  59. onReachBottom: function() {
  60. },
  61. /**
  62. * 获取聚焦
  63. */
  64. focus: function(e) {
  65. keyHeight = e.detail.height;
  66. this.setData({
  67. scrollHeight: (windowHeight - keyHeight) + 'px'
  68. });
  69. this.setData({
  70. toView: 'msg-' + (msgList.length - 1),
  71. inputBottom: keyHeight + 'px'
  72. })
  73. //计算msg高度
  74. // calScrollHeight(this, keyHeight);
  75. },
  76. //失去聚焦(软键盘消失)
  77. blur: function(e) {
  78. this.setData({
  79. scrollHeight: '100vh',
  80. inputBottom: 0
  81. })
  82. this.setData({
  83. toView: 'msg-' + (msgList.length - 1)
  84. })
  85. },
  86. /**
  87. * 发送点击监听
  88. */
  89. sendClick: function(e) {
  90. msgList.push({
  91. speaker: 'customer',
  92. contentType: 'text',
  93. content: e.detail.value
  94. })
  95. inputVal = '';
  96. this.setData({
  97. msgList,
  98. inputVal
  99. });
  100. },
  101. /**
  102. * 退回上一页
  103. */
  104. toBackClick: function() {
  105. wx.navigateBack({})
  106. },
  107. onShareAppMessage: function () {
  108. return {
  109. title: '小喃客服'
  110. }
  111. }
  112. })