index.js 5.7 KB

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