roomManger.js 5.3 KB

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