index.js 4.6 KB

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