roomManger.js 6.3 KB

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