roomManger.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // pages/roomManger/roomManger
  2. var util = require('./../../utils/util.js');
  3. var api = require('./../../config/api.js');
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. roomList: [],
  11. hasData: true,
  12. loading: false,
  13. isSearch: false,
  14. fetcherData: {
  15. type: 32,
  16. address: '',
  17. page: 1,
  18. size: 20,
  19. name: '',
  20. state: ''
  21. }
  22. },
  23. inputChange(e) {
  24. this.setData({
  25. 'fetcherData.name': e.detail.value,
  26. });
  27. },
  28. search() {
  29. if (this.data.fetcherData.name != '') {
  30. wx.showLoading({
  31. title: '加载中...',
  32. });
  33. this.setData({
  34. isSearch: true
  35. })
  36. this.searchRoomList()
  37. } else {
  38. if (this.data.isSearch) {
  39. this.setData({
  40. isSearch: false
  41. })
  42. this.searchRoomList()
  43. } else {
  44. // wx.showToast({
  45. // title: '请输入VR场景名称',
  46. // icon: 'none'
  47. // })
  48. wx.showLoading({
  49. title: '加载中...',
  50. });
  51. this.setData({
  52. isSearch: true
  53. })
  54. this.searchRoomList()
  55. }
  56. }
  57. },
  58. async getRoomList() {
  59. if (this.data.hasData) {
  60. if (!this.data.loading) {
  61. this.setData({
  62. loading: true
  63. })
  64. wx.showLoading({
  65. title: '加载中...',
  66. })
  67. try {
  68. const res = await util.request(api.roomChatList, this.data.fetcherData, 'post', 'application/json')
  69. console.log('roomData', res);
  70. // debugger
  71. if (res.code === 200) {
  72. if (res.data.list.length != 0) {
  73. this.setData({
  74. roomList: this.data.roomList.concat(res.data.list),
  75. 'fetcherData.page': this.data.fetcherData.page + 1
  76. })
  77. } else {
  78. this.setData({
  79. hasData: false
  80. })
  81. }
  82. }
  83. this.setData({
  84. loading: false
  85. })
  86. } catch (error) {
  87. this.setData({
  88. hasData: false
  89. })
  90. }
  91. }
  92. } else {
  93. console.log('没有更多数据')
  94. }
  95. },
  96. reloadData() {
  97. this.setData({
  98. hasData: true
  99. }, () => {
  100. this.getRoomList()
  101. })
  102. },
  103. searchRoomList() {
  104. if (!this.data.loading) {
  105. this.setData({
  106. loading: false
  107. })
  108. this.setData({
  109. 'fetcherData.page': 1,
  110. 'fetcherData.size': 100,
  111. })
  112. util.request(api.roomChatList, this.data.fetcherData).then((res) => {
  113. this.setData({
  114. loading: false
  115. })
  116. wx.hideLoading()
  117. if (res.errno === 0) {
  118. this.setData({
  119. roomList: res.data.data,
  120. })
  121. }
  122. }).catch(err => {
  123. this.setData({
  124. loading: false
  125. })
  126. });
  127. }
  128. },
  129. gotoWV: function (event) {
  130. let {
  131. id,
  132. roomId
  133. } = event.detail
  134. const type = this.data.fetcherData.type || 33
  135. wx.navigateTo({
  136. url: `/pages/webview/index?id=${id}&type=${type}&roomId=${roomId}`,
  137. })
  138. util.request(api.increaseViewCount, {
  139. brandId: id,
  140. type: type
  141. }, 'GET').then((res) => {
  142. });
  143. },
  144. // storeGotoWv(event) {
  145. // let {
  146. // id,
  147. // roomId,
  148. // index
  149. // } = event.detail
  150. // debugger;
  151. // wx.navigateTo({
  152. // url: `/pages/webview/index?id=${id}&type=${this.data.fetcherData.type}&roomId=${roomId}`,
  153. // })
  154. // util.request(api.increaseViewCount, {
  155. // brandId: id,
  156. // type: this.data.fetcherData.type
  157. // }, 'GET').then((res) => {
  158. // var num = 'roomList[' + index + '].pvTotalNum'
  159. // this.setData({
  160. // [num]: res.data
  161. // })
  162. // });
  163. // },
  164. /**
  165. * 生命周期函数--监听页面加载
  166. */
  167. onLoad: function (options) {
  168. getApp().checkNetStatu();
  169. console.log(options)
  170. this.setData({
  171. 'fetcherData.type': options.type
  172. })
  173. this.getRoomList()
  174. },
  175. /**
  176. * 生命周期函数--监听页面初次渲染完成
  177. */
  178. onReady: function () {
  179. },
  180. /**
  181. * 生命周期函数--监听页面显示
  182. */
  183. onShow: function () {
  184. },
  185. /**
  186. * 生命周期函数--监听页面隐藏
  187. */
  188. onHide: function () {
  189. },
  190. /**
  191. * 生命周期函数--监听页面卸载
  192. */
  193. onUnload: function () {
  194. },
  195. /**
  196. * 页面相关事件处理函数--监听用户下拉动作
  197. */
  198. onPullDownRefresh: function () {
  199. },
  200. /**
  201. * 页面上拉触底事件的处理函数
  202. */
  203. onReachBottom: function () {
  204. if (!this.data.isSearch) {
  205. this.getRoomList()
  206. }
  207. },
  208. /**
  209. * 用户点击右上角分享
  210. */
  211. onShareAppMessage: function () {
  212. }
  213. })