sence.js 4.2 KB

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