roomManger.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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 = { 101:'Start', 102:'NotStart', }
  162. listNmb[objlistNmb[this.data.fetcherData.state]] = res.data.count
  163. let { totalPages } = res.data
  164. this.setData({
  165. roomList: this.data.roomList.concat(res.data.data),
  166. 'fetcherData.page': this.data.fetcherData.page + 1,
  167. maxPage: totalPages == this.data.fetcherData.page,
  168. listNmb,
  169. })
  170. } else {
  171. this.setData({
  172. hasData: false
  173. })
  174. }
  175. }
  176. this.setData({
  177. loading: false
  178. })
  179. console.log('roomList', this.data.roomList, this.data.fetcherData.page);
  180. } catch (error) {
  181. this.setData({
  182. hasData: false
  183. })
  184. }
  185. }
  186. } else {
  187. console.log('没有更多数据')
  188. }
  189. },
  190. reloadData() {
  191. this.setData({
  192. hasData: true
  193. }, () => {
  194. this.getRoomList()
  195. })
  196. },
  197. searchRoomList() {
  198. if (!this.data.loading) {
  199. this.setData({
  200. loading: false
  201. })
  202. this.setData({
  203. 'fetcherData.page': 1,
  204. 'fetcherData.size': 100,
  205. })
  206. util.request(api.roomChatList, this.data.fetcherData, 'POST', 'application/json').then((res) => {
  207. this.setData({
  208. loading: false
  209. })
  210. wx.hideLoading()
  211. if (res.errno === 0) {
  212. let listNmb = this.data.listNmb
  213. let objlistNmb = { 101:'Start', 102:'NotStart', }
  214. listNmb[objlistNmb[this.data.fetcherData.state]] = res.data.count
  215. this.setData({
  216. roomList: res.data.data,
  217. listNmb,
  218. })
  219. }
  220. }).catch(err => {
  221. this.setData({
  222. loading: false
  223. })
  224. });
  225. }
  226. },
  227. gotoWV: function (event) {
  228. let {
  229. id,
  230. roomId
  231. } = event.detail
  232. const type = this.data.fetcherData.type || 33
  233. wx.navigateTo({
  234. url: `/pages/webview/index?id=${id}&type=${type}&roomId=${roomId}`,
  235. })
  236. util.request(api.increaseViewCount, {
  237. brandId: id,
  238. type: type
  239. }, 'GET').then((res) => {
  240. });
  241. },
  242. // storeGotoWv(event) {
  243. // let {
  244. // id,
  245. // roomId,
  246. // index
  247. // } = event.detail
  248. // debugger;
  249. // wx.navigateTo({
  250. // url: `/pages/webview/index?id=${id}&type=${this.data.fetcherData.type}&roomId=${roomId}`,
  251. // })
  252. // util.request(api.increaseViewCount, {
  253. // brandId: id,
  254. // type: this.data.fetcherData.type
  255. // }, 'GET').then((res) => {
  256. // var num = 'roomList[' + index + '].pvTotalNum'
  257. // this.setData({
  258. // [num]: res.data
  259. // })
  260. // });
  261. // },
  262. /**
  263. * 生命周期函数--监听页面加载
  264. */
  265. onLoad: function (options) {
  266. getApp().checkNetStatu();
  267. console.log(options)
  268. this.setData({
  269. 'fetcherData.type': options.type
  270. })
  271. this.getRoomList()
  272. this.getUserInfo()
  273. this.getStartNum()
  274. },
  275. /**
  276. * 生命周期函数--监听页面初次渲染完成
  277. */
  278. onReady: function () {
  279. },
  280. /**
  281. * 生命周期函数--监听页面显示
  282. */
  283. onShow: function () {
  284. },
  285. /**
  286. * 生命周期函数--监听页面隐藏
  287. */
  288. onHide: function () {
  289. },
  290. /**
  291. * 生命周期函数--监听页面卸载
  292. */
  293. onUnload: function () {
  294. },
  295. /**
  296. * 页面相关事件处理函数--监听用户下拉动作
  297. */
  298. onPullDownRefresh: function () {
  299. const that = this
  300. this.setData({
  301. hasData: true,
  302. 'fetcherData': {
  303. ...that.data.fetcherData,
  304. page: 1,
  305. },
  306. "roomList": [],
  307. }, () => {
  308. that.getRoomList()
  309. wx.stopPullDownRefresh()
  310. })
  311. },
  312. /**
  313. * 页面上拉触底事件的处理函数
  314. */
  315. onReachBottom: function () {
  316. if (!this.data.isSearch && !this.data.maxPage) {
  317. this.getRoomList()
  318. }
  319. },
  320. /**
  321. * 用户点击右上角分享
  322. */
  323. onShareAppMessage: function () {
  324. }
  325. })