index.js 5.3 KB

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