category.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. const util = require('../../utils/util.js');
  2. const api = require('../../config/api.js');
  3. const user = require('../../services/user.js');
  4. import header from './data'
  5. import { Router } from '../../utils/router.js'
  6. //获取应用实例
  7. Router({
  8. data: {
  9. showSearch: false,
  10. activeType:-1,
  11. header: header,
  12. noRecord:'',
  13. hideMask: false,
  14. inputShowed: false,
  15. keyword:'',
  16. url:'https://www.4dkankan.com/eShopMobile.html?m=',
  17. totalPages: 1,
  18. currentPage: 1,
  19. size: 10,
  20. loading: false,
  21. brandList:[]
  22. },
  23. onShareAppMessage: function () {
  24. return {
  25. path: '/pages/index/index'
  26. }
  27. },
  28. onPullDownRefresh(){
  29. this.setData({
  30. brandList: this.data.brandList.slice(0,10),
  31. currentPage: 1
  32. });
  33. this.getBrandList(1,false,true);
  34. getApp().onPullDownRefresh()
  35. },
  36. onReachBottom() {
  37. if (!this.data.loading) {
  38. this.loadMore();
  39. console.log('reach down')
  40. }
  41. },
  42. loadMore: function () {
  43. if (this.data.currentPage<this.data.totalPages) {
  44. console.log(this.data.currentPage + 1)
  45. this.getBrandList(this.data.currentPage + 1);
  46. } else {
  47. return;
  48. }
  49. },
  50. getBrandList(page,isSearch=false,refresh=false){
  51. this.setData({
  52. loading: true
  53. })
  54. let tempContent = this.data.brandList ?
  55. this.data.brandList :
  56. [];
  57. let { activeType, size, keyword,} = this.data
  58. util.request(api.IndexList, { type: activeType, page, name:keyword, size })
  59. .then(res=> {
  60. if (isSearch){
  61. // if (res.data.data.length <= 0) {
  62. // this.setData({
  63. // noRecord: true
  64. // });
  65. // }
  66. // else {
  67. wx.pageScrollTo({
  68. scrollTop: 0
  69. })
  70. this.setData({
  71. brandList: res.data.data,
  72. currentPage: res.data.currentPage,
  73. totalPages: res.data.totalPages,
  74. loading: false,
  75. noRecord: false,
  76. showSearch: false
  77. });
  78. // }
  79. }
  80. else if(refresh){
  81. this.setData({
  82. brandList: res.data.data,
  83. currentPage: res.data.currentPage,
  84. totalPages: res.data.totalPages,
  85. loading: false
  86. });
  87. }
  88. else {
  89. this.setData({
  90. brandList: tempContent.concat(res.data.data),
  91. currentPage: res.data.currentPage,
  92. totalPages: res.data.totalPages,
  93. loading: false
  94. });
  95. }
  96. });
  97. },
  98. inputChange: function (e) {
  99. let val = e.detail.value
  100. this.setData({
  101. keyword:val,
  102. noRecord: false
  103. })
  104. this.search()
  105. },
  106. handleScroll(ev) {
  107. this.setData({isFixed: ev.detail.isFixed})
  108. },
  109. search:function(){
  110. let {keyword} = this.data
  111. this.getBrandList(1, true)
  112. // if (this.brandList.length <= 0) {
  113. // this.setData({
  114. // noRecord: true
  115. // })
  116. // }
  117. // else {
  118. // this.setData({
  119. // activeType: -1,
  120. // noRecord: false,
  121. // showSearch: false
  122. // })
  123. // }
  124. },
  125. inputFocus: function () {
  126. },
  127. tapHeaderBar(e){
  128. let { id } = e.currentTarget.dataset
  129. this.setData({
  130. activeType: id,
  131. showSearch: false,
  132. keyword: '',
  133. brandList: [],
  134. currentPage: 1
  135. })
  136. wx.pageScrollTo({
  137. duration: 0,
  138. scrollTop: 0
  139. })
  140. this.getBrandList(1)
  141. },
  142. tabShow(){
  143. this.setData({
  144. showSearch: true
  145. })
  146. },
  147. tabHide() {
  148. this.setData({
  149. showSearch: false,
  150. noRecord:false,
  151. keyword:''
  152. })
  153. },
  154. onLoad: async function (options) {
  155. getApp().checkNetStatu();
  156. // this.checkNetStatu()
  157. this.setData({
  158. imgServer: util.imgServer
  159. })
  160. if (options.id !== 'search') {
  161. this.setData({activeType: options.id})
  162. } else {
  163. this.setData({inputShowed: true})
  164. }
  165. this.getBrandList(1)
  166. },
  167. onReady: function () {
  168. // 页面渲染完成
  169. },
  170. onShow: function (options) {
  171. if (global.type) {
  172. this.tapHeaderBar({
  173. currentTarget: {
  174. dataset: this.data.header[0]
  175. }
  176. })
  177. global.type = null
  178. }
  179. if(typeof this.getTabBar === 'function' && this.getTabBar()){
  180. this.getTabBar().setData({
  181. selected:0
  182. })
  183. }
  184. getApp().updateCardCount()
  185. // 页面显示
  186. },
  187. onHide: function () {
  188. // 页面隐藏
  189. },
  190. onUnload: function () {
  191. // 页面关闭
  192. },
  193. gotoWV: function (event){
  194. let { id } = event.currentTarget.dataset
  195. wx.navigateTo({
  196. url: `/pages/webview/index?id=${id}`,
  197. // url: `/pages/share/share?id=${id}`,
  198. })
  199. }
  200. })