roomManger.js 5.9 KB

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