roomManger.js 6.8 KB

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