index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // index.js
  2. let myPro = require("../../utils/wxRequest.js");
  3. let util = require("../../utils/util.js");
  4. Page({
  5. data: {
  6. page: 1,
  7. size: 10,
  8. dataList: [],
  9. loading: false,
  10. finished: false,
  11. content: "",
  12. userThumb: "", // 用户头像
  13. kfThumb: "", // 客服头像
  14. latestId: '', // 最新的一条
  15. openToView: true,
  16. toView: ''
  17. },
  18. onLoad: function (options) {
  19. // Do some initialize when page load.
  20. let that = this;
  21. that.setData({
  22. userThumb: getApp().globalData.userInfo.thumb,
  23. kfThumb: getApp().globalData.logoTu
  24. });
  25. // console.log("用户头像",getApp().globalData.userInfo.thumb)
  26. },
  27. onShow: function () {
  28. // Do something when page show.
  29. let that = this;
  30. // 滚动区域高度计算
  31. wx.getSystemInfo({
  32. success: function(res){
  33. let height = res.windowHeight;
  34. // that.setData({
  35. // scrollH: height + 160,
  36. // });
  37. console.log('总height',height)
  38. const query = wx.createSelectorQuery();
  39. // query.select('.tips').boundingClientRect();
  40. query.select('.wrap_pub').boundingClientRect();
  41. query.exec((res) =>{
  42. // 分别取出节点的高度
  43. let tipsH = res[0].height; // 发布框的高度 px
  44. let pubH = res[0].height; // 发布框的高度 px
  45. let scrollH = height - pubH;
  46. that.setData({
  47. scrollH: scrollH,
  48. initScrollH: scrollH
  49. });
  50. // wx.pageScrollTo({
  51. // scrollTop: scrollH,
  52. // duration: 100
  53. // })
  54. console.log('setBgHeight',getApp().globalData.setBgHeight)
  55. // console.log('pubH',pubH)
  56. console.log('scrollH',scrollH)
  57. });
  58. }
  59. });
  60. // 验证登录
  61. getApp().verifyLogin(function(loginStatus){
  62. if(loginStatus){
  63. that.setData({
  64. page: 1,
  65. openToView: true,
  66. dataList: [],
  67. init: true,
  68. finished: false
  69. });
  70. that.getDataList();
  71. }
  72. });
  73. },
  74. onReady: function () {
  75. // Do something when page ready.
  76. },
  77. onHide: function () {
  78. // Do something when page hide.
  79. },
  80. onUnload: function () {
  81. // Do something when page close.
  82. },
  83. onPullDownRefresh: function () {
  84. // Do something when pull down.
  85. // let that = this;
  86. // that.getDataList();
  87. // //停止当前页面下拉刷新
  88. // wx.stopPullDownRefresh();
  89. },
  90. onReachBottom: function () {
  91. // Do something when page reach bottom.
  92. },
  93. onPageScroll: function () {
  94. // Do something when page scroll
  95. },
  96. onResize: function () {
  97. // Do something when page resize
  98. },
  99. // 获取数据列表
  100. getDataList(){
  101. let that = this;
  102. let params = {
  103. page: that.data.page,
  104. size: that.data.size
  105. };
  106. myPro.wxRequest("user/v2/suggestionList","GET",params).then(res=>{
  107. let list = res.result;
  108. if(list.length != 0){
  109. if(that.data.page == 1){
  110. that.setData({
  111. dataList: list,
  112. page: that.data.page+1,
  113. init: false
  114. });
  115. console.log('openToView',that.data.openToView);
  116. setTimeout(function(){
  117. if(that.data.openToView){
  118. that.setData({
  119. toView: 'item'+ list[list.length -1].id
  120. });
  121. };
  122. },100)
  123. }else{
  124. list = list.concat(that.data.dataList);
  125. that.setData({
  126. dataList: list,
  127. page: that.data.page+1,
  128. init: false
  129. });
  130. }
  131. }else{
  132. wx.showToast({
  133. title: "暂无更多数据",
  134. icon: "none"
  135. });
  136. };
  137. }).catch(err=>{
  138. console.log("报错信息",err);
  139. wx.showToast({
  140. title: err,
  141. icon: "none"
  142. });
  143. })
  144. },
  145. // 获取输入内容
  146. getContent(event){
  147. let that = this;
  148. that.setData({
  149. content: event.detail
  150. });
  151. },
  152. // 实现得不好, 还是使用自带的
  153. // 聚焦
  154. bindFocus(event){
  155. let that = this;
  156. // console.log('focus',event);
  157. that.setData({
  158. content: event.detail.value,
  159. keybordH: event.detail.height, // 键盘高度
  160. scrollH: that.data.scrollH - event.detail.height
  161. });
  162. },
  163. // 失去焦点
  164. bindBlur(event){
  165. let that = this;
  166. that.setData({
  167. content: event.detail.value,
  168. keybordH: 0, // 键盘高度
  169. scrollH: that.data.initScrollH
  170. });
  171. },
  172. // 发布消息
  173. bindSendContent(){
  174. let that = this;
  175. if(!that.data.content){
  176. wx.showToast({
  177. title: "请输入内容",
  178. icon: "none"
  179. });
  180. return;
  181. };
  182. let params = {
  183. content: that.data.content
  184. };
  185. myPro.wxRequest("user/v2/suggestionApply","POST",params).then(res=>{
  186. that.setData({
  187. content: "",
  188. init: true
  189. });
  190. wx.showToast({
  191. title: res.msg,
  192. icon: "none"
  193. });
  194. // 重新拉取
  195. that.setData({
  196. page: 1,
  197. dataList: [],
  198. openToView: true,
  199. finished: false,
  200. });
  201. that.getDataList();
  202. }).catch(err=>{
  203. console.log("报错信息",err);
  204. wx.showToast({
  205. title: err,
  206. icon: "none"
  207. })
  208. })
  209. },
  210. // 滚动到顶部
  211. bindUpper(){
  212. let that = this;
  213. // console.log('触发了吗=====')
  214. if(!that.data.init){
  215. that.setData({
  216. openToView: false
  217. });
  218. that.getDataList();
  219. };
  220. }
  221. });