index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. const getHeight = require("../../utils/getRheRemainingHeight");
  2. const _Http = getApp().globalData.http;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. scrollHeight: 0, //滚动区域高度
  9. searchContent: "", //搜索内容
  10. mainActiveIndex: 0, //分类选择器打开分类的下标
  11. activeId: null, //分类选择器选择id
  12. activeName: null,
  13. items: [], //分类列表
  14. total: 0,
  15. sort: [],
  16. content: {
  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();
  30. this.getList();
  31. },
  32. /* 查询列表 */
  33. getList(init = false) {
  34. if (init.detail != undefined) init = init.detail;
  35. if (init) this.setData({
  36. ['content.pageNumber']: 1
  37. })
  38. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  39. let content = this.data.content;
  40. if (this.data.activeId) content.where.sat_sharematerial_classid = this.data.activeId;
  41. if (this.data.sort[0]) content.sort = this.data.sort;
  42. _Http.basic({
  43. "classname": "saletool.sharematerial.sharematerial",
  44. "method": "selectList",
  45. content
  46. }).then(res => {
  47. console.log("列表", res)
  48. this.selectComponent('#ListBox').RefreshToComplete();
  49. if (res.msg != '成功') return wx.showToast({
  50. title: res.data,
  51. icon: "none"
  52. })
  53. this.setData({
  54. list: (res.pageNumber == 1) ? res.data : this.data.list.concat(res.data),
  55. ['content.pageNumber']: res.pageNumber + 1,
  56. ['content.pageTotal']: res.pageTotal,
  57. total: res.total,
  58. sort: res.sort
  59. })
  60. })
  61. },
  62. /* 清除搜索输入 */
  63. searchClear() {
  64. this.setData({
  65. ['content.where.condition']: ""
  66. })
  67. },
  68. /* 搜索框输入 */
  69. searchInput({
  70. detail
  71. }) {
  72. this.setData({
  73. ['content.where.condition']: detail.trim()
  74. })
  75. this.getList(true)
  76. },
  77. /* 开关切换 */
  78. changeSwitch({
  79. detail
  80. }) {
  81. this.setData({
  82. sort: detail
  83. })
  84. this.getList(true);
  85. },
  86. /* 查询分类 */
  87. selectMenu(index = 0, res) {
  88. if (index == 5) return wx.showToast({
  89. title: res.data,
  90. icon: "none"
  91. });
  92. _Http.basic({
  93. "classname": "saletool.sharematerial.sharematerial",
  94. "method": "select",
  95. "content": {
  96. "parentid": 0
  97. }
  98. }).then(res => {
  99. if (res.msg != '成功') return this.selectMenu(index + 1, res);
  100. let str = JSON.stringify(res.data).replace(/classname/g, 'text').replace(/sat_sharematerial_classid/g, 'id');
  101. this.setData({
  102. items: JSON.parse(str)
  103. });
  104. });
  105. },
  106. /* 切换分类 */
  107. onClickItem({
  108. detail = {}
  109. }) {
  110. this.setData({
  111. activeId: this.data.activeId === detail.id ? null : detail.id,
  112. activeName: this.data.activeName === detail.text ? null : detail.text
  113. });
  114. this.getList(true);
  115. },
  116. onClickNav({
  117. detail = {}
  118. }) {
  119. this.setData({
  120. mainActiveIndex: detail.index || 0,
  121. });
  122. },
  123. /**
  124. * 生命周期函数--监听页面初次渲染完成
  125. */
  126. onReady() {
  127. //滚动区域高度
  128. getHeight.getHeight('.menu', this).then(res => {
  129. this.setData({
  130. scrollHeight: res
  131. })
  132. })
  133. },
  134. /**
  135. * 生命周期函数--监听页面显示
  136. */
  137. onShow() {
  138. },
  139. /**
  140. * 生命周期函数--监听页面隐藏
  141. */
  142. onHide() {
  143. },
  144. /**
  145. * 生命周期函数--监听页面卸载
  146. */
  147. onUnload() {
  148. },
  149. /**
  150. * 页面相关事件处理函数--监听用户下拉动作
  151. */
  152. onPullDownRefresh() {
  153. },
  154. /**
  155. * 页面上拉触底事件的处理函数
  156. */
  157. onReachBottom() {
  158. },
  159. /**
  160. * 用户点击右上角分享
  161. */
  162. onShareAppMessage() {
  163. },
  164. /**
  165. * 用户分享到朋友圈
  166. */
  167. onShareTimeline() {
  168. }
  169. })