ll
liukangdong
2024-08-06 d41f1f707dc643b726a42b9d2a63b186dd9e4f28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import { getZhongTaiProductNewsPage, getCatalogList,actionDo } from '../../api/index'
let touchDot = 0
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    category: [],
    secondCategory: [],
    showCate: true,
    animationData: {},
 
    catalogCode: '',
    tagCode: '',
    query: '',
    dataList: [],
    total: 0,
    pageNum: 1,
    pageSize: 10,
 
    // height: 0,
    // top: 0,
  },
  onLoad(options) {
    this.getCate()
    this.animation = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease',
    });
  },
  onReachBottom() {
    console.log('触底事件');
    const { total, dataList, pageNum } = this.data
    if(total > dataList.length){
      this.setData({ pageNum: pageNum + 1 })
      this.getList()
    }else{
      wx.showToast({
        title: '暂无更多数据',
        icon: 'none'
      })
    }
  },
  getCate() {
    getCatalogList({catalogCode: 'product_info'}).then(res => {
      this.setData({ category: res.data })
      if(res.data && res.data.length > 0){
        this.setData({catalogCode: res.data[0].code})
        this.gettag()
        this.getList()
      }
    })
  },
  gettag() {
    const { catalogCode } = this.data
    getCatalogList({
      catalogCode
    }).then(res => {
      if(res.data && res.data.length > 0){
        this.setData({ secondCategory: res.data })
      }
    })
  },
  itemClick(e) {
    const item = e.currentTarget.dataset.item
    const { dataList } = this.data
    dataList.forEach(ite => {
      if(item.id === ite.id){
        ite.viewCount += 1
      }
    })
    this.setData({ dataList })
    actionDo({actionType: 'view',id: item.id})
    if(item.contentType == 'link'){
      wx.navigateTo({
        url: '/pages/webView/index',
        success: function(res) {
          // 通过eventChannel向被打开页面传送数据
          res.eventChannel.emit('acceptDataFromOpenerPage', { link: item.content, title: item.title })
        }
      })
    }else{
      wx.navigateTo({
        url: '/pages/consult/detail?id='+item.id,
      })
    }    
  },
  searchList() {
    this.setData({ dataList: [], total: 0, pageNum: 1 })
    this.getList()
  },
  getList() {
    const { pageNum, pageSize, catalogCode, tagCode, query } = this.data
    getZhongTaiProductNewsPage({
      pageNum, pageSize, query, catalogCode: tagCode || catalogCode
    }).then(res => {
      if(res.data){
        this.setData({ 
          dataList: [ ...this.data.dataList, ...res.data.records ],
          total: res.data.total
        })
      }
      
    })
  },
  cateClick(e) {
    const { code } = e.currentTarget.dataset
    this.setData({ catalogCode: code,secondCategory: [], tagCode: ''  })
    this.gettag()
    this.getList()
    this.setData({ dataList: [], pageNum: 1 })
  },
  seCateClick(e) {
    const { code } = e.currentTarget.dataset
    if(this.data.tagCode == code){
      this.setData({ tagCode: '' })
    }else{
      this.setData({ tagCode: code })
    }
    this.setData({ dataList: [], pageNum: 1 })
    this.getList()
  },
  priviewFull(e){
      const item = e.currentTarget.dataset.item
      console.log('item', item);
      
    },
  onReady() {
 
  },
  bindscrolltoupper() {
    this.setData({ showCate: true })
    this.fadeIn();
  },
  touchstart(e){
    touchDot = e.detail.scrollTop;
  },
  touchmove(e) {
    var touchMove = e.detail.scrollTop;
    if(touchDot - touchMove > 16){
      touchDot = touchMove
      this.fadeOut();
    }
    if(touchDot - touchMove > 16){
      touchDot = touchMove
      setTimeout(() => {
        this.setData({ showCate: true })
        this.fadeIn();
      }, 200)
    }
  },
  fadeIn: function () {
    this.animation.opacity(1).step();
    this.setData({
      animationData: this.animation.export()
    });
 
  },
  fadeOut: function () {
    this.animation.opacity(0).step();
    this.setData({
      animationData: this.animation.export()
    });
    setTimeout(() => {
      this.setData({ showCate: false });
    }, 200); // 动画持续时间
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
 
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    let { info } = this.data
    console.log('点击了分享')
    if(info.users && info.users.userId){
      return {
        path: '/pages/detailDis/product?id=' + info.id + '&userId=' + info.users.id
      }
    }
  }
})