sence.js 4.4 KB

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