sence.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. util.request(api.increaseViewCount, {
  117. brandId: id
  118. }, 'GET').then((res) => {
  119. });
  120. },
  121. /**
  122. * 生命周期函数--监听页面加载
  123. */
  124. onLoad: function (options) {
  125. getApp().checkNetStatu();
  126. console.log(options)
  127. this.setData({
  128. 'fetcherData.type': options.type
  129. })
  130. if (options.type == 31) {
  131. wx.setNavigationBarTitle({
  132. title: 'VR场景'
  133. })
  134. } else {
  135. wx.setNavigationBarTitle({
  136. title: 'VR场景直播间'
  137. })
  138. }
  139. this.getRoomList()
  140. },
  141. /**
  142. * 生命周期函数--监听页面初次渲染完成
  143. */
  144. onReady: function () {
  145. },
  146. /**
  147. * 生命周期函数--监听页面显示
  148. */
  149. onShow: function () {
  150. },
  151. /**
  152. * 生命周期函数--监听页面隐藏
  153. */
  154. onHide: function () {
  155. },
  156. /**
  157. * 生命周期函数--监听页面卸载
  158. */
  159. onUnload: function () {
  160. },
  161. /**
  162. * 页面相关事件处理函数--监听用户下拉动作
  163. */
  164. onPullDownRefresh: function () {
  165. },
  166. /**
  167. * 页面上拉触底事件的处理函数
  168. */
  169. onReachBottom: function () {
  170. if (!this.data.isSearch) {
  171. this.getRoomList()
  172. }
  173. },
  174. /**
  175. * 用户点击右上角分享
  176. */
  177. onShareAppMessage: function () {
  178. }
  179. })