roomManger.js 4.8 KB

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