index.js 5.4 KB

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