roomManger.js 6.1 KB

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