闫增涛
2024-09-19 d7e794685c439cb820259813b5e826a0ea218914
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
// pages/bookExhibitionList/index.js
import Toast from "tdesign-miniprogram/toast/index";
import watch from "./watch/watch";
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    name: "测试watch",
    newPrice: "",
    loading: true,
    hidden: true,
    totalSize: "",
    start: 0,
    isMore: null,
    keynoteDisabled: true,
    value: "",
    keyword: "",
    nameSort: null,
    total: null,
    page: {
      start: 0,
      size: 16,
    },
    keynoteValue: [],
    filteredItems: [],
    newValue: null,
    bookExhibitionList: [],
    sorter: {
      value: "default",
    },
    product: {
      value: "*",
      options: [{
          value: "*",
          label: "总分类",
        },
        {
          value: "jsek_bFHigherEducation",
          label: "高等教育",
        },
        {
          value: "jsek_bFVocationalEducation",
          label: "职业教育",
        },
        {
          value: "jsek_bFTeacherEducation",
          label: "教师教育",
        },
      ],
    },
    multipleSelect: {
      value: [],
      options: [],
    },
    navBarHeight: "",
    barHeight: "",
    windowHeight: "",
    sorter: {
      value: "timeAsc",
      options: [{
          value: "nameAsc",
          label: "名称正序",
        },
        {
          value: "nameDesc",
          label: "名称倒序",
        },
        {
          value: "timeAsc",
          label: "出版时间正序",
        },
        {
          value: "timeDesc",
          label: "出版时间倒序",
        },
      ],
    },
    newValue: "",
    disbaleProject: true,
    disabledSort: false
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // this.setData({
    //   'product.value': '*',
    // });
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight =
      (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
    this.setData({
      navBarHeight: navBarHeight,
      barHeight: systInfo.statusBarHeight,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.bookExhibitionGet();
    this.keyProjectsGet(this.data.newPrice);
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},
  onScrollToLower() {
    if (this.data.bookExhibitionList.length < this.data.totalSize) {
      this.setData({
        isMore: true,
        start: this.data.start + 1,
      });
      this.bookExhibitionGet();
    } else {
      this.setData({
        isMore: true,
      });
      setTimeout(() => {
        this.setData({
          isMore: false,
        });
      }, 300);
    }
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.page.size >= this.data.total) {
      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() {},
  onShareTimeline() {},
 
  // 图片数据的接口
  bookExhibitionGet(newValue) {
    this.setData({
      disabledSort: false
    })
    let searchObj = {
      "Name*": this.data.keyword,
      "||subtitle*": this.data.keyword,
    };
 
    let sort = {};
    const sortOptions = {
      "*": {
        CreateDate: "Asc",
      },
      nameAsc: {
        Name: "Asc",
      },
      nameDesc: {
        Name: "Desc",
      },
      timeAsc: {
        CreateDate: "Asc",
      },
      timeDesc: {
        CreateDate: "Desc",
      },
    };
    sort = sortOptions[this.data.product.value] || {};
    app.MG.store
      .getProductList({
        storeInfo: "jsek_bookFair",
        path: this.data.newValue,
        queryType: "*",
        fields: {
          jsek_link: [],
          subtitle: [],
          "bookClassification*": this.data.keynoteValue || [],
          ...searchObj,
        },
        paging: {
          start: "0",
          size: this.data.start * 10,
        },
        sort: sort,
        // coverSize: {
        //   width: 100
        // },
      })
      .then((res) => {
        res.datas.forEach((item) => {
          if (item.subtitle == undefined) {
            item.subtitle = "";
          }
          item.subtitleName = item.subtitle + item.name;
        });
        this.data.total = res.total;
        if (res.datas.length == 0) {
          this.setData({
            disabledSort: true
          })
          if (!this.data.keynoteValue.length) {
            this.setData({
              disbaleProject: true
            });
          }
        }
        const list = [...res.datas];
        this.setData({
          bookExhibitionList: list,
          totalSize: res.total,
        });
        this.setData({
          loading: false,
          hidden: false,
        });
      });
  },
  //重点项目接口
  keyProjectsGet(newPrice) {
    this.setData({
      filteredItems: [], // 如果存在子项则赋值,否则赋值为空数组
    });
    //骨架屏
    this.setData({
      loading: true,
      hidden: true,
    });
    // 参数
    let parms = {
      refCodes: ["bookClassification"],
    };
    //请求数据
    app.MG.store.getProductTypeField(parms).then((res) => {
      // 格式化数据
      const checkData = JSON.parse(res[0].config);
      // 循环然后判断相匹配的数据赋值给filteredItems
      checkData.option.forEach((item) => {
        if (newPrice == item.value) {
          this.setData({
            filteredItems: item.child || [], // 如果存在子项则赋值,否则赋值为空数组
          });
        }
      });
      let singleSelectOptions = [];
      // 单列选择器选项
      // 单列选择器选项
      this.data.filteredItems.forEach((item) => {
        singleSelectOptions.push({
          label: item.name,
          value: item.value,
        });
      });
      if (singleSelectOptions.length === 0) {
        singleSelectOptions.push({
          label: "暂无数据",
        });
        this.setData({
          disbaleProject: true
        })
      }
      // 更新数据
      this.setData({
        "multipleSelect.options": singleSelectOptions,
      });
      // 取消骨架屏
      this.setData({
        loading: false,
        hidden: false,
      });
    });
    // if (newPrice) {
    //   this.setData({
    //     keynoteDisabled: false
    //   })
    // }
    // if (!newPrice) {
    //   this.setData({
    //     keynoteDisabled: true
    //   })
    // }
  },
 
  // 总分类
  // 总分类
  onChange(e) {
    const newValue = e.detail.value;
    this.setData({
      "product.value": newValue,
      newValue: newValue,
      disbaleProject: false,
      loading: true
    });
    let newPrice = "";
    if (newValue == "jsek_bFHigherEducation") {
      newPrice = "jsek_higherEducation";
    } else if (newValue == "jsek_bFVocationalEducation") {
      newPrice = "jsek_vocationalEducation";
    } else if (newValue == "jsek_bFTeacherEducation") {
      newPrice = "jsek_teacherEducation";
    } else {
      // 选择总分类
      this.setData({
        disbaleProject: true
      })
      newPrice = "";
    }
    this.keyProjectsGet(newPrice);
    this.bookExhibitionGet(newValue);
    if (this.data.keynoteValue) {
      //如果有数据就清空并刷新页面
      this.data.keynoteValue = [];
      this.bookExhibitionGet(newValue);
    }
  },
 
  // 重点项目
  handleMultipleSelect(e) {
    this.setData({
      "multipleSelect.value": e.detail.value,
    });
  },
  handleConfirm(event) {
    const {
      value
    } = event.detail;
    // 确认操作的处理逻辑
    // this.data.keynoteValue = value
    this.setData({
      keynoteValue: value,
      loading: true
    });
    this.bookExhibitionGet();
  },
 
  handleReset(e) {
    // 重置操作的处理逻辑
    this.data.keynoteValue = [];
    this.bookExhibitionGet();
  },
  onSwapRight() {
    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";
    this.bookExhibitionGet();
  },
  onBookExhibitionDetails: function (event) {
    const item = event.currentTarget.dataset.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,
    });
 
    this.bookExhibitionGet();
  },
  goBack() {
    wx.navigateBack();
  },
  onSort(e) {
    this.setData({
      "product.value": e.detail.value,
    });
 
    this.bookExhibitionGet();
  },
  onOpend() {},
});