index.js 4.9 KB

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