roomManger.js 7.9 KB

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