roomManger.js 6.0 KB

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