index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. const getHeight = require("../../utils/getRheRemainingHeight"),
  2. _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. let auth = options.auth ? JSON.parse(options.auth) : getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], ['商学院'])[0].apps;
  33. this.setData({
  34. optionList: auth[0].meta.auth.map(v => v.optionname)
  35. })
  36. this.selectMenu(0);
  37. this.selectList();
  38. },
  39. /* 查询菜单分类 */
  40. selectMenu(index) {
  41. if (index == '5') return wx.showToast({
  42. title: '加载失败,请稍后再试',
  43. icon: "none"
  44. })
  45. _Http.basic({
  46. "classname": "saletool.courseware.courseware",
  47. "method": "selectMenu",
  48. "content": {}
  49. }).then(res => {
  50. if (res.msg != '成功') return this.selectMenu(index + 1)
  51. let str = JSON.stringify(res.data).replace(/classname/g, 'text').replace(/sat_courseware_classid/g, 'id');
  52. this.setData({
  53. items: JSON.parse(str)
  54. })
  55. })
  56. },
  57. toDetail(e) {
  58. const {
  59. item
  60. } = e.currentTarget.dataset;
  61. wx.navigateTo({
  62. url: `./detail?id=${item.sat_coursewareid}&auth=${this.data.optionList}`,
  63. })
  64. },
  65. /* 获取列表 */
  66. selectList(init = false) {
  67. if (init.detail != undefined) init = init.detail;
  68. if (init) this.setData({
  69. ['content.pageNumber']: 1
  70. })
  71. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  72. let content = this.data.content;
  73. (this.data.activeId == "") ? delete(content.where.sat_courseware_classid): content.where.sat_courseware_classid = this.data.activeId;
  74. if (this.data.sort[0]) content.sort = this.data.sort;
  75. _Http.basic({
  76. "classname": "saletool.courseware.courseware",
  77. "method": "selectList",
  78. content
  79. }).then(res => {
  80. this.selectComponent('#ListBox').RefreshToComplete();
  81. if (res.msg != '成功') return wx.showToast({
  82. title: res.msg,
  83. icon: "none"
  84. })
  85. this.setData({
  86. list: (res.pageNumber == 1) ? res.data : this.data.list.concat(res.data),
  87. ['content.pageNumber']: res.pageNumber + 1,
  88. ['content.pageTotal']: res.pageTotal,
  89. total: res.total,
  90. sort: res.sort
  91. })
  92. })
  93. },
  94. /* 开始搜索 */
  95. startSearch({
  96. detail
  97. }) {
  98. clearTimeout(dowmCount);
  99. this.setData({
  100. "content.where.condition": detail.trim()
  101. })
  102. dowmCount = setTimeout(() => {
  103. this.selectList(true);
  104. }, 1000);
  105. },
  106. /* 关闭搜索 */
  107. closeSearch() {
  108. this.setData({
  109. "content.where.condition": ""
  110. })
  111. this.selectList(true);
  112. },
  113. switchChange({
  114. detail
  115. }) {
  116. this.setData({
  117. sort: detail
  118. })
  119. this.selectList(true);
  120. },
  121. onClickNav({
  122. detail = {}
  123. }) {
  124. this.setData({
  125. mainActiveIndex: detail.index || 0,
  126. });
  127. },
  128. onClickItem({
  129. detail = {}
  130. }) {
  131. const activeId = this.data.activeId === detail.id ? "" : detail.id,
  132. showText = this.data.showText === detail.text ? null : detail.text;
  133. this.setData({
  134. activeId,
  135. showText
  136. });
  137. this.selectComponent('#item').toggle();
  138. this.selectList(true);
  139. },
  140. /*生命周期函数--监听页面初次渲染完成*/
  141. onReady() {
  142. //滚动区域高度
  143. getHeight.getHeight('.menu', this).then(res => {
  144. this.setData({
  145. scrollHeight: res
  146. })
  147. })
  148. },
  149. })