sence.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // pages/sence/sence.js
  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: null,
  16. address: '',
  17. page: 1,
  18. size: 20,
  19. name: ''
  20. }
  21. },
  22. inputChange(e) {
  23. this.setData({
  24. 'fetcherData.name': e.detail.value,
  25. });
  26. },
  27. search() {
  28. if (this.data.fetcherData.name != '') {
  29. wx.showLoading({
  30. title: '加载中...',
  31. });
  32. this.setData({
  33. isSearch: true
  34. })
  35. this.searchRoomList()
  36. } else {
  37. wx.showToast({
  38. title: '请输入VR场景名称',
  39. icon: 'none'
  40. })
  41. }
  42. },
  43. getRoomList() {
  44. if (this.data.hasData) {
  45. if (!this.data.loading) {
  46. this.setData({
  47. loading: true
  48. })
  49. util.request(api.BrandList, this.data.fetcherData).then((res) => {
  50. this.setData({
  51. loading: false
  52. })
  53. if (res.errno === 0) {
  54. if (res.data.data.length != 0) {
  55. this.setData({
  56. roomList: this.data.roomList.concat(res.data.data),
  57. 'fetcherData.page': this.data.fetcherData.page + 1
  58. })
  59. } else {
  60. this.setData({
  61. hasData: false
  62. })
  63. }
  64. }
  65. }).catch(err => {
  66. this.setData({
  67. loading: false
  68. })
  69. });
  70. }
  71. } else {
  72. console.log('没有更多数据')
  73. }
  74. },
  75. reloadData() {
  76. this.setData({
  77. hasData: true
  78. }, () => {
  79. this.getRoomList()
  80. })
  81. },
  82. searchRoomList() {
  83. if (!this.data.loading) {
  84. this.setData({
  85. loading: false
  86. })
  87. this.setData({
  88. 'fetcherData.page': 1,
  89. 'fetcherData.size': 100,
  90. })
  91. util.request(api.BrandList, this.data.fetcherData).then((res) => {
  92. this.setData({
  93. loading: false
  94. })
  95. wx.hideLoading()
  96. if (res.errno === 0) {
  97. this.setData({
  98. roomList: res.data.data,
  99. })
  100. }
  101. }).catch(err => {
  102. this.setData({
  103. loading: false
  104. })
  105. });
  106. }
  107. },
  108. gotoWV: function (event) {
  109. let id = event.detail
  110. wx.navigateTo({
  111. url: `/pages/webview/index?id=${id}`,
  112. })
  113. },
  114. /**
  115. * 生命周期函数--监听页面加载
  116. */
  117. onLoad: function (options) {
  118. getApp().checkNetStatu();
  119. console.log(options)
  120. this.setData({
  121. 'fetcherData.type': options.type
  122. })
  123. if (options.type == 31) {
  124. wx.setNavigationBarTitle({
  125. title: 'VR场景'
  126. })
  127. } else {
  128. wx.setNavigationBarTitle({
  129. title: 'VR场景直播间'
  130. })
  131. }
  132. this.getRoomList()
  133. },
  134. /**
  135. * 生命周期函数--监听页面初次渲染完成
  136. */
  137. onReady: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面显示
  141. */
  142. onShow: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面隐藏
  146. */
  147. onHide: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面卸载
  151. */
  152. onUnload: function () {
  153. },
  154. /**
  155. * 页面相关事件处理函数--监听用户下拉动作
  156. */
  157. onPullDownRefresh: function () {
  158. },
  159. /**
  160. * 页面上拉触底事件的处理函数
  161. */
  162. onReachBottom: function () {
  163. if (!this.data.isSearch) {
  164. this.getRoomList()
  165. }
  166. },
  167. /**
  168. * 用户点击右上角分享
  169. */
  170. onShareAppMessage: function () {
  171. }
  172. })