123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- // pages/myFollow/myFollow.js
- const api = require('../../api/index')
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- menu:[
- {
- label:'收藏的专利',
- method:'selectCollectPatent'
- }
- ],
- queryParams:{
- current:1,
- size:10
- },
- total:0,
- tableData:[],
- checkList:[
- {
- type:"-1",
- label:'全部',
- icon:'',
- checked:true
- },
- {
- type:"1",
- label:'白名单',
- icon:'myIconanquanbangzhu',
- checked:false
- },
- {
- type:"2",
- label:'灰名单',
- icon:'myIconicon-test',
- checked:false
- },
- {
- type:"0",
- label:'黑名单',
- icon:'myIcongroup43',
- checked:false
- },
- ],
- checked:[],
- active:null,
- triggered:false,
- load:false,
- hasMore:true,
- showPopup:false,
- changeFollow:false,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- if(options.type == 0 || options.type){
- if(options.type != -1){
- this.setData(
- {
- checked:[options.type]
- }
- )
- }else{
- this.init()
- }
- this.setData(
- {
- active:options.type
- }
- )
- }else{
- this.init()
- }
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
-
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 页面功能
- */
- //关注和监控
- closePopup(e){
- this.setData(
- {
- showPopup:false
- }
- )
- wx.nextTick(() => {
- this.setData({ changeFollow: false }) // 在当前同步流程结束后,下一个时间片执行
- })
- },
- openPopup(e){
- console.log(e)
- this.setData(
- {
- showPopup:true
- }
- )
- if(e.detail && e.detail.changeFollow){
- this.setData(
- {
- changeFollow:true
- }
- )
- }
- },
- attention(e){
- const childComponent = this.selectComponent('#myProduct');
- // var {type} = e.detail
- if (childComponent) {
- childComponent.attention(e); // 调用子组件的方法
- }
- },
- cancelFollow2(e){
- const childComponent = this.selectComponent('#myProduct');
- // var {type} = e.detail
- if (childComponent) {
- childComponent.cancelFollow(e); // 调用子组件的方法
- }
- },
- //初始化加载
- init(){
- var params = {
- current:1,
- size:10
- }
- this.setData(
- {
- queryParams:params,
- total:0,
- tableData:[],
- hasMore:true
- }
- )
- this.getMyFollowProductList()
- },
- //下拉刷新
- onRefresh() {
- console.log('onRefresh')
- this.setData({
- triggered: true,
- })
- this.init()
- },
- //取消关注
- cancelFollow(e){
- var index = e.detail
- var data = this.data.tableData
- data.splice(index,1)
- this.setData(
- {
- tableData:data
- }
- )
- this.getMyFollowProductList(1)
- },
- //获取关注的产品
- getMyFollowProductList(type){
- var params = {
- ...this.data.queryParams,
- concernTypes:this.data.checked
- }
- wx.showLoading({
- title: '加载中',
- })
- api.queryConcernProduct(params).then(res=>{
- if(res.code == 200){
- var data = this.data.tableData
- wx.hideLoading()
- if(type){
- var startIndex = (this.data.queryParams.current-1)*this.data.queryParams.size
- var endIndex = data.length
- var len = endIndex - startIndex
- data.splice(startIndex,len,...res.data.data)
- }else{
- data = data.concat(res.data.data)
- }
-
-
- this.setData(
- {
- tableData:data,
- total:res.data.total,
- triggered: false,
- load:false
- }
- )
- if(this.data.total<=data.length){
- this.setData({
- hasMore:false
- })
- }
- api.notify(
- {
- type:'success',
- message:'查询成功',
- top:wx.getStorageSync('height')
- }
- )
- }
- }).catch(error=>{
- wx.hideLoading()
- this.setData({
- triggered: false,
- load:false
- })
- })
- },
- //加载更多
- loadMore(){
- var current = this.data.queryParams.current
- this.setData(
- {
- ['queryParams.current']:current+1,
- load :true
- }
- )
- this.getMyFollowProductList()
- },
- //获取筛选值
- onChange(e){
- // var data = e.detail
- var {name,title} = e.detail
- var data = []
- if(name != -1){
- data = [name]
- }
-
- this.setData({
- checked: data,
- });
- this.init()
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|