index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. sheetShow: false,
  30. actions: [{
  31. name: '上传图片',
  32. },
  33. {
  34. name: '上传视频',
  35. },
  36. {
  37. name: '上传图文',
  38. },
  39. ],
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad(options) {
  45. if (options.auth) {
  46. let auth = JSON.parse(options.auth)[0].meta.auth;
  47. this.setData({
  48. isInsert: auth.some(v => v.optionname == '新增')
  49. })
  50. }
  51. this.selectMenu();
  52. this.getList();
  53. },
  54. tabChange({
  55. detail
  56. }) {
  57. this.setData({
  58. tabsActiveIndex: detail.index
  59. });
  60. this.getList(true);
  61. },
  62. /* 查询列表 */
  63. getList(init = false) {
  64. if (init.detail != undefined) init = init.detail;
  65. if (init) this.setData({
  66. ['content.pageNumber']: 1
  67. })
  68. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  69. let content = this.data.content;
  70. (this.data.activeId != null) ? content.where.sat_sharematerial_classid = this.data.activeId: delete(content.where.sat_sharematerial_classid);
  71. if (this.data.sort[0]) content.sort = this.data.sort;
  72. _Http.basic({
  73. "classname": "saletool.sharematerial.sharematerial",
  74. "method": this.data.tabsActiveIndex == 0 ? "selectList" : "selectMyList",
  75. content
  76. }).then(res => {
  77. console.log("列表", res)
  78. this.selectComponent('#ListBox').RefreshToComplete();
  79. if (res.msg != '成功') return wx.showToast({
  80. title: res.data,
  81. icon: "none"
  82. });
  83. for (let i = 0; i < res.data.length; i++) {
  84. let list = MFT.fileList(res.data[i].attinfos);
  85. if (!list.length) continue;
  86. let obj = list.find(value => value.fileType == "image");
  87. if (!obj) continue;
  88. res.data[i].cover = MFT.getSpecifiedImage(obj);
  89. res.data[i].attinfos = list;
  90. }
  91. this.setData({
  92. list: (res.pageNumber == 1) ? res.data : this.data.list.concat(res.data),
  93. ['content.pageNumber']: res.pageNumber + 1,
  94. ['content.pageTotal']: res.pageTotal,
  95. total: res.total,
  96. sort: res.sort
  97. })
  98. })
  99. },
  100. /* 清除搜索输入 */
  101. searchClear() {
  102. this.setData({
  103. ['content.where.condition']: ""
  104. })
  105. },
  106. /* 搜索框输入 */
  107. searchInput({
  108. detail
  109. }) {
  110. clearTimeout(dowmCount);
  111. this.setData({
  112. ['content.where.condition']: detail.trim()
  113. })
  114. dowmCount = setTimeout(() => {
  115. this.getList(true)
  116. }, 1000);
  117. },
  118. /* 开关切换 */
  119. changeSwitch({
  120. detail
  121. }) {
  122. this.setData({
  123. sort: detail
  124. })
  125. this.getList(true);
  126. },
  127. /* 查询分类 */
  128. selectMenu(index = 0, res) {
  129. if (index == 5) return wx.showToast({
  130. title: res.data,
  131. icon: "none"
  132. });
  133. _Http.basic({
  134. "classname": "saletool.sharematerial.sharematerial",
  135. "method": "select",
  136. "content": {
  137. "parentid": 0
  138. }
  139. }).then(res => {
  140. if (res.msg != '成功') return this.selectMenu(index + 1, res);
  141. let str = JSON.stringify(res.data).replace(/classname/g, 'text').replace(/sat_sharematerial_classid/g, 'id');
  142. this.setData({
  143. items: JSON.parse(str)
  144. });
  145. });
  146. },
  147. /* 切换分类 */
  148. onClickItem({
  149. detail = {}
  150. }) {
  151. this.setData({
  152. activeId: this.data.activeId === detail.id ? null : detail.id,
  153. activeName: this.data.activeName === detail.text ? null : detail.text
  154. });
  155. this.selectComponent('#item').toggle(false);
  156. this.getList(true);
  157. },
  158. onClickNav({
  159. detail = {}
  160. }) {
  161. this.setData({
  162. mainActiveIndex: detail.index || 0,
  163. });
  164. },
  165. /**
  166. * 生命周期函数--监听页面初次渲染完成
  167. */
  168. onReady() {
  169. //滚动区域高度
  170. getHeight.getHeight('.menu', this).then(res => {
  171. this.setData({
  172. scrollHeight: res
  173. })
  174. })
  175. },
  176. addData() {
  177. this.setData({
  178. sheetShow: true
  179. });
  180. },
  181. sheetClose() {
  182. this.setData({
  183. sheetShow: false
  184. });
  185. },
  186. sheetSelect({
  187. detail
  188. }) {
  189. let type = '';
  190. switch (detail.name) {
  191. case "上传图片":
  192. type = 'image'
  193. break;
  194. case "上传视频":
  195. type = 'video'
  196. break;
  197. case "上传图文":
  198. type = 'richtext'
  199. break;
  200. }
  201. /* items是分类 */
  202. wx.navigateTo({
  203. url: `./upload?item=${JSON.stringify(this.data.items)}&type=${type}`
  204. })
  205. },
  206. })