roomManger.js 5.4 KB

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