index.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. let deleteList = [],
  79. initID = '9999' + wx.getStorageSync('userMsg').userid;
  80. res.data.forEach(v => (initID == v.sat_sharematerial_classid && v.title == '') ? deleteList.push(v.sat_sharematerialid) : '');
  81. if (deleteList.length != 0) return this.handleDelete(deleteList);
  82. this.selectComponent('#ListBox').RefreshToComplete();
  83. if (res.msg != '成功') return wx.showToast({
  84. title: res.msg,
  85. icon: "none"
  86. });
  87. for (let i = 0; i < res.data.length; i++) {
  88. let list = MFT.fileList(res.data[i].attinfos);
  89. if (!list.length) continue;
  90. let obj = list.find(value => value.fileType == "image");
  91. if (!obj) continue;
  92. res.data[i].cover = MFT.getSpecifiedImage(obj);
  93. res.data[i].attinfos = list;
  94. }
  95. this.setData({
  96. list: (res.pageNumber == 1) ? res.data : this.data.list.concat(res.data),
  97. ['content.pageNumber']: res.pageNumber + 1,
  98. ['content.pageTotal']: res.pageTotal,
  99. total: res.total,
  100. sort: res.sort
  101. })
  102. })
  103. },
  104. /* 处理批量删除 */
  105. handleDelete(list) {
  106. _Http.basic({
  107. "classname": "webmanage.saletool.sharematerial.sharematerial",
  108. "method": "delete",
  109. "content": {
  110. "sat_sharematerialid": list
  111. }
  112. }).then(res => {
  113. console.log("处理删除", res);
  114. if (res.msg == '成功') this.getList();
  115. })
  116. },
  117. /* 清除搜索输入 */
  118. searchClear() {
  119. this.setData({
  120. ['content.where.condition']: ""
  121. })
  122. },
  123. /* 搜索框输入 */
  124. searchInput({
  125. detail
  126. }) {
  127. clearTimeout(dowmCount);
  128. this.setData({
  129. ['content.where.condition']: detail.trim()
  130. })
  131. dowmCount = setTimeout(() => {
  132. this.getList(true)
  133. }, 1000);
  134. },
  135. /* 开关切换 */
  136. changeSwitch({
  137. detail
  138. }) {
  139. this.setData({
  140. sort: detail
  141. })
  142. this.getList(true);
  143. },
  144. /* 查询分类 */
  145. selectMenu(index = 0, res) {
  146. if (index == 5) return wx.showToast({
  147. title: res.msg,
  148. icon: "none"
  149. });
  150. _Http.basic({
  151. "classname": "saletool.sharematerial.sharematerial",
  152. "method": "select",
  153. "content": {
  154. "parentid": 0
  155. }
  156. }).then(res => {
  157. if (res.msg != '成功') return this.selectMenu(index + 1, res);
  158. let str = JSON.stringify(res.data).replace(/classname/g, 'text').replace(/sat_sharematerial_classid/g, 'id');
  159. this.setData({
  160. items: JSON.parse(str)
  161. });
  162. });
  163. },
  164. /* 切换分类 */
  165. onClickItem({
  166. detail = {}
  167. }) {
  168. this.setData({
  169. activeId: this.data.activeId === detail.id ? null : detail.id,
  170. activeName: this.data.activeName === detail.text ? null : detail.text
  171. });
  172. this.selectComponent('#item').toggle(false);
  173. this.getList(true);
  174. },
  175. onClickNav({
  176. detail = {}
  177. }) {
  178. this.setData({
  179. mainActiveIndex: detail.index || 0,
  180. });
  181. },
  182. /**
  183. * 生命周期函数--监听页面初次渲染完成
  184. */
  185. onReady() {
  186. //滚动区域高度
  187. getHeight.getHeight('.menu', this).then(res => {
  188. this.setData({
  189. scrollHeight: res
  190. })
  191. })
  192. },
  193. addData() {
  194. this.setData({
  195. sheetShow: true
  196. });
  197. },
  198. sheetClose() {
  199. this.setData({
  200. sheetShow: false
  201. });
  202. },
  203. sheetSelect({
  204. detail
  205. }) {
  206. let type = '';
  207. switch (detail.name) {
  208. case "上传图片":
  209. type = 'image'
  210. break;
  211. case "上传视频":
  212. type = 'video'
  213. break;
  214. case "上传图文":
  215. type = 'richtext'
  216. break;
  217. }
  218. /* items是分类 */
  219. wx.navigateTo({
  220. url: `./upload?item=${JSON.stringify(this.data.items)}&type=${type}`
  221. })
  222. },
  223. })