index.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. nocache: true,
  22. pageNumber: 1,
  23. pageSize: 20,
  24. pageTotal: 1,
  25. where: {
  26. condition: "",
  27. sat_sharematerial_classid: ""
  28. }
  29. },
  30. sheetShow: false,
  31. actions: [{
  32. name: '上传图片',
  33. },
  34. {
  35. name: '上传视频',
  36. },
  37. {
  38. name: '上传图文',
  39. },
  40. ],
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad(options) {
  46. if (options.auth) {
  47. let auth = JSON.parse(options.auth)[0].meta.auth;
  48. this.setData({
  49. isInsert: auth.some(v => v.optionname == '新增')
  50. })
  51. }
  52. this.selectMenu();
  53. this.getList();
  54. },
  55. tabChange({
  56. detail
  57. }) {
  58. this.setData({
  59. tabsActiveIndex: detail.index
  60. });
  61. this.getList(true);
  62. },
  63. /* 查询列表 */
  64. getList(init = false) {
  65. if (init.detail != undefined) init = init.detail;
  66. if (init) this.setData({
  67. ['content.pageNumber']: 1
  68. })
  69. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  70. let content = this.data.content;
  71. (this.data.activeId != null) ? content.where.sat_sharematerial_classid = this.data.activeId: delete(content.where.sat_sharematerial_classid);
  72. if (this.data.sort[0]) content.sort = this.data.sort;
  73. _Http.basic({
  74. "classname": "saletool.sharematerial.sharematerial",
  75. "method": this.data.tabsActiveIndex == 0 ? "selectList" : "selectMyList",
  76. content
  77. }).then(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. this.getList(true);
  123. },
  124. /* 搜索框输入 */
  125. searchInput({
  126. detail
  127. }) {
  128. if (this.data.content.where.condition == detail.trim()) return;
  129. clearTimeout(dowmCount);
  130. this.setData({
  131. ['content.where.condition']: detail.trim()
  132. })
  133. dowmCount = setTimeout(() => {
  134. this.getList(true)
  135. }, 1000);
  136. },
  137. /* 开关切换 */
  138. changeSwitch({
  139. detail
  140. }) {
  141. this.setData({
  142. sort: detail
  143. })
  144. this.getList(true);
  145. },
  146. /* 查询分类 */
  147. selectMenu(index = 0, res) {
  148. if (index == 5) return wx.showToast({
  149. title: res.msg,
  150. icon: "none"
  151. });
  152. _Http.basic({
  153. "classname": "saletool.sharematerial.sharematerial",
  154. "method": "select",
  155. "content": {
  156. "nocache": true,
  157. "parentid": 0
  158. }
  159. }).then(res => {
  160. if (res.msg != '成功') return this.selectMenu(index + 1, res);
  161. let str = JSON.stringify(res.data).replace(/classname/g, 'text').replace(/sat_sharematerial_classid/g, 'id');
  162. this.setData({
  163. items: JSON.parse(str)
  164. });
  165. });
  166. },
  167. /* 切换分类 */
  168. onClickItem({
  169. detail = {}
  170. }) {
  171. this.setData({
  172. activeId: this.data.activeId === detail.id ? null : detail.id,
  173. activeName: this.data.activeName === detail.text ? null : detail.text
  174. });
  175. this.selectComponent('#item').toggle(false);
  176. this.getList(true);
  177. },
  178. onClickNav({
  179. detail = {}
  180. }) {
  181. this.setData({
  182. mainActiveIndex: detail.index || 0,
  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. })