myFollow.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. // pages/myFollow/myFollow.js
  2. const api = require('../../api/index')
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. menu:[
  10. {
  11. label:'收藏的专利',
  12. method:'selectCollectPatent'
  13. }
  14. ],
  15. queryParams:{
  16. current:1,
  17. size:10
  18. },
  19. total:0,
  20. tableData:[],
  21. checkList:[
  22. {
  23. type:"-1",
  24. label:'全部',
  25. icon:'',
  26. checked:true
  27. },
  28. {
  29. type:"1",
  30. label:'白名单',
  31. icon:'myIconanquanbangzhu',
  32. checked:false
  33. },
  34. {
  35. type:"2",
  36. label:'灰名单',
  37. icon:'myIconicon-test',
  38. checked:false
  39. },
  40. {
  41. type:"0",
  42. label:'黑名单',
  43. icon:'myIcongroup43',
  44. checked:false
  45. },
  46. ],
  47. checked:[],
  48. active:null,
  49. triggered:false,
  50. load:false,
  51. hasMore:true,
  52. showPopup:false,
  53. changeFollow:false,
  54. },
  55. /**
  56. * 生命周期函数--监听页面加载
  57. */
  58. onLoad(options) {
  59. if(options.type == 0 || options.type){
  60. if(options.type != -1){
  61. this.setData(
  62. {
  63. checked:[options.type]
  64. }
  65. )
  66. }
  67. this.setData(
  68. {
  69. active:options.type
  70. }
  71. )
  72. }
  73. this.init()
  74. },
  75. /**
  76. * 生命周期函数--监听页面初次渲染完成
  77. */
  78. onReady() {
  79. },
  80. /**
  81. * 生命周期函数--监听页面显示
  82. */
  83. onShow() {
  84. },
  85. /**
  86. * 页面功能
  87. */
  88. //关注和监控
  89. closePopup(e){
  90. this.setData(
  91. {
  92. showPopup:false
  93. }
  94. )
  95. wx.nextTick(() => {
  96. this.setData({ changeFollow: false }) // 在当前同步流程结束后,下一个时间片执行
  97. })
  98. },
  99. openPopup(e){
  100. console.log(e)
  101. this.setData(
  102. {
  103. showPopup:true
  104. }
  105. )
  106. if(e.detail && e.detail.changeFollow){
  107. this.setData(
  108. {
  109. changeFollow:true
  110. }
  111. )
  112. }
  113. },
  114. attention(e){
  115. const childComponent = this.selectComponent('#myProduct');
  116. // var {type} = e.detail
  117. if (childComponent) {
  118. childComponent.attention(e); // 调用子组件的方法
  119. }
  120. },
  121. cancelFollow2(e){
  122. const childComponent = this.selectComponent('#myProduct');
  123. // var {type} = e.detail
  124. if (childComponent) {
  125. childComponent.cancelFollow(e); // 调用子组件的方法
  126. }
  127. },
  128. //初始化加载
  129. init(){
  130. var params = {
  131. current:1,
  132. size:10
  133. }
  134. this.setData(
  135. {
  136. queryParams:params,
  137. total:0,
  138. tableData:[],
  139. hasMore:true
  140. }
  141. )
  142. this.getMyFollowProductList()
  143. },
  144. //下拉刷新
  145. onRefresh() {
  146. console.log('onRefresh')
  147. this.setData({
  148. triggered: true,
  149. })
  150. this.init()
  151. },
  152. //取消关注
  153. cancelFollow(e){
  154. var index = e.detail
  155. var data = this.data.tableData
  156. data.splice(index,1)
  157. this.setData(
  158. {
  159. tableData:data
  160. }
  161. )
  162. this.getMyFollowProductList(1)
  163. },
  164. //获取关注的产品
  165. getMyFollowProductList(type){
  166. var params = {
  167. ...this.data.queryParams,
  168. concernTypes:this.data.checked
  169. }
  170. wx.showLoading({
  171. title: '加载中',
  172. })
  173. api.queryConcernProduct(params).then(res=>{
  174. if(res.code == 200){
  175. var data = this.data.tableData
  176. wx.hideLoading()
  177. if(type){
  178. var startIndex = (this.data.queryParams.current-1)*this.data.queryParams.size
  179. var endIndex = data.length
  180. var len = endIndex - startIndex
  181. data.splice(startIndex,len,...res.data.data)
  182. }else{
  183. data = data.concat(res.data.data)
  184. }
  185. this.setData(
  186. {
  187. tableData:data,
  188. total:res.data.total,
  189. triggered: false,
  190. load:false
  191. }
  192. )
  193. if(this.data.total<=data.length){
  194. this.setData({
  195. hasMore:false
  196. })
  197. }
  198. api.notify(
  199. {
  200. type:'success',
  201. message:'查询成功',
  202. top:wx.getStorageSync('height')
  203. }
  204. )
  205. }
  206. }).catch(error=>{
  207. wx.hideLoading()
  208. this.setData({
  209. triggered: false,
  210. load:false
  211. })
  212. })
  213. },
  214. //加载更多
  215. loadMore(){
  216. var current = this.data.queryParams.current
  217. this.setData(
  218. {
  219. ['queryParams.current']:current+1,
  220. load :true
  221. }
  222. )
  223. this.getMyFollowProductList()
  224. },
  225. //获取筛选值
  226. onChange(e){
  227. // var data = e.detail
  228. var {name,title} = e.detail
  229. var data = []
  230. if(name != -1){
  231. data = [name]
  232. }
  233. this.setData({
  234. checked: data,
  235. });
  236. this.init()
  237. },
  238. /**
  239. * 生命周期函数--监听页面隐藏
  240. */
  241. onHide() {
  242. },
  243. /**
  244. * 生命周期函数--监听页面卸载
  245. */
  246. onUnload() {
  247. },
  248. /**
  249. * 页面相关事件处理函数--监听用户下拉动作
  250. */
  251. onPullDownRefresh() {
  252. },
  253. /**
  254. * 页面上拉触底事件的处理函数
  255. */
  256. onReachBottom() {
  257. },
  258. /**
  259. * 用户点击右上角分享
  260. */
  261. onShareAppMessage() {
  262. }
  263. })