roomManger.js 5.5 KB

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