myFollow.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // pages/myFollow/myFollow.js
  2. const api = require('../../api/index')
  3. const app = getApp()
  4. import { $startWuxRefresher, $stopWuxRefresher,$stopWuxLoader} from '../../miniprogram_npm/wux-weapp/index'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. queryParams:{
  11. current:1,
  12. size:10
  13. },
  14. total:0,
  15. tableData:[],
  16. checkList:[
  17. // {
  18. // type:0,
  19. // label:'全部',
  20. // icon:'',
  21. // checked:true
  22. // },
  23. {
  24. type:1,
  25. label:'白名单',
  26. icon:'myIconanquanbangzhu',
  27. checked:false
  28. },
  29. {
  30. type:2,
  31. label:'灰名单',
  32. icon:'myIcongroup43',
  33. checked:false
  34. },
  35. {
  36. type:0,
  37. label:'黑名单',
  38. icon:'myIconicon-test',
  39. checked:false
  40. },
  41. ],
  42. checked:[],
  43. scrollTop: 0,
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad(options) {
  49. this.init()
  50. },
  51. /**
  52. * 生命周期函数--监听页面初次渲染完成
  53. */
  54. onReady() {
  55. },
  56. /**
  57. * 生命周期函数--监听页面显示
  58. */
  59. onShow() {
  60. },
  61. /**
  62. * 页面功能
  63. */
  64. //初始化加载
  65. init(){
  66. var params = {
  67. current:1,
  68. size:10
  69. }
  70. this.setData(
  71. {
  72. queryParams:params,
  73. total:0,
  74. tableData:[],
  75. }
  76. )
  77. this.getMyFollowProductList()
  78. },
  79. //下拉
  80. onPulling() {
  81. console.log('onPulling')
  82. },
  83. //下拉刷新
  84. onRefresh() {
  85. console.log('onRefresh')
  86. this.init()
  87. },
  88. //取消关注
  89. cancelFollow(e){
  90. var index = e.detail
  91. var data = this.data.tableData
  92. data.splice(index,1)
  93. this.setData(
  94. {
  95. tableData:data
  96. }
  97. )
  98. this.getMyFollowProductList(1)
  99. },
  100. //获取关注的产品
  101. getMyFollowProductList(type){
  102. var params = {
  103. ...this.data.queryParams,
  104. concernTypes:this.data.checked
  105. }
  106. wx.showLoading({
  107. title: '加载中',
  108. })
  109. api.queryConcernProduct(params).then(res=>{
  110. if(res.code == 200){
  111. var data = this.data.tableData
  112. wx.hideLoading()
  113. if(type){
  114. var startIndex = (this.data.queryParams.current-1)*this.data.queryParams.size
  115. var endIndex = data.length
  116. var len = endIndex - startIndex
  117. data.splice(startIndex,len,...res.data.data)
  118. }else{
  119. data = data.concat(res.data.data)
  120. }
  121. this.setData(
  122. {
  123. tableData:data,
  124. total:res.data.total
  125. }
  126. )
  127. api.notify(
  128. {
  129. type:'success',
  130. message:'查询成功',
  131. top:wx.getStorageSync('height')
  132. }
  133. )
  134. }
  135. }).catch(error=>{
  136. wx.hideLoading()
  137. })
  138. },
  139. //加载更多
  140. loadMore(){
  141. var current = this.data.queryParams.current
  142. this.setData(
  143. {
  144. ['queryParams.current']:current+1
  145. }
  146. )
  147. this.getMyFollowProductList()
  148. },
  149. //获取筛选值
  150. onChange(e){
  151. var data = e.detail
  152. this.setData({
  153. checked: data,
  154. });
  155. this.init()
  156. },
  157. /**
  158. * 生命周期函数--监听页面隐藏
  159. */
  160. onHide() {
  161. },
  162. /**
  163. * 生命周期函数--监听页面卸载
  164. */
  165. onUnload() {
  166. },
  167. /**
  168. * 页面相关事件处理函数--监听用户下拉动作
  169. */
  170. onPullDownRefresh() {
  171. },
  172. /**
  173. * 页面上拉触底事件的处理函数
  174. */
  175. onReachBottom() {
  176. },
  177. /**
  178. * 用户点击右上角分享
  179. */
  180. onShareAppMessage() {
  181. }
  182. })