bug
litian
2024-07-12 1951e6ccf8dff46e6f8c671308f6e4db694fc800
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
import {
  loginInfo
} from '../../../assets/js/login';
const app = getApp();
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    barHeight: '',
    navBarHeight: '',
    searchValue: '',
    userInfo: null,
    path: '*',
    pathList: [],
    bookList: [],
    //高级分类
    iconList: {
      value: "",
      options: [],
    },
    //一级分类
    stairList: {
      value: '',
      options: [{
        value: "",
        label: "一级分类",
      }],
    },
    //二级分类
    secondList: {
      value: [],
      options: [],
    },
    //高级分类选中
    assortCheck: {
      name: '',
      code: '',
    },
    stairCode: '', // 一级分类选中项
    secondCode: '', // 二级分类选中项
    sort: '', // 排序
    sortList: {
      value: "default",
      options: [{
          value: "default",
          label: "默认排序",
        },
        {
          value: "name-asc",
          label: "名称正序",
        },
        {
          value: "name-desc",
          label: "名称倒叙",
        },
        {
          value: "time-asc",
          label: "出版时间正序",
        },
        {
          value: "time-desc",
          label: "出版时间倒叙",
        },
      ],
    },
    //分页
    page: 1,
    limit: 10,
    pageTotalCount: 0,
    bottomLoading: false,
    isMoreData: false,
    // 返回顶部
    isBackTop: false,
    setScrollValue: 0,
    skeletonLoding: true,
    alreadyPaperBookList: [], //已申请纸质样书
    alreadyElectronicBookList: [], //已申请电子样书
    paperBookList: [], //样书单纸质书
    electronicBookList: [], //样书单电子书
    paperBookCount: 0, //纸质书剩余次数
    ebookCount: 0, //电子书剩余次数
    num: 0,
    x: 280,
    y: 300,
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this;
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
    that.setData({
      barHeight: systInfo.statusBarHeight,
      navBarHeight: navBarHeight,
    });
    // 搜索赋值
    if (options && options.searchValue) {
      that.setData({
        searchValue: options.searchValue,
      });
    }
    // 高级分类赋值
    if (options && options.assortCode) {
      that.setData({
        assortCheck: {
          name: options.assorName,
          code: options.assortCode,
          'iconList.value': options.assortCode
        },
      });
    }
    if (that.data.assortCheck.code) {
      // 获取一级分类
      ththatis.getStairList(that.data.assortCheck.code);
    }
    // 一级分类和path赋值
    if (options && options.assortCode && options.stairCode) {
      that.setData({
        'stairList.value': options.stairCode,
        stairCode: options.stairCode,
        path: `${options.assortCode}\\${options.stairCode}`,
      });
    }
    // 二级分类赋值
    if (options && options.secondCode) {
      that.setData({
        secondCode: options.secondCode,
        pathList: [{
          Path: options.secondCode,
          Type: '*',
          StoreRefCode: app.config.goodsStore,
        }],
      })
    }
    that.getIconTypeList();
 
    // 检查登录状态
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        if (data) {
          that.setData({
            userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey))
          })
          that.getAlreadyPBookList()
          that.getAlreadyEBookList()
          // 获取申请次数
          that.getSelectPaperBookCount()
          that.getSelectBookCount()
        }
      })
    } else {
      that.setData({
        userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey))
      })
      const paperBookList = wx.getStorageSync('paperBookList') ? JSON.parse(wx.getStorageSync('paperBookList')).length : 0
      const electronicBookList = wx.getStorageSync('electronicBookList') ? JSON.parse(wx.getStorageSync('electronicBookList')).length : 0
      this.setData({
        num: paperBookList + electronicBookList
      })
    }
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let that = this;
    that.setData({
      page: 1,
      paperBookList: [],
      electronicBookList: []
    })
    that.getAlreadyPBookList()
    that.getAlreadyEBookList()
    // 获取申请次数
    that.getSelectPaperBookCount()
    that.getSelectBookCount()
    if (wx.getStorageSync("paperBookList") || wx.getStorageSync("electronicBookList")) {
      if (wx.getStorageSync("paperBookList")) {
        that.setData({
          paperBookList: JSON.parse(wx.getStorageSync("paperBookList")),
        })
      }
      if (wx.getStorageSync("electronicBookList")) {
        that.setData({
          electronicBookList: JSON.parse(wx.getStorageSync("electronicBookList")),
        })
      }
      that.setData({
        num: Number(that.data.paperBookList.length) + Number(that.data.electronicBookList.length)
      })
    }
    that.getBookList(false);
  },
  goBack() {
    wx.navigateBack();
  },
 
  // 获取纸质书剩余次数
  getSelectPaperBookCount() {
    app.MG.app
      .getTicketResult({
        ticketRefCodeOrGuid: 'paperSampleBookapplyNum',
        roleId: this.data.userInfo.roleId
      })
      .then((res) => {
        this.setData({
          paperBookCount: res.totalCount - res.usedCount
        })
      })
  },
  // 获取电子书剩余次数
  getSelectBookCount() {
    app.MG.app
      .getTicketResult({
        ticketRefCodeOrGuid: 'electronicSampleBookapplyNum',
        roleId: this.data.userInfo.roleId
      })
      .then((res) => {
        this.setData({
          ebookCount: res.totalCount - res.usedCount
        })
      })
  },
  //获取高级分类
  getIconTypeList() {
    let query = {
      path: '*',
      filterList: [{
        value: 'Normal',
        field: 'state'
      }],
      queryType: '\\',
      searchList: [],
      size: '5',
      start: '0',
      storeRefCode: app.config.goodsStore,
      sort: {
        type: 'Asc',
        field: 'LinkOrder'
      }
    }
    app.MG.store.getStoreChannelList(query).then((res) => {
      let list = [{
        value: "",
        label: "总分类",
      }];
      if (res.datas.length > 0)(
        res.datas.forEach((item) => {
          item.value = item.refCode;
          item.label = item.name;
          if (item.refCode == 'jsek_higherEducation') {
            list.push(item)
          }
          if (item.refCode == 'jsek_vocationalEducation') {
            list.push(item)
          }
 
        })
      )
      this.setData({
        'iconList.options': list,
        'iconList.value': this.data.assortCheck.code,
      });
    })
  },
  // 获取一级列表
  getStairList(path) {
    const query = {
      path,
      filterList: [],
      queryType: '\\',
      searchList: [],
      size: '30',
      start: '0',
      storeRefCode: app.config.goodsStore,
      sort: {
        type: 'Asc',
        field: 'LinkOrder'
      },
    };
    app.MG.store.getStoreChannelList(query).then(async (res) => {
      let options = [{
        value: "",
        label: "一级分类",
      }];
      if (res.datas.length > 0) {
        for (let index = 0; index < res.datas.length; index++) {
          let item = res.datas[index];
          options.push({
            value: item.refCode,
            label: item.name,
          });
        }
      }
      this.setData({
        'stairList.options': options,
        'stairList.value': this.data.stairCode,
      });
    });
  },
  // 获取一级分类下二级分类
  getSecondList(path) {
    let options = [];
    let query = {
      path,
      filterList: [],
      queryType: '\\',
      searchList: [],
      size: '30',
      start: '0',
      storeRefCode: app.config.goodsStore,
      sort: {
        type: 'Asc',
        field: 'LinkOrder'
      },
    };
    app.MG.store.getStoreChannelList(query).then((res) => {
      if (res.datas.length > 0) {
        for (let index = 0; index < res.datas.length; index++) {
          const item = res.datas[index];
          options.push({
            value: `${item.pathLinks[0].linkPath}\\${item.id}`,
            label: item.name,
          });
        }
      }
      this.setData({
        'secondList.options': options,
      });
      const second = [this.data.secondCode]
      this.setData({
        'secondList.value': second
      })
    });
  },
 
  // 获取图书列表
  getBookList(isReachBottom) {
    let that = this;
    let sort;
    let pathObj = {};
    if (that.data.pathList.length) {
      pathObj = {
        subAccess: this.data.pathList,
      };
    } else {
      pathObj = {
        path: that.data.path,
        queryType: '*',
      };
    }
    if (this.data.sortList.value == "name-asc") {
      sort = {
        Name: "Asc",
        BaseType: "",
      };
    } else if (this.data.sortList.value == "name-desc") {
      sort = {
        Name: "Desc",
        BaseType: "",
      };
    } else if (this.data.sortList.value == "time-asc") {
      sort = {
        PublicationDate: "Asc",
        BaseType: "DateTime",
      };
    } else if (this.data.sortList.value == "time-desc") {
      sort = {
        PublicationDate: "Desc",
        BaseType: "DateTime",
      };
    } else if (this.data.sortList.value == "default") {
      sort = {
        field: "order",
        type: "Desc",
      };
    }
    // if (that.data.sort) {
    //   sort = {
    //     Name: that.data.sort,
    //     BaseType: '',
    //   };
    // } else {
    //   sort = {
    //     type: 'Desc',
    //     field: 'ViewCount',
    //   };
    // }
    // 搜索
    let searchObj = {};
    if (that.data.searchValue) {
      searchObj = {
        'Name*': that.data.searchValue,
        '||author*': that.data.searchValue,
        '||isbn*': that.data.searchValue,
        '||seriesName*': that.data.searchValue,
      };
    }
    const query = {
      ...pathObj,
      filterList: [{
        value: 'Normal',
        field: 'state',
      }, ],
      sort,
      paging: {
        start: that.data.page * that.data.limit - that.data.limit,
        size: that.data.limit
      },
      fields: {
        author: [],
        isbn: [],
        publicationDate: [],
        pdf: [],
        protectedEpub: [],
        isApplyBook: [],
        'isApplyBook>': ['1'],
        ...searchObj,
      },
    };
    app.MG.store.getProductList(query).then((res) => {
      try {
        if (res.datas.length > 0) {
          res.datas.forEach((item) => {
            item.paperDisabled = false
            item.paperChecked = false
            item.electronDisabled = false
            item.electronChecked = false
            if (item.purchasedSaleMethodIdList.indexOf(item.defaultSaleMethodId) > -1) {
              item.electronDisabled = true
              item.electronChecked = true
            }
            if (that.data.alreadyPaperBookList.length > 0) {
              that.data.alreadyPaperBookList.forEach((pBook) => {
                if (pBook.content.length > 0) {
                  pBook.content.forEach((pBookItem) => {
                    if (pBookItem.id === item.id && pBook.state == 'WaitAudit') {
                      item.paperDisabled = true
                      item.paperChecked = true
                    }
                    if (pBookItem.id === item.id && pBook.state == 'Normal') {
                      item.paperDisabled = false
                    }
                  })
                }
              })
            }
 
            if (that.data.alreadyElectronicBookList.length > 0) {
              that.data.alreadyElectronicBookList.forEach((eBook) => {
                if (eBook.content.length > 0) {
                  eBook.content.forEach((eBookItem) => {
                    if (eBookItem.id === item.id && !eBook.isExpiry && eBook.state != 'Reject') {
                      item.electronDisabled = true
                      item.electronChecked = true
                    }
                  })
                }
              })
            }
            if (that.data.paperBookList.length > 0) {
              for (let i = 0; i < that.data.paperBookList.length; i++) {
                if (that.data.paperBookList[i].id == item.id) {
                  item.paperChecked = true
                }
              }
            }
            if (that.data.electronicBookList.length > 0) {
              for (let i = 0; i < that.data.electronicBookList.length; i++) {
                if (that.data.electronicBookList[i].id == item.id) {
                  item.electronChecked = true
                }
              }
            }
          });
          let list = res.datas;
          //触底加载新数据并保留老数据
          if (isReachBottom) {
            list = [...this.data.bookList, ...list] //将新数据加入老数据中
          }
          that.setData({
            bookList: list,
            pageTotalCount: res.total,
            bottomLoading: false,
            isMoreData: list.length > 0 ? false : true,
            skeletonLoding: false,
          })
        } else {
          that.setData({
            skeletonLoding: false,
          })
        }
      } catch (error) {
        console.log(error)
      }
    });
  },
  //高级分类选择
  onChangeIcon(e) {
    this.setData({
      skeletonLoding: true,
      bookList: [],
      'assortCheck.code': e.detail.value,
      stairCode: '',
      secondCode: '',
      path: `${e.detail.value}`,
      'iconList.value': e.detail.value,
 
    });
    this.getBookList(false);
    this.getStairList(this.data.assortCheck.code);
 
  },
  // 一级分类切换
  onChangeStair(e) {
    const path = e.detail.value.length ?
      `${this.data.assortCheck.code}\\${e.detail.value}` :
      this.data.assortCheck.code;
    this.setData({
      skeletonLoding: true,
      bookList: [],
      pathList: [],
      stairCode: e.detail.value,
      secondCode: '',
      path: path,
      'stairList.value': e.detail.value,
      'secondList.value': ""
    });
    this.getBookList(false);
    this.getSecondList(path);
  },
  // 二级分类切换 
  onConfirmSecond(e) {
    const pathList = [];
    for (let index = 0; index < e.detail.value.length; index++) {
      const element = e.detail.value[index];
      pathList.push({
        Path: element,
        Type: '*',
        StoreRefCode: app.config.goodsStore,
      });
    }
    this.setData({
      skeletonLoding: true,
      pathList: pathList,
      'secondList.value': e.detail.value,
    });
    this.getBookList(false);
  },
  onResetSecond() {
    this.setData({
      skeletonLoding: true,
      pathList: [],
      'secondList.value': [],
    });
    this.getBookList(false);
  },
 
  // 排序切换
  onSortChange(e) {
    this.setData({
      backTop: "#assort-title",
      "sortList.value": e.detail.value,
    });
 
    let path;
    if (this.data.secondCode) {
      path = this.data.secondCode;
    } else if (this.data.stairCode) {
      path = `${this.data.assortCheck.code}\\${this.data.stairCode}`;
    } else {
      path = this.data.assortCheck.code;
    }
    this.setData({
      path: path,
    });
    this.getBookList(path);
  },
  // 搜索图书
  searchBook(e) {
    this.setData({
      searchValue: e.detail.value,
    });
    this.getBookList(false);
  },
  // 跳转图书详情
  goDetail(e) {
    const {
      book
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/packageBookService/pages/bookServices/detail/index?id=${book.id}&name=${book.name}`,
    });
  },
  //获取已申请纸质样书
  getAlreadyPBookList() {
    const data = {
      start: 0,
      size: 9999,
      topicIdOrRefCode: 'applyEntityBook',
      appRefCode: app.config.appRefCode,
      sort: {
        type: 'Desc',
        field: 'CreateDate'
      }
    }
    app.MG.ugc.getTopicMessageList(data).then((res) => {
      let list = [];
      res.datas.map((item) => {
        if (item.content) {
          item.content = JSON.parse(item.content)
        }
        list.push(item)
      })
      this.setData({
        alreadyPaperBookList: list,
      });
    })
  },
  //获取已申请电子样书
  getAlreadyEBookList() {
    const data = {
      start: 0,
      size: 9999,
      topicIdOrRefCode: 'applyBook',
      appRefCode: app.config.appRefCode,
      sort: {
        type: 'Desc',
        field: 'CreateDate'
      }
    }
    app.MG.ugc.getTopicMessageList(data).then((res) => {
      let list = []
      if (res.datas.length > 0) {
        res.datas.map((item) => {
          if (item.feedBack) {
            item.feedBack = JSON.parse(item.feedBack)
            if (item.feedBack.endDate) {
              let times = new Date(item.feedBack.endDate + ' 23:59:59').getTime()
              let currentDate = new Date().getTime()
              if (times < currentDate) {
                item.isExpiry = true
              }
            }
          }
          if (item.content) {
            item.content = JSON.parse(item.content)
          }
          if (item.state != 'Reject') {
            list.push(item)
          }
        })
        this.setData({
          alreadyElectronicBookList: list,
        });
        if (wx.getStorageSync(app.config.tokenKey)) {
          this.getBookList(false);
        }
      }
    })
  },
 
 
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    if (this._freshing) return
    this.setData({
      page: 1,
      limit: 10,
      pageTotalCount: 0,
      bottomLoading: false,
      isMoreData: false
    })
    this._freshing = true;
    this.setData({
      triggered: false,
    })
    this.getBookList(false);
    this._freshing = false
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.setData({
      bottomLoading: true,
      isMoreData: false
    })
    let bool = false;
    if (this.data.pageTotalCount > this.data.bookList.length) {
      bool = true;
      this.setData({
        page: this.data.page + 1,
      })
 
    } else {
      setTimeout(() => {
        this.setData({
          bottomLoading: false,
          isMoreData: true
        })
      }, 100)
      return false;
    }
    this.getBookList(bool);
  },
  //纸质样书
  onChangePaper(e) {
    const item = e.currentTarget.dataset.book;
    const index = this.data.bookList.findIndex(citem => citem.id == item.id)
    let role = this.data.userInfo != null ? this.data.userInfo.role : null
    if (role && role == 'Teacher') {
      // 是教师
      if (e.detail.checked) {
        // 点击选中
        if (this.data.paperBookCount == 0) {
          wx.showToast({
            title: "您的纸质样书申请次数已用尽,若要继续,请联系管理员!",
            icon: "none",
            duration: 1000,
          })
          return false;
        }
        if (this.data.paperBookList.length >= 2) {
          wx.showToast({
            title: "每次最多只可申请2本样书",
            icon: "none",
            duration: 1000,
          })
          return false;
        }
        this.addBookFun(item, "pBook")
        this.setData({
          ["bookList[" + index + "].paperChecked"]: e.detail.checked
        })
      } else {
        // 取消选中
        let pList = this.data.paperBookList;
        if (pList.length > 0) {
          pList.forEach((obj, index) => {
            if (obj.id == item.id) {
              pList.splice(index, 1);
            }
          })
        }
        this.setData({
          paperBookList: pList,
          num: this.data.num - 1,
          ["bookList[" + index + "].paperChecked"]: e.detail.checked
        })
        wx.setStorageSync("paperBookList", JSON.stringify(pList));
        wx.showToast({
          title: "已从样书申请单移除",
          icon: 'none',
          duration: 1000,
        })
      }
    } else {
      wx.showModal({
        title: '尊敬的用户,您好!', //提示的标题
        content: '请先进行教师认证?', //提示的内容
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: "/packageDomain/pages/teacherCertification/index",
            });
          }
        }
      })
    }
  },
 
  //选择电子样书
  async onChangeElectron(e) {
    const item = e.currentTarget.dataset.book;
    const index = this.data.bookList.findIndex(citem => citem.id == item.id)
    let role = this.data.userInfo != null ? this.data.userInfo.role : null
    if (role && role == 'Teacher') {
      // 是教师
      if (e.detail.checked) {
        // 点击选中
        //商品有无电子书 
        const obj = {
          path: '*',
          queryType: 'SubProduct',
          sort: {
            type: 'Desc',
            field: 'CreateDate'
          },
          paging: {
            start: 0,
            size: 1
          },
          mainProductId: item.id,
          fields: {
            bookshelf_pdf: [],
            bookshelf_protectedEpub: [],
          }
        }
        const res = await app.MG.store.getProductList(obj)
        if (res.datas.length > 0) {
          if (!res.datas[0].bookshelf_pdf && !res.datas[0].bookshelf_protectedEpub) {
            wx.showToast({
              title: "暂无电子书文件,请联系管理员!",
              icon: 'none',
              duration: 1000,
            })
            return false;
          }
        } else {
          if (!item.pdf && !item.protectedEpub) {
            wx.showToast({
              title: "暂无电子书文件,请联系管理员!",
              icon: 'none',
              duration: 1000,
            })
            return false;
          }
        }
        if (this.data.ebookCount == 0) {
          wx.showToast({
            title: "您的电子样书申请次数已用尽,若要继续,请联系管理员!",
            icon: "none",
            duration: 1000,
          })
          return false;
        }
        if (this.data.electronicBookList.length >= 2) {
          wx.showToast({
            title: "每次最多只可申请2本样书",
            icon: "none",
            duration: 1000,
          })
          return false;
        }
        this.addBookFun(item, "eBook")
        this.setData({
          ["bookList[" + index + "].electronChecked"]: e.detail.checked
        })
      } else {
        // 取消选中
        let eList = this.data.electronicBookList;
        if (eList.length > 0) {
          eList.forEach((obj, index) => {
            if (obj.id == item.id) {
              eList.splice(index, 1);
            }
          })
        }
        this.setData({
          electronicBookList: eList,
          num: this.data.num - 1,
          ["bookList[" + index + "].electronChecked"]: e.detail.checked
        })
        wx.setStorageSync("electronicBookList", JSON.stringify(eList));
        wx.showToast({
          title: "已从样书申请单移除",
          icon: 'none',
          duration: 1000,
        })
      }
    } else {
      wx.showModal({
        title: '尊敬的用户,您好!', //提示的标题
        content: '请先进行教师认证?', //提示的内容
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: "/packageDomain/pages/teacherCertification/index",
            });
          }
        }
      })
    }
  },
 
  //  添加样书
  addBookFun(item, type) {
    let itemAttr = null
    const eList = this.data.electronicBookList;
    const pList = this.data.paperBookList;
    itemAttr = {
      id: item.id,
      title: item.name || '-',
      icon: item.icon,
      checked: false,
      defaultSaleMethodId: item.defaultSaleMethodId,
      md5: item.datas.Icon,
      author: item.author || '-',
      price: item.price || '-',
      isbn: item.isbn || '-',
      publicationDate: item.publicationDate
    }
    if (type == 'eBook') {
      eList.push(itemAttr)
      this.setData({
        electronicBookList: eList,
      })
      wx.setStorageSync("electronicBookList", JSON.stringify(eList));
    } else {
      pList.push(itemAttr)
      this.setData({
        paperBookList: pList,
      })
      wx.setStorageSync("paperBookList", JSON.stringify(pList));
    }
    this.setData({
      num: this.data.num + 1
    })
    wx.showToast({
      title: "添加成功,在样书申请单等您哦~",
      icon: "none",
      duration: 1000,
    })
  },
  //去样书申请单
  goApply() {
    wx.navigateTo({
      url: "/packageDomain/pages/sampleBookList/applicationForm/index",
    });
  },
 
  // 监听滚动距离
  onPageScroll(e) {
    if (e && e.scrollTop >= 1000) {
      this.setData({
        isBackTop: true
      })
    } else {
      this.setData({
        isBackTop: false
      })
    }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
 
  }
})