闫增涛
2024-03-21 3baf9a943cdf11d4cdfb52b3756458529d0dcf2a
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
// pages/bookExhibitionList/index.js
import Toast from 'tdesign-miniprogram/toast/index';
 
const app = getApp()
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    value: '',
    keyword: '',
    nameSort: null,
    total: null,
    page: {
      start: 0,
      size: 16
    },
    keynoteValue: null,
    filteredItems: [],
    newValue: null,
    bookExhibitionList: [],
    sorter: {
      value: 'default',
    },
    product: {
      value: '*',
 
      options: [
        {
          value: '*',
          label: '总分类',
        },
        {
          value: 'jsek_bFHigherEducation',
          //重点项目
          price: 'jsek_higherEducation',
          label: '高等教育',
        },
        {
          value: 'jsek_bFVocationalEducation',
          //重点项目
          price: 'jsek_vocationalEducation',
          label: '职业教育',
        },
        {
          value: 'jsek_bFTeacherEducation',
          //重点项目
          price: 'jsek_teacherEducation',
          label: '教师教育',
        },
 
      ],
 
    },
    multipleSelect: {
      value: [],
      options: [],
    },
    navBarHeight: '',
    barHeight: '',
    windowHeight: '',
  },
 
 
 
  /**
    * 生命周期函数--监听页面加载
    */
  onLoad(options) {
    // 获取屏幕高度
    wx.getSystemInfo({
      success: function (res) {
        // this.setData({
        //   windowHeight: res.windowHeight
        // })
 
        // 获取节点的类名
        var query = wx.createSelectorQuery();
        query.select('.assembleContent').boundingClientRect();
        query.exec(function (res) {
 
          console.log(res, 'res');
          let node = res[0];
          node.setStyle({
            backgroundColor: '#0256b9',
          })
          // // 修改节点样式
          // if (node) {
          //   node.setStyle({
          //     backgroundColor: 'red',
          //     color: 'white'
          //   });
          // }
        });
      }
    });
 
    // console.log(this.data.filteredItems, 88888);
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
    this.setData({
      navBarHeight: navBarHeight,
      barHeight: systInfo.statusBarHeight,
    })
 
    // 单列选择器选项
    const singleSelectOptions = this.data.filteredItems.map(item => ({
      label: item.name,
      value: item.value,
      disabled: false,
    }))
 
    if (this.data.filteredItems = []) {
      console.log(11111);
      singleSelectOptions.push({
        label: '禁用选项',
        value: 'disabled',
        disabled: true,
      });
    }
 
    // singleSelectOptions.push({
    //   label: '禁用选项',
    //   value: 'disabled',
    //   disabled: true,
    // });
 
 
    // 更新数据
    this.setData({
      'multipleSelect.options': singleSelectOptions,
    });
 
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.bookExhibitionGet()
 
    this.keyProjectsGet()
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
 
  },
  onPullDownRefresh() {
    this.data.page.size = 16 //更改显示的值
    this.bookExhibitionGet(); // 调用方法加载更多数据
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    // console.log(this.data.page.size);
    // console.log(this.data.total);
    if (this.data.page.size >= this.data.total) {
      console.log('已加载完所有数据');
      Toast({
        context: this,
        selector: '#t-toast',
        message: '没有更多了',
        direction: 'column',
        duration: 1000,
        preventScrollThrough: true,
        icon: 'poweroff',
      });
    } else {
      // const currentPage = this.data.page.start + 1; // 获取当前页数并加1
      const newSize = this.data.page.size + 10; // 原来的基础上加10
      this.setData({
        // 'page.start': currentPage,
        'page.size': newSize
      });
      this.bookExhibitionGet(); // 调用方法加载更多数据
 
 
 
    }
  },
 
 
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
 
  },
  // 图片数据的接口
  bookExhibitionGet(newValue) {
    wx.showLoading({
      title: '加载中...',
    })
    let searchObj = {
      'Name*': this.data.keyword,
      '||subtitle*': this.data.keyword
    }
    // console.log(this.data.keynoteValue);
    let sort = {
      Name: this.data.nameSort || 'Desc'
    }
    app.MG.store.getProductList({
      storeInfo: 'jsek_bookFair',
      path: newValue,
      queryType: '*',
      fields: {
        jsek_link: [],
        subtitle: [],
        'bookClassification*': this.data.keynoteValue || [],
        ...searchObj
      },
      paging: this.data.page,
      sort: sort,
      // coverSize: {
      //   width: 100
      // },
    }).then(res => {
      res.datas.forEach((item) => {
        item.subtitleName = item.subtitle + item.name
      })
      console.log(res, 'item');
      this.data.total = res.total
 
      //  list.push(res.datas)
      const list = [...res.datas]
 
      this.setData({
        bookExhibitionList: list
      })
 
      //取消
      wx.hideLoading()
      // console.log(this.data.bookExhibitionList, '数据');
    })
 
  },
  //重点项目接口
  keyProjectsGet(newPrice) {
    // console.log(newPrice, 'newPrice');
    let parms = {
      refCodes: ['bookClassification']
    }
    app.MG.store.getProductTypeField(parms).then(res => {
 
      const checkData = JSON.parse(res[0].config)
 
 
      checkData.option.forEach(item => {
        if (newPrice == item.value) {
 
          this.setData({
            filteredItems: item.child || [] // 如果存在子项则赋值,否则赋值为空数组
          });
 
          // console.log(this.data.filteredItems);
 
        }
      })
 
      this.onLoad();
    })
  },
 
 
 
 
  // 总分类
  // 总分类
  onChange(e) {
 
    this.data.page.size = 16 //更改显示的值
    const newValue = e.detail.value;
    const selectedOption = this.data.product.options.find(option => option.value === newValue);
    const newPrice = selectedOption ? selectedOption.price : null;
    this.setData({
      'product.value': newValue,
      'product.price': newPrice, // 将选中的 price 值保存在数据中
    });
    this.bookExhibitionGet(newValue);
    this.keyProjectsGet(newPrice);
    // 调用更新页面数据的函数,传入新的 value 和 price 值
 
    if (this.data.keynoteValue) {
      //如果有数据就清空并刷新页面
      this.data.keynoteValue = []
 
      this.bookExhibitionGet(newValue)
      this.onLoad()
      console.log('true');
    } else {
      // this.bookExhibitionGet(newValue);
      // this.keyProjectsGet(newPrice);
      console.log('fals');
    }
 
  },
 
  // 重点项目
  handleMultipleSelect(e) {
    this.setData({
      'multipleSelect.value': e.detail.value,
    });
  },
  handleConfirm(event) {
    const { value } = event.detail;
    // 确认操作的处理逻辑
 
    console.log('确认操作,选中的值为:', value);
    this.data.keynoteValue = value
    this.bookExhibitionGet()
  },
  handleReset() {
    // 重置操作的处理逻辑
    this.data.keynoteValue = []
    console.log('重置操作');
    this.bookExhibitionGet()
  },
  onSwapRight() {
    // console.log('xxxxxx');
    // this.data.nameSort = 'Asc'
 
 
    if (!this.data.nameSort) {
      this.setData({
        nameSort: 'Desc',
      });
    } else if (this.data.nameSort == 'Desc') {
      this.setData({
        nameSort: 'Asc',
      });
    } else if (this.data.nameSort == 'Asc') {
      this.setData({
        nameSort: '',
      });
    }
 
    this.bookExhibitionGet()
 
  },
  onSwapLeft() {
    this.data.nameSort = 'Desc'
    // console.log('sssssss');
    this.bookExhibitionGet()
 
 
  },
  onBookExhibitionDetails: function (event) {
    const item = event.currentTarget.dataset.item;
    console.log(item);
    wx.navigateTo({
      url: '/pages/bookExhibitionDetails/index?id=' + item.id + '&bookName=' + item.name + '&subtitleName=' + item.subtitleName // 假设跳转到详情页面,并传递了id参数
    });
  },
  // 搜索框
  onSearchSubmit(e) {
    this.setData({
      keyword: e.detail.value
    })
    console.log(this.data.keyword, 'keyword');
    this.bookExhibitionGet()
  },
  goBack() {
    wx.navigateBack();
  },
})