roomManger.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. addRoom(){
  59. wx.navigateTo({
  60. url: `/pages/room/add`,
  61. })
  62. },
  63. async getRoomList() {
  64. if (this.data.hasData) {
  65. if (!this.data.loading) {
  66. this.setData({
  67. loading: true
  68. })
  69. wx.showLoading({
  70. title: '加载中...',
  71. })
  72. try {
  73. const res = await util.request(api.roomChatList, this.data.fetcherData, 'post', 'application/json')
  74. console.log('roomData', res);
  75. // debugger
  76. if (res.code === 200) {
  77. if (res.data.list.length != 0) {
  78. this.setData({
  79. roomList: this.data.roomList.concat(res.data.list),
  80. 'fetcherData.page': this.data.fetcherData.page + 1
  81. })
  82. } else {
  83. this.setData({
  84. hasData: false
  85. })
  86. }
  87. }
  88. this.setData({
  89. loading: false
  90. })
  91. } catch (error) {
  92. this.setData({
  93. hasData: false
  94. })
  95. }
  96. }
  97. } else {
  98. console.log('没有更多数据')
  99. }
  100. },
  101. reloadData() {
  102. this.setData({
  103. hasData: true
  104. }, () => {
  105. this.getRoomList()
  106. })
  107. },
  108. searchRoomList() {
  109. if (!this.data.loading) {
  110. this.setData({
  111. loading: false
  112. })
  113. this.setData({
  114. 'fetcherData.page': 1,
  115. 'fetcherData.size': 100,
  116. })
  117. util.request(api.roomChatList, this.data.fetcherData).then((res) => {
  118. this.setData({
  119. loading: false
  120. })
  121. wx.hideLoading()
  122. if (res.errno === 0) {
  123. this.setData({
  124. roomList: res.data.data,
  125. })
  126. }
  127. }).catch(err => {
  128. this.setData({
  129. loading: false
  130. })
  131. });
  132. }
  133. },
  134. gotoWV: function (event) {
  135. let {
  136. id,
  137. roomId
  138. } = event.detail
  139. const type = this.data.fetcherData.type || 33
  140. wx.navigateTo({
  141. url: `/pages/webview/index?id=${id}&type=${type}&roomId=${roomId}`,
  142. })
  143. util.request(api.increaseViewCount, {
  144. brandId: id,
  145. type: type
  146. }, 'GET').then((res) => {
  147. });
  148. },
  149. // storeGotoWv(event) {
  150. // let {
  151. // id,
  152. // roomId,
  153. // index
  154. // } = event.detail
  155. // debugger;
  156. // wx.navigateTo({
  157. // url: `/pages/webview/index?id=${id}&type=${this.data.fetcherData.type}&roomId=${roomId}`,
  158. // })
  159. // util.request(api.increaseViewCount, {
  160. // brandId: id,
  161. // type: this.data.fetcherData.type
  162. // }, 'GET').then((res) => {
  163. // var num = 'roomList[' + index + '].pvTotalNum'
  164. // this.setData({
  165. // [num]: res.data
  166. // })
  167. // });
  168. // },
  169. /**
  170. * 生命周期函数--监听页面加载
  171. */
  172. onLoad: function (options) {
  173. getApp().checkNetStatu();
  174. console.log(options)
  175. this.setData({
  176. 'fetcherData.type': options.type
  177. })
  178. this.getRoomList()
  179. },
  180. /**
  181. * 生命周期函数--监听页面初次渲染完成
  182. */
  183. onReady: function () {
  184. },
  185. /**
  186. * 生命周期函数--监听页面显示
  187. */
  188. onShow: function () {
  189. },
  190. /**
  191. * 生命周期函数--监听页面隐藏
  192. */
  193. onHide: function () {
  194. },
  195. /**
  196. * 生命周期函数--监听页面卸载
  197. */
  198. onUnload: function () {
  199. },
  200. /**
  201. * 页面相关事件处理函数--监听用户下拉动作
  202. */
  203. onPullDownRefresh: function () {
  204. },
  205. /**
  206. * 页面上拉触底事件的处理函数
  207. */
  208. onReachBottom: function () {
  209. if (!this.data.isSearch) {
  210. this.getRoomList()
  211. }
  212. },
  213. /**
  214. * 用户点击右上角分享
  215. */
  216. onShareAppMessage: function () {
  217. }
  218. })