index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. const _Http = getApp().globalData.http;
  2. let dowmCount = null;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. searchContent: "", //搜索内容
  9. mainActiveIndex: 0, //分类选择器打开分类的下标
  10. activeId: "", //分类选择器选择id
  11. showText: null, //左上显示文本
  12. items: [], //分类列表
  13. list: [], //列表
  14. sort: [],
  15. content: {
  16. nocache: true,
  17. pageNumber: 1,
  18. pageSize: 20,
  19. pageTotal: 1,
  20. where: {
  21. condition: ""
  22. }
  23. }
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad(options) {
  29. this.selectMenu(0);
  30. this.selectList();
  31. },
  32. /* 查询菜单分类 */
  33. selectMenu(index) {
  34. if (index == '5') return wx.showToast({
  35. title: '加载失败,请稍后再试',
  36. icon: "none"
  37. })
  38. _Http.basic({
  39. "classname": "saletool.courseware.courseware",
  40. "method": "selectMenu",
  41. "content": {}
  42. }).then(res => {
  43. if (res.msg != '成功') return this.selectMenu(index + 1)
  44. let str = JSON.stringify(res.data).replace(/classname/g, 'text').replace(/sat_courseware_classid/g, 'id');
  45. this.setData({
  46. items: JSON.parse(str)
  47. })
  48. })
  49. },
  50. toDetail(e) {
  51. const {
  52. item
  53. } = e.currentTarget.dataset;
  54. wx.navigateTo({
  55. url: `./detail?id=${item.sat_coursewareid}`,
  56. })
  57. },
  58. /* 获取列表 */
  59. selectList(init = false) {
  60. if (init.detail != undefined) init = init.detail;
  61. if (init) this.setData({
  62. ['content.pageNumber']: 1
  63. })
  64. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  65. let content = this.data.content;
  66. (this.data.activeId == "") ? delete(content.where.sat_courseware_classid): content.where.sat_courseware_classid = this.data.activeId;
  67. if (this.data.sort[0]) content.sort = this.data.sort;
  68. _Http.basic({
  69. "classname": "saletool.courseware.courseware",
  70. "method": "selectList",
  71. content
  72. }).then(res => {
  73. console.log('商学院', res)
  74. this.selectComponent('#ListBox').RefreshToComplete();
  75. if (res.msg != '成功') return wx.showToast({
  76. title: res.msg,
  77. icon: "none"
  78. })
  79. this.setData({
  80. list: (res.pageNumber == 1) ? res.data : this.data.list.concat(res.data),
  81. ['content.pageNumber']: res.pageNumber + 1,
  82. ['content.pageTotal']: res.pageTotal,
  83. total: res.total,
  84. sort: res.sort
  85. })
  86. })
  87. },
  88. /* 开始搜索 */
  89. startSearch({
  90. detail
  91. }) {
  92. clearTimeout(dowmCount);
  93. this.setData({
  94. "content.where.condition": detail.trim()
  95. })
  96. dowmCount = setTimeout(() => {
  97. this.selectList(true);
  98. }, 1000);
  99. },
  100. /* 关闭搜索 */
  101. closeSearch() {
  102. this.setData({
  103. "content.where.condition": ""
  104. })
  105. this.selectList(true);
  106. },
  107. switchChange({
  108. detail
  109. }) {
  110. this.setData({
  111. sort: detail
  112. })
  113. this.selectList(true);
  114. },
  115. onClickNav({
  116. detail = {}
  117. }) {
  118. this.setData({
  119. mainActiveIndex: detail.index || 0,
  120. });
  121. },
  122. onClickItem({
  123. detail = {}
  124. }) {
  125. const activeId = this.data.activeId === detail.id ? "" : detail.id,
  126. showText = this.data.showText === detail.text ? null : detail.text;
  127. this.setData({
  128. activeId,
  129. showText
  130. });
  131. this.selectComponent('#item').toggle();
  132. this.selectList(true);
  133. },
  134. /*生命周期函数--监听页面初次渲染完成*/
  135. onReady() {
  136. //滚动区域高度
  137. this.selectComponent("#ListBox").setHeight(".menu", this);
  138. },
  139. onShareAppMessage(res) {}
  140. })