myFollow.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. }else{
  67. this.init()
  68. }
  69. this.setData(
  70. {
  71. active:options.type
  72. }
  73. )
  74. }else{
  75. this.init()
  76. }
  77. },
  78. /**
  79. * 生命周期函数--监听页面初次渲染完成
  80. */
  81. onReady() {
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow() {
  87. },
  88. /**
  89. * 页面功能
  90. */
  91. //关注和监控
  92. closePopup(e){
  93. this.setData(
  94. {
  95. showPopup:false
  96. }
  97. )
  98. wx.nextTick(() => {
  99. this.setData({ changeFollow: false }) // 在当前同步流程结束后,下一个时间片执行
  100. })
  101. },
  102. openPopup(e){
  103. console.log(e)
  104. this.setData(
  105. {
  106. showPopup:true
  107. }
  108. )
  109. if(e.detail && e.detail.changeFollow){
  110. this.setData(
  111. {
  112. changeFollow:true
  113. }
  114. )
  115. }
  116. },
  117. attention(e){
  118. const childComponent = this.selectComponent('#myProduct');
  119. // var {type} = e.detail
  120. if (childComponent) {
  121. childComponent.attention(e); // 调用子组件的方法
  122. }
  123. },
  124. cancelFollow2(e){
  125. const childComponent = this.selectComponent('#myProduct');
  126. // var {type} = e.detail
  127. if (childComponent) {
  128. childComponent.cancelFollow(e); // 调用子组件的方法
  129. }
  130. },
  131. //初始化加载
  132. init(){
  133. var params = {
  134. current:1,
  135. size:10
  136. }
  137. this.setData(
  138. {
  139. queryParams:params,
  140. total:0,
  141. tableData:[],
  142. hasMore:true
  143. }
  144. )
  145. this.getMyFollowProductList()
  146. },
  147. //下拉刷新
  148. onRefresh() {
  149. console.log('onRefresh')
  150. this.setData({
  151. triggered: true,
  152. })
  153. this.init()
  154. },
  155. //取消关注
  156. cancelFollow(e){
  157. var index = e.detail
  158. var data = this.data.tableData
  159. data.splice(index,1)
  160. this.setData(
  161. {
  162. tableData:data
  163. }
  164. )
  165. this.getMyFollowProductList(1)
  166. },
  167. //获取关注的产品
  168. getMyFollowProductList(type){
  169. var params = {
  170. ...this.data.queryParams,
  171. concernTypes:this.data.checked
  172. }
  173. wx.showLoading({
  174. title: '加载中',
  175. })
  176. api.queryConcernProduct(params).then(res=>{
  177. if(res.code == 200){
  178. var data = this.data.tableData
  179. wx.hideLoading()
  180. if(type){
  181. var startIndex = (this.data.queryParams.current-1)*this.data.queryParams.size
  182. var endIndex = data.length
  183. var len = endIndex - startIndex
  184. data.splice(startIndex,len,...res.data.data)
  185. }else{
  186. data = data.concat(res.data.data)
  187. }
  188. this.setData(
  189. {
  190. tableData:data,
  191. total:res.data.total,
  192. triggered: false,
  193. load:false
  194. }
  195. )
  196. if(this.data.total<=data.length){
  197. this.setData({
  198. hasMore:false
  199. })
  200. }
  201. api.notify(
  202. {
  203. type:'success',
  204. message:'查询成功',
  205. top:wx.getStorageSync('height')
  206. }
  207. )
  208. }
  209. }).catch(error=>{
  210. wx.hideLoading()
  211. this.setData({
  212. triggered: false,
  213. load:false
  214. })
  215. })
  216. },
  217. //加载更多
  218. loadMore(){
  219. var current = this.data.queryParams.current
  220. this.setData(
  221. {
  222. ['queryParams.current']:current+1,
  223. load :true
  224. }
  225. )
  226. this.getMyFollowProductList()
  227. },
  228. //获取筛选值
  229. onChange(e){
  230. // var data = e.detail
  231. var {name,title} = e.detail
  232. var data = []
  233. if(name != -1){
  234. data = [name]
  235. }
  236. this.setData({
  237. checked: data,
  238. });
  239. this.init()
  240. },
  241. /**
  242. * 生命周期函数--监听页面隐藏
  243. */
  244. onHide() {
  245. },
  246. /**
  247. * 生命周期函数--监听页面卸载
  248. */
  249. onUnload() {
  250. },
  251. /**
  252. * 页面相关事件处理函数--监听用户下拉动作
  253. */
  254. onPullDownRefresh() {
  255. },
  256. /**
  257. * 页面上拉触底事件的处理函数
  258. */
  259. onReachBottom() {
  260. },
  261. /**
  262. * 用户点击右上角分享
  263. */
  264. onShareAppMessage() {
  265. }
  266. })