sence.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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}&type=${this.data.fetcherData.type}`,
  131. })
  132. // wx.navigateTo({
  133. // url: `/pages/webview/index?a=1046450_32_1_4370970_1`,
  134. // })
  135. // wx.navigateTo({
  136. // url: `/pages/webview/index?id=1046450&type=32&join=true&roomId=4370970&many=true`,
  137. // })
  138. util.request(api.increaseViewCount, {
  139. brandId: id,
  140. type:this.data.fetcherData.type
  141. }, 'GET').then((res) => {
  142. });
  143. },
  144. storeGotoWv(event) {
  145. let {
  146. id,
  147. index
  148. } = event.detail
  149. wx.navigateTo({
  150. url: `/pages/webview/index?id=${id}&type=${this.data.fetcherData.type}`,
  151. })
  152. util.request(api.increaseViewCount, {
  153. brandId: id,
  154. type:this.data.fetcherData.type
  155. }, 'GET').then((res) => {
  156. var num = 'roomList[' + index + '].pvTotalNum'
  157. this.setData({
  158. [num]: res.data
  159. })
  160. });
  161. },
  162. /**
  163. * 生命周期函数--监听页面加载
  164. */
  165. onLoad: function (options) {
  166. getApp().checkNetStatu();
  167. console.log(options)
  168. this.setData({
  169. 'fetcherData.type': options.type
  170. })
  171. if (options.type == 31) {
  172. wx.setNavigationBarTitle({
  173. title: '场景列表'
  174. })
  175. } else {
  176. wx.setNavigationBarTitle({
  177. title: '带看'
  178. })
  179. }
  180. this.getRoomList()
  181. },
  182. /**
  183. * 生命周期函数--监听页面初次渲染完成
  184. */
  185. onReady: function () {
  186. },
  187. /**
  188. * 生命周期函数--监听页面显示
  189. */
  190. onShow: function () {
  191. },
  192. /**
  193. * 生命周期函数--监听页面隐藏
  194. */
  195. onHide: function () {
  196. },
  197. /**
  198. * 生命周期函数--监听页面卸载
  199. */
  200. onUnload: function () {
  201. },
  202. /**
  203. * 页面相关事件处理函数--监听用户下拉动作
  204. */
  205. onPullDownRefresh: function () {
  206. },
  207. /**
  208. * 页面上拉触底事件的处理函数
  209. */
  210. onReachBottom: function () {
  211. if (!this.data.isSearch) {
  212. this.getRoomList()
  213. }
  214. },
  215. /**
  216. * 用户点击右上角分享
  217. */
  218. onShareAppMessage: function () {
  219. }
  220. })