sence.js 3.6 KB

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