index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. const getHeight = require("../../utils/getRheRemainingHeight");
  2. const _Http = getApp().globalData.http;
  3. let dowmCount = null;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. optionList: [],
  10. scrollHeight: 0, //滚动区域高度
  11. searchContent: "", //搜索内容
  12. mainActiveIndex: 0, //分类选择器打开分类的下标
  13. activeId: "", //分类选择器选择id
  14. showText: null, //左上显示文本
  15. items: [], //分类列表
  16. list: [], //列表
  17. sort: [],
  18. content: {
  19. nocache: true,
  20. pageNumber: 1,
  21. pageSize: 20,
  22. pageTotal: 1,
  23. where: {
  24. condition: ""
  25. }
  26. }
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad(options) {
  32. if (options.auth) {
  33. let auth = JSON.parse(options.auth)[0].meta.auth;
  34. this.setData({
  35. optionList: auth.map(v => v.optionname)
  36. })
  37. }
  38. this.selectMenu(0);
  39. this.selectList();
  40. },
  41. /* 查询菜单分类 */
  42. selectMenu(index) {
  43. if (index == '5') return wx.showToast({
  44. title: '加载失败,请稍后再试',
  45. icon: "none"
  46. })
  47. _Http.basic({
  48. "classname": "saletool.courseware.courseware",
  49. "method": "selectMenu",
  50. "content": {}
  51. }).then(res => {
  52. if (res.msg != '成功') return this.selectMenu(index + 1)
  53. let str = JSON.stringify(res.data).replace(/classname/g, 'text').replace(/sat_courseware_classid/g, 'id');
  54. this.setData({
  55. items: JSON.parse(str)
  56. })
  57. })
  58. },
  59. toDetail(e) {
  60. const {
  61. item
  62. } = e.currentTarget.dataset;
  63. wx.navigateTo({
  64. url: `./detail?id=${item.sat_coursewareid}&auth=${this.data.optionList}`,
  65. })
  66. },
  67. /* 获取列表 */
  68. selectList(init = false) {
  69. if (init.detail != undefined) init = init.detail;
  70. if (init) this.setData({
  71. ['content.pageNumber']: 1
  72. })
  73. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  74. let content = this.data.content;
  75. (this.data.activeId == "") ? delete(content.where.sat_courseware_classid): content.where.sat_courseware_classid = this.data.activeId;
  76. if (this.data.sort[0]) content.sort = this.data.sort;
  77. _Http.basic({
  78. "classname": "saletool.courseware.courseware",
  79. "method": "selectList",
  80. content
  81. }).then(res => {
  82. this.selectComponent('#ListBox').RefreshToComplete();
  83. if (res.msg != '成功') return wx.showToast({
  84. title: res.msg,
  85. icon: "none"
  86. })
  87. this.setData({
  88. list: (res.pageNumber == 1) ? res.data : this.data.list.concat(res.data),
  89. ['content.pageNumber']: res.pageNumber + 1,
  90. ['content.pageTotal']: res.pageTotal,
  91. total: res.total,
  92. sort: res.sort
  93. })
  94. })
  95. },
  96. /* 开始搜索 */
  97. startSearch({
  98. detail
  99. }) {
  100. clearTimeout(dowmCount);
  101. this.setData({
  102. "content.where.condition": detail.trim()
  103. })
  104. dowmCount = setTimeout(() => {
  105. this.selectList(true);
  106. }, 1000);
  107. },
  108. /* 关闭搜索 */
  109. closeSearch() {
  110. this.setData({
  111. "content.where.condition": ""
  112. })
  113. this.selectList(true);
  114. },
  115. switchChange({
  116. detail
  117. }) {
  118. this.setData({
  119. sort: detail
  120. })
  121. this.selectList(true);
  122. },
  123. onClickNav({
  124. detail = {}
  125. }) {
  126. this.setData({
  127. mainActiveIndex: detail.index || 0,
  128. });
  129. },
  130. onClickItem({
  131. detail = {}
  132. }) {
  133. const activeId = this.data.activeId === detail.id ? "" : detail.id,
  134. showText = this.data.showText === detail.text ? null : detail.text;
  135. this.setData({
  136. activeId,
  137. showText
  138. });
  139. this.selectComponent('#item').toggle();
  140. this.selectList(true);
  141. },
  142. /**
  143. * 生命周期函数--监听页面初次渲染完成
  144. */
  145. onReady() {
  146. //滚动区域高度
  147. getHeight.getHeight('.menu', this).then(res => {
  148. this.setData({
  149. scrollHeight: res
  150. })
  151. })
  152. },
  153. /**
  154. * 生命周期函数--监听页面显示
  155. */
  156. onShow() {
  157. },
  158. /**
  159. * 生命周期函数--监听页面隐藏
  160. */
  161. onHide() {
  162. },
  163. /**
  164. * 生命周期函数--监听页面卸载
  165. */
  166. onUnload() {
  167. },
  168. /**
  169. * 页面相关事件处理函数--监听用户下拉动作
  170. */
  171. onPullDownRefresh() {
  172. },
  173. /**
  174. * 页面上拉触底事件的处理函数
  175. */
  176. onReachBottom() {
  177. },
  178. /**
  179. * 用户点击右上角分享
  180. */
  181. onShareAppMessage() {
  182. }
  183. })